From patchwork Wed Oct 19 09:01:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17626 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 24902C327C for ; Wed, 19 Oct 2022 09:01:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A167062E3E; Wed, 19 Oct 2022 11:01:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1666170078; 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=0Ue9THUhpmedFyaLuXpRdIMyNnw2+UjnWoUdil+ZwyLWI7U8MNSVkDBANANtpcvKn Y1smdm7L4i2rHrforawfayOoAPABrnGGhd2USV2jGUPTlSu+Yrg9qkI5uOY68PtIp5 gEzRW3NW02yx5OLCmryHPxhQf+Dz6bUjrrdqVGZJKLrbZP6ger53iw0UKZPtat3GKE Q+g4mLKUMWqL8vwyowIxGX82HKKVPxHOSIGon+Mwpd79CoibVWinxwAvz0za6wk2zz ZY//pQu6i34PYPga6Kvk7gbtg+nNm2D2ZijEPIpzQgeZyQsr7nAto4O0ENVp7Gth6m QZlCZfSaU08Hg== Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 89BA462DD7 for ; Wed, 19 Oct 2022 11:01:17 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="A7HI0cCD"; dkim-atps=neutral Received: by mail-wm1-x335.google.com with SMTP id l14-20020a05600c1d0e00b003c6ecc94285so420626wms.1 for ; Wed, 19 Oct 2022 02:01:17 -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=ZPzBiNF1VfWzy9TrECDZS8BLt3LUNp1q4BLHZaXn4hI=; b=A7HI0cCDLgxsQ51FHSxhdQG+JiHsPChwLafwFzSdapY05K6vKZ8K4IdlI1PgXgT28M iPiIFQ2n6Zr+vkzoD6x3nZcyttxZ5KrxEHywtygT/di+CxsjpW1rHY0P3sV0Pju1J5EX 27+PDhaWFWukcU5XCd5ldy2bAswXlCLZj2txPQPpGUKoimMQqKFgS99xxsy/51RPlq3+ O7lDWfHZEx1N7cPsb807qZOVcEV6/jmvs/oVHuNf0LuCUEagIy5fyvK/EDlEis5Xp0YZ 66VYGRKafzys1Asp/w7/5HsOmAcbC45OuhJiq4Wzg99g2Noo2Y20pKmI8MKAQLOzKKqv N6OQ== 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=ZPzBiNF1VfWzy9TrECDZS8BLt3LUNp1q4BLHZaXn4hI=; b=032Mdb/VZGWp/OyLU5G9Qzjp5fM63tL6+BIwVYsnxzEusn5C7Ft74FIZ2moIt2UZ9d lRI8IXaONiTV+kg/KitrTzV9ERMGuovkEqeFZ8zu3Hj5wGF9kRfZyiiupVIkimDkfdBI yv5qzBeYL3Mze/nvEwi7hDUr2qXytl8nviUSr6/yoxoO6R/T1SMa7eQFQCP8HCRwaPqS YQM+2tRq90jIa/mrkW8NQQ7B5Rgr/6dQAMW/5gav7Zcvq6ZUp4g9Jum52Mu390SPI6D3 YlrSXmzpmKv1zLiw34bqwIpVVV2WMfQ/boUn7k38rOJSvyfEN5AAQjbT+F4nz/XmN3YL qiGA== X-Gm-Message-State: ACrzQf3oOwRGgqSDYoRD5wEt10kDOeIpDQ0jSgpPddWdBVZg2oapfq1f XNtfUCYd5z8NsiU1AsmT4/bzeM9CWCzKgw== X-Google-Smtp-Source: AMsMyM6eOCslnk3MdtGr4VLRjX1+jb5e59QrYHUjLcJAMHpWyrOcumpKhg1ypuROGiMHcwHvz/Rd4A== X-Received: by 2002:a05:600c:288:b0:3c6:c44a:1d30 with SMTP id 8-20020a05600c028800b003c6c44a1d30mr25849475wmk.46.1666170077080; Wed, 19 Oct 2022 02:01:17 -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.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Oct 2022 02:01:16 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 19 Oct 2022 10:01:01 +0100 Message-Id: <20221019090107.19975-2-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 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: Kieran Bingham --- 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 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(); From patchwork Wed Oct 19 09:01:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17628 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 B7CF6C327C 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 59BB962E45; Wed, 19 Oct 2022 11:01:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1666170082; 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=rzJHQLgcry5lyfe4YuKlAypa9mxdcOJemv3bQbYqJlhli6PribSm/xhN17GK7xCg0 T+jqk+rOOplRQv9WcxbrrKAGvAQYjkoDBa3Y4AQD/GPi9Eajc5OSQFpO3E8a0AtP06 xKiEV06jsu/6HI3Pm6U1aSXc3v3PdllFyBh6cFDVaVywIDnysDrjnLFJg31YAz5NII gQljuv0zAsI5i+sYBRfFgPr/BKRddKdfKWv0+DW5PRE7ITT8q7vtvaoxtxJwLh3t8c 1eStHY5psHywKhyuWaeaM1PGDikjS6dtEac07HH1GnzjpMTS9LDMPVLK3KjOpRPIH1 UBrkmqpTz3PAA== Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F3F0A62DD7 for ; Wed, 19 Oct 2022 11:01:19 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="KJLJRTJ6"; dkim-atps=neutral Received: by mail-wr1-x42e.google.com with SMTP id bk15so27951232wrb.13 for ; Wed, 19 Oct 2022 02:01:19 -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=+T3xcs+sb+8OgweMkuTstG9ZLZCS0dNJ3UIDGexYQRk=; b=KJLJRTJ6h7OP8R17WjoJsZ45MjO99Svbg/ekQBQuNBQ8z6MaclHtbV3+AX6bG4LjZJ Q/oJp0OnnRZfxS75UJ0jrZnXtsk2wzr2zXmXybK/ESgV6bFb2PkWMAoxJSRf+vimRhWs kVC6Qw5CVruiDF2ketphO6RK8CRwd0kNpGL2D/Z5XkHkQU0A8Nm9fxhGqD3jFPjdYMFq p8R+tkEtC7/GKH1m3bLrKEsNWzVhD3EUYj2uqiMvIUTWIunHed8enZAQcRMhbwru3z5l EVlhwdN0UuuXIlDO30eOcUshis3d1iuBi0I6eEa2nSPjOKdaPjkOHsyEEMVjAMn5ojf1 LZqg== 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=+T3xcs+sb+8OgweMkuTstG9ZLZCS0dNJ3UIDGexYQRk=; b=sxNSOKws79G9B+1hG6gdurDZ44+Wcq/FY0v7JX3uZyuupEn/CU3pucFlBPt/NmiE7v vzvmuvBAr1+lq+4x+Eyo7kd1MjHF5qRViCF9wG10ewtKUv/vKUfVrcHtE8BN05csOPCU v5E8Ngyh0f4bb+QRDpabV0KH2mGM5Rr1Oian3HnvCFjmEE0EQJx80I+V3TAr54ggKOi3 eYdKoyx3aHJVWGESq7ruz+wQ497SKXw8ykPFBIWR5ykjkmsMpbTdJHM8ovQPmPKuMhzA JBzpMuoTFvy2bW2NF0Ktu2cuFMKg4Eh3lSJVRI7ugYkWipEw2y+pbxebCEUvC5Shxerh 80sg== X-Gm-Message-State: ACrzQf3GgBcmeuc1ZjltoZ5D4CvZ1xnUvPcari6pyFqa4cMssWZr+5mP cVjl0pt6mbWz/LG7NJ566kp4J9vldqPZ5g== X-Google-Smtp-Source: AMsMyM5GY850MYVKP/zF/gnzgiV8FQ/Jaf+do/AUTquBo4dvqmkvSqI6THRA6yTQyxkwD6YLhkXoNw== X-Received: by 2002:a05:6000:2aa:b0:231:ac4f:196d with SMTP id l10-20020a05600002aa00b00231ac4f196dmr4170023wry.121.1666170079444; Wed, 19 Oct 2022 02:01:19 -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.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Oct 2022 02:01:18 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 19 Oct 2022 10:01:03 +0100 Message-Id: <20221019090107.19975-4-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 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 Wed Oct 19 09:01:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17629 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 B23F7C0DA4 for ; Wed, 19 Oct 2022 09:01:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C173262E4F; Wed, 19 Oct 2022 11:01:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1666170082; 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=onnfr8lZTCy5FjwPPsP0l8NsiswES8DO4CNh71n4fv0Gs21sF6tOOf1u8Ahu+TwqB OAW+UD2pkQBzkOFEOdJuFa/y00gW/o9yRuRguhO8L2A1xM0PjXeUDY0/Q1cTC8EmOs y/H3hMGNJ4awwW/y1h4EaRIWTZV+9BanBZWz5dJARNyZ9+oKEsBECKjW4wycbgCk2A 2zcUR6ADlHxVvFtbSwg3x1HDKP7y2e4R5oBRSs5OILJjwzhv7QQD7oqjD+IsK4wnZO NV5eUs8LloqVz2r4iRsTgQ3AdB1/7+o+IrWy/m82MnVJ79Tv3NePKAfSqT2iVf4haF DPnEmoEDKlVEw== Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 06D8462E44 for ; Wed, 19 Oct 2022 11:01:21 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="H5UO7zd6"; dkim-atps=neutral Received: by mail-wm1-x329.google.com with SMTP id e18so12482035wmq.3 for ; Wed, 19 Oct 2022 02:01:21 -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=bo43RPn2Wf8VvpHKyuSwKItQaXGqKlJBIO1xs6MhjIo=; b=H5UO7zd636sPFw22zGTqQMyGm2lSC5UHy51T0AcTb/RSDIM9PXGDh7LwEe9oHJW94t C9DpNuI/zuZtAxaGHMXgOBTsZQuXAk7b3vXfqpIasBrNXM+9D1Bq8IVm/UByiJmMtM+P Xtu+/PQgwfeNjBgiM3T/fSLjdCzUPmHDfOQwu0GPtXRldeUo0e9PbFZX680uWXa3kV08 CgqUjMAxAxe7Qk/83Jy2Oxg0tM6bqFi6YmRDonh1sMAatLuqJIc0E0HCBZPb8bTQbyVo YDcA81ozIN3u9IWW+zcdmKOINndpP6rrQJLU57aOSJegnmijyjdn8IHLWlp+wAjpNCxx 27Fw== 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=bo43RPn2Wf8VvpHKyuSwKItQaXGqKlJBIO1xs6MhjIo=; b=NHA0Fu22RVtm36wzxdJCPiD2Oy/Hfjc5gLeCBE+//i/gWjDBqAqzZEfw9VoJFJztMh rDNGEXLLWdpuTKWkXVWakh5MBfSGUTUEv8irjLsx6RXf0+gzLf4gb8HT27vRGL0Xwhat ifiUh25dWfH4we3tXD4cFt8CzjBkw8a9eW96ecQe/dwvGOO2AnHzh8Rerjj3w+6tyVpB u3b/MGWUZRBfqvwtwVXmPswkglZh5f8dtwfEciv5zSg/eEO1C9fy+p/HZeDDAZeygvJ5 8wrsWkYbwWP3y+vleb+618nfwGsn4m9b+rRnupgpFI24md4EbhrH9vhtoPdgdI6zcy5R 6bzQ== X-Gm-Message-State: ACrzQf1C/pM37vdA4k+cDDrB2cSkJBomKEs7V4v5Vy5qXRgslietHk4j FvZuQGA8eU4Hr9CD08nOkbvPBzdLs+T5Bg== X-Google-Smtp-Source: AMsMyM46UGP9Sk6pDp0Hz5DmdlMHmh5F/Og+wnp6FLXLayUYDEKhD+Q+cwgiI1V288ZvujJuhvTTbA== X-Received: by 2002:a1c:283:0:b0:3c6:c025:3f3b with SMTP id 125-20020a1c0283000000b003c6c0253f3bmr24379373wmc.101.1666170080474; Wed, 19 Oct 2022 02:01:20 -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.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Oct 2022 02:01:19 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 19 Oct 2022 10:01:04 +0100 Message-Id: <20221019090107.19975-5-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 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 Reviewed-by: Kieran Bingham --- 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 Wed Oct 19 09:01:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17630 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 39AF9C327C for ; Wed, 19 Oct 2022 09:01:26 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D6F6462E55; Wed, 19 Oct 2022 11:01:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1666170085; bh=j5PQ+nf/o1EwX49vwnSLKLQnrh26xJfINWtBYZg6WO4=; 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=IdprpAqH59Q8mT+q9WBO9AQ6hJXmBQgGz5/m5zm34UoxjwZh/l8z7WWkYwCUFVmE9 kJF7mmjD8mgnY64B2muv5RfvemfjDxIezRAYh+BCf6cYvXiEkHSCOKm5iReMuulf7h sYlwpPP7oDb2/7C0CUgswUfiSVhDf8tRdzcwYZgf4bDzlYaHFw/J60GbbY2+hNK9wJ 9KwwqnJGV492OTDSY+eLlNYZWJxj/0o0cj501J5+R86zgf2hlYsfGO3wzVBkV+vREu k4pXRDf5zz7EQtZfJf4LJGGQabjXk9Rit24t90jMazXPn4wOQPIih1rH7hU/cidN+x DOfqLZVMWlqSw== Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2A54762E4C for ; Wed, 19 Oct 2022 11:01:22 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="OjFV/vKR"; dkim-atps=neutral Received: by mail-wr1-x432.google.com with SMTP id b4so27944138wrs.1 for ; Wed, 19 Oct 2022 02:01:22 -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=C08pD0BBWsfh+mVfb1uG3tXySSr8+tqVZu1o8cdDMyA=; b=OjFV/vKRlGl+jLlYa2z5S/nRsvjFR0f9Bh3v8SFMeWEe52knR/UMNPg+yms5dfzPlQ xq4N1vTBlKhT6zcmaNUOhqFu9/q8P0VjDQgvASXSAYJWma5REcOExfgv5uAotySLTAkS Im0Sbzi4cCycRyjVBl/i1yKfzLKK1HYnCOFY/mRTZTmRVvTTkbi9QXNo5cupMT71EQpQ weayX8M//yVu5CWN189B0/VDbJAjfaREyvsyPu7fv7drh/x+mtKx4VUYGF3U6qfpUT1q KKgwErmohFmLmL2aYSms1PWecpTj/+nNAqxivi0nDDpX2Ilp0XfXhckISg6qO6rMKqxs DyZg== 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=C08pD0BBWsfh+mVfb1uG3tXySSr8+tqVZu1o8cdDMyA=; b=P5RxQKWGsgiN05pJ3lLwebJYThviTFWYQxurp2UGl98V+lA8yqnZIPC26NYTp4szwS Fba1RUWls6K0/q3PslXZV/SBT8txGLkWpRMoM39O70MHb+Vuy364RjXBXAD+nUYPW10K WAKKIr6ybeHlw/Qq4+REjMCtLbCpuODwp6M3uc1jQnxZKsy+KFra1Bw7VwgOvaRZY1gj jFjtjGEhSco6Wag83K1faRcASa8W6KNGtjrAHHZSZNh+bmZMqXVwhe7a2gY1lzo7rZMB Jq5xPcYs+XPOyT3EclC3zNza7DZaF/yn6oVCIDjaKtB26z/3ql9A6y4MuhxJNHy3b5Dg u7Iw== X-Gm-Message-State: ACrzQf0Q3AGmk+ryTre7Qoj2Um5b5fYqezAOM7rAIg1ozI7KCf0QqmF6 zOeIxtOtXEISSn3UaqBMjZ7SrnySdlxtkg== X-Google-Smtp-Source: AMsMyM6iQdwk9Pq5pmOjDs96Qotima4SJeYHbiHY4UaggRsZlxKsglX9wJT4bUEWZJFKNlI06UKEdQ== X-Received: by 2002:adf:ce0e:0:b0:22e:525:c090 with SMTP id p14-20020adfce0e000000b0022e0525c090mr4395820wrn.238.1666170081376; Wed, 19 Oct 2022 02:01:21 -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.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Oct 2022 02:01:20 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 19 Oct 2022 10:01:05 +0100 Message-Id: <20221019090107.19975-6-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 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" Allow the IPA to 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. At present, only a single index into this array is used. 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 Reviewed-by: Kieran Bingham --- src/ipa/raspberrypi/raspberrypi.cpp | 65 ++++++++++++++++------------- 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index b74f1ecf738f..9e7792f5dfbe 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 @@ -320,6 +324,7 @@ void IPARPi::start(const ControlList &controls, StartConfig *startConfig) firstStart_ = false; lastRunTimestamp_ = 0; + metadataIdx_ = 0; } void IPARPi::setMode(const IPACameraSensorInfo &sensorInfo) @@ -539,14 +544,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()); @@ -557,24 +563,24 @@ 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, { static_cast(awbStatus->gainR), static_cast(awbStatus->gainB) }); 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, { static_cast(blackLevelStatus->blackLevelR), @@ -582,7 +588,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 @@ -593,7 +599,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++) @@ -1006,9 +1012,10 @@ 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_); + lastMetadata = std::move(rpiMetadata); fillDeviceStatus(data.controls); if (data.embeddedBufferPresent) { @@ -1025,7 +1032,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) @@ -1041,7 +1048,7 @@ void IPARPi::prepareISP(const ISPConfig &data) * current frame, or any other bits of metadata that were added * in helper_->Prepare(). */ - rpiMetadata_.merge(lastMetadata); + rpiMetadata.merge(lastMetadata); processPending_ = false; return; } @@ -1051,48 +1058,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); @@ -1116,11 +1123,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!"; @@ -1130,11 +1139,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 Wed Oct 19 09:01:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17631 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 4E671C0DA4 for ; Wed, 19 Oct 2022 09:01:27 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DC4B762E4C; Wed, 19 Oct 2022 11:01:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1666170086; bh=njQ9gW5DKOXOyMQ0F7GWvUGNhge0VpeeJz1MElUPrg4=; 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=D4sJfp623TCg/D0eoGQHDcvHAmQ4Ftms9TfHdg4Eoe7bq9p8S+O7t6dwRc9wmkej8 5BTgOiDM4QZViCVN7Zoh40LsWL5MdlQMniNGOPu5WtNTp3TEqIgeOvZKHyZ2VpwbPU NLpWIsD6Yf31jy8UPOVUvCQzgz4P5js6ghth1qu1RvQw0RoNYFVYnBC307bfZUjcLQ niHv3AZTTbd+YLTWfwoCUp7rP78UIbROaEq79H77AOBTGeoKpmpDFfIuOLQTAMQozt fND4IaoB9c+aqkmpZotz2hxLDAW86elo+ZISduEJ9IHqBQIkuJuLzAdd545bhh/spC DF4F1bJeyClyg== 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 34E8962E46 for ; Wed, 19 Oct 2022 11:01:23 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="OctBth4T"; dkim-atps=neutral Received: by mail-wr1-x42f.google.com with SMTP id n12so27810880wrp.10 for ; Wed, 19 Oct 2022 02:01:23 -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=W917K/nmtTKhwmLkk3bJj7stCIhhxNruF7ozW1jiSAU=; b=OctBth4TcIHemxsXPy9Nfwhu5mj2oO/9ikehYJ4WGn+B1VntgndrBEuPm07PMZ/dkn z0Assm2OE1qzRzhZG2BOIHuK1EvNehax3t2i7wIm9ZsrcEdhlOdXLF+DsvmadoG+se+7 LlzrqaXZqrWKvbroFdlLAZSh/Kpi0NMZeTgPcLg/r68v2gzR8RoSHwxzOykt/5tR5i/g fL1weqSzu1dMRXkj/L5wCdclcdGsIC6Ww8JjcwmhmFzLypdrsq2JB06ziLnZ2JljbzSX 9bPi201VTrv2Q0Kogd1oJHcIlVN/O1dPgThk0dGXWkH3i1XAjP/OStjJMxirmRnj8UCA iDaA== 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=W917K/nmtTKhwmLkk3bJj7stCIhhxNruF7ozW1jiSAU=; b=op/m9eJUYibXR+gqr+crqI/ZFLmj0PhqWLnmjRB4YMObf0+GylUE5r9kQ7t2H//xZU JotbvTnyB074pAeS4+BDVZq/SH6Qi937ax1gaux7cFlDHhoNha9OcuNmS6h0JBmMsiDk vAtxtX+44O+AfKuk4oeX2GQBXh2FfFIMVSj2dq7J5FB1TBDhDrhuP5ZgYdTL4I+kMkxy AY6k4xm0Kb0wJLZxP6F830uH6X7pWwxrCPj620JKXYaZfDDRY3ktTeewOlaOX2UNE/V9 NjtcjxRqwWqq9rv21cNRDar61hW6wec2ievtyehqH2fAwPxsk2NG+P0M1dWpwfVo8rJY jgsQ== X-Gm-Message-State: ACrzQf36trnHUtgB66+L1FgNSceqHDF2Xw0yed9sMO5NW10e3SYHYUO0 JQuL0WAr1yMcuVqiubJtWECmaXPkcVfAPg== X-Google-Smtp-Source: AMsMyM6lviXBBuajoqIJUHRmMAhYLL7aQI/AR3GjbTNl+vNt1asBU+XNufmRvGVh0G3PtfXJb6mkJA== X-Received: by 2002:a05:6000:1051:b0:22e:5d8a:d3d5 with SMTP id c17-20020a056000105100b0022e5d8ad3d5mr4309112wrx.476.1666170082582; Wed, 19 Oct 2022 02:01:22 -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.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Oct 2022 02:01:21 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 19 Oct 2022 10:01:06 +0100 Message-Id: <20221019090107.19975-7-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 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 pipeline handler to the IPA and eventually back to the pipeline handler through the setDelayedControls signal. This cookie is used to index the RPiController::Metadata object to be used for the frame. 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 Reviewed-by: Kieran Bingham --- include/libcamera/ipa/raspberrypi.mojom | 4 +++- src/ipa/raspberrypi/raspberrypi.cpp | 12 +++++++----- .../pipeline/raspberrypi/raspberrypi.cpp | 19 +++++++++++++------ 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/include/libcamera/ipa/raspberrypi.mojom b/include/libcamera/ipa/raspberrypi.mojom index 40f78d9e3b3f..bb5abd895262 100644 --- a/include/libcamera/ipa/raspberrypi.mojom +++ b/include/libcamera/ipa/raspberrypi.mojom @@ -37,6 +37,8 @@ struct ISPConfig { uint32 bayerBufferId; bool embeddedBufferPresent; libcamera.ControlList controls; + uint32 ipaCookie; + uint32 delayCookie; }; struct IPAConfig { @@ -137,5 +139,5 @@ interface IPARPiEventInterface { runIsp(uint32 bufferId); embeddedComplete(uint32 bufferId); setIspControls(libcamera.ControlList controls); - setDelayedControls(libcamera.ControlList controls); + setDelayedControls(libcamera.ControlList controls, uint32 delayCookie); }; diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index 9e7792f5dfbe..aed8f68aded9 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -168,6 +168,7 @@ private: RPiController::Controller controller_; std::array rpiMetadata_; unsigned int metadataIdx_; + unsigned int lastMetadataIdx_; /* * We count frames to decide if the frame must be hidden (e.g. from @@ -324,7 +325,6 @@ void IPARPi::start(const ControlList &controls, StartConfig *startConfig) firstStart_ = false; lastRunTimestamp_ = 0; - metadataIdx_ = 0; } void IPARPi::setMode(const IPACameraSensorInfo &sensorInfo) @@ -535,6 +535,8 @@ void IPARPi::signalIspPrepare(const ISPConfig &data) * avoid running the control algos for a few frames in case * they are "unreliable". */ + lastMetadataIdx_ = metadataIdx_; + metadataIdx_ = data.ipaCookie % rpiMetadata_.size(); prepareISP(data); frameCount_++; @@ -1011,11 +1013,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) { @@ -1048,7 +1049,8 @@ 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_[lastMetadataIdx_]; + rpiMetadata.mergeCopy(lastMetadata); processPending_ = false; return; } @@ -1147,7 +1149,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 23f2460190f4..8f6c6c0ce89f 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -206,7 +206,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 delayCookie); void setSensorControls(ControlList &controls); void unicamTimeout(); @@ -262,6 +262,7 @@ public: struct BayerFrame { FrameBuffer *buffer; ControlList controls; + unsigned int delayCookie; }; std::queue bayerQueue_; @@ -294,6 +295,9 @@ public: /* Have internal buffers been allocated? */ bool buffersAllocated_; + /* Frame cookie to pass to the IPA */ + unsigned int ipaCookie_; + private: void checkRequestCompleted(); void fillRequestMetadata(const ControlList &bufferControls, @@ -1064,7 +1068,8 @@ int PipelineHandlerRPi::start(Camera *camera, const ControlList *controls) * Reset the delayed controls with the gain and exposure values set by * the IPA. */ - data->delayedCtrls_->reset(); + data->ipaCookie_ = 0; + data->delayedCtrls_->reset(data->ipaCookie_); data->state_ = RPiCameraData::State::Idle; @@ -1792,9 +1797,9 @@ void RPiCameraData::setIspControls(const ControlList &controls) handleState(); } -void RPiCameraData::setDelayedControls(const ControlList &controls) +void RPiCameraData::setDelayedControls(const ControlList &controls, uint32_t delayCookie) { - if (!delayedCtrls_->push(controls)) + if (!delayedCtrls_->push(controls, delayCookie)) LOG(RPI, Error) << "V4L2 DelayedControl set failed"; handleState(); } @@ -1867,13 +1872,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, delayCookie] = 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), delayCookie }); } else { embeddedQueue_.push(buffer); } @@ -2168,6 +2173,8 @@ void RPiCameraData::tryRunPipeline() ipa::RPi::ISPConfig ispPrepare; ispPrepare.bayerBufferId = ipa::RPi::MaskBayerData | bayerId; ispPrepare.controls = std::move(bayerFrame.controls); + ispPrepare.ipaCookie = ipaCookie_++; + ispPrepare.delayCookie = bayerFrame.delayCookie; if (embeddedBuffer) { unsigned int embeddedId = unicam_[Unicam::Embedded].getBufferId(embeddedBuffer); From patchwork Wed Oct 19 09:01:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17632 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 42B3AC3285 for ; Wed, 19 Oct 2022 09:01:28 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C0D2E62E58; Wed, 19 Oct 2022 11:01:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1666170087; bh=/6GhMhetbOE+yc09yQxkOk8kZ5IJvoL23EuHpX7OmxE=; 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=ggKxW1RMVvTDOuEItjnRAUUgYY4A9GSX3+3Bzb87f5RbrlYmcFFKB4Az5Zh4qXaUm PmK6gM/VQRGcVBI+sM3jbwTil8MeKhPGI/AehQHia/abOkWWCd/O2+eD6wkUAyiSFe FjmGRHdEfgfTNY7HGssY6Gb7nT3P0bhiMcixuBGtJGNiiIvbH+rskOXDIXS3bR6fgW d4vW8dCvlThcIRw/4bYjhToDuHdZQDysp4vJGNnkerxrECgnywqw7g06E92K97tVkJ CZfEnVorjCumEri67vgrVyskn5pWq9evyEjon4eMmeqHMVG/1dnkPx5WeXdzZ94i/s ASYpTSSXKVurg== Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5ED5F62E46 for ; Wed, 19 Oct 2022 11:01:24 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="E0HutGw/"; dkim-atps=neutral Received: by mail-wr1-x431.google.com with SMTP id j7so28002922wrr.3 for ; Wed, 19 Oct 2022 02:01:24 -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=Ti3vLKdKN85OxloaVfMzj8nn2D6wytryKDydft3JQig=; b=E0HutGw/ZZpDkjzo3R5CnjJ8lzl/WJc9vZIuxe2ouUZwlTg0e35zISBm99RAzcbtiq ETtTGBRxGGtqakbpdYoDkcik49gmQ/Hxy7J8u9PSRR+l9Wpsbb/dob89AvMZqWhRaFa3 XlKZP3iniiJLYIQj7YKYzCsDbbQbvy4GpJw05NtFyJ/R9poHYa3edAhnOYQeMdHU1CVi nIOUketKPvvatO1PjpKtI+m2RrDpqhnEnUGXNqEtuYg/jOAnG1g3rgtUS2bSk5+Vz0tU moAIxlx5U+HhEQCGxXIbHj4TO+uunAOG3PwRKErcYanfiuiY2aDn4XX05FAsba/tdnr8 aVfg== 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=Ti3vLKdKN85OxloaVfMzj8nn2D6wytryKDydft3JQig=; b=PHzwHcPkxnDbgfhIifhskBsL7TLzXNEP8PCUev/8GDLCffF9s+v007jWdeJFzmJoLv UDXCyti7Na19/1SAn8Nwsiu7xx5nlkAD4p1nhvTOkIcmBKZzUwE5QKgV552dNG7qFE6d vRuBJZdAE+VqNbo21QcY2V3EaQYDU2nK4lSDtcMoM6IfqJ48Zc3GydFMgCLtI0OE98qq wTXdAvFoPHgjeJ6992AgPWxRn1vr7Ex+eOoa5IJnru+1ngRrzSJX0n054dRdpoSq/ANX eF6/k3qvwoT0DW4iGGJ75k/gCbGSIHhRWdnJ/9yRWr+KpAzOSgHCmP8++G7FI5i8PAOe zCbg== X-Gm-Message-State: ACrzQf0XJbHLP6592eJFyy/bD6uHAb7XHBG7z4iKIFG6VjAxyfQRAZX9 q5f1/VdN9hn4Xc8Tf2q0O6KOqJhT8+RfYQ== X-Google-Smtp-Source: AMsMyM7iuAQ/AxrLObElWL/I9hep7QaegpDEU1Vo3U399KIeqj9FRgAaYaCKiyQ47stcfBIyBLNKCA== X-Received: by 2002:a5d:64a8:0:b0:22e:409f:a3cb with SMTP id m8-20020a5d64a8000000b0022e409fa3cbmr4285667wrp.168.1666170083803; Wed, 19 Oct 2022 02:01:23 -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.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Oct 2022 02:01:23 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 19 Oct 2022 10:01:07 +0100 Message-Id: <20221019090107.19975-8-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 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 Reviewed-by: Kieran Bingham --- 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 aed8f68aded9..983745fcad98 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -1029,6 +1029,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.delayCookie]; + 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.