From patchwork Mon Sep 26 09:57:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17398 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 E9A2BBD16B for ; Mon, 26 Sep 2022 09:57:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 730C862255; Mon, 26 Sep 2022 11:57:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1664186271; bh=bR2XcJuN9v/o7WELV1bz1uQ//2GkfmEfO0JjDU9qjxk=; 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=W1K4adyrOf0LiDhLHih5ghv2vmmTlqE8mMFhoG7rawIy+XP2Keb3gRdnrTm3A7GIM IkRLVEGvvub48TRUTPiMaf0zAKGR3T1BvsWMtkKXXJPV6muCacMuv45GaZ4XVo5MXN cMxc/apIcHSG8/n/JLnCAuvQRHI707ZUYnXZ46iqD0eNGC5GsFa2r5eXiwExuz0JgN oTHqZ/6r0kZ1jSBvtK3fvjlG4glL037ZPVEBjH7/S9XV2D+7EjI44MIfa9JbnNdWxU 3+3R9FtYuxFC66WlnxpAjlG8CzMA3o7tehGKVEakMlCkP5LQSGG1I7W7S9OxYVZj3R kGRwE3bn7105A== Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 697AD6224C for ; Mon, 26 Sep 2022 11:57:49 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="DPt/ksiH"; dkim-atps=neutral Received: by mail-wr1-x434.google.com with SMTP id r7so9390058wrm.2 for ; Mon, 26 Sep 2022 02:57:49 -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; bh=ZPzBiNF1VfWzy9TrECDZS8BLt3LUNp1q4BLHZaXn4hI=; b=DPt/ksiH78sHZTwA46IjGmkcEr5OVpN/CIrZFfnL9+aporFn5yq2yTT+f30M9EEBTa +BQkPtzTnk6/JofAibh/oKlWXDHBxorbxqN1NB8OerqkwN32SHvsIewWaG6r7jsWt60b qGqhTG6tXclPpFEF7lk3X81t1Z5UoeWEjOFhOglj3L6ns7m3D3a4rFFR/X7aiRf7hgzl 0Qm/i7B8sn79h5vo75sY54Db21diiwJXNVzP5E6z53TTM+VweeJEyyWkpA+mIn4+Rczg OLFWvt+s0UvLarSPdErMpsXOaq5MUtOqCUBi9nDnztlPWYdv4gBn1aX30+siXij5DMoG UIGw== 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; bh=ZPzBiNF1VfWzy9TrECDZS8BLt3LUNp1q4BLHZaXn4hI=; b=0fhKbDot5S7hMxuQB9VupuFYqKpRN3i+q+amwi/8VYCizqLEwd5FtUtG5q597C9PzN w2KSPTx0CO69i9J2EC3YpDzH/Hw4or0vwoEa9AeNBRMOVf9zm7kk5B225EycJ6h7NALA lUWFKnS5cta4M8OjvEZgaYQPWDH8li0UyoqUEch8aZTskXB6kd0mmD/HoJYE0MlaBtEA 5ujwDhknYOsOnBKiDm4fEYI0RqyulZml7UIDVsKVAlmtk5zo83SwEYNAOUBIqHFby/+Q cVwXzYK+KuKkgB8jx3UOPwQinhUO70kjkLFLhNti/KNVGhkCTDMVPZU5IVK8SB71Dex4 Qp0g== X-Gm-Message-State: ACrzQf2g3UETA65Z9mGEpL9Qwn8pQDcwiWbMMwa4A5YhokKKbdH6B1fl zSzs8RU2jB3mAwjVfIrpJxO6j87C6dcQtZLk X-Google-Smtp-Source: AMsMyM7wFHHAA3CKtnkeQh9FRAO5EDMgArziysnZ15yjNWlv4shy7G5NmBCf3OZTJyBn2VLikvsfsQ== X-Received: by 2002:adf:fe06:0:b0:228:db6f:41ae with SMTP id n6-20020adffe06000000b00228db6f41aemr13626894wrr.577.1664186268893; Mon, 26 Sep 2022 02:57:48 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id p22-20020a05600c419600b003a4efb794d7sm10160671wmh.36.2022.09.26.02.57.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Sep 2022 02:57:47 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 26 Sep 2022 10:57:31 +0100 Message-Id: <20220926095737.30506-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220926095737.30506-1-naush@raspberrypi.com> References: <20220926095737.30506-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 1/7] delayed_controls: Template the ControlRingBuffer class 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" Convert ControlRingBuffer to a templated class to allow arbitrary ring buffer array types to be defined. Rename ControlRingBuffer to RingBuffer to indicate this. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Tested-by: David Plowman Reviewed-by: Laurent Pinchart --- include/libcamera/internal/delayed_controls.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/include/libcamera/internal/delayed_controls.h b/include/libcamera/internal/delayed_controls.h index aef37077103c..de8026e3e4f0 100644 --- a/include/libcamera/internal/delayed_controls.h +++ b/include/libcamera/internal/delayed_controls.h @@ -53,17 +53,18 @@ private: /* \todo Make the listSize configurable at instance creation time. */ static constexpr int listSize = 16; - class ControlRingBuffer : public std::array + template + class RingBuffer : public std::array { public: - Info &operator[](unsigned int index) + T &operator[](unsigned int index) { - return std::array::operator[](index % listSize); + return std::array::operator[](index % listSize); } - const Info &operator[](unsigned int index) const + const T &operator[](unsigned int index) const { - return std::array::operator[](index % listSize); + return std::array::operator[](index % listSize); } }; @@ -75,7 +76,7 @@ private: uint32_t queueCount_; uint32_t writeCount_; /* \todo Evaluate if we should index on ControlId * or unsigned int */ - std::unordered_map values_; + std::unordered_map> values_; }; } /* namespace libcamera */ From patchwork Mon Sep 26 09:57:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17399 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 63A55BD16B for ; Mon, 26 Sep 2022 09:57:53 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 12E8262257; Mon, 26 Sep 2022 11:57:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1664186273; bh=IQ11zrL8V8CcGgD8ZYN8HRBUrVWQ+jswWC4R4SNfUE4=; 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=OYMomx2DeBq9YXRjsxmF7G0a989QwoWbtxDBIwlU7nRaxSiGZGOmrrTeMUQWRO3hA i7YbqZUyWt71cJVTIl8ZyPIFpwFK+HTG/nCZdU+k2EPYCrAVvGvUvdiaxt8JtktvcX 4+9Dt2cut8COat1AZFU8oqz9A4t/1HfhV1MVMTqzXHjtK29URDpdk+Sa9wdTceK1L3 KfIDhjebR4kXvrjw8ICVEN9X+Ga8l7Ro+210CXY32Clet46s/kYzoqQzJJ/YBLWh18 nVyzq40x2iiCCtTy3/cvOSzgTsmtf7rl+79IpTKufoUmDJY1VZHKXHc8zeHih0mQN7 Jf4h3yZJSTYpA== Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4EF4962253 for ; Mon, 26 Sep 2022 11:57:51 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="UhHUhNoT"; dkim-atps=neutral Received: by mail-wr1-x430.google.com with SMTP id y5so9372501wrh.3 for ; Mon, 26 Sep 2022 02:57:51 -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; bh=Cw53K/DDEYku/Ke9JjEC7XgUkQg4Iac6pUiLiZMSKJI=; b=UhHUhNoTf9sru2w0ahF3BFSPLvdU63qyG+jbrGNErDxBoJxPB4uZ1OIt1CmdTmhKh5 GOt0zCFW0SpK0ZRwS5BLe6HZURrIPzB6QqTPcPeo1+wxtIXF0RimvK5vDnn1oyvCfKXx WGaDYShbIuRHdhZJrWiOPleh35vLb0VuOUJs48UNxoTpl6/0p7BEp4r7OPVN5R1AKt+r DdQUvm7IcumeZAuAOqM4OCUEqqzU9xODiIf9Qfu/BFlKy4lQv7tL8b35IxsfmEBque23 Evn1edD9BcebbNiF52oREQS+8FrjsOtQ9caVQqnLqepj39QozNPM7oASiwJN6opdo9+F 2DaA== 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; bh=Cw53K/DDEYku/Ke9JjEC7XgUkQg4Iac6pUiLiZMSKJI=; b=l4HyZxbNa3hYHcngwCjGObd1n3M18LYCIju681dQ914K+Avfio/q+snunlEFUDfY9a BWBqNpIviuRvYO1kgoh/yCztot3m22r3liQGy9H5/UwpLn2OKVd2vrjvxByiw3HAWLNa +DbmpOt0khOYImZaRNRgrPeChUYBBMsx2ISUB3pydxASbyn4+a6/lIUfoukroKGBY5ut PmfB5ymwWEpiCxSgUU1U2G3eCWMMxMdAQULjMnOpUs+/FjdqCG+Ri4isMtvmam7edxcv GLSbPe/nW5lqX5l7AuigW16FSIw20ccuqOj2HSDEi2v1X8hGgmlLo0yTcN061KKwZ5v6 WnVQ== X-Gm-Message-State: ACrzQf0AdR7a/o7z+6nRa4Ctom2rb8t06qRgPsLQyvfraqeysVNmEkVU otOkxrHJGnD6BJOnZ/vZpgc6JqFjagrNJM+F X-Google-Smtp-Source: AMsMyM7e9llJTcZAI1J50oNh+tscb1FNOiQSVOUC9bHCxZOc3tQWB9P5tV2z/wZVUeRago+2fvsSyw== X-Received: by 2002:a5d:5110:0:b0:22b:214:38e4 with SMTP id s16-20020a5d5110000000b0022b021438e4mr12901016wrt.219.1664186270819; Mon, 26 Sep 2022 02:57:50 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id p22-20020a05600c419600b003a4efb794d7sm10160671wmh.36.2022.09.26.02.57.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Sep 2022 02:57:49 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 26 Sep 2022 10:57:32 +0100 Message-Id: <20220926095737.30506-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220926095737.30506-1-naush@raspberrypi.com> References: <20220926095737.30506-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 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 --- 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 93219a6c1134..b0f0b22c5298 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -1385,7 +1385,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 dcd81650c32d..39e69d748693 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -1864,7 +1864,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 25fbf9f1a0a9..97df33ceece4 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -1187,8 +1187,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(); From patchwork Mon Sep 26 09:57:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17400 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 D0D01BD16B for ; Mon, 26 Sep 2022 09:58:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8BF2F62253; Mon, 26 Sep 2022 11:58:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1664186287; bh=uLP2iD4+d5hVVPRB9S50teMWW/Bbnhk3D9hEpEiufrw=; 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=gZoPdW1Uj/N+lWBjZnIuadezR5Ee+mhINOpg0cEHEOZturP3jd2DktL/5VQHADniE vQvgzqbikQjsPlRCP08Hmgi87CEhcWKeSKu/exQn4Z6bvpuwgaqVdyUYSOKrFjlt7d DsBoZ34BJkbNoRI13TvRU0OR0XE7NsTr1h509aHdMFiE8TdPio8xp4WxIlLwi0xoWg HbeHcgzuMRusBJNLaUXPvOZGh6795zFC6kBQpeQsevAJwcnUQf3FXcrgWd+ZxJZUym w3NWCGUI7BA2P56PBo5nQndMA9IkTb8ru0NBproro2clcxkyxGRM2se6yfQjoENyWf V0Kxo6g2d8DEA== Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 839C76224C for ; Mon, 26 Sep 2022 11:58:06 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="Y/1mNWKX"; dkim-atps=neutral Received: by mail-wm1-x32d.google.com with SMTP id t4so4096237wmj.5 for ; Mon, 26 Sep 2022 02:58:06 -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; bh=+T3xcs+sb+8OgweMkuTstG9ZLZCS0dNJ3UIDGexYQRk=; b=Y/1mNWKXlqbDzZ+r3C97EjXz+av7TmfW9xc7mTPLvP3CvKKbptZPIJtkN3t/78TIuo mRIW8mk+eIdHHlx9nk0H14jMYZ3WehA1dKs3bkHz3+eSxcIQapAnf/6Wci0+anmq07d5 hCi69CR/L9ldwMa3duEat/89gUjc3CPLLXcUKNXgoXFKop7Ys+GjqVQSNPUaW0gORJW4 VRutzjr0m+Sh7wUaozXzF/Sw/Y1DpjEbfDr09coqmUKeKGdgIb+Seq5AK34+1U95EwBZ z1kgV5patB3xMW6Xj27PHJFDyu/vvU2m8cI/kFnbX87cZIe7lMt+ij3hfSkEtB+0iW4C PgYQ== 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; bh=+T3xcs+sb+8OgweMkuTstG9ZLZCS0dNJ3UIDGexYQRk=; b=8CW4KgXYOKL2Adk3ZNxoA3gSn2298i8IJr+Q7e6vYPTGDE6hDyibVVAcHikpHLMJp7 45jA6pWDg2lyAHf0hXPjJPMk2nll1GceBqwVsV98vS7FbacCpIbL6I077WJSW/12OT7c fEbHJUtS1MNg6lWxpZeoYaeb0fYaT/Y1yrUPStlf36AwiLToU/8J/DfgVP2/iYFRy3Vg zBd8r2u3aXSvqeRcM1U/Kh/KGz98vTUb7pWWHpQxMbVw7B0tvH4LD2by1+2VkWKVcBJR 5KtXLWEkGYfOMzBmEXtGgYIppr0Tdb88z4cVt/eDKsvH/4qoPqHNyU+FwIaZcz50gCAq abEQ== X-Gm-Message-State: ACrzQf25dObgqO8HACFyq0+47q7xqJwQSJYNsCPyWQKVAvWntpzn76MU DYSsfLw4X8/lex9mTvGV3uTsd49XMtvOXkt1 X-Google-Smtp-Source: AMsMyM6J+xTVibGdxWlfRSHWo70B/LmQpTY2zHVD5m68Wabl14HaQachvd+hHll/dUkWeY7/WR8D1A== X-Received: by 2002:a05:600c:5486:b0:3b4:7e47:e19 with SMTP id iv6-20020a05600c548600b003b47e470e19mr14308168wmb.12.1664186286129; Mon, 26 Sep 2022 02:58:06 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id p22-20020a05600c419600b003a4efb794d7sm10160671wmh.36.2022.09.26.02.57.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Sep 2022 02:57:58 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 26 Sep 2022 10:57:33 +0100 Message-Id: <20220926095737.30506-4-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220926095737.30506-1-naush@raspberrypi.com> References: <20220926095737.30506-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 3/7] tests: delayed_controls: Add cookie value test 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" Add a test for passing and returning cookie values in DelayedControls. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman --- test/delayed_controls.cpp | 44 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/test/delayed_controls.cpp b/test/delayed_controls.cpp index 322c545998b2..5cc7d3aed4fd 100644 --- a/test/delayed_controls.cpp +++ b/test/delayed_controls.cpp @@ -267,6 +267,45 @@ protected: return TestPass; } + int cookieValue() + { + std::unordered_map delays = { + { V4L2_CID_BRIGHTNESS, { 1, false } }, + }; + std::unique_ptr delayed = + std::make_unique(dev_.get(), delays); + ControlList ctrls; + + /* Set a cookie to the reset value. */ + const unsigned int startCookie = 0x1234; + ctrls.set(V4L2_CID_BRIGHTNESS, 1); + dev_->setControls(&ctrls); + delayed->reset(startCookie); + + /* Trigger the first frame start event */ + delayed->applyControls(0); + + for (unsigned int i = 1; i < 100; i++) { + ctrls.set(V4L2_CID_BRIGHTNESS, 1); + delayed->push(ctrls, startCookie + i); + + delayed->applyControls(i); + + auto [result, cookie] = delayed->get(i); + unsigned int expected = startCookie + i - 1; + if (cookie != expected) { + cerr << "Failed cookie value" + << " frame " << i + << " expected cookie " << expected + << " got cookie " << cookie + << endl; + return TestFail; + } + } + + return TestPass; + } + int run() override { int ret; @@ -291,6 +330,11 @@ protected: if (ret) return ret; + /* Test cookie values. */ + ret = cookieValue(); + if (ret) + return ret; + return TestPass; } From patchwork Mon Sep 26 09:57:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17401 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 59FCBBD16B for ; Mon, 26 Sep 2022 09:58:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 129B56225A; Mon, 26 Sep 2022 11:58:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1664186291; bh=naXEqMC/INqUw+OoX1V7tmh3rdoy6RmaWlVoUDk/4qI=; 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=vxwV42e9p+72UKk9eKa2R219MbWoZ4kTHtCJtkRlcfPbJ8r3eXuxMSLSN74XVrQHk HvgIGal8nMcGFekByFIfT0U5BVB1dAc95eoABAAxUyqwXNCnLIdW/EjxiKKFeyp56U 5vniJTkITZWpBfvCbCzRCVS/V4S5GvA7ydjUPJ+OiOT7xwH3l4p9RMtKKarZWdsRpJ 85c8qopXpMjXHKx0gXysfYz8GxzTLf8VSL16wHzVoFkQa4lMpxbLK09JyAvZSr48nj +oL609oIO/dUrmzw+CYmjHrObEP8Wr0oEljvtw2aHVtHA/bA93aCK7XXF9FDUdcPCU B1mgGePLWYzkA== Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6AA036224C for ; Mon, 26 Sep 2022 11:58:09 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="qr4dsU6T"; dkim-atps=neutral Received: by mail-wr1-x42f.google.com with SMTP id cc5so9362273wrb.6 for ; Mon, 26 Sep 2022 02:58:09 -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; bh=bo43RPn2Wf8VvpHKyuSwKItQaXGqKlJBIO1xs6MhjIo=; b=qr4dsU6Tf1ALqHJ2s+IkeN3j2BFyR7DMdzeRHtJCvfa6dZPyr1khrkYHyRWkzQcsKu t54iq3XtFIEkP4vWt2z9cWNvy0UPxKVwOQKjTWtcvpJZbKiVgOiOfjwngKDZvkUdc2Sd 6r5JV/bPpbs6seEJQhNXimaeK37pBtudXU7+U25DYJxP3E1myqm7xmgipZeXYgzl5pW+ q7/lo0uHpD+WVL0hT/XUXs79yqHFC5kWW5aEk3jnamOlOS+Hrh60l7SW/BDmVGrW7Asy BLOz0Jl+6VRIgK+7JK0Apzswn2qtEQd+FmLrVgWILa7DXHLEs1OcDIHShfNELLT5TrNl QMtA== 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; bh=bo43RPn2Wf8VvpHKyuSwKItQaXGqKlJBIO1xs6MhjIo=; b=6BMJyh0jhVYHcqKzsSwLGcMRnnyk37QRGtwZW7ak1IF3ck2Ih+OzLnhGsIT95LyIF2 IuzoudCHojZ+cmLXlCZmf0jvpaq1pNw+vlX2cs2dZJCBeo0tuWPassAiWWN5zNNBRLgR 4v1nVwGT9BJeSaXGtNPikIlmlT6Crgv8Xvub3JXKpf253KmjakwGt7RLTmXnCXr+d8Zk zndAlcbS7Z5DdEic8hQ7DOp1fOcw1RuSiRhUo+5+/Skzzxe6GLXhIC0btChCixqGYX8F e/4c/wyAoi7c/i1KKEcKGXrOZjg6fUcA6hDMDIbouUwx18cb5K97HkL0hYvsJE+57wNu 1haw== X-Gm-Message-State: ACrzQf2wz6qqgAa5QXFEwapBSNchcVQuodPBMz6LrojEMSBnNTqaDNsB Z5qQg8IQYcdYCbjspFQCVzZT6AyaVf9dDBa1 X-Google-Smtp-Source: AMsMyM56F761mKbo/39DO+G5Cf1qVyhm2pva64Yw3/SkrKG+KeLCob3NiLQS0GXFXvbvaAaYHv26fg== X-Received: by 2002:a5d:5258:0:b0:229:9c2c:3120 with SMTP id k24-20020a5d5258000000b002299c2c3120mr13207766wrc.695.1664186288939; Mon, 26 Sep 2022 02:58:08 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id p22-20020a05600c419600b003a4efb794d7sm10160671wmh.36.2022.09.26.02.58.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Sep 2022 02:58:06 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 26 Sep 2022 10:57:34 +0100 Message-Id: <20220926095737.30506-5-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220926095737.30506-1-naush@raspberrypi.com> References: <20220926095737.30506-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 4/7] ipa: raspberrypi: Add RPiController::Metadata::mergeCopy 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" Add a new member function to RPiController::Metadata that copies unique key/value pairs from one object to the other. This is different from std::map::merge that would remove the key/value pairs from the source object. Signed-off-by: Naushir Patuck --- src/ipa/raspberrypi/controller/metadata.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/ipa/raspberrypi/controller/metadata.h b/src/ipa/raspberrypi/controller/metadata.h index 0f7ebfaf4c25..ddce491784e9 100644 --- a/src/ipa/raspberrypi/controller/metadata.h +++ b/src/ipa/raspberrypi/controller/metadata.h @@ -78,6 +78,16 @@ public: data_.merge(other.data_); } + void mergeCopy(const Metadata &other) + { + std::scoped_lock lock(mutex_, other.mutex_); + /* + * If the metadata key exists, ignore this item and copy only + * unique key/value pairs. + */ + data_.insert(other.data_.begin(), other.data_.end()); + } + template T *getLocked(std::string const &tag) { From patchwork Mon Sep 26 09:57:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17402 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 F2535BD16B for ; Mon, 26 Sep 2022 09:58:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A781A6225E; Mon, 26 Sep 2022 11:58:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1664186292; bh=FdO+0iW6DgkgyYw5e18qWIoV4tuve6nHlsQNyOBKS0o=; 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=0Y8vCAlol3tzdGYxqiPDVCdyX2tr5VZjJ2pKk5lQ8DfCcMrTAy+5+DeK5RJrkI8SS Bkad2JkaY7OXn6IQeISHY2vsdxw14EUIcbARJ6b2lmpx6MlOf8ZYsdXBQcF8L5yIHQ NRt8hkwwpOmhrTos1Qe+ilFVnKZWeoS9Ck+GLg08zyOpX2PpHRJdOyuGUbklFqunZi dP3UGA1a/VYjQNEt6Ww6zWiYfL3Z6kAx0pHWu/9DWAEH4QxH9Fn/gmXOCGopn8Y+RP /To2/pYtMBMjCm/x4OqrsrKZ1niKTyd3di+XPE5SCRheTkgGyj5tne3WYB27OkUvNO rfXn2nAoTUJiQ== Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 887476224C for ; Mon, 26 Sep 2022 11:58:11 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="MIDXOyEm"; dkim-atps=neutral Received: by mail-wm1-x334.google.com with SMTP id n35-20020a05600c502300b003b4924c6868so7778695wmr.1 for ; Mon, 26 Sep 2022 02:58:11 -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; bh=J0rP7W+kbeDPc1Be4ITqwvmzGhcrPvfbVLStz8XRHTA=; b=MIDXOyEmRzvpQBI7ffCYsGeTnwA7mf5DhfEttHLPQA6Wr4jXYw+TGACcROptQMcuo/ 0+O6/ThG5BZWn9bd3UvDaAVTE8e14G2PW2zdT4poYTeRGAMBFKtdFf7opv1r7Xpdzrvc hDSaWgUhPGs/Hn3aAuj1Wt5VkkRUTt8CNwf46KWjjR0J4AjFrAMnFp2sF6HtOwZkEoev 3v8cffMoRyEWbC/0AUDFQo9dS3Tl6tSNctI/xtExaRK2eCpMHexb1yXGoGeNSg5GQuHv BDJxS+NUonVf7O8jPxrnirqY7XAUuXlWUqpAOtxJgy3BxvwhdjrLapAtjfrevaiIekSH 6Mag== 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; bh=J0rP7W+kbeDPc1Be4ITqwvmzGhcrPvfbVLStz8XRHTA=; b=cW+dhUrAj2tN7NTrSvJ1u3kYRRVTrMQGJRemXZm4fxfr8Aeer0B8c6XOAJS0gxV3iX AITQddZ2xC/tmcD3Sp2NmoacwI5SRW7L0qtXZ4Vb3RZD3Ih/3PIHNZ16VdWI6ZeEEH1N 81QOMWppnRDQulAUE+e+jIslrXipbCqzRd65xWlOWexrirBNrW6EbVeRV04M3K1zQWF7 WRiLlZ5DSbcm4DcLOnkEjRy20Pw8UWDMt+Sv49nXq2LKfRf+RyLXSR/yQojbW2Zmqk7S wYIEtA2Ee1WLffj7+51Mu176lSOEdAu4G0lwP5xuIlBD7HgqE1bgEi9gNcQ3bGwDzK9L 5AHw== X-Gm-Message-State: ACrzQf3RhBLWflH6+mnpqIwPM/0SgNxz4iTWMxYgCayTxfOfYmQjsTaB 2YdcGxPkGnr97Bwbb4W0fhVE2gF2jrgHy6fk X-Google-Smtp-Source: AMsMyM5awHHv0roMXulIIth7KaspwmyoCNVPwGwkCAjnNS7dMAQLzCJIh57R6LlfNeRx4cZyKSVOmA== X-Received: by 2002:a05:600c:1906:b0:3b4:c979:e686 with SMTP id j6-20020a05600c190600b003b4c979e686mr14742722wmq.107.1664186290836; Mon, 26 Sep 2022 02:58:10 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id p22-20020a05600c419600b003a4efb794d7sm10160671wmh.36.2022.09.26.02.58.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Sep 2022 02:58:09 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 26 Sep 2022 10:57:35 +0100 Message-Id: <20220926095737.30506-6-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220926095737.30506-1-naush@raspberrypi.com> References: <20220926095737.30506-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 5/7] ipa: raspberrypi: Use an array of RPiController::Metadata objects 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" Cycle through an array of RPiController::Metadata objects, one per prepare()/process() invocation, when running the controller algorithms. This allows historical metadata objects to be retained, and subsequently passed into the controller algorithms on future frames. This change provides a route to fixing a problem with the AGC algorithm, where if a manual shutter/gain is requested, the algorithm does not currently retain any context of the total exposure that it has calculated. As a result, the wrong digital gain would be applied when the frame with the manual shutter/gain is processed by the ISP. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Tested-by: David Plowman --- src/ipa/raspberrypi/raspberrypi.cpp | 69 +++++++++++++++++------------ 1 file changed, 40 insertions(+), 29 deletions(-) diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index 8d731435764e..63cccda901c1 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -57,6 +57,9 @@ namespace libcamera { using namespace std::literals::chrono_literals; using utils::Duration; +/* Number of metadata objects available in the context list. */ +constexpr unsigned int numMetadataContexts = 16; + /* Configure the sensor with these values initially. */ constexpr double defaultAnalogueGain = 1.0; constexpr Duration defaultExposureTime = 20.0ms; @@ -163,7 +166,8 @@ private: /* Raspberry Pi controller specific defines. */ std::unique_ptr helper_; RPiController::Controller controller_; - RPiController::Metadata rpiMetadata_; + std::array rpiMetadata_; + unsigned int metadataIdx_; /* * We count frames to decide if the frame must be hidden (e.g. from @@ -319,6 +323,7 @@ void IPARPi::start(const ControlList &controls, StartConfig *startConfig) firstStart_ = false; lastRunTimestamp_ = 0; + metadataIdx_ = 0; } void IPARPi::setMode(const IPACameraSensorInfo &sensorInfo) @@ -513,6 +518,7 @@ void IPARPi::signalStatReady(uint32_t bufferId) reportMetadata(); statsMetadataComplete.emit(bufferId & MaskID, libcameraMetadata_); + metadataIdx_ = (metadataIdx_ + 1) % rpiMetadata_.size(); } void IPARPi::signalQueueRequest(const ControlList &controls) @@ -536,14 +542,15 @@ void IPARPi::signalIspPrepare(const ISPConfig &data) void IPARPi::reportMetadata() { - std::unique_lock lock(rpiMetadata_); + RPiController::Metadata &rpiMetadata = rpiMetadata_[metadataIdx_]; + std::unique_lock lock(rpiMetadata); /* * Certain information about the current frame and how it will be * processed can be extracted and placed into the libcamera metadata * buffer, where an application could query it. */ - DeviceStatus *deviceStatus = rpiMetadata_.getLocked("device.status"); + DeviceStatus *deviceStatus = rpiMetadata.getLocked("device.status"); if (deviceStatus) { libcameraMetadata_.set(controls::ExposureTime, deviceStatus->shutterSpeed.get()); @@ -554,17 +561,17 @@ void IPARPi::reportMetadata() libcameraMetadata_.set(controls::SensorTemperature, *deviceStatus->sensorTemperature); } - AgcStatus *agcStatus = rpiMetadata_.getLocked("agc.status"); + AgcStatus *agcStatus = rpiMetadata.getLocked("agc.status"); if (agcStatus) { libcameraMetadata_.set(controls::AeLocked, agcStatus->locked); libcameraMetadata_.set(controls::DigitalGain, agcStatus->digitalGain); } - LuxStatus *luxStatus = rpiMetadata_.getLocked("lux.status"); + LuxStatus *luxStatus = rpiMetadata.getLocked("lux.status"); if (luxStatus) libcameraMetadata_.set(controls::Lux, luxStatus->lux); - AwbStatus *awbStatus = rpiMetadata_.getLocked("awb.status"); + AwbStatus *awbStatus = rpiMetadata.getLocked("awb.status"); if (awbStatus) { libcameraMetadata_.set(controls::ColourGains, Span({ static_cast(awbStatus->gainR), @@ -572,7 +579,7 @@ void IPARPi::reportMetadata() libcameraMetadata_.set(controls::ColourTemperature, awbStatus->temperatureK); } - BlackLevelStatus *blackLevelStatus = rpiMetadata_.getLocked("black_level.status"); + BlackLevelStatus *blackLevelStatus = rpiMetadata.getLocked("black_level.status"); if (blackLevelStatus) libcameraMetadata_.set(controls::SensorBlackLevels, Span({ static_cast(blackLevelStatus->blackLevelR), @@ -580,7 +587,7 @@ void IPARPi::reportMetadata() static_cast(blackLevelStatus->blackLevelG), static_cast(blackLevelStatus->blackLevelB) })); - FocusStatus *focusStatus = rpiMetadata_.getLocked("focus.status"); + FocusStatus *focusStatus = rpiMetadata.getLocked("focus.status"); if (focusStatus && focusStatus->num == 12) { /* * We get a 4x3 grid of regions by default. Calculate the average @@ -591,7 +598,7 @@ void IPARPi::reportMetadata() libcameraMetadata_.set(controls::FocusFoM, focusFoM); } - CcmStatus *ccmStatus = rpiMetadata_.getLocked("ccm.status"); + CcmStatus *ccmStatus = rpiMetadata.getLocked("ccm.status"); if (ccmStatus) { float m[9]; for (unsigned int i = 0; i < 9; i++) @@ -1002,10 +1009,10 @@ void IPARPi::returnEmbeddedBuffer(unsigned int bufferId) void IPARPi::prepareISP(const ISPConfig &data) { int64_t frameTimestamp = data.controls.get(controls::SensorTimestamp).value_or(0); - RPiController::Metadata lastMetadata; + RPiController::Metadata &rpiMetadata = rpiMetadata_[metadataIdx_]; Span embeddedBuffer; - lastMetadata = std::move(rpiMetadata_); + rpiMetadata.clear(); fillDeviceStatus(data.controls); if (data.embeddedBufferPresent) { @@ -1022,7 +1029,7 @@ void IPARPi::prepareISP(const ISPConfig &data) * This may overwrite the DeviceStatus using values from the sensor * metadata, and may also do additional custom processing. */ - helper_->prepare(embeddedBuffer, rpiMetadata_); + helper_->prepare(embeddedBuffer, rpiMetadata); /* Done with embedded data now, return to pipeline handler asap. */ if (data.embeddedBufferPresent) @@ -1038,7 +1045,9 @@ void IPARPi::prepareISP(const ISPConfig &data) * current frame, or any other bits of metadata that were added * in helper_->Prepare(). */ - rpiMetadata_.merge(lastMetadata); + RPiController::Metadata &lastMetadata = + rpiMetadata_[metadataIdx_ == 0 ? rpiMetadata_.size() - 1 : metadataIdx_ - 1]; + rpiMetadata.mergeCopy(lastMetadata); processPending_ = false; return; } @@ -1048,48 +1057,48 @@ void IPARPi::prepareISP(const ISPConfig &data) ControlList ctrls(ispCtrls_); - controller_.prepare(&rpiMetadata_); + controller_.prepare(&rpiMetadata); /* Lock the metadata buffer to avoid constant locks/unlocks. */ - std::unique_lock lock(rpiMetadata_); + std::unique_lock lock(rpiMetadata); - AwbStatus *awbStatus = rpiMetadata_.getLocked("awb.status"); + AwbStatus *awbStatus = rpiMetadata.getLocked("awb.status"); if (awbStatus) applyAWB(awbStatus, ctrls); - CcmStatus *ccmStatus = rpiMetadata_.getLocked("ccm.status"); + CcmStatus *ccmStatus = rpiMetadata.getLocked("ccm.status"); if (ccmStatus) applyCCM(ccmStatus, ctrls); - AgcStatus *dgStatus = rpiMetadata_.getLocked("agc.status"); + AgcStatus *dgStatus = rpiMetadata.getLocked("agc.status"); if (dgStatus) applyDG(dgStatus, ctrls); - AlscStatus *lsStatus = rpiMetadata_.getLocked("alsc.status"); + AlscStatus *lsStatus = rpiMetadata.getLocked("alsc.status"); if (lsStatus) applyLS(lsStatus, ctrls); - ContrastStatus *contrastStatus = rpiMetadata_.getLocked("contrast.status"); + ContrastStatus *contrastStatus = rpiMetadata.getLocked("contrast.status"); if (contrastStatus) applyGamma(contrastStatus, ctrls); - BlackLevelStatus *blackLevelStatus = rpiMetadata_.getLocked("black_level.status"); + BlackLevelStatus *blackLevelStatus = rpiMetadata.getLocked("black_level.status"); if (blackLevelStatus) applyBlackLevel(blackLevelStatus, ctrls); - GeqStatus *geqStatus = rpiMetadata_.getLocked("geq.status"); + GeqStatus *geqStatus = rpiMetadata.getLocked("geq.status"); if (geqStatus) applyGEQ(geqStatus, ctrls); - DenoiseStatus *denoiseStatus = rpiMetadata_.getLocked("denoise.status"); + DenoiseStatus *denoiseStatus = rpiMetadata.getLocked("denoise.status"); if (denoiseStatus) applyDenoise(denoiseStatus, ctrls); - SharpenStatus *sharpenStatus = rpiMetadata_.getLocked("sharpen.status"); + SharpenStatus *sharpenStatus = rpiMetadata.getLocked("sharpen.status"); if (sharpenStatus) applySharpen(sharpenStatus, ctrls); - DpcStatus *dpcStatus = rpiMetadata_.getLocked("dpc.status"); + DpcStatus *dpcStatus = rpiMetadata.getLocked("dpc.status"); if (dpcStatus) applyDPC(dpcStatus, ctrls); @@ -1111,11 +1120,13 @@ void IPARPi::fillDeviceStatus(const ControlList &sensorControls) LOG(IPARPI, Debug) << "Metadata - " << deviceStatus; - rpiMetadata_.set("device.status", deviceStatus); + rpiMetadata_[metadataIdx_].set("device.status", deviceStatus); } void IPARPi::processStats(unsigned int bufferId) { + RPiController::Metadata &rpiMetadata = rpiMetadata_[metadataIdx_]; + auto it = buffers_.find(bufferId); if (it == buffers_.end()) { LOG(IPARPI, Error) << "Could not find stats buffer!"; @@ -1125,11 +1136,11 @@ void IPARPi::processStats(unsigned int bufferId) Span mem = it->second.planes()[0]; bcm2835_isp_stats *stats = reinterpret_cast(mem.data()); RPiController::StatisticsPtr statistics = std::make_shared(*stats); - helper_->process(statistics, rpiMetadata_); - controller_.process(statistics, &rpiMetadata_); + helper_->process(statistics, rpiMetadata); + controller_.process(statistics, &rpiMetadata); struct AgcStatus agcStatus; - if (rpiMetadata_.get("agc.status", agcStatus) == 0) { + if (rpiMetadata.get("agc.status", agcStatus) == 0) { ControlList ctrls(sensorCtrls_); applyAGC(&agcStatus, ctrls); From patchwork Mon Sep 26 09:57:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17403 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 8B405BD16B for ; Mon, 26 Sep 2022 09:58:14 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 433B06225D; Mon, 26 Sep 2022 11:58:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1664186294; bh=Pm0asb9k6Zx7lke8Ff6P78qNyo908O1gaFveL/DwuZo=; 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=Vp04PZgI6Tp+hjYK6HjnzuGRnL6W0iYpIN4dzZqqjAYBztSIm6XnVnu8A13Z0UmPj GXoSNKxpN6VXGFkKBKEp6+8m50isld1t493aEFGEjXxtfKIOHRJh+8fISHsVvXBYIF OwFMhWWmvjPWvxrweJJyHeEtczh72T0uGFY1Paf+Qbp3FsJvJ0pS+PvwjzTxmLj1sU mzWM4a4nOXgACdUopMWqEYnQXTrTFk0r+X+rV8trA8fIK4J1RWsdcxFaCBD90lpaWB +yvg3o0zn9Dz1Rxc/ViO+zrbNx9okS2i2VzHXV8/c62CrYuumtXzH8ZWJZv7f0L4jy qsVT1HmQlkUGQ== Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3CF7962257 for ; Mon, 26 Sep 2022 11:58:13 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="Sdu/urem"; dkim-atps=neutral Received: by mail-wm1-x32d.google.com with SMTP id t4so4096411wmj.5 for ; Mon, 26 Sep 2022 02:58:13 -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; bh=L7BGo9XsieqoGsVj+4OcyYvMZVvrKWhrge2dYXTBIuo=; b=Sdu/uremNEz5jvfA2T9sEo0BH99rJQVkDhZvGc6jh2PLCzguVTCOUnxVJuG18I/Vzr 364ftmWggUnmrhCpBQD8g95hnxDI6mNvSNppix7Ed0+YAJwksBRWRSqJKZcmcPUztsp+ +NqgTFInznc9JLT1XhJQv0FUDa8TXDWDkmgW5KrXmm4eeXjWsIu+tiahmR5ztFIVVqZU JH5NLoUCdZdlxEGHfeuDtaNDDInpSpZj5uj4/dQFaf4zalQZC6gFBaNI117F1zTYkn0z jjAdUdYnpVGc8lDYV8qAMBAcrwMXyVPm85TwEj9ifQiMyH3wRZn2tqyOr2iMRAkMjZH4 w1/g== 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; bh=L7BGo9XsieqoGsVj+4OcyYvMZVvrKWhrge2dYXTBIuo=; b=h+elmFFDa3pdYrqalrxq3r5q434otUuSUWXFjtll77+wr4AVxqFDqvUFH9Z781C1pw I4JhqtUH+IKzdA68AedTXKtbbZ5qfcYEi6zJIS/WjATvhUf+ABknUWS+RH4CZGTj9jaj JNvtY3oZfywRrkXenVALGUP3CnwFKaZAW8rBMoiqkeO6PlaySGRsc7mtG45tBzHHOt8t nPNtd0RxGupqKJQKHNPbWD2UAh/3qZyf19HDPm/t5U/cRhA0UsK4H7TukQJEjl8A8tu/ 9XHaIPJ8aP32Qly+H3gRHDG4IRQ9zoczZaOLLp2DViAIPiLmGpgz4Owb4h/RD7kf6IUY qRtA== X-Gm-Message-State: ACrzQf3U4N5S5uTWaq+cM23IMVuAvfEVcELosHEgfOImLBAHJXHuGyNy sU1wyfvKXr3K3yuNStSaWtxgv9ppEzq94K4P X-Google-Smtp-Source: AMsMyM6q1LUnJLKdpjXBc9ftbZsRF19nVHUQFftl7l4qR4jzwOibb8JrS4JXCJ9vQNQvgTCT5p3N4A== X-Received: by 2002:a05:600c:5114:b0:3b5:428:cf67 with SMTP id o20-20020a05600c511400b003b50428cf67mr14209848wms.80.1664186292827; Mon, 26 Sep 2022 02:58:12 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id p22-20020a05600c419600b003a4efb794d7sm10160671wmh.36.2022.09.26.02.58.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Sep 2022 02:58:11 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 26 Sep 2022 10:57:36 +0100 Message-Id: <20220926095737.30506-7-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220926095737.30506-1-naush@raspberrypi.com> References: <20220926095737.30506-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 6/7] pipeline: ipa: raspberrypi: Use IPA cookies 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" Pass an IPA cookie from the IPA to the pipeline handler through the setDelayedControls signal. This cookie is the index of the current RPiController::Metadata context used for the frame. The cookie is subsequently passed into DelayedControls together with the controls to action. The IPA cookie is then returned from DelayedControls when the frame with the applied controls has been returned from the sensor, and eventually passed back to the IPA from the signalIspPrepare signal. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Tested-by: David Plowman --- include/libcamera/ipa/raspberrypi.mojom | 3 ++- src/ipa/raspberrypi/raspberrypi.cpp | 2 +- src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 12 +++++++----- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/include/libcamera/ipa/raspberrypi.mojom b/include/libcamera/ipa/raspberrypi.mojom index c0de435b7b33..fb806a1518d5 100644 --- a/include/libcamera/ipa/raspberrypi.mojom +++ b/include/libcamera/ipa/raspberrypi.mojom @@ -36,6 +36,7 @@ struct ISPConfig { uint32 bayerBufferId; bool embeddedBufferPresent; libcamera.ControlList controls; + uint32 ipaCookie; }; struct IPAConfig { @@ -136,5 +137,5 @@ interface IPARPiEventInterface { runIsp(uint32 bufferId); embeddedComplete(uint32 bufferId); setIspControls(libcamera.ControlList controls); - setDelayedControls(libcamera.ControlList controls); + setDelayedControls(libcamera.ControlList controls, uint32 ipaCookie); }; diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index 63cccda901c1..0e80ef9c7b95 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -1144,7 +1144,7 @@ void IPARPi::processStats(unsigned int bufferId) ControlList ctrls(sensorCtrls_); applyAGC(&agcStatus, ctrls); - setDelayedControls.emit(ctrls); + setDelayedControls.emit(ctrls, metadataIdx_); } } diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 39e69d748693..09680a72f58a 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -208,7 +208,7 @@ public: void runIsp(uint32_t bufferId); void embeddedComplete(uint32_t bufferId); void setIspControls(const ControlList &controls); - void setDelayedControls(const ControlList &controls); + void setDelayedControls(const ControlList &controls, uint32_t ipaCookie); void setSensorControls(ControlList &controls); void unicamTimeout(); @@ -264,6 +264,7 @@ public: struct BayerFrame { FrameBuffer *buffer; ControlList controls; + unsigned int ipaCookie; }; std::queue bayerQueue_; @@ -1789,9 +1790,9 @@ void RPiCameraData::setIspControls(const ControlList &controls) handleState(); } -void RPiCameraData::setDelayedControls(const ControlList &controls) +void RPiCameraData::setDelayedControls(const ControlList &controls, uint32_t ipaCookie) { - if (!delayedCtrls_->push(controls)) + if (!delayedCtrls_->push(controls, ipaCookie)) LOG(RPI, Error) << "V4L2 DelayedControl set failed"; handleState(); } @@ -1864,13 +1865,13 @@ void RPiCameraData::unicamBufferDequeue(FrameBuffer *buffer) * Lookup the sensor controls used for this frame sequence from * DelayedControl and queue them along with the frame buffer. */ - auto [ctrl, cookie] = delayedCtrls_->get(buffer->metadata().sequence); + auto [ctrl, ipaCookie] = 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. */ ctrl.set(controls::SensorTimestamp, buffer->metadata().timestamp); - bayerQueue_.push({ buffer, std::move(ctrl) }); + bayerQueue_.push({ buffer, std::move(ctrl), ipaCookie }); } else { embeddedQueue_.push(buffer); } @@ -2165,6 +2166,7 @@ void RPiCameraData::tryRunPipeline() ipa::RPi::ISPConfig ispPrepare; ispPrepare.bayerBufferId = ipa::RPi::MaskBayerData | bayerId; ispPrepare.controls = std::move(bayerFrame.controls); + ispPrepare.ipaCookie = bayerFrame.ipaCookie; if (embeddedBuffer) { unsigned int embeddedId = unicam_[Unicam::Embedded].getBufferId(embeddedBuffer); From patchwork Mon Sep 26 09:57:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17404 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 1582EBD16B for ; Mon, 26 Sep 2022 09:58:17 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B74F562264; Mon, 26 Sep 2022 11:58:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1664186296; bh=lWX/rkuLsVjrzcRtKwbMiibWwShPlxC4AofWEXu6Um8=; 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=ROYdOxa6DQ1Qz/Vl+F/DolGwvBY307ZeIJa2yJKQMKHd33u//5omx4TTRAhjTJCUE Zz5k6yV4wOjRHEMaJ4eVpY3I6l+jjp5JRfCAKyLARmJ3z3COiKOzNtX4mhRXmAY+CD 3POqDBr1zlCSitWtwhQDNxcnnn5i7nM6CODhFnbiMFKBGZvZksgAUmWiQdoG4Jr4p1 zvWf9hPSrpzCorj1uZyBiSMZO4Z8Cl4dpkTJk/ffF3z9W8wO2lFh5fsUCsbuX33iUO SQJDPSMzs7fdRY+PhkHr81Kjtn20Y+vci/kRXqg3oKdwI6s9T2RS3aC/j6CGrDSjE9 I3ZtM3rAeefmA== Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F0B0B62260 for ; Mon, 26 Sep 2022 11:58:14 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="LkvvOlav"; dkim-atps=neutral Received: by mail-wm1-x336.google.com with SMTP id o5so4120291wms.1 for ; Mon, 26 Sep 2022 02:58:14 -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; bh=tnUgZJUKUkP6fVcpYTtvEJuRHxAYGbHl5Vo84ysJuZ0=; b=LkvvOlavcUaz5TBUmbgk9ugD0KrkhgERaHS0RABX9TiPq8O3Fhg1c7EitCONhdtzVN +aDKHT1WS7+O5q/Ovv6qdh8WjnaXVuv6FTtewFn715MEIUyNu4CZlwhDqstqQtlcPfxp ILkYcj5DOwJKJ4++k+ueoxnZcBPypKJ5KGwU5kEBblRAWnN5reWpdZftqCYUrhwyySVc Jl5Z+FZ8QdrDj40LYRNHPgEa+PpYyaI6RMYWfdsaYF8g4A6R4xPEqnwywK4I+y4hoiXf y95dKoCutTeSuiIR6noLzE9/1YWUI8UE9SY9EOwv7dpe0fTHmTBvbdBaWdvrsgpJryo8 OO3Q== 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; bh=tnUgZJUKUkP6fVcpYTtvEJuRHxAYGbHl5Vo84ysJuZ0=; b=RupjxvxRWv1WpQE3k51TzLBgg9QGRPJjSbioh+hXucS7ocLcZzJ3ffQSbGWSBCJoDU lmav/M0eXbtt0KfIUekrB/v1QyuKeAsgzdHA/TQaqOFKOgFVYmS4SGGuXJb2Ie69nmVy jgPsny3foBoXRL5rAIXxJGu1TxuubFRsrrx8Hhz0g4C66Xb5IwlCUI2AHBN0Ay89Yxbe 7NlY5DoqyMNNFa6rgXf21hcrTvCKabKhKZY8usBdZXedlXEgiGDI2sI6zQpA25Eu93QW MyI3pR++AeYxmQCQzunXbzD+c0Bewo2fBUPiOJxeAHPpnUSOz7LR/C8Txw6YRFtP8bBf YBNg== X-Gm-Message-State: ACrzQf2JasWxJBOHjZ1wtLKKcw5idLdcVeevM75zB1x2bJSAFBqTRjmQ INi6FIJr8pVCAXbscT6IdTWKe/4BDDDp5AoY X-Google-Smtp-Source: AMsMyM4+3yet6Bj+D9suthFGcX1HkjdmmE1SRwF/ndrIDy21hrsw+JsTp4G0/qfVb4qOCqJubb+ufA== X-Received: by 2002:a7b:c392:0:b0:3b4:acef:3523 with SMTP id s18-20020a7bc392000000b003b4acef3523mr14843407wmj.37.1664186294440; Mon, 26 Sep 2022 02:58:14 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id p22-20020a05600c419600b003a4efb794d7sm10160671wmh.36.2022.09.26.02.58.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Sep 2022 02:58:13 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 26 Sep 2022 10:57:37 +0100 Message-Id: <20220926095737.30506-8-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220926095737.30506-1-naush@raspberrypi.com> References: <20220926095737.30506-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 7/7] ipa: raspberrypi: agc: Fix digital gain calculation for manual 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: , 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" The digital gain calculation uses a total exposure value computed with the current AGC state. However, this is wrong in the case of manual shutter/gain controls, as the total exposure value used must be the value computed when the AGC sent the manual shutter/gain controls to the pipeline handler to action. To fix this, the IPA now adds the historical AgcStatus structure to the metadata (tagged with "agc.delayed_status"). This historical AgcStatus structure contains the total exposure value calculated when the AGC sent the manual shutter/gain controls to the pipeline handler. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Tested-by: David Plowman --- src/ipa/raspberrypi/controller/rpi/agc.cpp | 10 ++++++++-- src/ipa/raspberrypi/raspberrypi.cpp | 11 +++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp index bd54a639d637..b18bd7b5b19e 100644 --- a/src/ipa/raspberrypi/controller/rpi/agc.cpp +++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp @@ -408,6 +408,12 @@ void Agc::switchMode(CameraMode const &cameraMode, void Agc::prepare(Metadata *imageMetadata) { + Duration totalExposureValue = status_.totalExposureValue; + AgcStatus delayedStatus; + + if (!imageMetadata->get("agc.delayed_status", delayedStatus)) + totalExposureValue = delayedStatus.totalExposureValue; + status_.digitalGain = 1.0; fetchAwbStatus(imageMetadata); /* always fetch it so that Process knows it's been done */ @@ -418,8 +424,8 @@ void Agc::prepare(Metadata *imageMetadata) Duration actualExposure = deviceStatus.shutterSpeed * deviceStatus.analogueGain; if (actualExposure) { - status_.digitalGain = status_.totalExposureValue / actualExposure; - LOG(RPiAgc, Debug) << "Want total exposure " << status_.totalExposureValue; + status_.digitalGain = totalExposureValue / actualExposure; + LOG(RPiAgc, Debug) << "Want total exposure " << totalExposureValue; /* * Never ask for a gain < 1.0, and also impose * some upper limit. Make it customisable? diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index 0e80ef9c7b95..bc438e99eff6 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -1025,6 +1025,17 @@ void IPARPi::prepareISP(const ISPConfig &data) embeddedBuffer = it->second.planes()[0]; } + /* + * AGC wants to know the algorithm status from the time it actioned the + * sensor exposure/gain changes. So fetch it from the metadata list + * indexed by the IPA cookie returned, and put it in the current frame + * metadata. + */ + AgcStatus agcStatus; + RPiController::Metadata &delayedMetadata = rpiMetadata_[data.ipaCookie]; + if (!delayedMetadata.get("agc.status", agcStatus)) + rpiMetadata.set("agc.delayed_status", agcStatus); + /* * This may overwrite the DeviceStatus using values from the sensor * metadata, and may also do additional custom processing.