From patchwork Mon Sep 5 07:39:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17297 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 0118BC327D for ; Mon, 5 Sep 2022 07:40:04 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BD25862055; Mon, 5 Sep 2022 09:40:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1662363603; bh=gBEVAsghRyLUxKvoBP8RRSW7iyAeDStcB1KGpH1JaZU=; 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=J88yF96sIEub2NPucSFvrXEkQ0gJm7SyBJc13ut7QQ3MwMWCWbMqS2T/bedPkOOcw Y6DV/G+8xg2x+w+qiJfYpy56pYpu2Hgi3fHTJQTIqd1f8GRYeBKFxK6aSbCt+w13Do jUEogmvIp9eZHxSmV5mHJVg1VUs0m8Cj5FySqn5L53lu8SlMCw6dfItZ435NiKUG2N S07kQkNm02hUcx1khLSNgcuFlkd1+B43gTxbi1qPXdITuXlI2euYdMsbtqr6LqfUg0 bZ4Xs6OaiHShKp7NCBb5ZzEoVb0mDXxLR25z9QCYBGkz3anLFdW+oHcYSGvBQqvs4h lZYPlIPkgioUw== Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7132C6201C for ; Mon, 5 Sep 2022 09:40:02 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="RzxeWYAT"; dkim-atps=neutral Received: by mail-wr1-x435.google.com with SMTP id b5so10129234wrr.5 for ; Mon, 05 Sep 2022 00:40:02 -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=YJjap5Vlhvd2qi+OflmsVt8uhRG4R/2mis0V9sewWMk=; b=RzxeWYATs6sjM/vmO+31Ea/XFnqKmFOpXsEHXj7RnC/iBxhII707W19NOs5R+Wy+E0 XUcM3cHmR8XLMk9yeikOWkVienUav9IEkgG7izLCDJGIyknfPfYMZsTvKl2FxPZknq3g ReziLa//SIf71obNCDHAjKDf5cxnQ3VuHmsrpfx5KFtJskKT+w6ZrVZCECFesgpncyso u52dEmIR7yjCQOl8IoBlqMOayk3lvlzq991jAFl0VtYfnRXarsKfvisHBKjvLcssxasc SoQ7v0zPSdnJ/Na3fltVIY+0mfjJbOzwh9mKZVfO2uw1H13S+wJV5JsaznGRM0ACbofp 9X6g== 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=YJjap5Vlhvd2qi+OflmsVt8uhRG4R/2mis0V9sewWMk=; b=soLZj4n4uIjMcc1665RDulmq0dcAJinlXurmHxeRyFNuNRAfXfI0DLSkAXjHM3OBXr SWTYptheDW1n/0PziCvan6IIMNbHnNgnv0Vd2nPsjwF7459QRJdjrTdY2go0bDdNgBVc vIksbAJ9colCoBIOp6yDGnqGxgIQRkkt2MUwxKGUR+tfZyl5UzUknCCWklONJEKmiTKU GELf38WBmHLuSuHsdMjap0ZFIEM0evaNQkjqtkn++k/gC9VUdURQRsWL+wZNk9OcG1zw LQFJUaIgvZAiQR3Cfs9TwfGekadZlZo+AxdqtSg4GnEeJ625tXmNSLPmo74EcDzf9ArX HIlQ== X-Gm-Message-State: ACgBeo2BIjQRJiBWKXLB+zXbAukZA3Tje8FWC9bjcWAH3ui8LESRrq5x 4JU2B0OSsW6dyNvt9Lv6IGtOCTFSoTH6v6PZ X-Google-Smtp-Source: AA6agR7V7/MW2dRe3hW7BuI3LhiiDqF6fWsmHnQgxyZZN8251xNSJi1xETsg3mBlZlH7J6uhhVAOHw== X-Received: by 2002:a5d:588d:0:b0:225:6e1a:8696 with SMTP id n13-20020a5d588d000000b002256e1a8696mr23374023wrf.512.1662363601833; Mon, 05 Sep 2022 00:40:01 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id v16-20020a5d5910000000b00228a6ce17b4sm1342841wrd.37.2022.09.05.00.40.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 00:40:00 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 5 Sep 2022 08:39:50 +0100 Message-Id: <20220905073956.7342-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220905073956.7342-1-naush@raspberrypi.com> References: <20220905073956.7342-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 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. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Tested-by: David Plowman --- 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..f6e622f1dfba 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 ControlRingBuffer : 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 5 07:39:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17298 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 63A9EC3272 for ; Mon, 5 Sep 2022 07:40:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2066962061; Mon, 5 Sep 2022 09:40:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1662363606; bh=g+yojow+QSITK4eB7dyNWvdns/J7/9ZmNwJ1ghjHEIY=; 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=nm+P+hMKVg2aiuuprv1Cv4nyuBXFH3H9Uax6KL+xUf46ob+YgXNSQrbDKTBCeXvub XO3Yqe9zWncjlC5vDrbeo0+N5umlguTNJ37c5U3AfsRKG/dumOTy8OkOCnDRj2rGrm TPPv/HJGBEuGRI+4DsZMuuhEkGtkc9IrDgTao5QQLgl+VcZha55CgQeYOjvEDM0HPS 4KpPkJoWWPAITclxmIRGnxtMmXUSGT/5wI7c7xqRZlJxMYsea8O4DFBFmu1njYlHM8 MYu7UGEF75BBnovxJNAeoMXJrnHP4rfALncJYhZ2sEaNp9cw9BKvsh2KWxcJIsSG4X nZ0lM6wuULP4Q== Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 185CC6201C for ; Mon, 5 Sep 2022 09:40:04 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="iPefwIYe"; dkim-atps=neutral Received: by mail-wm1-x332.google.com with SMTP id z14-20020a7bc7ce000000b003a5db0388a8so6446870wmk.1 for ; Mon, 05 Sep 2022 00:40:04 -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=TLd3IVP2iO3I4bZNxOYJauQGUqiKFviOy3ElyLrY/78=; b=iPefwIYeatMCNizzzBR4qfU8y2g7kRZg+RSaix+K3Lz6uRqGdp4YuRSo4bxcoR58Hf 55edx+nHo1lfb85uZIyF9BzgOxt3Cx4hkmCKID8MMFQwEtxWpOyiJ1tbJkc1mSHACVCj OnDGacOLXSIUKn/4P83xa9an34MhWJV3nyyq5FlE/x3Yhc/70+r3HR9PXBqXi8WjB/8q uGsdZMyxhgGURQ7PJRIkAgo7sfqq+X+gykENpeN5s2wm4i4mPqLiU4hqsdKVL9/oXB7e OytN+se/wXPIei+7UZZd22yANhHiQqxWYiNrqx0YuZjfAuWtZIMDmIGSkuWmhmWpd5hV EB3A== 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=TLd3IVP2iO3I4bZNxOYJauQGUqiKFviOy3ElyLrY/78=; b=7dBfI920RotyNOI+aQ7K7Cu4e9rgvsOl5xSPz0ont7FF3vj4X24GU3T1d86SGl2Zq6 wEkgD2X5hUjAaOj0gnPF3QceAEV+DWbSHvH4lXdcMkLKmSIo9H63U3Va/TqOxFMdO6eo zXJH5JkGWXRb59kfNTrw5wziGEE2YTi3nru0MUUe5UNzXbd9QR8tmHFRkTmD8sxvZ7jK 042UXNCXAcBTbX+M1Ac12ku+42IH2O6AIpQt6lUAEdhdcSvYB4NSioNgXJtrsQzkxw4U GsSDZaUPKgZLooOlPrYtFbGB9B/Hs8vtUl8h8TXYnkBDvi50X8BYqNdMGx8DfZGLZAi8 fo+g== X-Gm-Message-State: ACgBeo2UFb6PFORZXiXiD3NduLkROsd2ksMEU5TozkKDc2Q21446Pw+T 7Q5QMQ+jyzBbngz2dc3KVCvrC3rbTQ2OkQ5b X-Google-Smtp-Source: AA6agR70xaqn+T2vtJo1y9nmESOLXLR6plPTHBnyCQzrl5RGH7GPtLikn7aikVTD5+mo6jWjFwxqug== X-Received: by 2002:a7b:c045:0:b0:3a5:ff4e:5528 with SMTP id u5-20020a7bc045000000b003a5ff4e5528mr10252712wmc.150.1662363603332; Mon, 05 Sep 2022 00:40:03 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id v16-20020a5d5910000000b00228a6ce17b4sm1342841wrd.37.2022.09.05.00.40.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 00:40:02 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 5 Sep 2022 08:39:51 +0100 Message-Id: <20220905073956.7342-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220905073956.7342-1-naush@raspberrypi.com> References: <20220905073956.7342-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 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 | 17 +++++++++++------ 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, 25 insertions(+), 16 deletions(-) diff --git a/include/libcamera/internal/delayed_controls.h b/include/libcamera/internal/delayed_controls.h index f6e622f1dfba..fa222bb17d23 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_; + ControlRingBuffer cookies_; }; } /* namespace libcamera */ diff --git a/src/libcamera/delayed_controls.cpp b/src/libcamera/delayed_controls.cpp index 777441e8222a..c2198d0e8d77 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,14 @@ 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. * * \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 +183,7 @@ bool DelayedControls::push(const ControlList &controls) << " at index " << queueCount_; } + cookies_[queueCount_] = cookie; queueCount_++; return true; @@ -198,9 +202,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 +222,7 @@ ControlList DelayedControls::get(uint32_t sequence) << " at index " << index; } - return out; + return { out, cookies_[index] }; } /** @@ -276,7 +281,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 b4094898ca6c..d34a906c3cea 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -1848,7 +1848,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 03bbe6b467ae..cec90810ff95 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -1159,8 +1159,9 @@ void PipelineHandlerRkISP1::statReady(FrameBuffer *buffer) if (data->frame_ <= buffer->metadata().sequence) data->frame_ = buffer->metadata().sequence + 1; + auto [controls, cooke] = 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 5 07:39:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17299 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 C9592C3272 for ; Mon, 5 Sep 2022 07:40:08 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 90B2D62068; Mon, 5 Sep 2022 09:40:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1662363608; bh=YG8zKuN4cx17jT26zExVUEUn1t8fvoswfulGuF4ti20=; 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=ne786i4FaRbhmGmZLrf9FCQiI+TsgR8bu97IW40AUTtC2d2XuGHyJERGNA8jaAGC9 FyKOEcDwGOx7Ltgvu/NF1LSlO/gS2Yn8Jq8LKChhCvlcPte61I4wM22uRto/DVUi/r qZxztC9bRPbF2vgQuE63I1aNW9hq/e17in14SKrbyf3upF4f7yhLNkRDZw8dOSZeKW iROC7Idglz6mu45jg5hqqppizfKu1L2IX/jC/f4W3CwDJHpp6oo+8CcE/FaW96b6bl MJijzWpTkIZjnJsX/w4R5cGXauV/S4QBe2lafJgHm1Ep6BvgIpMBEfr0fZ31KRqWX2 iDCrGM+M87MgQ== 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 2137E62058 for ; Mon, 5 Sep 2022 09:40:05 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="ZDdzBBHH"; dkim-atps=neutral Received: by mail-wr1-x431.google.com with SMTP id c11so5883643wrp.11 for ; Mon, 05 Sep 2022 00:40:05 -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=CiHEOsMF91m92inxh4BZs7UxuXbwFOzk4SqKgH3uS1Q=; b=ZDdzBBHHT9L4WCTDaUwPi6eHhy8HOv36oIO+Jyk6j5hO2gpHpEY0IUk/0L/4c7aCqw e4rjaEJC+afnbkQjrkhkK9rkIc6w4gl8+QU1iApFV4RSCXlT/sEXhKfztS5wwF1BwbkI n3JY73ASSLPQIPKeUiNoxbaME3mJrdi31ptEJqDf8H2fN1lywAWJ4Ftns97Tiov8Wt5U 02eZA5gu1tu9JpNMgSyo1jQUzACavz1QDG2yrAChgQeIAfeHaS/LxlLc/hZc9mdZgS9/ 0HzJ/cz1TusOGDI3iiYBb8g5fMHayDqYAQVP2bgVwZB8ViMXK59+8grPyZvucBnsF1aI BVGQ== 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=CiHEOsMF91m92inxh4BZs7UxuXbwFOzk4SqKgH3uS1Q=; b=Ji2sa1jlQhIMeJIDbgRDi4/FmgvM0QljgFQssxpn3ElSfz8OU7NHRejGnrrkBHLs92 B2hSvF/5y+0s7KvuP72FMa4p+tW6lbye/5OU/G4h8fM/7VpbDYG5FOmWxQEZml2eS3t/ FOgC6fzGusEFfxFcrMKoRsx8NmtJ2TvFMKNOPFwFcUdMsbzOmTLBAoFIAGATc7N1fI8Q PldFzkL2v3m7MX6UDZdkjYJhwn0lKANpcYm62JtMoX0LknIJlihW2oFHvjG97w/4lCpk xLsiEEC77kR77hcDXyuWltMG5T+2RUSkRSnufQLlrT5F/0d5930poHoSDwuGMZmN/rTU 8Vkw== X-Gm-Message-State: ACgBeo0vE1sr5Dokyv7ag5KANkkOgTEeGR3mtp7sR3X7j76+o802PzXF hRxNlNwhXxeQnrKcL27knqwyMB3Uotz/9Rhi X-Google-Smtp-Source: AA6agR6tRcgLXyKXer3qlusDcX3wZFciJfIgkVyCbVHYULmivuUtg/BdXO1MjtM8W5tbiUNcczYr6A== X-Received: by 2002:a05:6000:1546:b0:226:ee3f:a5d2 with SMTP id 6-20020a056000154600b00226ee3fa5d2mr14130169wry.76.1662363604619; Mon, 05 Sep 2022 00:40:04 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id v16-20020a5d5910000000b00228a6ce17b4sm1342841wrd.37.2022.09.05.00.40.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 00:40:03 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 5 Sep 2022 08:39:52 +0100 Message-Id: <20220905073956.7342-4-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220905073956.7342-1-naush@raspberrypi.com> References: <20220905073956.7342-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 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 5 07:39:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17300 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 7044EC327D for ; Mon, 5 Sep 2022 07:40:09 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 059CB62067; Mon, 5 Sep 2022 09:40:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1662363609; bh=U7rRLgZNVeakhzpRY7gzpK21lH//TwjRw+pO6UfATzU=; 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=glPjdIuNp0lmXSyIBRUGL6uV6F7XMsk7aXiaPkZYswdyiXt1LTK/9vI9ZLtVk3TIb CI4g2VelbkDlklzaxlfZaiIKZiEq6dWm5oNKMdOc3Hp6pa8QBdu0pqUidLc5APjnhu dd+6nGAQCd0pzBh64RKyWGUxQOfOEgILm0axpFNTYjJEF9a/kkhhuEWZaVzX8CAZ7B YCP6DJted6c6F9BnRZqY/pcENgGbm6ajB0fXHu4LLDekf+rYWC3rQJk4g+Ah/F9G8h 3ahOS5fBZFSV1K0Vvpm/jBhEvNfB/aVpZeFPe7TVw70wUcSOoZ8nOlgaK3W7BS2Kn5 ULpmTEFr/Ph7w== 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 7CDBC62058 for ; Mon, 5 Sep 2022 09:40:06 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="bsXv9JCj"; dkim-atps=neutral Received: by mail-wm1-x334.google.com with SMTP id v7-20020a1cac07000000b003a6062a4f81so7277973wme.1 for ; Mon, 05 Sep 2022 00:40: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=W8bW29zIOyXkNjvwpfgjJZmcaplT23dZq31GBRrrDss=; b=bsXv9JCjyNwv34Sz2Ey7zDI3QNraMutGQ2XnnH017TI8kvrHGlTe4umjB+Lc9mptzc eX6uRxoWv5DbAE5QxiubjxGyz4lq8IxGjhCAN8ARsSsNh4DVOXfakWbM+6dW39T4xoxt BEQCnLlFluMWZmHo7+4bXGmYIIoytSjZCR2hqlRlzMkoXWHPo6uATxQBqhszNzqbaQYU kVj3GTJAF28B80OCl+z83VP5d7gmQ4/AI2xWLop6+rDLKqQsUYQPwt7BRX3zauYRT1Ub rFRKEaAbjmoZKeEtIgZ7jOP+YQZLds4JDAbWcfm3pBnIthft4pCzpB3gxN08HQfdeQK+ +lsQ== 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=W8bW29zIOyXkNjvwpfgjJZmcaplT23dZq31GBRrrDss=; b=Rt7UNMBIU3OglcinhcVPKxzz2BFZmXHRVVDMpMsDcM3BSmHw6OXfa8nTyVK64sg9D5 isOnDSp48b6RevMc5bJHid5zoGhRUPm3MUgCSDtljj+zBlBSCSGmeQK+5s1EC6nUZefI fYlSnzwkqXkHFH5aDsYVCqwxOhwY3l2+QuCHNHhCuGM6qA84AnJwBYlmuvfOk+zsADUF S7pU+n+hudOFvKy9KOWhQ2pvSaaWvV+FsJ7hLDahm8LZp15+G/yZ3OZBToDB5WevM4as BTDPY3V7XGETfSbTBmrvwp3TLM/TaPXvggGuZvaibA8ssfXV1w4rIF2GRlHMBa0mzL8p oO4g== X-Gm-Message-State: ACgBeo23GE3wLvGBX+g4vHt4aGhJguixrbzJXSN9IdWLCcJqoCRof/Ys wh79prPHeRgIoma8lmwa+ikpmLPN1/VadcZS X-Google-Smtp-Source: AA6agR59LEvGm9UrPDqinKBKgUQW0iPRvJgHZGbmyGYOfK5/Niy/ip89Rf7Esv/3ALf0dSDUzw4BLw== X-Received: by 2002:a05:600c:4148:b0:3a5:4f94:577b with SMTP id h8-20020a05600c414800b003a54f94577bmr10107956wmm.167.1662363605834; Mon, 05 Sep 2022 00:40:05 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id v16-20020a5d5910000000b00228a6ce17b4sm1342841wrd.37.2022.09.05.00.40.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 00:40:04 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 5 Sep 2022 08:39:53 +0100 Message-Id: <20220905073956.7342-5-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220905073956.7342-1-naush@raspberrypi.com> References: <20220905073956.7342-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 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 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/ipa/raspberrypi/controller/metadata.h b/src/ipa/raspberrypi/controller/metadata.h index 0f7ebfaf4c25..3816e9f8536d 100644 --- a/src/ipa/raspberrypi/controller/metadata.h +++ b/src/ipa/raspberrypi/controller/metadata.h @@ -78,6 +78,18 @@ public: data_.merge(other.data_); } + void mergeCopy(Metadata &other) + { + std::scoped_lock lock(mutex_, other.mutex_); + for (auto &kv : other.data_) { + /* + * If the metadata key exists, ignore this item and copy + * only unique key/value pairs. + */ + data_.insert(kv); + } + } + template T *getLocked(std::string const &tag) { From patchwork Mon Sep 5 07:39:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17301 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 03D1BC327E for ; Mon, 5 Sep 2022 07:40:09 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9911D62070; Mon, 5 Sep 2022 09:40:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1662363609; bh=VfIc76xxCBkQTU6St66/eRRU9AtqP02ewDytavvodXI=; 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=Eh1gMniuj12ODuB+83gBrSB8sHWBO0MFbiiRSnAqydDMfA94utJU3oug1UtcA5SIr 7W85Yl44rqFBEb0XNv9x3EpOlwMKYjT+Kvgn+sLKtGwrArgtIeLJIZOtJQdRUDlMki sJoQ8tHrRwIKYhTGVpty4yyPX05ws9TNeq+hrUb0MlGZlHH9kMFGNDj18OlWgOrbuu yaKgd/c5H8hJiyhPNNXFx0ifTSB8p5zqau7NYcL17b4aCPf7vLn5Pt2rnYR0+HK01x 3RHz0R2EyK+CeGnkO+tuAuu0Ai4Qn8szEF552ITe0rEznYtki7HYyuJVodFr1thLUj Y3XHhIUb1no8g== 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 DFD1A62067 for ; Mon, 5 Sep 2022 09:40:07 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="XlKEgAn/"; dkim-atps=neutral Received: by mail-wr1-x42f.google.com with SMTP id e13so10144731wrm.1 for ; Mon, 05 Sep 2022 00:40:07 -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=Qqc/dg1qIaUBbIhfBkvNsu6duUiVZA3Iti9oNkXI1rw=; b=XlKEgAn//gRHcABQNgOvR336PGHhtsG6B90b98lkTAy7f99y/qOf3tY/sXkILrioYB J/qehj2NQXbHn43XJhGNn07Y77eOylVFAlTriee/nRzObk5aeDy2VGlBKPOeUXKQJLmp I1h7hhkhErl0h/ErTYe0bwfuYfbTQJCWpXkzkaSfwsWPFTI9rt1kdJSbTkJzb6fTVIKo rSacNNwdHPomnFwYWGUQRcXd3lokbmx4FCYfhAQ5aviAggQqi4z3Xg9boV/zYPl/Nn1n z3cP6lsBZFGROP20UQKEN3Xbf5JqsGD8Vdvi+aowU09YPvct4yeehX6nsih/7w6G3kn9 oGNA== 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=Qqc/dg1qIaUBbIhfBkvNsu6duUiVZA3Iti9oNkXI1rw=; b=X9Oijikj/BATXTFLyrL20IDRWFoPDtxNuF9Spx3i6rt0GneUue89jqESapTLhNalqw YnwQ7TJ/XOpepB9zLaJlQDAhQmKlxJLVafsSdqKBBm/kcXdqCvqaiJylc8m5nCqrLsoM 1PPQyY4QjDTaTqqMusvtULhtEh8W95lL7F9HTwLUIJpzKNRqTDEevzcdAS569sBv2nX4 bcGiVxGIbVW/mIVmtkCwzKPUUNBczrCHBK6J7e4FTLJ97FpCwmPLBXb6Mcetx3Hh8HrZ R/LkUBSJnSK6dTBu7eoaARXNdqdWFToZTPyJvbpzsdeUfD/gnMGdxeTIjTVDvPPuxQdP 5SCg== X-Gm-Message-State: ACgBeo1CJegVyc2SSsk5yzu+MAQhtwUTdpknHgbBXhdLZfJ3h7ugZeLV 4K4VSCQW0FiRxhUGyhX29PHcct7tu+yoxDLP X-Google-Smtp-Source: AA6agR6wROAsk8puiJOJbaC5rW8UGT5UqO0I+Dyx1lepjO/vL0CtHw/YLfGkmJrXLJyMHsf3wpBMHw== X-Received: by 2002:a5d:64a4:0:b0:226:df7c:2e5d with SMTP id m4-20020a5d64a4000000b00226df7c2e5dmr18520057wrp.416.1662363607324; Mon, 05 Sep 2022 00:40:07 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id v16-20020a5d5910000000b00228a6ce17b4sm1342841wrd.37.2022.09.05.00.40.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 00:40:06 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 5 Sep 2022 08:39:54 +0100 Message-Id: <20220905073956.7342-6-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220905073956.7342-1-naush@raspberrypi.com> References: <20220905073956.7342-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 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 5 07:39:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17302 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 8433FC3272 for ; Mon, 5 Sep 2022 07:40:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1C46862076; Mon, 5 Sep 2022 09:40:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1662363611; bh=HepHC9Nxj5KfTuENUVpqffKzK4BBpq4Gyfr3StYe2mw=; 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=aYslv1ZQrN7NJPWnFkd0hYkngRcR7hlQ7IDpS2o43guuW7KP/lEN/aqhQmM/nKQAC r39pA1TN8W9WgI0d+BvVBglghRY8r7JbEyKZDFo2B6sJXqXf4Sm3RBGMQNc+fOr9jO +7i5nlrn4eFhkmMfgldvwsYbfOSm5hjpDdjV9iAd64JkQrRBlIeyMnQZNFcLXyPjqS kriOr2AUFy4YAXi9yTlOEgfHJTNKztksQYdKWGutZlXPtQ0dq1McaDorZUbAOEB8rf LdtXNMkfxM766TUN/hQSLdJZFolUhrMmJhkkxs0F0QOapiAcoJ2uHeoKGdE4fES4Yu 7bOepJOa69XZQ== Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 723A76206A for ; Mon, 5 Sep 2022 09:40:09 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="KIo9loSJ"; dkim-atps=neutral Received: by mail-wm1-x331.google.com with SMTP id i188-20020a1c3bc5000000b003a7b6ae4eb2so7273595wma.4 for ; Mon, 05 Sep 2022 00:40: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=wY8QaiimazJlQuDYAQIxMBOCIKxqVsqdc+VzLIYLd4A=; b=KIo9loSJ3iTAMNp3kjzcZff4CxcypzKBTtzoffglQh8hJxMrPOxyTNAio1TWACFtvE YybFm3tcTyxvCQzbSkBsxFk8xJAz+p5VlfEOkc2GpuqkW+O5wod0WF/h3xSR8kkVyZF2 P+iwltl4UlsF3Rs7OyWSTB2E4fg95xLQM9WCipmH9RlGVoId9WzRVG++6lGd6xbw5Kwz taGLHWynSvrLlBIalhzIp6drag8z6p797U+URzgyTeo/gfLGa5gfp/WMljJGBvYHjm5U xEVUhrnuH4P9j2kj6CpmDEwFOIxK6QR/lQbHpw0z5ApSFrZtJ8CO7DG8s+wYYRMuWl47 V51A== 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=wY8QaiimazJlQuDYAQIxMBOCIKxqVsqdc+VzLIYLd4A=; b=OzI4J+h/rfS1FTf1rYLXQlckG6ymmnl1AAIquHh7kymFV4bn3cD9ZYmjqBLHVIvFaM RTcqtzS2zu0JXtxjfh6jcrkO4oFo6esuJ+R1M0NhxxUqCm8nNijfc3BB+quF46D5kpBe lfHZrzIekWwuw5u/H5yu4j3JB1s96bKSce7dWDCwHGZCYe1+ek9tAIFFvfnFiCB9f/lM he5GnC44YMMwEeLy7iw7schcN0YZ10OC5c/n1BzbYxFev40lW6Ar/iY3SSuJchl1V45h /kR3XUt1fl8/ceMjGinwGrLSk9xHFO+RO7m21n2w0Wz2PeM2nBE3x24nJwUqGARvP8EE PAJQ== X-Gm-Message-State: ACgBeo0HUOhKY65UhgulpEuUTUSQscCRcz61trQBA8+QaLB2C1eRdmY3 X0QaGXXGmYTWG3JK5Y66W5PAcH702J+anSjJ X-Google-Smtp-Source: AA6agR5hSSxGq3UnLJLqJCF0i3e4Qzy+puCMbcgWj9lp8ghT9vYbI9A1xoDGCVgCcqfPHb5Fb7Bcwg== X-Received: by 2002:a05:600c:1c95:b0:3a5:c28a:df3e with SMTP id k21-20020a05600c1c9500b003a5c28adf3emr10117329wms.40.1662363608666; Mon, 05 Sep 2022 00:40:08 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id v16-20020a5d5910000000b00228a6ce17b4sm1342841wrd.37.2022.09.05.00.40.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 00:40:07 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 5 Sep 2022 08:39:55 +0100 Message-Id: <20220905073956.7342-7-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220905073956.7342-1-naush@raspberrypi.com> References: <20220905073956.7342-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 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 d34a906c3cea..4d4c9e1fb9c4 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(); @@ -259,6 +259,7 @@ public: struct BayerFrame { FrameBuffer *buffer; ControlList controls; + unsigned int ipaCookie; }; std::queue bayerQueue_; @@ -1784,9 +1785,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(); } @@ -1848,13 +1849,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); } @@ -2148,6 +2149,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 5 07:39:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17303 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 228D8C327D for ; Mon, 5 Sep 2022 07:40:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CCB1062054; Mon, 5 Sep 2022 09:40:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1662363611; bh=3D5mP/TcXrH/mVvjO0UQb80rXuYUzyT8+7a/q2SMD+0=; 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=RsEe7nDs+0zkW31eCEQFxzlXihxsfC9B+ptScrxo9YnIKpxjLechULX4LBFPlv6Cw 5ZTqD3bE1rap8rRJWLPkfv61ElQnVNSvyEXyU4/ITb0FafqUk1qOFzXG3peBIQgVtq 9jULVb+8bfcwL4N/Xtlfr1AlaruvqCOHyGZpKx4qkTJV6Ew8g/Wg5GWLzXdQ/FpqRn akYMhjVK+9iHKjDUu0QFiSytp30Ob6DkBI2mpOFJElbLVxXCCsoSZgxL9l7YsFPuWC SBjjdS+8zxoXjpmcXA2S02Tkh98uTQhcMcDs6g1838rt8iH9C4hvTRY02Hnfj4BvnW 11GJF6pupwz0Q== 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 6106362065 for ; Mon, 5 Sep 2022 09:40:10 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="jsBT35t0"; dkim-atps=neutral Received: by mail-wr1-x432.google.com with SMTP id w5so10093961wrn.12 for ; Mon, 05 Sep 2022 00:40:10 -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=1Zzkg/UuOevXN4rX2S7SZgpXxqbkmqHLsiA2gpwjQi4=; b=jsBT35t0KA87kcyF6jlH/vJOqYEn1RJg8Wa1EfUCGylFDWWPEMmBO+TOIOaCLp4xrU kYKYRmNuDVWOQSNjTXpxZMODAWx6u8mOeKImIbpsL27XXBqKg4DYn7PUs2NsS/LeY3Ql kY7fUHweA2bQStPxlyItsBKLotd8HjCwpj1suhZDY9VmO5MJ2KzRQcQUG+qOZJrEVLyu qxcXy9Myxopgbqa6rPmOIvwh4E4K6L92IW6JfUCgJRIywM7ggh7wdgvQtiZ4VaAHNReT kn1hJYscOIZDpn98EZyaEmPRLkdaQkSSMPqilyMFQgKb3+u46NoyAd6rssqrfCc8gQCO rMzg== 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=1Zzkg/UuOevXN4rX2S7SZgpXxqbkmqHLsiA2gpwjQi4=; b=ydlHuM7c3USudfQhyXN9yX28sQNndwCR6CjDYau6y334skIOccl5ky6usZmF2ehTrZ lQx+bA/YDTL96H9U54OU240RNINNOZzsmuIS+PTq27lR3Xnh67221rJ5m4EpivH8MnFM 9vuPBiqyi2W2ETXKkYqG4DrmK0fyVcdIvmv4IDR/uUd+vc423y8Z3Kjahn9WHHFy2HnP 0TQw2VJYQ277w/WCIqVny4LMEJ/z9QZemGIZOkAsbgkIlk7amBJSoRY9p6RE6dLfXdn5 vTfwWEotSexuaooa/cSelZPezrdyrSXSvt+iyYimrRulP/EnOPA0PHEhX/23AxPaYfyt ckkg== X-Gm-Message-State: ACgBeo3qrmCr9G3ZUHQAofIDFh1MH6YJNBdpV36+wLF+Q2oYtXIW4DbR oKuJqOZrmFzb67U73ebrKeU4KTh7M+N5VPgK X-Google-Smtp-Source: AA6agR4xzg0gtgpYU/fT/47szjBEI43SDO+ibPHRoZfIEH5afo5ikE1Vro8mCv2Q1QAeiHDVOX/NVQ== X-Received: by 2002:adf:e112:0:b0:21d:7195:3a8d with SMTP id t18-20020adfe112000000b0021d71953a8dmr24437585wrz.371.1662363609820; Mon, 05 Sep 2022 00:40:09 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id v16-20020a5d5910000000b00228a6ce17b4sm1342841wrd.37.2022.09.05.00.40.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 00:40:08 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 5 Sep 2022 08:39:56 +0100 Message-Id: <20220905073956.7342-8-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220905073956.7342-1-naush@raspberrypi.com> References: <20220905073956.7342-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 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.