From patchwork Wed Oct 19 09:01:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17627 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 1C851C0DA4 for ; Wed, 19 Oct 2022 09:01:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D380762E37; Wed, 19 Oct 2022 11:01:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1666170081; bh=UntYsoOmCryGyWKA+wnI7n3tSkGOrY5INPDdjnLUPFs=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Z0PRE/Rh9QASKUlKV+5ugnLWOgCuxp75Jbq57lANLMSX1d7eKEYjmz6OPMKxnvcjT R1WRj1y1P/gjtmOjtFTt9n0wEFzIZn5lXsWHuzOt6vFurzGiLtuDQMNh8etntiZKgx MFbk7mL1h6IT3zByoblCLt0Q+1s7psxW74+ig/WJe31AT/BUlTmgYWHDt5BmeK5aqx OYwWxGqzDbUcDpyC9kxpGF8WFT2JlJis4VrmOOxgEEzrvyaPMbOZmkHZS3I6+pFknn qL07bOiAPTZdn2zDq9zVluYPkUFDISR4PQmyTzBguy/kJLrI7eNMKZa7AMfVKFRCX/ uT1/oxqv2OWxQ== Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 517F162E44 for ; Wed, 19 Oct 2022 11:01:18 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="PIyDYPOj"; dkim-atps=neutral Received: by mail-wr1-x42a.google.com with SMTP id bu30so27997396wrb.8 for ; Wed, 19 Oct 2022 02:01:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yESThd+2Y5C1Vw4cwozsKb3HqyWcTJnJ+yXPhzqbGXI=; b=PIyDYPOjz46EkNMNZ79pkoUe4l2qFhzih9BzSILJaAm1In3lLL2D3cxlEaQNg4cyKT +0YFgGmE0Uo6gcOpUHL5VNFg8E+4ERu8vZyTajIEzUzB7yH7pS/GtWHL31vyPya8D7lG WtN/yUb5Gh9ZGT934VHPTYf/RXG7dmrQvvJPcmOUTUTG8FYa9cz16j5R837Gad3CBpSw QEKOhyMTe4Bi+j7/LyLaqzdA99DE4C+KzaKHSP2DK6MQpFwF5323hBXajlNuOfDbUwSu i1e6bM9tGQVNeIdu7RJejE5jJPG25A3owOiM4eN8JG8vRcd7kzk57rSV4i1THiBuRafB dWHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yESThd+2Y5C1Vw4cwozsKb3HqyWcTJnJ+yXPhzqbGXI=; b=3CXBg4ikzGkrqNQrAFJ8FoJcsyKnZ8Jxcgk2qD+b85VwHm7IXJaR9Bkzh5ytsv1LT7 DRG3WMjfE+2OOXZxenTriaVBNgqqewPCqi5ZywgYKo0mcQ0j0p1dNEIsX1TMjAWx3CQI Tlkdt2rWTSOJMSZCWRgCIIJn/lm/SVfXtNDvGe5Gl0YXMrhDDgAclosKmBrLi08I6GtN pBPpcmc8CYN2UwIppN8dstzQEb/wMhOZi9npRLygvGPsFSKXiO/U7Kd2DRQBXfUxKVcs rIpKN15Ws2Y3dMN9khppxij0oTaBsVV+x4xv5cp+vY5fOpgbKe/gQMKgWhLyRyQVGnjU tXUA== X-Gm-Message-State: ACrzQf2ybTzMCeIRBU9Q79PkZ65j552t0nT4WGwLSVsxX0M3d20aildo l+faahfIVCpJUIoHghq4Ka+pVJEJ7HYEDg== X-Google-Smtp-Source: AMsMyM4UX5lI1VWj6vGrUV1FbXxYxHOlDzcorbz/u0CfIzCEiaQKzus3k5e4KSTi3iuLfgaAPSu5Tg== X-Received: by 2002:adf:9d8a:0:b0:230:5212:d358 with SMTP id p10-20020adf9d8a000000b002305212d358mr4363764wre.405.1666170078114; Wed, 19 Oct 2022 02:01:18 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id r9-20020a05600c458900b003b47b913901sm1017595wmo.1.2022.10.19.02.01.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Oct 2022 02:01:17 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 19 Oct 2022 10:01:02 +0100 Message-Id: <20221019090107.19975-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221019090107.19975-1-naush@raspberrypi.com> References: <20221019090107.19975-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 2/7] delayed_controls: Add user cookie to DelayedControls 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: , X-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Allow the caller to provide a cookie value to DelayedControls::reset and DelayedControls::push. This cookie value is returned from DelayedControls::get for the frame that has the control values applied to it. The cookie value is useful in tracking when a set of controls has been applied to a frame. In a subsequent commit, it will be used by the Raspberry Pi IPA to track the IPA context used when setting the control values. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Tested-by: David Plowman Reviewed-by: Kieran Bingham --- include/libcamera/internal/delayed_controls.h | 8 +++++--- src/libcamera/delayed_controls.cpp | 20 ++++++++++++------- src/libcamera/pipeline/ipu3/ipu3.cpp | 3 ++- .../pipeline/raspberrypi/raspberrypi.cpp | 2 +- src/libcamera/pipeline/rkisp1/rkisp1.cpp | 3 ++- test/delayed_controls.cpp | 8 ++++---- 6 files changed, 27 insertions(+), 17 deletions(-) diff --git a/include/libcamera/internal/delayed_controls.h b/include/libcamera/internal/delayed_controls.h index de8026e3e4f0..c7e79150afb8 100644 --- a/include/libcamera/internal/delayed_controls.h +++ b/include/libcamera/internal/delayed_controls.h @@ -9,6 +9,7 @@ #include #include +#include #include @@ -27,10 +28,10 @@ public: DelayedControls(V4L2Device *device, const std::unordered_map &controlParams); - void reset(); + void reset(unsigned int cookie = 0); - bool push(const ControlList &controls); - ControlList get(uint32_t sequence); + bool push(const ControlList &controls, unsigned int cookie = 0); + std::pair get(uint32_t sequence); void applyControls(uint32_t sequence); @@ -77,6 +78,7 @@ private: uint32_t writeCount_; /* \todo Evaluate if we should index on ControlId * or unsigned int */ std::unordered_map> values_; + RingBuffer cookies_; }; } /* namespace libcamera */ diff --git a/src/libcamera/delayed_controls.cpp b/src/libcamera/delayed_controls.cpp index 777441e8222a..3e7f60f9c421 100644 --- a/src/libcamera/delayed_controls.cpp +++ b/src/libcamera/delayed_controls.cpp @@ -109,14 +109,16 @@ DelayedControls::DelayedControls(V4L2Device *device, /** * \brief Reset state machine + * \param[in] cookie User supplied reset cookie value * * Resets the state machine to a starting position based on control values * retrieved from the device. */ -void DelayedControls::reset() +void DelayedControls::reset(unsigned int cookie) { queueCount_ = 1; writeCount_ = 0; + cookies_[0] = cookie; /* Retrieve control as reported by the device. */ std::vector ids; @@ -140,13 +142,15 @@ void DelayedControls::reset() /** * \brief Push a set of controls on the queue * \param[in] controls List of controls to add to the device queue + * \param[in] cookie User supplied cookie value for \a controls * * Push a set of controls to the control queue. This increases the control queue - * depth by one. + * depth by one. The \a cookie value will be subsequently returned from + * \a get() for the frame with all controls applied. * * \returns true if \a controls are accepted, or false otherwise */ -bool DelayedControls::push(const ControlList &controls) +bool DelayedControls::push(const ControlList &controls, const unsigned int cookie) { /* Copy state from previous frame. */ for (auto &ctrl : values_) { @@ -180,6 +184,7 @@ bool DelayedControls::push(const ControlList &controls) << " at index " << queueCount_; } + cookies_[queueCount_] = cookie; queueCount_++; return true; @@ -198,9 +203,10 @@ bool DelayedControls::push(const ControlList &controls) * push(). The max history from the current sequence number that yields valid * values are thus 16 minus number of controls pushed. * - * \return The controls at \a sequence number + * \return The controls at \a sequence number and associated user supplied + * cookie value. */ -ControlList DelayedControls::get(uint32_t sequence) +std::pair DelayedControls::get(uint32_t sequence) { unsigned int index = std::max(0, sequence - maxDelay_); @@ -217,7 +223,7 @@ ControlList DelayedControls::get(uint32_t sequence) << " at index " << index; } - return out; + return { out, cookies_[index] }; } /** @@ -276,7 +282,7 @@ void DelayedControls::applyControls(uint32_t sequence) while (writeCount_ > queueCount_) { LOG(DelayedControls, Debug) << "Queue is empty, auto queue no-op."; - push({}); + push({}, cookies_[queueCount_ - 1]); } device_->setControls(&out); diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 3b892d9671c5..bf612089fdcb 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -1389,7 +1389,8 @@ void IPU3CameraData::cio2BufferReady(FrameBuffer *buffer) request->metadata().set(controls::SensorTimestamp, buffer->metadata().timestamp); - info->effectiveSensorControls = delayedCtrls_->get(buffer->metadata().sequence); + auto [controls, cookie] = delayedCtrls_->get(buffer->metadata().sequence); + info->effectiveSensorControls = std::move(controls); if (request->findBuffer(&rawStream_)) pipe()->completeBuffer(request, buffer); diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 343f8cb2c7ed..23f2460190f4 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -1867,7 +1867,7 @@ void RPiCameraData::unicamBufferDequeue(FrameBuffer *buffer) * Lookup the sensor controls used for this frame sequence from * DelayedControl and queue them along with the frame buffer. */ - ControlList ctrl = delayedCtrls_->get(buffer->metadata().sequence); + auto [ctrl, cookie] = delayedCtrls_->get(buffer->metadata().sequence); /* * Add the frame timestamp to the ControlList for the IPA to use * as it does not receive the FrameBuffer object. diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 455ee2a0a711..20049d089472 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -1191,8 +1191,9 @@ void PipelineHandlerRkISP1::statReady(FrameBuffer *buffer) if (data->frame_ <= buffer->metadata().sequence) data->frame_ = buffer->metadata().sequence + 1; + auto [controls, cookie] = data->delayedCtrls_->get(buffer->metadata().sequence); data->ipa_->processStatsBuffer(info->frame, info->statBuffer->cookie(), - data->delayedCtrls_->get(buffer->metadata().sequence)); + controls); } REGISTER_PIPELINE_HANDLER(PipelineHandlerRkISP1) diff --git a/test/delayed_controls.cpp b/test/delayed_controls.cpp index a8ce9828d73d..322c545998b2 100644 --- a/test/delayed_controls.cpp +++ b/test/delayed_controls.cpp @@ -96,7 +96,7 @@ protected: delayed->applyControls(i); - ControlList result = delayed->get(i); + auto [result, cookie] = delayed->get(i); int32_t brightness = result.get(V4L2_CID_BRIGHTNESS).get(); if (brightness != value) { cerr << "Failed single control without delay" @@ -138,7 +138,7 @@ protected: delayed->applyControls(i); - ControlList result = delayed->get(i); + auto [result, cookie] = delayed->get(i); int32_t brightness = result.get(V4L2_CID_BRIGHTNESS).get(); if (brightness != expected) { cerr << "Failed single control with delay" @@ -187,7 +187,7 @@ protected: delayed->applyControls(i); - ControlList result = delayed->get(i); + auto [result, cookie] = delayed->get(i); int32_t brightness = result.get(V4L2_CID_BRIGHTNESS).get(); int32_t contrast = result.get(V4L2_CID_CONTRAST).get(); if (brightness != expected || contrast != expected + 1) { @@ -247,7 +247,7 @@ protected: delayed->applyControls(i); - ControlList result = delayed->get(i); + auto [result, cookie] = delayed->get(i); int32_t brightness = result.get(V4L2_CID_BRIGHTNESS).get(); int32_t contrast = result.get(V4L2_CID_CONTRAST).get();