{"id":27477,"url":"https://patchwork.libcamera.org/api/patches/27477/?format=json","web_url":"https://patchwork.libcamera.org/patch/27477/","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":"<20260723154327.1357866-29-barnabas.pocze@ideasonboard.com>","date":"2026-07-23T15:43:11","name":"[RFC,v2,28/43] ipa: ipu3: agc: Port to `AgcAlgorithm`","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"633835c944530286d66587898c483296fde74dd6","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/people/216/?format=json","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/27477/mbox/","series":[{"id":6075,"url":"https://patchwork.libcamera.org/api/series/6075/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=6075","date":"2026-07-23T15:42:43","name":"ipa: libipa: agc rework","version":2,"mbox":"https://patchwork.libcamera.org/series/6075/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/27477/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/27477/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 DFA04C330F\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 23 Jul 2026 15:44:13 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6618667F61;\n\tThu, 23 Jul 2026 17:44:13 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C565167EE9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 23 Jul 2026 17:43:37 +0200 (CEST)","from pb-laptop.local (185.182.215.156.nat.pool.zt.hu\n\t[185.182.215.156])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id DDA991F0F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 23 Jul 2026 17:42:36 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"DlBOGd7F\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1784821357;\n\tbh=Vt7om6ccARtXL5GpKXsiQHPVFf5cfN3oZo6/DWPDRVs=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=DlBOGd7FUmDSX6+cKQmYizhVkzO0mvup/BaxBlelrBQ46DsC00o40NCweSOMKVvmR\n\t/flyXBrYxyEBdHfZ/QTMyHXsL99+wggY4Y33/Ub7cNaYl6ilUyeWag2TN1qGSQ6tWt\n\troGNq4/OL2OzcvDMDPLn7VQNlFMVjaRQHiOqpvl4=","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Subject":"[RFC PATCH v2 28/43] ipa: ipu3: agc: Port to `AgcAlgorithm`","Date":"Thu, 23 Jul 2026 17:43:11 +0200","Message-ID":"<20260723154327.1357866-29-barnabas.pocze@ideasonboard.com>","X-Mailer":"git-send-email 2.55.0","In-Reply-To":"<20260723154327.1357866-1-barnabas.pocze@ideasonboard.com>","References":"<20260723154327.1357866-1-barnabas.pocze@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","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":"Use the `AgcAlgorithm` class to implement the ipu3 agc algorithm.\n\nSigned-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n---\n src/ipa/ipu3/algorithms/agc.cpp | 108 ++++++++++---------------\n src/ipa/ipu3/algorithms/agc.h   |  15 ++--\n src/ipa/ipu3/ipa_context.cpp    |  49 +++---------\n src/ipa/ipu3/ipa_context.h      |  27 +++----\n src/ipa/ipu3/ipu3.cpp           | 135 +++++---------------------------\n 5 files changed, 92 insertions(+), 242 deletions(-)","diff":"diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp\nindex e74db62960..c9ea02ed00 100644\n--- a/src/ipa/ipu3/algorithms/agc.cpp\n+++ b/src/ipa/ipu3/algorithms/agc.cpp\n@@ -8,7 +8,6 @@\n #include \"agc.h\"\n \n #include <algorithm>\n-#include <chrono>\n \n #include <libcamera/base/log.h>\n #include <libcamera/base/utils.h>\n@@ -48,17 +47,10 @@ namespace ipa::ipu3::algorithms {\n \n LOG_DEFINE_CATEGORY(IPU3Agc)\n \n-/* Minimum limit for analogue gain value */\n-static constexpr double kMinAnalogueGain = 1.0;\n-\n-/* \\todo Honour the FrameDurationLimits control instead of hardcoding a limit */\n-static constexpr utils::Duration kMaxExposureTime = 60ms;\n-\n /* Histogram constants */\n static constexpr uint32_t knumHistogramBins = 256;\n \n Agc::Agc()\n-\t: minExposureTime_(0s), maxExposureTime_(0s)\n {\n }\n \n@@ -76,11 +68,18 @@ int Agc::init(IPAContext &context, const ValueNode &tuningData)\n {\n \tint ret;\n \n-\tret = agc_.parseTuningData(tuningData);\n+\tret = agc_.init(tuningData);\n \tif (ret)\n \t\treturn ret;\n \n-\tcontext.ctrlMap.merge(agc_.controls());\n+\tret = agc_.configure(context.configuration.agc, context.activeState.agc, {\n+\t\t.sensor = context.camHelper.get(),\n+\t\t.sensorInfo = context.sensorInfo,\n+\t\t.sensorControls = context.sensorControls,\n+\t\t.ctrlMap = context.ctrlMap,\n+\t});\n+\tif (ret)\n+\t\treturn ret;\n \n \treturn 0;\n }\n@@ -95,32 +94,36 @@ int Agc::init(IPAContext &context, const ValueNode &tuningData)\n int Agc::configure(IPAContext &context,\n \t\t   [[maybe_unused]] const IPAConfigInfo &configInfo)\n {\n-\tconst IPASessionConfiguration &configuration = context.configuration;\n-\tIPAActiveState &activeState = context.activeState;\n-\n-\tstride_ = configuration.grid.stride;\n-\tbdsGrid_ = configuration.grid.bdsGrid;\n-\n-\tminExposureTime_ = configuration.agc.minExposureTime;\n-\tmaxExposureTime_ = std::min(configuration.agc.maxExposureTime,\n-\t\t\t\t    kMaxExposureTime);\n-\n-\tminAnalogueGain_ = std::max(configuration.agc.minAnalogueGain, kMinAnalogueGain);\n-\tmaxAnalogueGain_ = configuration.agc.maxAnalogueGain;\n-\n-\t/* Configure the default exposure and gain. */\n-\tactiveState.agc.gain = minAnalogueGain_;\n-\tactiveState.agc.exposure = 10ms / configuration.sensor.lineDuration;\n-\n-\tcontext.activeState.agc.constraintMode = agc_.constraintModes().begin()->first;\n-\tcontext.activeState.agc.exposureMode = agc_.exposureModeHelpers().begin()->first;\n+\tstride_ =  context.configuration.grid.stride;\n+\tbdsGrid_ = context.configuration.grid.bdsGrid;\n+\n+\treturn agc_.configure(context.configuration.agc, context.activeState.agc, {\n+\t\t.sensor = context.camHelper.get(),\n+\t\t.sensorInfo = context.sensorInfo,\n+\t\t.sensorControls = context.sensorControls,\n+\t\t.ctrlMap = context.ctrlMap,\n+\t\t.autoAllowed = true, // \\todo if not raw?\n+\t});\n+}\n \n-\t/* \\todo Run this again when FrameDurationLimits is passed in */\n-\tagc_.setLimits(minExposureTime_, maxExposureTime_, minAnalogueGain_,\n-\t\t       maxAnalogueGain_, {});\n-\tagc_.resetFrameCount();\n+/**\n+ * \\copydoc libcamera::ipa::Algorithm::queueRequest\n+ */\n+void Agc::queueRequest(IPAContext &context, [[maybe_unused]] const uint32_t frame,\n+\t\t       IPAFrameContext &frameContext, const ControlList &controls)\n+{\n+\tagc_.queueRequest(context.configuration.agc, context.activeState.agc,\n+\t\t\t  frameContext.agc, controls);\n+}\n \n-\treturn 0;\n+/**\n+ * \\copydoc libcamera::ipa::Algorithm::prepare\n+ */\n+void Agc::prepare(IPAContext &context, [[maybe_unused]] const uint32_t frame,\n+\t\t  IPAFrameContext &frameContext,\n+\t\t  [[maybe_unused]] ipu3_uapi_params *params)\n+{\n+\tagc_.prepare(context.activeState.agc, frameContext.agc);\n }\n \n Histogram Agc::parseStatistics(const ipu3_uapi_stats_3a *stats,\n@@ -228,16 +231,7 @@ void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame,\n {\n \tHistogram hist = parseStatistics(stats, context.configuration.grid.bdsGrid);\n \n-\t/*\n-\t * The Agc algorithm needs to know the effective exposure value that was\n-\t * applied to the sensor when the statistics were collected.\n-\t */\n-\tutils::Duration exposureTime = context.configuration.sensor.lineDuration\n-\t\t\t\t     * frameContext.sensor.exposure;\n-\tdouble analogueGain = frameContext.sensor.gain;\n-\tutils::Duration effectiveExposureValue = exposureTime * analogueGain;\n-\n-\tconst auto &newEv = agc_.calculateNewEv({\n+\tagc_.process(context.configuration.agc, context.activeState.agc, frameContext.agc, {{\n \t\t.traits = AgcTraits{\n \t\t\trgbTriples_,\n \t\t\t{{\n@@ -248,29 +242,9 @@ void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame,\n \t\t\tbdsGrid_,\n \t\t},\n \t\t.yHist = hist,\n-\t\t.effectiveExposureValue = effectiveExposureValue,\n-\t\t.constraintModeIndex = context.activeState.agc.constraintMode,\n-\t\t.exposureModeIndex = context.activeState.agc.exposureMode,\n-\t});\n-\n-\tLOG(IPU3Agc, Debug)\n-\t\t<< \"Divided up exposure time, analogue gain and digital gain are \"\n-\t\t<< newEv.exposureTime << \", \" << newEv.analogueGain << \" and \" << newEv.digitalGain;\n-\n-\tIPAActiveState &activeState = context.activeState;\n-\t/* Update the estimated exposure time and gain. */\n-\tactiveState.agc.exposure = newEv.exposureTime / context.configuration.sensor.lineDuration;\n-\tactiveState.agc.gain = newEv.analogueGain;\n-\n-\tmetadata.set(controls::AnalogueGain, frameContext.sensor.gain);\n-\tmetadata.set(controls::ExposureTime, exposureTime.get<std::micro>());\n-\n-\t/* \\todo Use VBlank value calculated from each frame exposure. */\n-\tuint32_t vTotal = context.configuration.sensor.size.height\n-\t\t\t+ context.configuration.sensor.defVBlank;\n-\tutils::Duration frameDuration = context.configuration.sensor.lineDuration\n-\t\t\t\t      * vTotal;\n-\tmetadata.set(controls::FrameDuration, frameDuration.get<std::micro>());\n+\t\t.exposure = frameContext.sensor.exposure,\n+\t\t.gain = frameContext.sensor.gain,\n+\t}}, metadata);\n }\n \n REGISTER_IPA_ALGORITHM(Agc, \"Agc\")\ndiff --git a/src/ipa/ipu3/algorithms/agc.h b/src/ipa/ipu3/algorithms/agc.h\nindex d08da7600e..634b1f8a7a 100644\n--- a/src/ipa/ipu3/algorithms/agc.h\n+++ b/src/ipa/ipu3/algorithms/agc.h\n@@ -13,7 +13,7 @@\n \n #include <libcamera/geometry.h>\n \n-#include \"libipa/agc_mean_luminance.h\"\n+#include \"libipa/agc.h\"\n #include \"libipa/histogram.h\"\n \n #include \"algorithm.h\"\n@@ -32,6 +32,11 @@ public:\n \n \tint init(IPAContext &context, const ValueNode &tuningData) override;\n \tint configure(IPAContext &context, const IPAConfigInfo &configInfo) override;\n+\tvoid queueRequest(IPAContext &context, const uint32_t frame,\n+\t\t\t  IPAFrameContext &frameContext, const ControlList &controls) override;\n+\tvoid prepare(IPAContext &context, const uint32_t frame,\n+\t\t     IPAFrameContext &frameContext,\n+\t\t     ipu3_uapi_params *params)  override;\n \tvoid process(IPAContext &context, const uint32_t frame,\n \t\t     IPAFrameContext &frameContext,\n \t\t     const ipu3_uapi_stats_3a *stats,\n@@ -41,17 +46,11 @@ private:\n \tHistogram parseStatistics(const ipu3_uapi_stats_3a *stats,\n \t\t\t\t  const ipu3_uapi_grid_config &grid);\n \n-\tutils::Duration minExposureTime_;\n-\tutils::Duration maxExposureTime_;\n-\n-\tdouble minAnalogueGain_;\n-\tdouble maxAnalogueGain_;\n-\n \tuint32_t stride_;\n \tipu3_uapi_grid_config bdsGrid_;\n \tstd::vector<std::tuple<uint8_t, uint8_t, uint8_t>> rgbTriples_;\n \n-\tAgcMeanLuminance agc_;\n+\tAgcAlgorithm agc_;\n };\n \n } /* namespace ipa::ipu3::algorithms */\ndiff --git a/src/ipa/ipu3/ipa_context.cpp b/src/ipa/ipu3/ipa_context.cpp\nindex 3b22f79176..c358b09981 100644\n--- a/src/ipa/ipu3/ipa_context.cpp\n+++ b/src/ipa/ipu3/ipa_context.cpp\n@@ -46,12 +46,21 @@ namespace libcamera::ipa::ipu3 {\n  * \\var IPAContext::configuration\n  * \\brief The IPA session configuration, immutable during the session\n  *\n+ * \\var IPAContext::sensorInfo\n+ * \\brief The IPA camera session details, immutable during the session\n+ *\n+ * \\var IPAContext::sensorControls\n+ * \\brief The camera sensor controls, immutable during the session\n+ *\n  * \\var IPAContext::frameContexts\n  * \\brief Ring buffer of the IPAFrameContext(s)\n  *\n  * \\var IPAContext::activeState\n  * \\brief The current state of IPA algorithms\n  *\n+ * \\var IPAContext::camHelper\n+ * \\brief The camera sensor helper\n+ *\n  * \\var IPAContext::ctrlMap\n  * \\brief A ControlInfoMap::Map of controls populated by the algorithms\n  */\n@@ -95,48 +104,11 @@ namespace libcamera::ipa::ipu3 {\n /**\n  * \\var IPASessionConfiguration::agc\n  * \\brief AGC parameters configuration of the IPA\n- *\n- * \\var IPASessionConfiguration::agc.minExposureTime\n- * \\brief Minimum exposure time supported with the configured sensor\n- *\n- * \\var IPASessionConfiguration::agc.maxExposureTime\n- * \\brief Maximum exposure time supported with the configured sensor\n- *\n- * \\var IPASessionConfiguration::agc.minAnalogueGain\n- * \\brief Minimum analogue gain supported with the configured sensor\n- *\n- * \\var IPASessionConfiguration::agc.maxAnalogueGain\n- * \\brief Maximum analogue gain supported with the configured sensor\n- */\n-\n-/**\n- * \\var IPASessionConfiguration::sensor\n- * \\brief Sensor-specific configuration of the IPA\n- *\n- * \\var IPASessionConfiguration::sensor.lineDuration\n- * \\brief Line duration in microseconds\n- *\n- * \\var IPASessionConfiguration::sensor.defVBlank\n- * \\brief The default vblank value of the sensor\n- *\n- * \\var IPASessionConfiguration::sensor.size\n- * \\brief Sensor output resolution\n  */\n \n /**\n  * \\var IPAActiveState::agc\n  * \\brief Context for the Automatic Gain Control algorithm\n- *\n- * The exposure and gain determined are expected to be applied to the sensor\n- * at the earliest opportunity.\n- *\n- * \\var IPAActiveState::agc.exposure\n- * \\brief Exposure time expressed as a number of lines\n- *\n- * \\var IPAActiveState::agc.gain\n- * \\brief Analogue gain multiplier\n- *\n- * The gain should be adapted to the sensor specific gain code before applying.\n  */\n \n /**\n@@ -185,6 +157,9 @@ namespace libcamera::ipa::ipu3 {\n  *\n  * \\var IPAFrameContext::sensor.gain\n  * \\brief Analogue gain multiplier\n+ *\n+ * \\var IPAFrameContext::agc\n+ * \\brief Per-frame state for the AGC algorithm\n  */\n \n } /* namespace libcamera::ipa::ipu3 */\ndiff --git a/src/ipa/ipu3/ipa_context.h b/src/ipa/ipu3/ipa_context.h\nindex 97fcf06cd4..51133b10d5 100644\n--- a/src/ipa/ipu3/ipa_context.h\n+++ b/src/ipa/ipu3/ipa_context.h\n@@ -15,6 +15,8 @@\n #include <libcamera/controls.h>\n #include <libcamera/geometry.h>\n \n+#include <libipa/agc.h>\n+#include <libipa/camera_sensor_helper.h>\n #include <libipa/fc_queue.h>\n \n namespace libcamera {\n@@ -32,18 +34,8 @@ struct IPASessionConfiguration {\n \t\tipu3_uapi_grid_config afGrid;\n \t} af;\n \n-\tstruct {\n-\t\tutils::Duration minExposureTime;\n-\t\tutils::Duration maxExposureTime;\n-\t\tdouble minAnalogueGain;\n-\t\tdouble maxAnalogueGain;\n+\tstruct Agc : agc::Session {\n \t} agc;\n-\n-\tstruct {\n-\t\tint32_t defVBlank;\n-\t\tutils::Duration lineDuration;\n-\t\tSize size;\n-\t} sensor;\n };\n \n struct IPAActiveState {\n@@ -53,11 +45,7 @@ struct IPAActiveState {\n \t\tbool stable;\n \t} af;\n \n-\tstruct {\n-\t\tuint32_t exposure;\n-\t\tdouble gain;\n-\t\tuint32_t constraintMode;\n-\t\tuint32_t exposureMode;\n+\tstruct Agc : agc::ActiveState {\n \t} agc;\n \n \tstruct {\n@@ -81,6 +69,9 @@ struct IPAFrameContext : public FrameContext {\n \t\tuint32_t exposure;\n \t\tdouble gain;\n \t} sensor;\n+\n+\tstruct Agc : agc::FrameContext {\n+\t} agc;\n };\n \n struct IPAContext {\n@@ -90,10 +81,14 @@ struct IPAContext {\n \t}\n \n \tIPASessionConfiguration configuration;\n+\tIPACameraSensorInfo sensorInfo;\n+\tControlInfoMap sensorControls;\n \tIPAActiveState activeState;\n \n \tFCQueue<IPAFrameContext> frameContexts;\n \n+\tstd::unique_ptr<CameraSensorHelper> camHelper;\n+\n \tControlInfoMap::Map ctrlMap;\n };\n \ndiff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp\nindex 51379808cd..0935050a33 100644\n--- a/src/ipa/ipu3/ipu3.cpp\n+++ b/src/ipa/ipu3/ipu3.cpp\n@@ -6,7 +6,6 @@\n  */\n \n #include <algorithm>\n-#include <array>\n #include <cmath>\n #include <limits>\n #include <map>\n@@ -166,24 +165,15 @@ protected:\n \tstd::string logPrefix() const override;\n \n private:\n-\tvoid updateControls(const IPACameraSensorInfo &sensorInfo,\n-\t\t\t    const ControlInfoMap &sensorControls,\n-\t\t\t    ControlInfoMap *ipaControls);\n-\tvoid updateSessionConfiguration(const ControlInfoMap &sensorControls);\n+\tvoid updateControls(ControlInfoMap *ipaControls);\n \n \tvoid setControls(unsigned int frame);\n \tvoid calculateBdsGrid(const Size &bdsOutputSize);\n \n \tstd::map<unsigned int, MappedFrameBuffer> buffers_;\n \n-\tControlInfoMap sensorCtrls_;\n \tControlInfoMap lensCtrls_;\n \n-\tIPACameraSensorInfo sensorInfo_;\n-\n-\t/* Interface to the Camera Helper */\n-\tstd::unique_ptr<CameraSensorHelper> camHelper_;\n-\n \t/* Local parameter storage */\n \tstruct IPAContext context_;\n };\n@@ -198,36 +188,6 @@ std::string IPAIPU3::logPrefix() const\n \treturn \"ipu3\";\n }\n \n-/**\n- * \\brief Compute IPASessionConfiguration using the sensor information and the\n- * sensor V4L2 controls\n- */\n-void IPAIPU3::updateSessionConfiguration(const ControlInfoMap &sensorControls)\n-{\n-\tconst ControlInfo vBlank = sensorControls.find(V4L2_CID_VBLANK)->second;\n-\tcontext_.configuration.sensor.defVBlank = vBlank.def().get<int32_t>();\n-\n-\tconst ControlInfo &v4l2Exposure = sensorControls.find(V4L2_CID_EXPOSURE)->second;\n-\tint32_t minExposure = v4l2Exposure.min().get<int32_t>();\n-\tint32_t maxExposure = v4l2Exposure.max().get<int32_t>();\n-\n-\tconst ControlInfo &v4l2Gain = sensorControls.find(V4L2_CID_ANALOGUE_GAIN)->second;\n-\tint32_t minGain = v4l2Gain.min().get<int32_t>();\n-\tint32_t maxGain = v4l2Gain.max().get<int32_t>();\n-\n-\t/*\n-\t * When the AGC computes the new exposure values for a frame, it needs\n-\t * to know the limits for exposure time and analogue gain.\n-\t * As it depends on the sensor, update it with the controls.\n-\t *\n-\t * \\todo take VBLANK into account for maximum exposure time\n-\t */\n-\tcontext_.configuration.agc.minExposureTime = minExposure * context_.configuration.sensor.lineDuration;\n-\tcontext_.configuration.agc.maxExposureTime = maxExposure * context_.configuration.sensor.lineDuration;\n-\tcontext_.configuration.agc.minAnalogueGain = camHelper_->gain(minGain);\n-\tcontext_.configuration.agc.maxAnalogueGain = camHelper_->gain(maxGain);\n-}\n-\n /**\n  * \\brief Compute camera controls using the sensor information and the sensor\n  * V4L2 controls\n@@ -240,54 +200,12 @@ void IPAIPU3::updateSessionConfiguration(const ControlInfoMap &sensorControls)\n  * - controls::ExposureTime\n  * - controls::FrameDurationLimits\n  */\n-void IPAIPU3::updateControls(const IPACameraSensorInfo &sensorInfo,\n-\t\t\t     const ControlInfoMap &sensorControls,\n-\t\t\t     ControlInfoMap *ipaControls)\n+void IPAIPU3::updateControls(ControlInfoMap *ipaControls)\n {\n-\tControlInfoMap::Map controls{};\n-\tdouble lineDuration = context_.configuration.sensor.lineDuration.get<std::micro>();\n-\n-\t/*\n-\t * Compute exposure time limits by using line length and pixel rate\n-\t * converted to microseconds. Use the V4L2_CID_EXPOSURE control to get\n-\t * exposure min, max and default and convert it from lines to\n-\t * microseconds.\n-\t */\n-\tconst ControlInfo &v4l2Exposure = sensorControls.find(V4L2_CID_EXPOSURE)->second;\n-\tint32_t minExposure = v4l2Exposure.min().get<int32_t>() * lineDuration;\n-\tint32_t maxExposure = v4l2Exposure.max().get<int32_t>() * lineDuration;\n-\tint32_t defExposure = v4l2Exposure.def().get<int32_t>() * lineDuration;\n-\tcontrols[&controls::ExposureTime] = ControlInfo(minExposure, maxExposure,\n-\t\t\t\t\t\t\tdefExposure);\n+\tControlInfoMap::Map ctrlMap;\n \n-\t/*\n-\t * Compute the frame duration limits.\n-\t *\n-\t * The frame length is computed assuming a fixed line length combined\n-\t * with the vertical frame sizes.\n-\t */\n-\tconst ControlInfo &v4l2HBlank = sensorControls.find(V4L2_CID_HBLANK)->second;\n-\tuint32_t hblank = v4l2HBlank.def().get<int32_t>();\n-\tuint32_t lineLength = sensorInfo.outputSize.width + hblank;\n-\n-\tconst ControlInfo &v4l2VBlank = sensorControls.find(V4L2_CID_VBLANK)->second;\n-\tstd::array<uint32_t, 3> frameHeights{\n-\t\tv4l2VBlank.min().get<int32_t>() + sensorInfo.outputSize.height,\n-\t\tv4l2VBlank.max().get<int32_t>() + sensorInfo.outputSize.height,\n-\t\tv4l2VBlank.def().get<int32_t>() + sensorInfo.outputSize.height,\n-\t};\n-\n-\tstd::array<int64_t, 3> frameDurations;\n-\tfor (unsigned int i = 0; i < frameHeights.size(); ++i) {\n-\t\tuint64_t frameSize = lineLength * frameHeights[i];\n-\t\tframeDurations[i] = frameSize / (sensorInfo.pixelRate / 1000000U);\n-\t}\n-\tcontrols[&controls::FrameDurationLimits] = ControlInfo(frameDurations[0],\n-\t\t\t\t\t\t\t       frameDurations[1],\n-\t\t\t\t\t\t\t       Span<const int64_t, 2>{ { frameDurations[2], frameDurations[2] } });\n-\n-\tcontrols.insert(context_.ctrlMap.begin(), context_.ctrlMap.end());\n-\t*ipaControls = ControlInfoMap(std::move(controls), controls::controls);\n+\tctrlMap.insert(context_.ctrlMap.begin(), context_.ctrlMap.end());\n+\t*ipaControls = ControlInfoMap(std::move(ctrlMap), controls::controls);\n }\n \n /**\n@@ -302,18 +220,19 @@ int IPAIPU3::init(const IPASettings &settings,\n \t\t  const ControlInfoMap &sensorControls,\n \t\t  ControlInfoMap *ipaControls)\n {\n-\tcamHelper_ = CameraSensorHelperFactoryBase::create(settings.sensorModel);\n-\tif (camHelper_ == nullptr) {\n+\tcontext_.camHelper = CameraSensorHelperFactoryBase::create(settings.sensorModel);\n+\tif (!context_.camHelper) {\n \t\tLOG(IPAIPU3, Error)\n \t\t\t<< \"Failed to create camera sensor helper for \"\n \t\t\t<< settings.sensorModel;\n \t\treturn -ENODEV;\n \t}\n \n+\tcontext_.sensorInfo = sensorInfo;\n+\tcontext_.sensorControls = sensorControls;\n+\n \t/* Clean context */\n \tcontext_.configuration = {};\n-\tcontext_.configuration.sensor.lineDuration =\n-\t\tsensorInfo.minLineLength * 1.0s / sensorInfo.pixelRate;\n \n \t/* Load the tuning data file. */\n \tFile file(settings.configurationFile);\n@@ -347,7 +266,7 @@ int IPAIPU3::init(const IPASettings &settings,\n \t\treturn ret;\n \n \t/* Initialize controls. */\n-\tupdateControls(sensorInfo, sensorControls, ipaControls);\n+\tupdateControls(ipaControls);\n \n \treturn 0;\n }\n@@ -466,7 +385,8 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo,\n \t\treturn -ENODATA;\n \t}\n \n-\tsensorInfo_ = configInfo.sensorInfo;\n+\tcontext_.sensorInfo = configInfo.sensorInfo;\n+\tcontext_.sensorControls = configInfo.sensorControls;\n \n \tlensCtrls_ = configInfo.lensControls;\n \n@@ -475,31 +395,16 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo,\n \tcontext_.configuration = {};\n \tcontext_.frameContexts.clear();\n \n-\t/* Initialise the sensor configuration. */\n-\tcontext_.configuration.sensor.lineDuration =\n-\t\tsensorInfo_.minLineLength * 1.0s / sensorInfo_.pixelRate;\n-\tcontext_.configuration.sensor.size = sensorInfo_.outputSize;\n-\n-\t/*\n-\t * Compute the sensor V4L2 controls to be used by the algorithms and\n-\t * to be set on the sensor.\n-\t */\n-\tsensorCtrls_ = configInfo.sensorControls;\n-\n \tcalculateBdsGrid(configInfo.bdsOutputSize);\n \n-\t/* Update the camera controls using the new sensor settings. */\n-\tupdateControls(sensorInfo_, sensorCtrls_, ipaControls);\n-\n-\t/* Update the IPASessionConfiguration using the sensor settings. */\n-\tupdateSessionConfiguration(sensorCtrls_);\n-\n \tfor (const auto &algo : algorithms()) {\n \t\tint ret = algo->configure(context_, configInfo);\n \t\tif (ret)\n \t\t\treturn ret;\n \t}\n \n+\tupdateControls(ipaControls);\n+\n \treturn 0;\n }\n \n@@ -598,7 +503,7 @@ void IPAIPU3::processStats(const uint32_t frame,\n \tIPAFrameContext &frameContext = context_.frameContexts.get(frame);\n \n \tstd::tie(frameContext.sensor.exposure, frameContext.sensor.gain)\n-\t\t= agc::extractControls(sensorControls, camHelper_.get());\n+\t\t= agc::extractControls(sensorControls, context_.camHelper.get());\n \n \tControlList metadata(controls::controls);\n \n@@ -643,10 +548,12 @@ void IPAIPU3::queueRequest(const uint32_t frame, const ControlList &controls)\n  */\n void IPAIPU3::setControls(unsigned int frame)\n {\n-\tControlList ctrls(sensorCtrls_);\n+\tIPAFrameContext &frameContext = context_.frameContexts.get(frame);\n+\n+\tControlList ctrls(context_.sensorControls);\n \tagc::prepareControls(\n-\t\tctrls, camHelper_.get(),\n-\t\tcontext_.activeState.agc.exposure, context_.activeState.agc.gain\n+\t\tctrls, context_.camHelper.get(),\n+\t\tframeContext.agc.exposure, frameContext.agc.gain\n \t);\n \n \tControlList lensCtrls(lensCtrls_);\n","prefixes":["RFC","v2","28/43"]}