{"id":14593,"url":"https://patchwork.libcamera.org/api/patches/14593/?format=json","web_url":"https://patchwork.libcamera.org/patch/14593/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20211113084947.21892-4-jeanmichel.hautbois@ideasonboard.com>","date":"2021-11-13T08:49:36","name":"[libcamera-devel,v5,03/14] ipa: ipu3: Use sensor controls to update frameContext","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"e2b8afcf0bf05625cd0bbc6b9aecc22e14b15dd3","submitter":{"id":75,"url":"https://patchwork.libcamera.org/api/people/75/?format=json","name":"Jean-Michel Hautbois","email":"jeanmichel.hautbois@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/14593/mbox/","series":[{"id":2717,"url":"https://patchwork.libcamera.org/api/series/2717/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2717","date":"2021-11-13T08:49:33","name":"IPA: IPU3: Introduce per-frame controls","version":5,"mbox":"https://patchwork.libcamera.org/series/2717/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/14593/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/14593/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 53A79C324E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 13 Nov 2021 08:49:58 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5C1EE603B5;\n\tSat, 13 Nov 2021 09:49:56 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5E63460368\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 13 Nov 2021 09:49:51 +0100 (CET)","from tatooine.ideasonboard.com (unknown\n\t[IPv6:2a01:e0a:169:7140:4d35:9445:6881:4ffd])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 132C4E0C;\n\tSat, 13 Nov 2021 09:49:51 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"Nw+cLrrT\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1636793391;\n\tbh=2bJqhll3vqe8ksNtFPj2X2w6mRPKr3rqtiWbi97iWSc=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=Nw+cLrrTY8k1oiIDQA/a9CFbopHrvrx/cF/77Kc5dq9418CqDLiNcPOMDJOKxYwvy\n\tyHY5LAt5SVHqYKRaZA0t3LLSixtbmFwqN3wNlWj3eemPPQCopDxHQpsTrmV17xDGlb\n\tJbgDQ65GtDjAPlSGuNZbszgit43xetbW1XeItTa8=","From":"Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Sat, 13 Nov 2021 09:49:36 +0100","Message-Id":"<20211113084947.21892-4-jeanmichel.hautbois@ideasonboard.com>","X-Mailer":"git-send-email 2.32.0","In-Reply-To":"<20211113084947.21892-1-jeanmichel.hautbois@ideasonboard.com>","References":"<20211113084947.21892-1-jeanmichel.hautbois@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v5 03/14] ipa: ipu3: Use sensor controls\n\tto update frameContext","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"The pipeline handler populates the new sensorControls ControlList, to\nhave the effective exposure and gain values for the current frame. This\nis done when a statistics buffer is received.\n\nMake those values the frameContext::sensor values for the frame when the\nEventStatReady event is received.\n\nAGC also needs to use frameContext.sensor as its input values and\nframeContext.agc as its output values. Modify computeExposure by passing\nit the frameContext instead of individual exposure and gain values.\n\nSigned-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nReviewed-by: Umang Jain <umang.jain@ideasonboard.com>\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n---\n src/ipa/ipu3/algorithms/agc.cpp | 19 ++++++++++---------\n src/ipa/ipu3/algorithms/agc.h   |  2 +-\n src/ipa/ipu3/ipa_context.cpp    | 11 +++++++++++\n src/ipa/ipu3/ipa_context.h      |  5 +++++\n src/ipa/ipu3/ipu3.cpp           |  3 +++\n 5 files changed, 30 insertions(+), 10 deletions(-)","diff":"diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp\nindex b5d736c1..5723f6f3 100644\n--- a/src/ipa/ipu3/algorithms/agc.cpp\n+++ b/src/ipa/ipu3/algorithms/agc.cpp\n@@ -169,10 +169,9 @@ void Agc::filterExposure()\n \n /**\n  * \\brief Estimate the new exposure and gain values\n- * \\param[inout] exposure The exposure value reference as a number of lines\n- * \\param[inout] gain The gain reference to be updated\n+ * \\param[inout] frameContext The shared IPA frame Context\n  */\n-void Agc::computeExposure(uint32_t &exposure, double &analogueGain)\n+void Agc::computeExposure(IPAFrameContext &frameContext)\n {\n \t/* Algorithm initialization should wait for first valid frames */\n \t/* \\todo - have a number of frames given by DelayedControls ?\n@@ -189,6 +188,10 @@ void Agc::computeExposure(uint32_t &exposure, double &analogueGain)\n \t\treturn;\n \t}\n \n+\t/* Get the effective exposure and gain applied on the sensor. */\n+\tuint32_t exposure = frameContext.sensor.exposure;\n+\tdouble analogueGain = frameContext.sensor.gain;\n+\n \t/* Estimate the gain needed to have the proportion wanted */\n \tdouble evGain = kEvGainTarget * knumHistogramBins / iqMean_;\n \n@@ -233,8 +236,9 @@ void Agc::computeExposure(uint32_t &exposure, double &analogueGain)\n \t\t\t    << shutterTime << \" and \"\n \t\t\t    << stepGain;\n \n-\texposure = shutterTime / lineDuration_;\n-\tanalogueGain = stepGain;\n+\t/* Update the estimated exposure and gain. */\n+\tframeContext.agc.exposure = shutterTime / lineDuration_;\n+\tframeContext.agc.gain = stepGain;\n \n \t/*\n \t * Update the exposure value for the next process call.\n@@ -257,11 +261,8 @@ void Agc::computeExposure(uint32_t &exposure, double &analogueGain)\n  */\n void Agc::process(IPAContext &context, const ipu3_uapi_stats_3a *stats)\n {\n-\t/* Get the latest exposure and gain applied */\n-\tuint32_t &exposure = context.frameContext.agc.exposure;\n-\tdouble &analogueGain = context.frameContext.agc.gain;\n \tmeasureBrightness(stats, context.configuration.grid.bdsGrid);\n-\tcomputeExposure(exposure, analogueGain);\n+\tcomputeExposure(context.frameContext);\n \tframeCount_++;\n }\n \ndiff --git a/src/ipa/ipu3/algorithms/agc.h b/src/ipa/ipu3/algorithms/agc.h\nindex 69e0b831..f0db25ee 100644\n--- a/src/ipa/ipu3/algorithms/agc.h\n+++ b/src/ipa/ipu3/algorithms/agc.h\n@@ -34,7 +34,7 @@ private:\n \tvoid measureBrightness(const ipu3_uapi_stats_3a *stats,\n \t\t\t       const ipu3_uapi_grid_config &grid);\n \tvoid filterExposure();\n-\tvoid computeExposure(uint32_t &exposure, double &gain);\n+\tvoid computeExposure(IPAFrameContext &frameContext);\n \n \tuint64_t frameCount_;\n \tuint64_t lastFrame_;\ndiff --git a/src/ipa/ipu3/ipa_context.cpp b/src/ipa/ipu3/ipa_context.cpp\nindex 2355a9c7..a7ff957d 100644\n--- a/src/ipa/ipu3/ipa_context.cpp\n+++ b/src/ipa/ipu3/ipa_context.cpp\n@@ -119,6 +119,17 @@ namespace libcamera::ipa::ipu3 {\n  * \\brief White balance gain for B channel\n  */\n \n+/**\n+ * \\var IPAFrameContext::sensor\n+ * \\brief Effective sensor values\n+ *\n+ * \\var IPAFrameContext::sensor.exposure\n+ * \\brief Exposure time expressed as a number of lines\n+ *\n+ * \\var IPAFrameContext::sensor.gain\n+ * \\brief Analogue gain multiplier\n+ */\n+\n /**\n  * \\var IPAFrameContext::toneMapping\n  * \\brief Context for ToneMapping and Gamma control\ndiff --git a/src/ipa/ipu3/ipa_context.h b/src/ipa/ipu3/ipa_context.h\nindex 1e46c61a..a5a19800 100644\n--- a/src/ipa/ipu3/ipa_context.h\n+++ b/src/ipa/ipu3/ipa_context.h\n@@ -47,6 +47,11 @@ struct IPAFrameContext {\n \t\t} gains;\n \t} awb;\n \n+\tstruct {\n+\t\tuint32_t exposure;\n+\t\tdouble gain;\n+\t} sensor;\n+\n \tstruct {\n \t\tdouble gamma;\n \t\tstruct ipu3_uapi_gamma_corr_lut gammaCorrection;\ndiff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp\nindex bcc3863b..38e86e58 100644\n--- a/src/ipa/ipu3/ipu3.cpp\n+++ b/src/ipa/ipu3/ipu3.cpp\n@@ -549,6 +549,9 @@ void IPAIPU3::processEvent(const IPU3Event &event)\n \t\tconst ipu3_uapi_stats_3a *stats =\n \t\t\treinterpret_cast<ipu3_uapi_stats_3a *>(mem.data());\n \n+\t\tcontext_.frameContext.sensor.exposure = event.sensorControls.get(V4L2_CID_EXPOSURE).get<int32_t>();\n+\t\tcontext_.frameContext.sensor.gain = camHelper_->gain(event.sensorControls.get(V4L2_CID_ANALOGUE_GAIN).get<int32_t>());\n+\n \t\tparseStatistics(event.frame, event.frameTimestamp, stats);\n \t\tbreak;\n \t}\n","prefixes":["libcamera-devel","v5","03/14"]}