Show a patch.

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

{
    "id": 15441,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/15441/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/15441/",
    "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": "<20220310205130.336361-4-umang.jain@ideasonboard.com>",
    "date": "2022-03-10T20:51:30",
    "name": "[libcamera-devel,3/3] ipa: ipu3: Add a IPAFrameContext queue",
    "commit_ref": null,
    "pull_url": null,
    "state": "changes-requested",
    "archived": false,
    "hash": "d929055d6c6585d04408b1e2bdac498313222274",
    "submitter": {
        "id": 86,
        "url": "https://patchwork.libcamera.org/api/1.1/people/86/?format=api",
        "name": "Umang Jain",
        "email": "umang.jain@ideasonboard.com"
    },
    "delegate": {
        "id": 12,
        "url": "https://patchwork.libcamera.org/api/1.1/users/12/?format=api",
        "username": "uajain",
        "first_name": "Umang",
        "last_name": "Jain",
        "email": "umang.jain@ideasonboard.com"
    },
    "mbox": "https://patchwork.libcamera.org/patch/15441/mbox/",
    "series": [
        {
            "id": 2958,
            "url": "https://patchwork.libcamera.org/api/1.1/series/2958/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2958",
            "date": "2022-03-10T20:51:27",
            "name": "ipa: ipu3: IPAFrameContext Queue",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/2958/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/15441/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/15441/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\r\n\t[92.243.16.209])\r\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 86320BF415\r\n\tfor <parsemail@patchwork.libcamera.org>;\r\n\tThu, 10 Mar 2022 20:51:46 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\r\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 37C35601F8;\r\n\tThu, 10 Mar 2022 21:51:46 +0100 (CET)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\r\n\t[213.167.242.64])\r\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C4F60601F8\r\n\tfor <libcamera-devel@lists.libcamera.org>;\r\n\tThu, 10 Mar 2022 21:51:44 +0100 (CET)",
            "from perceval.ideasonboard.com (unknown [103.251.226.203])\r\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 807CB49C;\r\n\tThu, 10 Mar 2022 21:51:43 +0100 (CET)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\r\n\ts=mail; t=1646945506;\r\n\tbh=IVaFY/hnHs02d0E2RY5oc/+SqGASU0V6X5B/MkD0QQE=;\r\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\r\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\r\n\tFrom;\r\n\tb=gfq4zUAI3GbjIu0TVbZpGrhBonyqfxiZ8wV1U2fYofk2lQMhMx4EVDyTqbGc8870I\r\n\tyM6Pyh61+u+kL0irrJ0KrypdWuwD7qai2Ha/HbJEDdwgob2bmj43aBKO1//kYBUSQ3\r\n\tdxkSlkhGLIJX0+8E/Uk7TVSW3ZbmeXzw3QkwTo6c2cZeOOPq61e/mL3OCwxOwnhT8H\r\n\tuNbPJLAgD6om3Y3fEq7qVCyEOQ95aFnwdaQLY6Htu9VzKwrvyLKuTABdRII8Dgm87p\r\n\t+lTv6zhsfhP2Cl9IknR7kdCpzuQImw6KC0BIe2sEMtPUbOyHgFqsaWHUTtZtSPGcR5\r\n\tMk6zg8dm6kqdg==",
            "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\r\n\ts=mail; t=1646945504;\r\n\tbh=IVaFY/hnHs02d0E2RY5oc/+SqGASU0V6X5B/MkD0QQE=;\r\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\r\n\tb=dLMRG4hbmI5BYGCmSlzpjjb/5aIedZGZhiprg44+BQAYgAW28sgzRFexwzhe1lhGM\r\n\t7So8CR31ZVsoyCEuknotqOrcONpOUGhyYR4P5GEIhGmCT+42hsoc79rPSeH4rEU1rn\r\n\tRlLHZdaALPguDf/Lo9AnuSB6Ukl2/I6F/tGXXfCE="
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \r\n\tunprotected) header.d=ideasonboard.com\r\n\theader.i=@ideasonboard.com\r\n\theader.b=\"dLMRG4hb\"; dkim-atps=neutral",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Fri, 11 Mar 2022 02:21:30 +0530",
        "Message-Id": "<20220310205130.336361-4-umang.jain@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.31.1",
        "In-Reply-To": "<20220310205130.336361-1-umang.jain@ideasonboard.com>",
        "References": "<20220310205130.336361-1-umang.jain@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH 3/3] ipa: ipu3: Add a IPAFrameContext queue",
        "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>,\r\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>,\r\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>",
        "From": "Umang Jain via libcamera-devel <libcamera-devel@lists.libcamera.org>",
        "Reply-To": "Umang Jain <umang.jain@ideasonboard.com>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "Having a single IPAFrameContext queue is limiting especially when\nwe need to preserve per-frame controls coming in through\nlibcamera::Request. Right now, we are not processing any controls\non the IPA side (processControls()) but sooner or later we need to\npreserve the controls setting for the frames in the context in a\nretrievable fashion. Hence a std::deque is introduced to preserve\nthe frame context of the incoming request's settings as soon as it is\nqueued.\n\nSince IPAIPU3::processControls() is executed on\nIPU3CameraData::queuePendingRequests() code path, we need to store the\nincoming control setting in a separate IPAFrameContext and push that\ninto the queue. The IPAFrameContext is then dropped when processing for\nthat frame has been finished.\n\nSigned-off-by: Umang Jain <umang.jain@ideasonboard.com>\n---\n src/ipa/ipu3/algorithms/agc.cpp          | 16 ++++-----\n src/ipa/ipu3/algorithms/agc.h            |  4 +--\n src/ipa/ipu3/algorithms/awb.cpp          | 17 +++++-----\n src/ipa/ipu3/algorithms/tone_mapping.cpp | 14 ++++----\n src/ipa/ipu3/ipa_context.cpp             | 42 ++++++++++++++++++++++++\n src/ipa/ipu3/ipa_context.h               | 12 +++++++\n src/ipa/ipu3/ipu3.cpp                    | 41 +++++++++++++++++++----\n 7 files changed, 115 insertions(+), 31 deletions(-)",
    "diff": "diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp\r\nindex cdc1327a..b24744f2 100644\r\n--- a/src/ipa/ipu3/algorithms/agc.cpp\r\n+++ b/src/ipa/ipu3/algorithms/agc.cpp\r\n@@ -87,7 +87,7 @@ int Agc::configure(IPAContext &context,\r\n \t\t   [[maybe_unused]] const IPAConfigInfo &configInfo)\r\n {\r\n \tIPASessionConfiguration &configuration = context.configuration;\r\n-\tIPAFrameContext &frameContext = context.frameContext;\r\n+\tIPAFrameContext &frameContext = context.getFrameContext(0);\r\n \r\n \tstride_ = configuration.grid.stride;\r\n \r\n@@ -182,14 +182,14 @@ utils::Duration Agc::filterExposure(utils::Duration exposureValue)\r\n  * \\param[in] yGain The gain calculated based on the relative luminance target\r\n  * \\param[in] iqMeanGain The gain calculated based on the relative luminance target\r\n  */\r\n-void Agc::computeExposure(IPAContext &context, double yGain,\r\n-\t\t\t  double iqMeanGain)\r\n+void Agc::computeExposure(const uint32_t frame, IPAContext &context,\r\n+\t\t\t  double yGain, double iqMeanGain)\r\n {\r\n \tconst IPASessionConfiguration &configuration = context.configuration;\r\n-\tIPAFrameContext &frameContext = context.frameContext;\r\n \t/* Get the effective exposure and gain applied on the sensor. */\r\n-\tuint32_t exposure = frameContext.sensor.exposure;\r\n-\tdouble analogueGain = frameContext.sensor.gain;\r\n+\tuint32_t exposure = context.prevFrameContext.sensor.exposure;\r\n+\tdouble analogueGain = context.prevFrameContext.sensor.gain;\r\n+\tIPAFrameContext &frameContext = context.getFrameContext(frame);\r\n \r\n \t/* Use the highest of the two gain estimates. */\r\n \tdouble evGain = std::max(yGain, iqMeanGain);\r\n@@ -344,7 +344,7 @@ void Agc::process(const uint32_t frame, IPAContext &context, const ipu3_uapi_sta\r\n \tdouble yTarget = kRelativeLuminanceTarget;\r\n \r\n \tfor (unsigned int i = 0; i < 8; i++) {\r\n-\t\tdouble yValue = estimateLuminance(context.frameContext,\r\n+\t\tdouble yValue = estimateLuminance(context.prevFrameContext,\r\n \t\t\t\t\t\t  context.configuration.grid.bdsGrid,\r\n \t\t\t\t\t\t  stats, yGain);\r\n \t\tdouble extraGain = std::min(10.0, yTarget / (yValue + .001));\r\n@@ -357,7 +357,7 @@ void Agc::process(const uint32_t frame, IPAContext &context, const ipu3_uapi_sta\r\n \t\t\tbreak;\r\n \t}\r\n \r\n-\tcomputeExposure(context, yGain, iqMeanGain);\r\n+\tcomputeExposure(frame, context, yGain, iqMeanGain);\r\n \tframeCount_++;\r\n }\r\n \r\ndiff --git a/src/ipa/ipu3/algorithms/agc.h b/src/ipa/ipu3/algorithms/agc.h\r\nindex e48506e5..f35de05f 100644\r\n--- a/src/ipa/ipu3/algorithms/agc.h\r\n+++ b/src/ipa/ipu3/algorithms/agc.h\r\n@@ -34,8 +34,8 @@ private:\r\n \tdouble measureBrightness(const ipu3_uapi_stats_3a *stats,\r\n \t\t\t\t const ipu3_uapi_grid_config &grid) const;\r\n \tutils::Duration filterExposure(utils::Duration currentExposure);\r\n-\tvoid computeExposure(IPAContext &context, double yGain,\r\n-\t\t\t     double iqMeanGain);\r\n+\tvoid computeExposure(const uint32_t frame, IPAContext &context,\r\n+\t\t\t     double yGain, double iqMeanGain);\r\n \tdouble estimateLuminance(IPAFrameContext &frameContext,\r\n \t\t\t\t const ipu3_uapi_grid_config &grid,\r\n \t\t\t\t const ipu3_uapi_stats_3a *stats,\r\ndiff --git a/src/ipa/ipu3/algorithms/awb.cpp b/src/ipa/ipu3/algorithms/awb.cpp\r\nindex f1e753e6..00ac2984 100644\r\n--- a/src/ipa/ipu3/algorithms/awb.cpp\r\n+++ b/src/ipa/ipu3/algorithms/awb.cpp\r\n@@ -390,16 +390,17 @@ void Awb::calculateWBGains(const ipu3_uapi_stats_3a *stats)\r\n void Awb::process(const uint32_t frame, IPAContext &context, const ipu3_uapi_stats_3a *stats)\r\n {\r\n \tcalculateWBGains(stats);\r\n+\tIPAFrameContext &frameContext = context.getFrameContext(frame);\r\n \r\n \t/*\r\n \t * Gains are only recalculated if enough zones were detected.\r\n \t * The results are cached, so if no results were calculated, we set the\r\n \t * cached values from asyncResults_ here.\r\n \t */\r\n-\tcontext.frameContext.awb.gains.blue = asyncResults_.blueGain;\r\n-\tcontext.frameContext.awb.gains.green = asyncResults_.greenGain;\r\n-\tcontext.frameContext.awb.gains.red = asyncResults_.redGain;\r\n-\tcontext.frameContext.awb.temperatureK = asyncResults_.temperatureK;\r\n+\tframeContext.awb.gains.blue = asyncResults_.blueGain;\r\n+\tframeContext.awb.gains.green = asyncResults_.greenGain;\r\n+\tframeContext.awb.gains.red = asyncResults_.redGain;\r\n+\tframeContext.awb.temperatureK = asyncResults_.temperatureK;\r\n }\r\n \r\n constexpr uint16_t Awb::threshold(float value)\r\n@@ -450,10 +451,10 @@ void Awb::prepare([[maybe_unused]] const uint32_t frame, IPAContext &context, ip\r\n \tparams->acc_param.bnr.opt_center_sqr.y_sqr_reset = params->acc_param.bnr.opt_center.y_reset\r\n \t\t\t\t\t\t\t* params->acc_param.bnr.opt_center.y_reset;\r\n \t/* Convert to u3.13 fixed point values */\r\n-\tparams->acc_param.bnr.wb_gains.gr = 8192 * context.frameContext.awb.gains.green;\r\n-\tparams->acc_param.bnr.wb_gains.r  = 8192 * context.frameContext.awb.gains.red;\r\n-\tparams->acc_param.bnr.wb_gains.b  = 8192 * context.frameContext.awb.gains.blue;\r\n-\tparams->acc_param.bnr.wb_gains.gb = 8192 * context.frameContext.awb.gains.green;\r\n+\tparams->acc_param.bnr.wb_gains.gr = 8192 * context.prevFrameContext.awb.gains.green;\r\n+\tparams->acc_param.bnr.wb_gains.r  = 8192 * context.prevFrameContext.awb.gains.red;\r\n+\tparams->acc_param.bnr.wb_gains.b  = 8192 * context.prevFrameContext.awb.gains.blue;\r\n+\tparams->acc_param.bnr.wb_gains.gb = 8192 * context.prevFrameContext.awb.gains.green;\r\n \r\n \tLOG(IPU3Awb, Debug) << \"Color temperature estimated: \" << asyncResults_.temperatureK;\r\n \r\ndiff --git a/src/ipa/ipu3/algorithms/tone_mapping.cpp b/src/ipa/ipu3/algorithms/tone_mapping.cpp\r\nindex bba5bc9a..f0fbaaf7 100644\r\n--- a/src/ipa/ipu3/algorithms/tone_mapping.cpp\r\n+++ b/src/ipa/ipu3/algorithms/tone_mapping.cpp\r\n@@ -42,7 +42,7 @@ int ToneMapping::configure(IPAContext &context,\r\n \t\t\t   [[maybe_unused]] const IPAConfigInfo &configInfo)\r\n {\r\n \t/* Initialise tone mapping gamma value. */\r\n-\tcontext.frameContext.toneMapping.gamma = 0.0;\r\n+\tcontext.frameContextQueue.front().toneMapping.gamma = 0.0;\r\n \r\n \treturn 0;\r\n }\r\n@@ -62,7 +62,7 @@ void ToneMapping::prepare([[maybe_unused]] const uint32_t frame,\r\n {\r\n \t/* Copy the calculated LUT into the parameters buffer. */\r\n \tmemcpy(params->acc_param.gamma.gc_lut.lut,\r\n-\t       context.frameContext.toneMapping.gammaCorrection.lut,\r\n+\t       context.prevFrameContext.toneMapping.gammaCorrection.lut,\r\n \t       IPU3_UAPI_GAMMA_CORR_LUT_ENTRIES *\r\n \t       sizeof(params->acc_param.gamma.gc_lut.lut[0]));\r\n \r\n@@ -73,7 +73,7 @@ void ToneMapping::prepare([[maybe_unused]] const uint32_t frame,\r\n \r\n /**\r\n  * \\brief Calculate the tone mapping look up table\r\n- * \\param frame The frame number\r\n+ te* \\param frame The frame number\r\n  * \\param context The shared IPA context\r\n  * \\param stats The IPU3 statistics and ISP results\r\n  *\r\n@@ -83,6 +83,8 @@ void ToneMapping::prepare([[maybe_unused]] const uint32_t frame,\r\n void ToneMapping::process(const uint32_t frame, IPAContext &context,\r\n \t\t\t  [[maybe_unused]] const ipu3_uapi_stats_3a *stats)\r\n {\r\n+\tIPAFrameContext &frameContext = context.getFrameContext(frame);\r\n+\r\n \t/*\r\n \t * Hardcode gamma to 1.1 as a default for now.\r\n \t *\r\n@@ -90,11 +92,11 @@ void ToneMapping::process(const uint32_t frame, IPAContext &context,\r\n \t */\r\n \tgamma_ = 1.1;\r\n \r\n-\tif (context.frameContext.toneMapping.gamma == gamma_)\r\n+\tif (frameContext.toneMapping.gamma == gamma_)\r\n \t\treturn;\r\n \r\n \tstruct ipu3_uapi_gamma_corr_lut &lut =\r\n-\t\tcontext.frameContext.toneMapping.gammaCorrection;\r\n+\t\tframeContext.toneMapping.gammaCorrection;\r\n \r\n \tfor (uint32_t i = 0; i < std::size(lut.lut); i++) {\r\n \t\tdouble j = static_cast<double>(i) / (std::size(lut.lut) - 1);\r\n@@ -104,7 +106,7 @@ void ToneMapping::process(const uint32_t frame, IPAContext &context,\r\n \t\tlut.lut[i] = gamma * 8191;\r\n \t}\r\n \r\n-\tcontext.frameContext.toneMapping.gamma = gamma_;\r\n+\tframeContext.toneMapping.gamma = gamma_;\r\n }\r\n \r\n } /* namespace ipa::ipu3::algorithms */\r\ndiff --git a/src/ipa/ipu3/ipa_context.cpp b/src/ipa/ipu3/ipa_context.cpp\r\nindex 9c4ec936..41cbf717 100644\r\n--- a/src/ipa/ipu3/ipa_context.cpp\r\n+++ b/src/ipa/ipu3/ipa_context.cpp\r\n@@ -24,6 +24,48 @@ namespace libcamera::ipa::ipu3 {\r\n  * may also be updated in the start() operation.\r\n  */\r\n \r\n+/**\r\n+ * \\brief Retrieve the context of a particular frame\r\n+ * \\param[in] frame Frame number\r\n+ *\r\n+ * Retrieve the frame context of the \\a frame.\r\n+ *\r\n+ * \\return The frame context of the given frame number or nullptr, if not found\r\n+ */\r\n+IPAFrameContext &IPAContext::getFrameContext(const uint32_t frame)\r\n+{\r\n+\tauto iter = frameContextQueue.begin();\r\n+\twhile (iter != frameContextQueue.end()) {\r\n+\t\tif (iter->frame == frame)\r\n+\t\t\treturn *iter;\r\n+\r\n+\t\titer++;\r\n+\t}\r\n+\r\n+\t/*\r\n+\t * \\todo Handle the case where frame-context is not found here.\r\n+\t * Should we be FATAL ?\r\n+\t */\r\n+\treturn *iter; /* returns frameContextQueue.end() */\r\n+}\r\n+\r\n+/**\r\n+ * \\brief Construct a IPAFrameContext instance\r\n+ */\r\n+IPAFrameContext::IPAFrameContext() = default;\r\n+\r\n+/**\r\n+ * \\brief Move constructor for IPAFrameContext\r\n+ * \\param[in] other The other IPAFrameContext\r\n+ */\r\n+IPAFrameContext::IPAFrameContext(IPAFrameContext &&other) = default;\r\n+\r\n+/**\r\n+ * \\brief Move assignment operator for IPAFrameContext\r\n+ * \\param[in] other The other IPAFrameContext\r\n+ */\r\n+IPAFrameContext &IPAFrameContext::operator=(IPAFrameContext &&other) = default;\r\n+\r\n /**\r\n  * \\struct IPAFrameContext\r\n  * \\brief Per-frame context for algorithms\r\ndiff --git a/src/ipa/ipu3/ipa_context.h b/src/ipa/ipu3/ipa_context.h\r\nindex d993359a..eca346d6 100644\r\n--- a/src/ipa/ipu3/ipa_context.h\r\n+++ b/src/ipa/ipu3/ipa_context.h\r\n@@ -8,6 +8,8 @@\r\n \r\n #pragma once\r\n \r\n+#include <deque>\r\n+\r\n #include <linux/intel-ipu3.h>\r\n \r\n #include <libcamera/base/utils.h>\r\n@@ -39,6 +41,12 @@ struct IPASessionConfiguration {\r\n };\r\n \r\n struct IPAFrameContext {\r\n+\tuint32_t frame;\r\n+\r\n+\tIPAFrameContext();\r\n+\tIPAFrameContext(IPAFrameContext &&other);\r\n+\tIPAFrameContext &operator=(IPAFrameContext &&other);\r\n+\r\n \tstruct {\r\n \t\tuint32_t exposure;\r\n \t\tdouble gain;\r\n@@ -66,8 +74,12 @@ struct IPAFrameContext {\r\n };\r\n \r\n struct IPAContext {\r\n+\tIPAFrameContext &getFrameContext(const uint32_t frame);\r\n \tIPASessionConfiguration configuration;\r\n \tIPAFrameContext frameContext;\r\n+\r\n+\tstd::deque<IPAFrameContext> frameContextQueue;\r\n+\tIPAFrameContext prevFrameContext;\r\n };\r\n \r\n } /* namespace ipa::ipu3 */\r\ndiff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp\r\nindex 3d5c5706..f3128b0a 100644\r\n--- a/src/ipa/ipu3/ipu3.cpp\r\n+++ b/src/ipa/ipu3/ipu3.cpp\r\n@@ -349,6 +349,8 @@ int IPAIPU3::start()\r\n  */\r\n void IPAIPU3::stop()\r\n {\r\n+\twhile (!context_.frameContextQueue.empty())\r\n+\t\tcontext_.frameContextQueue.pop_front();\r\n }\r\n \r\n /**\r\n@@ -451,6 +453,14 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo,\r\n \t */\r\n \tctrls_ = configInfo.sensorControls;\r\n \r\n+\t/*\r\n+\t * Insert a initial context into the queue to faciliate\r\n+\t * algo->configure() below.\r\n+\t */\r\n+\tIPAFrameContext initContext;\r\n+\tinitContext.frame = 0;\r\n+\tcontext_.frameContextQueue.push_back(std::move(initContext));\r\n+\r\n \tcalculateBdsGrid(configInfo.bdsOutputSize);\r\n \r\n \t/* Clean frameContext at each reconfiguration. */\r\n@@ -501,10 +511,25 @@ void IPAIPU3::unmapBuffers(const std::vector<unsigned int> &ids)\r\n \r\n void IPAIPU3::frameStarted([[maybe_unused]] const uint32_t frame)\r\n {\r\n+\tIPAFrameContext newContext;\r\n+\tnewContext.frame = frame;\r\n+\r\n+\tcontext_.frameContextQueue.push_back(std::move(newContext));\r\n }\r\n \r\n void IPAIPU3::frameCompleted([[maybe_unused]] const uint32_t frame)\r\n {\r\n+\twhile (!context_.frameContextQueue.empty()) {\r\n+\t\tauto &fc = context_.frameContextQueue.front();\r\n+\t\tif (fc.frame < frame)\r\n+\t\t\tcontext_.frameContextQueue.pop_front();\r\n+\r\n+\t\t/* Keep newer frames */\r\n+\t\tif (fc.frame >= frame) {\r\n+\t\t\tcontext_.prevFrameContext = std::move(fc);\r\n+\t\t\tbreak;\r\n+\t\t}\r\n+\t}\r\n }\r\n \r\n /**\r\n@@ -547,8 +572,9 @@ void IPAIPU3::processStatsBuffer(const uint32_t frame, const int64_t frameTimest\r\n \tconst ipu3_uapi_stats_3a *stats =\r\n \t\treinterpret_cast<ipu3_uapi_stats_3a *>(mem.data());\r\n \r\n-\tcontext_.frameContext.sensor.exposure = sensorControls.get(V4L2_CID_EXPOSURE).get<int32_t>();\r\n-\tcontext_.frameContext.sensor.gain = camHelper_->gain(sensorControls.get(V4L2_CID_ANALOGUE_GAIN).get<int32_t>());\r\n+       IPAFrameContext &curFrameContext = context_.getFrameContext(frame);\r\n+       curFrameContext.sensor.exposure = sensorControls.get(V4L2_CID_EXPOSURE).get<int32_t>();\r\n+       curFrameContext.sensor.gain = camHelper_->gain(sensorControls.get(V4L2_CID_ANALOGUE_GAIN).get<int32_t>());\r\n \r\n \tparseStatistics(frame, frameTimestamp, stats);\r\n }\r\n@@ -623,11 +649,11 @@ void IPAIPU3::parseStatistics(unsigned int frame,\r\n \tint64_t frameDuration = (vBlank + sensorInfo_.outputSize.height) * lineDuration;\r\n \tctrls.set(controls::FrameDuration, frameDuration);\r\n \r\n-\tctrls.set(controls::AnalogueGain, context_.frameContext.sensor.gain);\r\n+\tctrls.set(controls::AnalogueGain, context_.prevFrameContext.sensor.gain);\r\n \r\n-\tctrls.set(controls::ColourTemperature, context_.frameContext.awb.temperatureK);\r\n+\tctrls.set(controls::ColourTemperature, context_.prevFrameContext.awb.temperatureK);\r\n \r\n-\tctrls.set(controls::ExposureTime, context_.frameContext.sensor.exposure * lineDuration);\r\n+\tctrls.set(controls::ExposureTime, context_.prevFrameContext.sensor.exposure * lineDuration);\r\n \r\n \t/*\r\n \t * \\todo The Metadata provides a path to getting extended data\r\n@@ -651,8 +677,9 @@ void IPAIPU3::parseStatistics(unsigned int frame,\r\n  */\r\n void IPAIPU3::setControls(unsigned int frame)\r\n {\r\n-\tint32_t exposure = context_.frameContext.agc.exposure;\r\n-\tint32_t gain = camHelper_->gainCode(context_.frameContext.agc.gain);\r\n+\tIPAFrameContext &context = context_.getFrameContext(frame);\r\n+\tint32_t exposure = context.agc.exposure;\r\n+\tint32_t gain = camHelper_->gainCode(context.agc.gain);\r\n \r\n \tControlList ctrls(ctrls_);\r\n \tctrls.set(V4L2_CID_EXPOSURE, exposure);",
    "prefixes": [
        "libcamera-devel",
        "3/3"
    ]
}