Show a patch.

GET /api/1.1/patches/27192/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 27192,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/27192/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/27192/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20260703153819.1088752-14-barnabas.pocze@ideasonboard.com>",
    "date": "2026-07-03T15:38:15",
    "name": "[RFC,v1,13/17] ipa: ipu3: Port to `AgcMeanLuminanceAlgorithm`",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "1f91451026d5521297fb2f9cd2b24e010881c419",
    "submitter": {
        "id": 216,
        "url": "https://patchwork.libcamera.org/api/1.1/people/216/?format=api",
        "name": "Barnabás Pőcze",
        "email": "barnabas.pocze@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/27192/mbox/",
    "series": [
        {
            "id": 6036,
            "url": "https://patchwork.libcamera.org/api/1.1/series/6036/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=6036",
            "date": "2026-07-03T15:38:02",
            "name": "ipa: libipa: agc rework",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/6036/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/27192/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/27192/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 ABDE5C330F\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  3 Jul 2026 15:38:44 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2422F66008;\n\tFri,  3 Jul 2026 17:38:41 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9AB5365FD1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  3 Jul 2026 17:38:25 +0200 (CEST)",
            "from pb-laptop.local (185.221.140.128.nat.pool.zt.hu\n\t[185.221.140.128])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 8800EDF3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  3 Jul 2026 17:37:39 +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=\"QzvoOIyE\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1783093059;\n\tbh=EpXVn8DUACcO1Qs1kjcPbmVPnUJvJ8nOFUvevW9d86U=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=QzvoOIyEzTfu6hD9qJ5O6crTmPTVHUpGOLbnk/HSMqx/besoS4QQOrYceswZqHWj3\n\tY8z0hgd5EBNi58jyDNywYEJi5b2tMbphUVwCO/JiESoZ5sSqvW3ajOS6Hye9adn+DG\n\tFz+HAGi5nRctzbfrP4HIN32QdP6pv0D11zWfY4Bk=",
        "From": "=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Subject": "[RFC PATCH v1 13/17] ipa: ipu3: Port to `AgcMeanLuminanceAlgorithm`",
        "Date": "Fri,  3 Jul 2026 17:38:15 +0200",
        "Message-ID": "<20260703153819.1088752-14-barnabas.pocze@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.54.0",
        "In-Reply-To": "<20260703153819.1088752-1-barnabas.pocze@ideasonboard.com>",
        "References": "<20260703153819.1088752-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": "Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n---\n src/ipa/ipu3/algorithms/agc.cpp | 128 ++++++++++++-----------------\n src/ipa/ipu3/algorithms/agc.h   |  13 ++-\n src/ipa/ipu3/ipa_context.cpp    |  49 +++---------\n src/ipa/ipu3/ipa_context.h      |  27 +++----\n src/ipa/ipu3/ipu3.cpp           | 138 ++++++--------------------------\n 5 files changed, 104 insertions(+), 251 deletions(-)",
    "diff": "diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp\nindex 5b152dcda2..0ca02390bd 100644\n--- a/src/ipa/ipu3/algorithms/agc.cpp\n+++ b/src/ipa/ipu3/algorithms/agc.cpp\n@@ -48,17 +48,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 +69,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,\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 +95,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,\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@@ -229,50 +233,20 @@ void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame,\n \tHistogram hist = parseStatistics(stats, context.configuration.grid.bdsGrid);\n \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-\tAgcTraits agcTraits{\n-\t\trgbTriples_,\n-\t\t{{\n-\t\t\tcontext.activeState.awb.gains.red,\n-\t\t\tcontext.activeState.awb.gains.blue,\n-\t\t\tcontext.activeState.awb.gains.green,\n-\t\t}},\n-\t\tbdsGrid_,\n-\t};\n-\n-\tutils::Duration newExposureTime;\n-\tdouble aGain, qGain, dGain;\n-\tstd::tie(newExposureTime, aGain, qGain, dGain) =\n-\t\tagc_.calculateNewEv(context.activeState.agc.constraintMode,\n-\t\t\t\t    context.activeState.agc.exposureMode, hist,\n-\t\t\t\t    effectiveExposureValue, agcTraits);\n-\n-\tLOG(IPU3Agc, Debug)\n-\t\t<< \"Divided up exposure time, analogue gain and digital gain are \"\n-\t\t<< newExposureTime << \", \" << aGain << \" and \" << dGain;\n-\n-\tIPAActiveState &activeState = context.activeState;\n-\t/* Update the estimated exposure time and gain. */\n-\tactiveState.agc.exposure = newExposureTime / context.configuration.sensor.lineDuration;\n-\tactiveState.agc.gain = aGain;\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+\tagc_.process(context.configuration.agc, context.activeState.agc, frameContext.agc, {{\n+\t\t.traits = AgcTraits{\n+\t\t\trgbTriples_,\n+\t\t\t{{\n+\t\t\t\tcontext.activeState.awb.gains.red,\n+\t\t\t\tcontext.activeState.awb.gains.blue,\n+\t\t\t\tcontext.activeState.awb.gains.green,\n+\t\t\t}},\n+\t\t\tbdsGrid_,\n+\t\t},\n+\t\t.hist = hist,\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..d0a82949c7 100644\n--- a/src/ipa/ipu3/algorithms/agc.h\n+++ b/src/ipa/ipu3/algorithms/agc.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+\tAgcMeanLuminanceAlgorithm 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..682fe4474f 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_mean_luminance.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 : AgcMeanLuminanceAlgorithm::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 : AgcMeanLuminanceAlgorithm::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 : AgcMeanLuminanceAlgorithm::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 4bdc4b7677..fa8e1031f1 100644\n--- a/src/ipa/ipu3/ipu3.cpp\n+++ b/src/ipa/ipu3/ipu3.cpp\n@@ -165,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@@ -197,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@@ -239,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-\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+\tControlInfoMap::Map ctrlMap;\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@@ -301,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@@ -346,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@@ -465,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@@ -474,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@@ -596,8 +502,10 @@ void IPAIPU3::processStats(const uint32_t frame,\n \n \tIPAFrameContext &frameContext = context_.frameContexts.get(frame);\n \n-\tframeContext.sensor.exposure = sensorControls.get(V4L2_CID_EXPOSURE).get<int32_t>();\n-\tframeContext.sensor.gain = camHelper_->gain(sensorControls.get(V4L2_CID_ANALOGUE_GAIN).get<int32_t>());\n+\tframeContext.sensor = {\n+\t\t.exposure = static_cast<uint32_t>(sensorControls.get(V4L2_CID_EXPOSURE).get<int32_t>()),\n+\t\t.gain = context_.camHelper->gain(sensorControls.get(V4L2_CID_ANALOGUE_GAIN).get<int32_t>()),\n+\t};\n \n \tControlList metadata(controls::controls);\n \n@@ -642,10 +550,12 @@ void IPAIPU3::queueRequest(const uint32_t frame, const ControlList &controls)\n  */\n void IPAIPU3::setControls(unsigned int frame)\n {\n-\tint32_t exposure = context_.activeState.agc.exposure;\n-\tint32_t gain = camHelper_->gainCode(context_.activeState.agc.gain);\n+\tIPAFrameContext &frameContext = context_.frameContexts.get(frame);\n+\n+\tint32_t exposure = frameContext.agc.exposure;\n+\tint32_t gain = context_.camHelper->gainCode(frameContext.agc.gain);\n \n-\tControlList ctrls(sensorCtrls_);\n+\tControlList ctrls(context_.sensorControls);\n \tctrls.set(V4L2_CID_EXPOSURE, exposure);\n \tctrls.set(V4L2_CID_ANALOGUE_GAIN, gain);\n \n",
    "prefixes": [
        "RFC",
        "v1",
        "13/17"
    ]
}