From patchwork Wed Nov 10 07:22:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14511 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 437B8BF415 for ; Wed, 10 Nov 2021 07:22:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id EECBE60371; Wed, 10 Nov 2021 08:22:21 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="MygaKImK"; dkim-atps=neutral Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 747656036C for ; Wed, 10 Nov 2021 08:22:20 +0100 (CET) Received: by mail-pj1-x102a.google.com with SMTP id x7so774659pjn.0 for ; Tue, 09 Nov 2021 23:22:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=r7f2fGj+mUTwvthsJCh3urmoJouWjESIr9jPyXgtAyw=; b=MygaKImKmaHcPWC/42xcrbv1lFt1dMF9cOefhkBQlUWuwRJQNY0Q4d1mWEjpMKr/Pq GEWgevON3lUwexlkNGwqNf7tdtQBl/z5HNLJYSurFB19oSLM28rC8hpXsXly4FfLJN4Z YfUjKO+E9Uo0mn/cSi1q7Z/+zDosTb5t+89LQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=r7f2fGj+mUTwvthsJCh3urmoJouWjESIr9jPyXgtAyw=; b=S6a2QkHEsMB0BqzdFUg2tT7hYNGSdjKB1Vj87mJ0+pbq8hVNgTlAWuLNH35H+PoVON /dsgrH0hFH7Dd82Rs1J0AC1ITQYEynKnlGYSEEe+OUocpHi2kIVxYBr8mayY+aF88qUu oZaCl+ZYQSI8XejdR1PU2Pi40dSvfS8Cs7DtIGl/KLtn3zneG1Ro8QBTy3x+9fta6oCT Lvxn9m7wlAdrj1yfLBZRq8QnfB0yPDWp2Es2kpZ406Z/mQf7Mng5uJAN8t1jd1FG5dZI NTD371d0B8oYEHXvl9rBmSCZoTTDld83qwSTZtSnljIix+ZOWA1z0dSQGk0DHvtLZFeo E4FQ== X-Gm-Message-State: AOAM532FRPhDhQ/OnoBlBGZU/W/dZ9c67g9A/aRhPD+VQX+t89r7E+Hv z/xuPmTXYk1BkmipgsnvGgm+PNxOmTiVJg== X-Google-Smtp-Source: ABdhPJzMMgP5jt3VyflccDSV12XFxvneFeNBB8abU8JEtYZd8Jg5iZHhanYjl1MmDQhhtv9SZQEPqg== X-Received: by 2002:a17:90a:1913:: with SMTP id 19mr14565776pjg.174.1636528938796; Tue, 09 Nov 2021 23:22:18 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:4a73:e1bd:9b3f:4903]) by smtp.gmail.com with ESMTPSA id r1sm5073669pjm.23.2021.11.09.23.22.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Nov 2021 23:22:18 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 10 Nov 2021 16:22:07 +0900 Message-Id: <20211110072207.3273703-4-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc0.344.g81b53c2807-goog In-Reply-To: <20211110072207.3273703-1-hiroh@chromium.org> References: <20211110072207.3273703-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 4/4] libcamera: pipeline: ipu3: Apply the requested test pattern mode X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" This enables ipu3 pipeline handler to apply the test pattern mode per frame. Signed-off-by: Hirokazu Honda Reviewed-by: Jean-Michel Hautbois --- include/libcamera/internal/camera_sensor.h | 1 + src/libcamera/camera_sensor.cpp | 34 ++++++++++++++++++++++ src/libcamera/pipeline/ipu3/ipu3.cpp | 29 ++++++++++++++++-- 3 files changed, 62 insertions(+), 2 deletions(-) diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index 60ce0c45..ed782476 100644 --- a/include/libcamera/internal/camera_sensor.h +++ b/include/libcamera/internal/camera_sensor.h @@ -58,6 +58,7 @@ public: const ControlInfoMap &controls() const; ControlList getControls(const std::vector &ids); int setControls(ControlList *ctrls); + int applyRequestControls(Request *request); V4L2Subdevice *device() { return subdev_.get(); } diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index cfb9bc17..a20f3d95 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -755,6 +755,40 @@ int CameraSensor::setControls(ControlList *ctrls) return subdev_->setControls(ctrls); } +/** + * \brief Apply controls associated with Request + * \param[in] request Request that may contain contorls to be applied + * + * Some controls have to be applied for a capture associated with Request. + * This picks up such controls and set the driver them. + * + * \return 0 on success or an error code otherwise + */ +int32_t CameraSensor::applyRequestControls(Request *request) +{ + /* Assumes applying the test pattern mode affects immediately. */ + if (request->controls().contains(controls::draft::TestPatternMode)) { + const int32_t testPatternMode = request->controls().get( + controls::draft::TestPatternMode); + + LOG(CameraSensor, Debug) << "Apply test pattern mode: " + << testPatternMode; + + int ret = setTestPatternMode( + static_cast(testPatternMode)); + if (ret) { + LOG(CameraSensor, Error) + << "Failed to set test pattern mode: " << ret; + return ret; + } + + request->metadata().set(controls::draft::TestPatternMode, + testPatternMode); + } + + return 0; +} + /** * \fn CameraSensor::device() * \brief Retrieve the camera sensor device diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 63cb7f11..f4137f2d 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -59,6 +59,7 @@ public: void statBufferReady(FrameBuffer *buffer); void queuePendingRequests(); void cancelPendingRequests(); + void frameStart(uint32_t sequence); CIO2Device cio2_; ImgUDevice *imgu_; @@ -77,7 +78,10 @@ public: std::unique_ptr ipa_; + /* Requests before queueing cio2 device. */ std::queue pendingRequests_; + /* Requests queued in cio2 device and before passing imgu device. */ + std::queue processingRequests_; ControlInfoMap ipaControls_; @@ -802,6 +806,7 @@ void PipelineHandlerIPU3::stop(Camera *camera) ret |= data->imgu_->stop(); ret |= data->cio2_.stop(); + if (ret) LOG(IPU3, Warning) << "Failed to stop camera " << camera->id(); @@ -822,6 +827,8 @@ void IPU3CameraData::cancelPendingRequests() pipe()->completeRequest(request); pendingRequests_.pop(); } + + processingRequests_ = {}; } void IPU3CameraData::queuePendingRequests() @@ -852,6 +859,8 @@ void IPU3CameraData::queuePendingRequests() info->rawBuffer = rawBuffer; + processingRequests_.push(request); + ipa::ipu3::IPU3Event ev; ev.op = ipa::ipu3::EventProcessControls; ev.frame = info->id; @@ -1131,8 +1140,8 @@ int PipelineHandlerIPU3::registerCameras() data->delayedCtrls_ = std::make_unique(cio2->sensor()->device(), params); - data->cio2_.frameStart().connect(data->delayedCtrls_.get(), - &DelayedControls::applyControls); + data->cio2_.frameStart().connect(data.get(), + &IPU3CameraData::frameStart); /* Convert the sensor rotation to a transformation */ int32_t rotation = 0; @@ -1423,6 +1432,22 @@ void IPU3CameraData::statBufferReady(FrameBuffer *buffer) ipa_->processEvent(ev); } +void IPU3CameraData::frameStart(uint32_t sequence) +{ + if (!processingRequests_.empty()) { + /* Handle controls which are to be set ready for the next frame to start. */ + Request *request = processingRequests_.front(); + processingRequests_.pop(); + + int ret = cio2_.sensor()->applyRequestControls(request); + if (ret) + LOG(IPU3, Error) << "Failed applying controls: " << ret; + } + + /* Controls that don't affect immediately are applied in delayedCtrls. */ + delayedCtrls_->applyControls(sequence); +} + REGISTER_PIPELINE_HANDLER(PipelineHandlerIPU3) } /* namespace libcamera */