[{"id":22201,"web_url":"https://patchwork.libcamera.org/comment/22201/","msgid":"<164605863371.2189824.2623563457141987020@Monstersaurus>","date":"2022-02-28T14:30:33","subject":"Re: [libcamera-devel] [PATCH v4 3/4] ipa: ipu3: agc: Introduce\n\tlineDuration in IPASessionConfiguration","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Jean-Michel Hautbois (2022-02-24 15:11:12)\n> Instead of having a local cached value for line duration, store it in\n> the IPASessionConfiguration::sensor structure.\n> While at it, configure the default analogue gain and shutter speed to\n> controlled fixed values.\n> \n> The latter is set to be 10ms as it will in most cases be close to the\n> one needed, making the AGC faster to converge.\n> \n> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> \n> ---\n> v4: clean only frameContext at configure call.\n>     [Kieran, I took your R-b if you are ok ?]\n\nFine with me if I already gave it ;-)\n\nI'll skim down through this to be sure anyway.\n\nI have a worry about the context_ = {}; to clean / initialise it now\nthat there is a utils::Duration in it.\n\nI think it can possibly be fine, but we probably need to validate it.\n\n\n> ---\n>  src/ipa/ipu3/algorithms/agc.cpp | 26 ++++++++++++++------------\n>  src/ipa/ipu3/algorithms/agc.h   |  3 +--\n>  src/ipa/ipu3/ipa_context.cpp    |  8 ++++++++\n>  src/ipa/ipu3/ipa_context.h      |  4 ++++\n>  src/ipa/ipu3/ipu3.cpp           | 28 +++++++++++++++-------------\n>  5 files changed, 42 insertions(+), 27 deletions(-)\n> \n> diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp\n> index a929085c..1eb1bcef 100644\n> --- a/src/ipa/ipu3/algorithms/agc.cpp\n> +++ b/src/ipa/ipu3/algorithms/agc.cpp\n> @@ -71,7 +71,7 @@ static constexpr uint32_t kNumStartupFrames = 10;\n>  static constexpr double kRelativeLuminanceTarget = 0.16;\n>  \n>  Agc::Agc()\n> -       : frameCount_(0), lineDuration_(0s), minShutterSpeed_(0s),\n> +       : frameCount_(0), minShutterSpeed_(0s),\n>           maxShutterSpeed_(0s), filteredExposure_(0s)\n>  {\n>  }\n> @@ -83,13 +83,13 @@ Agc::Agc()\n>   *\n>   * \\return 0\n>   */\n> -int Agc::configure(IPAContext &context, const IPAConfigInfo &configInfo)\n> +int Agc::configure(IPAContext &context,\n> +                  [[maybe_unused]] const IPAConfigInfo &configInfo)\n>  {\n> -       stride_ = context.configuration.grid.stride;\n> +       IPASessionConfiguration &configuration = context.configuration;\n> +       IPAFrameContext &frameContext = context.frameContext;\n>  \n> -       /* \\todo use the IPAContext to provide the limits */\n> -       lineDuration_ = configInfo.sensorInfo.lineLength * 1.0s\n> -                     / configInfo.sensorInfo.pixelRate;\n> +       stride_ = configuration.grid.stride;\n>  \n>         minShutterSpeed_ = context.configuration.agc.minShutterSpeed;\n>         maxShutterSpeed_ = std::min(context.configuration.agc.maxShutterSpeed,\n> @@ -99,8 +99,8 @@ int Agc::configure(IPAContext &context, const IPAConfigInfo &configInfo)\n>         maxAnalogueGain_ = std::min(context.configuration.agc.maxAnalogueGain, kMaxAnalogueGain);\n>  \n>         /* Configure the default exposure and gain. */\n> -       context.frameContext.agc.gain = minAnalogueGain_;\n> -       context.frameContext.agc.exposure = minShutterSpeed_ / lineDuration_;\n> +       frameContext.agc.gain = std::max(minAnalogueGain_, kMinAnalogueGain);\n> +       frameContext.agc.exposure = 10ms / configuration.sensor.lineDuration;\n>  \n>         return 0;\n>  }\n> @@ -182,9 +182,11 @@ utils::Duration Agc::filterExposure(utils::Duration exposureValue)\n>   * \\param[in] yGain The gain calculated based on the relative luminance target\n>   * \\param[in] iqMeanGain The gain calculated based on the relative luminance target\n>   */\n> -void Agc::computeExposure(IPAFrameContext &frameContext, double yGain,\n> +void Agc::computeExposure(IPAContext &context, double yGain,\n>                           double iqMeanGain)\n>  {\n> +       const IPASessionConfiguration &configuration = context.configuration;\n> +       IPAFrameContext &frameContext = context.frameContext;\n>         /* Get the effective exposure and gain applied on the sensor. */\n>         uint32_t exposure = frameContext.sensor.exposure;\n>         double analogueGain = frameContext.sensor.gain;\n> @@ -200,7 +202,7 @@ void Agc::computeExposure(IPAFrameContext &frameContext, double yGain,\n>         /* extracted from Rpi::Agc::computeTargetExposure */\n>  \n>         /* Calculate the shutter time in seconds */\n> -       utils::Duration currentShutter = exposure * lineDuration_;\n> +       utils::Duration currentShutter = exposure * configuration.sensor.lineDuration;\n>  \n>         /*\n>          * Update the exposure value for the next computation using the values\n> @@ -247,7 +249,7 @@ void Agc::computeExposure(IPAFrameContext &frameContext, double yGain,\n>                             << stepGain;\n>  \n>         /* Update the estimated exposure and gain. */\n> -       frameContext.agc.exposure = shutterTime / lineDuration_;\n> +       frameContext.agc.exposure = shutterTime / configuration.sensor.lineDuration;\n>         frameContext.agc.gain = stepGain;\n>  }\n>  \n> @@ -354,7 +356,7 @@ void Agc::process(IPAContext &context, const ipu3_uapi_stats_3a *stats)\n>                         break;\n>         }\n>  \n> -       computeExposure(context.frameContext, yGain, iqMeanGain);\n> +       computeExposure(context, yGain, iqMeanGain);\n>         frameCount_++;\n>  }\n>  \n> diff --git a/src/ipa/ipu3/algorithms/agc.h b/src/ipa/ipu3/algorithms/agc.h\n> index 84bfe045..ad705605 100644\n> --- a/src/ipa/ipu3/algorithms/agc.h\n> +++ b/src/ipa/ipu3/algorithms/agc.h\n> @@ -34,7 +34,7 @@ private:\n>         double measureBrightness(const ipu3_uapi_stats_3a *stats,\n>                                  const ipu3_uapi_grid_config &grid) const;\n>         utils::Duration filterExposure(utils::Duration currentExposure);\n> -       void computeExposure(IPAFrameContext &frameContext, double yGain,\n> +       void computeExposure(IPAContext &context, double yGain,\n>                              double iqMeanGain);\n>         double estimateLuminance(IPAFrameContext &frameContext,\n>                                  const ipu3_uapi_grid_config &grid,\n> @@ -43,7 +43,6 @@ private:\n>  \n>         uint64_t frameCount_;\n>  \n> -       utils::Duration lineDuration_;\n>         utils::Duration minShutterSpeed_;\n>         utils::Duration maxShutterSpeed_;\n>  \n> diff --git a/src/ipa/ipu3/ipa_context.cpp b/src/ipa/ipu3/ipa_context.cpp\n> index 86794ac1..9c4ec936 100644\n> --- a/src/ipa/ipu3/ipa_context.cpp\n> +++ b/src/ipa/ipu3/ipa_context.cpp\n> @@ -86,6 +86,14 @@ namespace libcamera::ipa::ipu3 {\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> +\n>  /**\n>   * \\var IPAFrameContext::agc\n>   * \\brief Context for the Automatic Gain Control algorithm\n> diff --git a/src/ipa/ipu3/ipa_context.h b/src/ipa/ipu3/ipa_context.h\n> index c6dc0814..e7c49828 100644\n> --- a/src/ipa/ipu3/ipa_context.h\n> +++ b/src/ipa/ipu3/ipa_context.h\n> @@ -31,6 +31,10 @@ struct IPASessionConfiguration {\n>                 double minAnalogueGain;\n>                 double maxAnalogueGain;\n>         } agc;\n> +\n> +       struct {\n> +               utils::Duration lineDuration;\n> +       } sensor;\n>  };\n>  \n>  struct IPAFrameContext {\n> diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp\n> index c0c29416..17324616 100644\n> --- a/src/ipa/ipu3/ipu3.cpp\n> +++ b/src/ipa/ipu3/ipu3.cpp\n> @@ -173,8 +173,6 @@ private:\n>         uint32_t minGain_;\n>         uint32_t maxGain_;\n>  \n> -       utils::Duration lineDuration_;\n> -\n>         /* Interface to the Camera Helper */\n>         std::unique_ptr<CameraSensorHelper> camHelper_;\n>  \n> @@ -206,8 +204,8 @@ void IPAIPU3::updateSessionConfiguration(const ControlInfoMap &sensorControls)\n>          *\n>          * \\todo take VBLANK into account for maximum shutter speed\n>          */\n> -       context_.configuration.agc.minShutterSpeed = minExposure * lineDuration_;\n> -       context_.configuration.agc.maxShutterSpeed = maxExposure * lineDuration_;\n> +       context_.configuration.agc.minShutterSpeed = minExposure * context_.configuration.sensor.lineDuration;\n> +       context_.configuration.agc.maxShutterSpeed = maxExposure * context_.configuration.sensor.lineDuration;\n\nSome long lines, but those might only be easier to shorten if we had a\nlocal reference to the configuration structure or sensor configuration?\n\n>         context_.configuration.agc.minAnalogueGain = camHelper_->gain(minGain);\n>         context_.configuration.agc.maxAnalogueGain = camHelper_->gain(maxGain);\n>  }\n> @@ -229,6 +227,7 @@ void IPAIPU3::updateControls(const IPACameraSensorInfo &sensorInfo,\n>                              ControlInfoMap *ipaControls)\n>  {\n>         ControlInfoMap::Map controls{};\n> +       double lineDuration = context_.configuration.sensor.lineDuration.get<std::micro>();\n>  \n>         /*\n>          * Compute exposure time limits by using line length and pixel rate\n> @@ -237,9 +236,9 @@ void IPAIPU3::updateControls(const IPACameraSensorInfo &sensorInfo,\n>          * microseconds.\n>          */\n>         const ControlInfo &v4l2Exposure = sensorControls.find(V4L2_CID_EXPOSURE)->second;\n> -       int32_t minExposure = v4l2Exposure.min().get<int32_t>() * lineDuration_.get<std::micro>();\n> -       int32_t maxExposure = v4l2Exposure.max().get<int32_t>() * lineDuration_.get<std::micro>();\n> -       int32_t defExposure = v4l2Exposure.def().get<int32_t>() * lineDuration_.get<std::micro>();\n> +       int32_t minExposure = v4l2Exposure.min().get<int32_t>() * lineDuration;\n> +       int32_t maxExposure = v4l2Exposure.max().get<int32_t>() * lineDuration;\n> +       int32_t defExposure = v4l2Exposure.def().get<int32_t>() * lineDuration;\n>         controls[&controls::ExposureTime] = ControlInfo(minExposure, maxExposure,\n>                                                         defExposure);\n>  \n> @@ -293,6 +292,10 @@ int IPAIPU3::init(const IPASettings &settings,\n>                 return -ENODEV;\n>         }\n>  \n> +       /* Clean context */\n> +       context_ = {};\n\nContext_ now contains a utils::Duration which is a std::chrono::duration\ntype.\n\nWhat happens to that /object/ when this context is cleaned? Does it lose\nany state? Or does it correctly get initialised successfully?\n\nWe might want to validate that this is safe C++ ... I'm quite fearful\nthat it might not be.\n\n\n\n> +       context_.configuration.sensor.lineDuration = sensorInfo.lineLength * 1.0s / sensorInfo.pixelRate;\n> +\n>         /* Construct our Algorithms */\n>         algorithms_.push_back(std::make_unique<algorithms::Agc>());\n>         algorithms_.push_back(std::make_unique<algorithms::Awb>());\n> @@ -454,12 +457,10 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo,\n>  \n>         defVBlank_ = itVBlank->second.def().get<int32_t>();\n>  \n> -       /* Clean context at configuration */\n> -       context_ = {};\n> -\n>         calculateBdsGrid(configInfo.bdsOutputSize);\n>  \n> -       lineDuration_ = sensorInfo_.lineLength * 1.0s / sensorInfo_.pixelRate;\n> +       /* Clean frameContext at each reconfiguration. */\n> +       context_.frameContext = {};\n\nYes, I think this is likely required for now, but should go when we get\na per-frame frameContext.\n\n>         /* Update the camera controls using the new sensor settings. */\n>         updateControls(sensorInfo_, ctrls_, ipaControls);\n> @@ -620,6 +621,7 @@ void IPAIPU3::parseStatistics(unsigned int frame,\n>                               [[maybe_unused]] int64_t frameTimestamp,\n>                               const ipu3_uapi_stats_3a *stats)\n>  {\n> +       double lineDuration = context_.configuration.sensor.lineDuration.get<std::micro>();\n>         ControlList ctrls(controls::controls);\n>  \n>         for (auto const &algo : algorithms_)\n> @@ -628,14 +630,14 @@ void IPAIPU3::parseStatistics(unsigned int frame,\n>         setControls(frame);\n>  \n>         /* \\todo Use VBlank value calculated from each frame exposure. */\n> -       int64_t frameDuration = (defVBlank_ + sensorInfo_.outputSize.height) * lineDuration_.get<std::micro>();\n> +       int64_t frameDuration = (defVBlank_ + sensorInfo_.outputSize.height) * lineDuration;\n>         ctrls.set(controls::FrameDuration, frameDuration);\n>  \n>         ctrls.set(controls::AnalogueGain, context_.frameContext.sensor.gain);\n>  \n>         ctrls.set(controls::ColourTemperature, context_.frameContext.awb.temperatureK);\n>  \n> -       ctrls.set(controls::ExposureTime, context_.frameContext.sensor.exposure * lineDuration_.get<std::micro>());\n> +       ctrls.set(controls::ExposureTime, context_.frameContext.sensor.exposure * lineDuration);\n>  \n>         /*\n>          * \\todo The Metadata provides a path to getting extended data\n> -- \n> 2.32.0\n>","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 01B1BBE08A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 28 Feb 2022 14:30:38 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2D90061166;\n\tMon, 28 Feb 2022 15:30:37 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2F4A561101\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 28 Feb 2022 15:30:36 +0100 (CET)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id CEDF6486;\n\tMon, 28 Feb 2022 15:30:35 +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=\"U4jEcXxB\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1646058635;\n\tbh=3/vXUQrmnnL324SKkwHKp5bIdREzeHorIztqz/b94fI=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=U4jEcXxBfJFofFoxw/KHfuI5wuKS2mWSt/R3Bi0KkAD+scm4e/dNtGZYXq3J/mqTM\n\t68pStUagV8Vw+8MppNjOirJzsIQCyuyLyFtAkbvw+ceqF2aQaq9YIBISyuueuvgZ5Q\n\tcWRyzK7JP2weelfBpwruxdsADhukNDeK5hDTcpHg=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20220224151113.109858-4-jeanmichel.hautbois@ideasonboard.com>","References":"<20220224151113.109858-1-jeanmichel.hautbois@ideasonboard.com>\n\t<20220224151113.109858-4-jeanmichel.hautbois@ideasonboard.com>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Mon, 28 Feb 2022 14:30:33 +0000","Message-ID":"<164605863371.2189824.2623563457141987020@Monstersaurus>","User-Agent":"alot/0.10","Subject":"Re: [libcamera-devel] [PATCH v4 3/4] ipa: ipu3: agc: Introduce\n\tlineDuration in IPASessionConfiguration","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>"}},{"id":22202,"web_url":"https://patchwork.libcamera.org/comment/22202/","msgid":"<fe7b6943-2863-867b-fcd3-28d9a6f49b90@ideasonboard.com>","date":"2022-02-28T16:54:05","subject":"Re: [libcamera-devel] [PATCH v4 3/4] ipa: ipu3: agc: Introduce\n\tlineDuration in IPASessionConfiguration","submitter":{"id":86,"url":"https://patchwork.libcamera.org/api/people/86/","name":"Umang Jain","email":"umang.jain@ideasonboard.com"},"content":"Hi JM,\n\n\nOn 2/24/22 20:41, Jean-Michel Hautbois wrote:\n> Instead of having a local cached value for line duration, store it in\n> the IPASessionConfiguration::sensor structure.\n> While at it, configure the default analogue gain and shutter speed to\n> controlled fixed values.\n>\n> The latter is set to be 10ms as it will in most cases be close to the\n> one needed, making the AGC faster to converge.\n>\n> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n>\n> ---\n> v4: clean only frameContext at configure call.\n>      [Kieran, I took your R-b if you are ok ?]\n> ---\n>   src/ipa/ipu3/algorithms/agc.cpp | 26 ++++++++++++++------------\n>   src/ipa/ipu3/algorithms/agc.h   |  3 +--\n>   src/ipa/ipu3/ipa_context.cpp    |  8 ++++++++\n>   src/ipa/ipu3/ipa_context.h      |  4 ++++\n>   src/ipa/ipu3/ipu3.cpp           | 28 +++++++++++++++-------------\n>   5 files changed, 42 insertions(+), 27 deletions(-)\n>\n> diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp\n> index a929085c..1eb1bcef 100644\n> --- a/src/ipa/ipu3/algorithms/agc.cpp\n> +++ b/src/ipa/ipu3/algorithms/agc.cpp\n> @@ -71,7 +71,7 @@ static constexpr uint32_t kNumStartupFrames = 10;\n>   static constexpr double kRelativeLuminanceTarget = 0.16;\n>   \n>   Agc::Agc()\n> -\t: frameCount_(0), lineDuration_(0s), minShutterSpeed_(0s),\n> +\t: frameCount_(0), minShutterSpeed_(0s),\n>   \t  maxShutterSpeed_(0s), filteredExposure_(0s)\n>   {\n>   }\n> @@ -83,13 +83,13 @@ Agc::Agc()\n>    *\n>    * \\return 0\n>    */\n> -int Agc::configure(IPAContext &context, const IPAConfigInfo &configInfo)\n> +int Agc::configure(IPAContext &context,\n> +\t\t   [[maybe_unused]] const IPAConfigInfo &configInfo)\n>   {\n> -\tstride_ = context.configuration.grid.stride;\n> +\tIPASessionConfiguration &configuration = context.configuration;\n> +\tIPAFrameContext &frameContext = context.frameContext;\n>   \n> -\t/* \\todo use the IPAContext to provide the limits */\n> -\tlineDuration_ = configInfo.sensorInfo.lineLength * 1.0s\n> -\t\t      / configInfo.sensorInfo.pixelRate;\n> +\tstride_ = configuration.grid.stride;\n>   \n>   \tminShutterSpeed_ = context.configuration.agc.minShutterSpeed;\n>   \tmaxShutterSpeed_ = std::min(context.configuration.agc.maxShutterSpeed,\n> @@ -99,8 +99,8 @@ int Agc::configure(IPAContext &context, const IPAConfigInfo &configInfo)\n>   \tmaxAnalogueGain_ = std::min(context.configuration.agc.maxAnalogueGain, kMaxAnalogueGain);\n>   \n>   \t/* Configure the default exposure and gain. */\n> -\tcontext.frameContext.agc.gain = minAnalogueGain_;\n> -\tcontext.frameContext.agc.exposure = minShutterSpeed_ / lineDuration_;\n> +\tframeContext.agc.gain = std::max(minAnalogueGain_, kMinAnalogueGain);\n> +\tframeContext.agc.exposure = 10ms / configuration.sensor.lineDuration;\n\n\nCan 10ms be assigned to something like kminShutterSpeed_ or something?\n\nI am satisfied with the changes so,\n\nReviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n\n>   \n>   \treturn 0;\n>   }\n> @@ -182,9 +182,11 @@ utils::Duration Agc::filterExposure(utils::Duration exposureValue)\n>    * \\param[in] yGain The gain calculated based on the relative luminance target\n>    * \\param[in] iqMeanGain The gain calculated based on the relative luminance target\n>    */\n> -void Agc::computeExposure(IPAFrameContext &frameContext, double yGain,\n> +void Agc::computeExposure(IPAContext &context, double yGain,\n>   \t\t\t  double iqMeanGain)\n>   {\n> +\tconst IPASessionConfiguration &configuration = context.configuration;\n> +\tIPAFrameContext &frameContext = context.frameContext;\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> @@ -200,7 +202,7 @@ void Agc::computeExposure(IPAFrameContext &frameContext, double yGain,\n>   \t/* extracted from Rpi::Agc::computeTargetExposure */\n>   \n>   \t/* Calculate the shutter time in seconds */\n> -\tutils::Duration currentShutter = exposure * lineDuration_;\n> +\tutils::Duration currentShutter = exposure * configuration.sensor.lineDuration;\n>   \n>   \t/*\n>   \t * Update the exposure value for the next computation using the values\n> @@ -247,7 +249,7 @@ void Agc::computeExposure(IPAFrameContext &frameContext, double yGain,\n>   \t\t\t    << stepGain;\n>   \n>   \t/* Update the estimated exposure and gain. */\n> -\tframeContext.agc.exposure = shutterTime / lineDuration_;\n> +\tframeContext.agc.exposure = shutterTime / configuration.sensor.lineDuration;\n>   \tframeContext.agc.gain = stepGain;\n>   }\n>   \n> @@ -354,7 +356,7 @@ void Agc::process(IPAContext &context, const ipu3_uapi_stats_3a *stats)\n>   \t\t\tbreak;\n>   \t}\n>   \n> -\tcomputeExposure(context.frameContext, yGain, iqMeanGain);\n> +\tcomputeExposure(context, yGain, iqMeanGain);\n>   \tframeCount_++;\n>   }\n>   \n> diff --git a/src/ipa/ipu3/algorithms/agc.h b/src/ipa/ipu3/algorithms/agc.h\n> index 84bfe045..ad705605 100644\n> --- a/src/ipa/ipu3/algorithms/agc.h\n> +++ b/src/ipa/ipu3/algorithms/agc.h\n> @@ -34,7 +34,7 @@ private:\n>   \tdouble measureBrightness(const ipu3_uapi_stats_3a *stats,\n>   \t\t\t\t const ipu3_uapi_grid_config &grid) const;\n>   \tutils::Duration filterExposure(utils::Duration currentExposure);\n> -\tvoid computeExposure(IPAFrameContext &frameContext, double yGain,\n> +\tvoid computeExposure(IPAContext &context, double yGain,\n>   \t\t\t     double iqMeanGain);\n>   \tdouble estimateLuminance(IPAFrameContext &frameContext,\n>   \t\t\t\t const ipu3_uapi_grid_config &grid,\n> @@ -43,7 +43,6 @@ private:\n>   \n>   \tuint64_t frameCount_;\n>   \n> -\tutils::Duration lineDuration_;\n>   \tutils::Duration minShutterSpeed_;\n>   \tutils::Duration maxShutterSpeed_;\n>   \n> diff --git a/src/ipa/ipu3/ipa_context.cpp b/src/ipa/ipu3/ipa_context.cpp\n> index 86794ac1..9c4ec936 100644\n> --- a/src/ipa/ipu3/ipa_context.cpp\n> +++ b/src/ipa/ipu3/ipa_context.cpp\n> @@ -86,6 +86,14 @@ namespace libcamera::ipa::ipu3 {\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> +\n>   /**\n>    * \\var IPAFrameContext::agc\n>    * \\brief Context for the Automatic Gain Control algorithm\n> diff --git a/src/ipa/ipu3/ipa_context.h b/src/ipa/ipu3/ipa_context.h\n> index c6dc0814..e7c49828 100644\n> --- a/src/ipa/ipu3/ipa_context.h\n> +++ b/src/ipa/ipu3/ipa_context.h\n> @@ -31,6 +31,10 @@ struct IPASessionConfiguration {\n>   \t\tdouble minAnalogueGain;\n>   \t\tdouble maxAnalogueGain;\n>   \t} agc;\n> +\n> +\tstruct {\n> +\t\tutils::Duration lineDuration;\n> +\t} sensor;\n>   };\n>   \n>   struct IPAFrameContext {\n> diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp\n> index c0c29416..17324616 100644\n> --- a/src/ipa/ipu3/ipu3.cpp\n> +++ b/src/ipa/ipu3/ipu3.cpp\n> @@ -173,8 +173,6 @@ private:\n>   \tuint32_t minGain_;\n>   \tuint32_t maxGain_;\n>   \n> -\tutils::Duration lineDuration_;\n> -\n>   \t/* Interface to the Camera Helper */\n>   \tstd::unique_ptr<CameraSensorHelper> camHelper_;\n>   \n> @@ -206,8 +204,8 @@ void IPAIPU3::updateSessionConfiguration(const ControlInfoMap &sensorControls)\n>   \t *\n>   \t * \\todo take VBLANK into account for maximum shutter speed\n>   \t */\n> -\tcontext_.configuration.agc.minShutterSpeed = minExposure * lineDuration_;\n> -\tcontext_.configuration.agc.maxShutterSpeed = maxExposure * lineDuration_;\n> +\tcontext_.configuration.agc.minShutterSpeed = minExposure * context_.configuration.sensor.lineDuration;\n> +\tcontext_.configuration.agc.maxShutterSpeed = maxExposure * context_.configuration.sensor.lineDuration;\n>   \tcontext_.configuration.agc.minAnalogueGain = camHelper_->gain(minGain);\n>   \tcontext_.configuration.agc.maxAnalogueGain = camHelper_->gain(maxGain);\n>   }\n> @@ -229,6 +227,7 @@ void IPAIPU3::updateControls(const IPACameraSensorInfo &sensorInfo,\n>   \t\t\t     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> @@ -237,9 +236,9 @@ void IPAIPU3::updateControls(const IPACameraSensorInfo &sensorInfo,\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_.get<std::micro>();\n> -\tint32_t maxExposure = v4l2Exposure.max().get<int32_t>() * lineDuration_.get<std::micro>();\n> -\tint32_t defExposure = v4l2Exposure.def().get<int32_t>() * lineDuration_.get<std::micro>();\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> @@ -293,6 +292,10 @@ int IPAIPU3::init(const IPASettings &settings,\n>   \t\treturn -ENODEV;\n>   \t}\n>   \n> +\t/* Clean context */\n> +\tcontext_ = {};\n> +\tcontext_.configuration.sensor.lineDuration = sensorInfo.lineLength * 1.0s / sensorInfo.pixelRate;\n> +\n>   \t/* Construct our Algorithms */\n>   \talgorithms_.push_back(std::make_unique<algorithms::Agc>());\n>   \talgorithms_.push_back(std::make_unique<algorithms::Awb>());\n> @@ -454,12 +457,10 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo,\n>   \n>   \tdefVBlank_ = itVBlank->second.def().get<int32_t>();\n>   \n> -\t/* Clean context at configuration */\n> -\tcontext_ = {};\n> -\n>   \tcalculateBdsGrid(configInfo.bdsOutputSize);\n>   \n> -\tlineDuration_ = sensorInfo_.lineLength * 1.0s / sensorInfo_.pixelRate;\n> +\t/* Clean frameContext at each reconfiguration. */\n> +\tcontext_.frameContext = {};\n>   \n>   \t/* Update the camera controls using the new sensor settings. */\n>   \tupdateControls(sensorInfo_, ctrls_, ipaControls);\n> @@ -620,6 +621,7 @@ void IPAIPU3::parseStatistics(unsigned int frame,\n>   \t\t\t      [[maybe_unused]] int64_t frameTimestamp,\n>   \t\t\t      const ipu3_uapi_stats_3a *stats)\n>   {\n> +\tdouble lineDuration = context_.configuration.sensor.lineDuration.get<std::micro>();\n>   \tControlList ctrls(controls::controls);\n>   \n>   \tfor (auto const &algo : algorithms_)\n> @@ -628,14 +630,14 @@ void IPAIPU3::parseStatistics(unsigned int frame,\n>   \tsetControls(frame);\n>   \n>   \t/* \\todo Use VBlank value calculated from each frame exposure. */\n> -\tint64_t frameDuration = (defVBlank_ + sensorInfo_.outputSize.height) * lineDuration_.get<std::micro>();\n> +\tint64_t frameDuration = (defVBlank_ + sensorInfo_.outputSize.height) * lineDuration;\n>   \tctrls.set(controls::FrameDuration, frameDuration);\n>   \n>   \tctrls.set(controls::AnalogueGain, context_.frameContext.sensor.gain);\n>   \n>   \tctrls.set(controls::ColourTemperature, context_.frameContext.awb.temperatureK);\n>   \n> -\tctrls.set(controls::ExposureTime, context_.frameContext.sensor.exposure * lineDuration_.get<std::micro>());\n> +\tctrls.set(controls::ExposureTime, context_.frameContext.sensor.exposure * lineDuration);\n>   \n>   \t/*\n>   \t * \\todo The Metadata provides a path to getting extended data","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 9A351BF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 28 Feb 2022 16:54:13 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E7CDF61166;\n\tMon, 28 Feb 2022 17:54:12 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6A7E261101\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 28 Feb 2022 17:54:12 +0100 (CET)","from [192.168.1.106] (unknown [103.251.226.77])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 55467478;\n\tMon, 28 Feb 2022 17:54:11 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"jUCB0D/j\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1646067252;\n\tbh=nC1LT6OFYQt3E+nEDi/r+pyl4xk/4yeYWbYsNjP/LE4=;\n\th=Date:Subject:To:References:From:In-Reply-To:From;\n\tb=jUCB0D/jLDD+GwvFCv+wi31xEaS3aUiU+NcSu/aiRk8RWUeJDKwWtoQgP7oyZq0Hm\n\tWg1yipiF8VIFQXygnCUNCLf0zSB6ldjLeXgNT1ZNuLvqG7fj28CkRyQjAJ3ghP0PuN\n\tsY/sqaNnCRFzWgug4fbqhSNQaPBGyfINcsncoLnU=","Message-ID":"<fe7b6943-2863-867b-fcd3-28d9a6f49b90@ideasonboard.com>","Date":"Mon, 28 Feb 2022 22:24:05 +0530","MIME-Version":"1.0","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101\n\tThunderbird/91.4.1","Content-Language":"en-US","To":"Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20220224151113.109858-1-jeanmichel.hautbois@ideasonboard.com>\n\t<20220224151113.109858-4-jeanmichel.hautbois@ideasonboard.com>","From":"Umang Jain <umang.jain@ideasonboard.com>","In-Reply-To":"<20220224151113.109858-4-jeanmichel.hautbois@ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","Subject":"Re: [libcamera-devel] [PATCH v4 3/4] ipa: ipu3: agc: Introduce\n\tlineDuration in IPASessionConfiguration","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>"}},{"id":22262,"web_url":"https://patchwork.libcamera.org/comment/22262/","msgid":"<51fd85af-489e-6379-8bde-ce58a7092972@ideasonboard.com>","date":"2022-03-11T13:49:57","subject":"Re: [libcamera-devel] [PATCH v4 3/4] ipa: ipu3: agc: Introduce\n\tlineDuration in IPASessionConfiguration","submitter":{"id":97,"url":"https://patchwork.libcamera.org/api/people/97/","name":"Nicolas Dufresne via libcamera-devel","email":"libcamera-devel@lists.libcamera.org"},"content":"Hi Kieran,\n\nOn 2/28/22 20:00, Kieran Bingham wrote:\n> Quoting Jean-Michel Hautbois (2022-02-24 15:11:12)\n>> Instead of having a local cached value for line duration, store it in\n>> the IPASessionConfiguration::sensor structure.\n>> While at it, configure the default analogue gain and shutter speed to\n>> controlled fixed values.\n>>\n>> The latter is set to be 10ms as it will in most cases be close to the\n>> one needed, making the AGC faster to converge.\n>>\n>> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\n>> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n>>\n>> ---\n>> v4: clean only frameContext at configure call.\n>>      [Kieran, I took your R-b if you are ok ?]\n> Fine with me if I already gave it ;-)\n>\n> I'll skim down through this to be sure anyway.\n>\n> I have a worry about the context_ = {}; to clean / initialise it now\n> that there is a utils::Duration in it.\n>\n> I think it can possibly be fine, but we probably need to validate it.\n\n\nGood spotting!\n\nI validated with,\n\n--- a/src/ipa/ipu3/ipu3.cpp\n+++ b/src/ipa/ipu3/ipu3.cpp\n@@ -293,7 +293,9 @@ int IPAIPU3::init(const IPASettings &settings,\n         }\n\n         /* Clean context */\n+       context_.configuration.sensor.lineDuration = 345ms;\n         context_ = {};\n+       LOG(IPAIPU3, Info) << \"lineduration after reset : \" << \ncontext_.configuration.sensor.lineDuration.get<std::milli>();\n         context_.configuration.sensor.lineDuration = \nsensorInfo.lineLength * 1.0s / sensorInfo.pixelRate;\n\ngives an o/p:\n\n[8:20:50.953925353] [29439]  INFO IPAIPU3 ipu3.cpp:298 lineduration \nafter reset : 0\n\nso it seems it should be fine.\n\n>\n>\n>> ---\n>>   src/ipa/ipu3/algorithms/agc.cpp | 26 ++++++++++++++------------\n>>   src/ipa/ipu3/algorithms/agc.h   |  3 +--\n>>   src/ipa/ipu3/ipa_context.cpp    |  8 ++++++++\n>>   src/ipa/ipu3/ipa_context.h      |  4 ++++\n>>   src/ipa/ipu3/ipu3.cpp           | 28 +++++++++++++++-------------\n>>   5 files changed, 42 insertions(+), 27 deletions(-)\n>>\n>> diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp\n>> index a929085c..1eb1bcef 100644\n>> --- a/src/ipa/ipu3/algorithms/agc.cpp\n>> +++ b/src/ipa/ipu3/algorithms/agc.cpp\n>> @@ -71,7 +71,7 @@ static constexpr uint32_t kNumStartupFrames = 10;\n>>   static constexpr double kRelativeLuminanceTarget = 0.16;\n>>   \n>>   Agc::Agc()\n>> -       : frameCount_(0), lineDuration_(0s), minShutterSpeed_(0s),\n>> +       : frameCount_(0), minShutterSpeed_(0s),\n>>            maxShutterSpeed_(0s), filteredExposure_(0s)\n>>   {\n>>   }\n>> @@ -83,13 +83,13 @@ Agc::Agc()\n>>    *\n>>    * \\return 0\n>>    */\n>> -int Agc::configure(IPAContext &context, const IPAConfigInfo &configInfo)\n>> +int Agc::configure(IPAContext &context,\n>> +                  [[maybe_unused]] const IPAConfigInfo &configInfo)\n>>   {\n>> -       stride_ = context.configuration.grid.stride;\n>> +       IPASessionConfiguration &configuration = context.configuration;\n>> +       IPAFrameContext &frameContext = context.frameContext;\n>>   \n>> -       /* \\todo use the IPAContext to provide the limits */\n>> -       lineDuration_ = configInfo.sensorInfo.lineLength * 1.0s\n>> -                     / configInfo.sensorInfo.pixelRate;\n>> +       stride_ = configuration.grid.stride;\n>>   \n>>          minShutterSpeed_ = context.configuration.agc.minShutterSpeed;\n>>          maxShutterSpeed_ = std::min(context.configuration.agc.maxShutterSpeed,\n>> @@ -99,8 +99,8 @@ int Agc::configure(IPAContext &context, const IPAConfigInfo &configInfo)\n>>          maxAnalogueGain_ = std::min(context.configuration.agc.maxAnalogueGain, kMaxAnalogueGain);\n>>   \n>>          /* Configure the default exposure and gain. */\n>> -       context.frameContext.agc.gain = minAnalogueGain_;\n>> -       context.frameContext.agc.exposure = minShutterSpeed_ / lineDuration_;\n>> +       frameContext.agc.gain = std::max(minAnalogueGain_, kMinAnalogueGain);\n>> +       frameContext.agc.exposure = 10ms / configuration.sensor.lineDuration;\n>>   \n>>          return 0;\n>>   }\n>> @@ -182,9 +182,11 @@ utils::Duration Agc::filterExposure(utils::Duration exposureValue)\n>>    * \\param[in] yGain The gain calculated based on the relative luminance target\n>>    * \\param[in] iqMeanGain The gain calculated based on the relative luminance target\n>>    */\n>> -void Agc::computeExposure(IPAFrameContext &frameContext, double yGain,\n>> +void Agc::computeExposure(IPAContext &context, double yGain,\n>>                            double iqMeanGain)\n>>   {\n>> +       const IPASessionConfiguration &configuration = context.configuration;\n>> +       IPAFrameContext &frameContext = context.frameContext;\n>>          /* Get the effective exposure and gain applied on the sensor. */\n>>          uint32_t exposure = frameContext.sensor.exposure;\n>>          double analogueGain = frameContext.sensor.gain;\n>> @@ -200,7 +202,7 @@ void Agc::computeExposure(IPAFrameContext &frameContext, double yGain,\n>>          /* extracted from Rpi::Agc::computeTargetExposure */\n>>   \n>>          /* Calculate the shutter time in seconds */\n>> -       utils::Duration currentShutter = exposure * lineDuration_;\n>> +       utils::Duration currentShutter = exposure * configuration.sensor.lineDuration;\n>>   \n>>          /*\n>>           * Update the exposure value for the next computation using the values\n>> @@ -247,7 +249,7 @@ void Agc::computeExposure(IPAFrameContext &frameContext, double yGain,\n>>                              << stepGain;\n>>   \n>>          /* Update the estimated exposure and gain. */\n>> -       frameContext.agc.exposure = shutterTime / lineDuration_;\n>> +       frameContext.agc.exposure = shutterTime / configuration.sensor.lineDuration;\n>>          frameContext.agc.gain = stepGain;\n>>   }\n>>   \n>> @@ -354,7 +356,7 @@ void Agc::process(IPAContext &context, const ipu3_uapi_stats_3a *stats)\n>>                          break;\n>>          }\n>>   \n>> -       computeExposure(context.frameContext, yGain, iqMeanGain);\n>> +       computeExposure(context, yGain, iqMeanGain);\n>>          frameCount_++;\n>>   }\n>>   \n>> diff --git a/src/ipa/ipu3/algorithms/agc.h b/src/ipa/ipu3/algorithms/agc.h\n>> index 84bfe045..ad705605 100644\n>> --- a/src/ipa/ipu3/algorithms/agc.h\n>> +++ b/src/ipa/ipu3/algorithms/agc.h\n>> @@ -34,7 +34,7 @@ private:\n>>          double measureBrightness(const ipu3_uapi_stats_3a *stats,\n>>                                   const ipu3_uapi_grid_config &grid) const;\n>>          utils::Duration filterExposure(utils::Duration currentExposure);\n>> -       void computeExposure(IPAFrameContext &frameContext, double yGain,\n>> +       void computeExposure(IPAContext &context, double yGain,\n>>                               double iqMeanGain);\n>>          double estimateLuminance(IPAFrameContext &frameContext,\n>>                                   const ipu3_uapi_grid_config &grid,\n>> @@ -43,7 +43,6 @@ private:\n>>   \n>>          uint64_t frameCount_;\n>>   \n>> -       utils::Duration lineDuration_;\n>>          utils::Duration minShutterSpeed_;\n>>          utils::Duration maxShutterSpeed_;\n>>   \n>> diff --git a/src/ipa/ipu3/ipa_context.cpp b/src/ipa/ipu3/ipa_context.cpp\n>> index 86794ac1..9c4ec936 100644\n>> --- a/src/ipa/ipu3/ipa_context.cpp\n>> +++ b/src/ipa/ipu3/ipa_context.cpp\n>> @@ -86,6 +86,14 @@ namespace libcamera::ipa::ipu3 {\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>> +\n>>   /**\n>>    * \\var IPAFrameContext::agc\n>>    * \\brief Context for the Automatic Gain Control algorithm\n>> diff --git a/src/ipa/ipu3/ipa_context.h b/src/ipa/ipu3/ipa_context.h\n>> index c6dc0814..e7c49828 100644\n>> --- a/src/ipa/ipu3/ipa_context.h\n>> +++ b/src/ipa/ipu3/ipa_context.h\n>> @@ -31,6 +31,10 @@ struct IPASessionConfiguration {\n>>                  double minAnalogueGain;\n>>                  double maxAnalogueGain;\n>>          } agc;\n>> +\n>> +       struct {\n>> +               utils::Duration lineDuration;\n>> +       } sensor;\n>>   };\n>>   \n>>   struct IPAFrameContext {\n>> diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp\n>> index c0c29416..17324616 100644\n>> --- a/src/ipa/ipu3/ipu3.cpp\n>> +++ b/src/ipa/ipu3/ipu3.cpp\n>> @@ -173,8 +173,6 @@ private:\n>>          uint32_t minGain_;\n>>          uint32_t maxGain_;\n>>   \n>> -       utils::Duration lineDuration_;\n>> -\n>>          /* Interface to the Camera Helper */\n>>          std::unique_ptr<CameraSensorHelper> camHelper_;\n>>   \n>> @@ -206,8 +204,8 @@ void IPAIPU3::updateSessionConfiguration(const ControlInfoMap &sensorControls)\n>>           *\n>>           * \\todo take VBLANK into account for maximum shutter speed\n>>           */\n>> -       context_.configuration.agc.minShutterSpeed = minExposure * lineDuration_;\n>> -       context_.configuration.agc.maxShutterSpeed = maxExposure * lineDuration_;\n>> +       context_.configuration.agc.minShutterSpeed = minExposure * context_.configuration.sensor.lineDuration;\n>> +       context_.configuration.agc.maxShutterSpeed = maxExposure * context_.configuration.sensor.lineDuration;\n> Some long lines, but those might only be easier to shorten if we had a\n> local reference to the configuration structure or sensor configuration?\n\n\nyes, there are few as well in algorithms too. Those need to trimmed as \nwell I think.\n\nLocal reference seems a solution, but then would be not be neat when the \ncontext itself becomes large and we are using local references all the IPA.\n\nI see some upside while code reading - that the 'x value' comes the \ncontext - which will be a hidden when using local references. Just my \npreference.\n\n>\n>>          context_.configuration.agc.minAnalogueGain = camHelper_->gain(minGain);\n>>          context_.configuration.agc.maxAnalogueGain = camHelper_->gain(maxGain);\n>>   }\n>> @@ -229,6 +227,7 @@ void IPAIPU3::updateControls(const IPACameraSensorInfo &sensorInfo,\n>>                               ControlInfoMap *ipaControls)\n>>   {\n>>          ControlInfoMap::Map controls{};\n>> +       double lineDuration = context_.configuration.sensor.lineDuration.get<std::micro>();\n>>   \n>>          /*\n>>           * Compute exposure time limits by using line length and pixel rate\n>> @@ -237,9 +236,9 @@ void IPAIPU3::updateControls(const IPACameraSensorInfo &sensorInfo,\n>>           * microseconds.\n>>           */\n>>          const ControlInfo &v4l2Exposure = sensorControls.find(V4L2_CID_EXPOSURE)->second;\n>> -       int32_t minExposure = v4l2Exposure.min().get<int32_t>() * lineDuration_.get<std::micro>();\n>> -       int32_t maxExposure = v4l2Exposure.max().get<int32_t>() * lineDuration_.get<std::micro>();\n>> -       int32_t defExposure = v4l2Exposure.def().get<int32_t>() * lineDuration_.get<std::micro>();\n>> +       int32_t minExposure = v4l2Exposure.min().get<int32_t>() * lineDuration;\n>> +       int32_t maxExposure = v4l2Exposure.max().get<int32_t>() * lineDuration;\n>> +       int32_t defExposure = v4l2Exposure.def().get<int32_t>() * lineDuration;\n>>          controls[&controls::ExposureTime] = ControlInfo(minExposure, maxExposure,\n>>                                                          defExposure);\n>>   \n>> @@ -293,6 +292,10 @@ int IPAIPU3::init(const IPASettings &settings,\n>>                  return -ENODEV;\n>>          }\n>>   \n>> +       /* Clean context */\n>> +       context_ = {};\n> Context_ now contains a utils::Duration which is a std::chrono::duration\n> type.\n>\n> What happens to that /object/ when this context is cleaned? Does it lose\n> any state? Or does it correctly get initialised successfully?\n>\n> We might want to validate that this is safe C++ ... I'm quite fearful\n> that it might not be.\n\n\nAnswered and validated above. Should be okay!\n\n>\n>\n>\n>> +       context_.configuration.sensor.lineDuration = sensorInfo.lineLength * 1.0s / sensorInfo.pixelRate;\n>> +\n>>          /* Construct our Algorithms */\n>>          algorithms_.push_back(std::make_unique<algorithms::Agc>());\n>>          algorithms_.push_back(std::make_unique<algorithms::Awb>());\n>> @@ -454,12 +457,10 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo,\n>>   \n>>          defVBlank_ = itVBlank->second.def().get<int32_t>();\n>>   \n>> -       /* Clean context at configuration */\n>> -       context_ = {};\n>> -\n>>          calculateBdsGrid(configInfo.bdsOutputSize);\n>>   \n>> -       lineDuration_ = sensorInfo_.lineLength * 1.0s / sensorInfo_.pixelRate;\n>> +       /* Clean frameContext at each reconfiguration. */\n>> +       context_.frameContext = {};\n> Yes, I think this is likely required for now, but should go when we get\n> a per-frame frameContext.\n\n\nAh something for me to take note of for my (already submitted) \nIPAFrameContext queue series o_O\n\n>\n>>          /* Update the camera controls using the new sensor settings. */\n>>          updateControls(sensorInfo_, ctrls_, ipaControls);\n>> @@ -620,6 +621,7 @@ void IPAIPU3::parseStatistics(unsigned int frame,\n>>                                [[maybe_unused]] int64_t frameTimestamp,\n>>                                const ipu3_uapi_stats_3a *stats)\n>>   {\n>> +       double lineDuration = context_.configuration.sensor.lineDuration.get<std::micro>();\n>>          ControlList ctrls(controls::controls);\n>>   \n>>          for (auto const &algo : algorithms_)\n>> @@ -628,14 +630,14 @@ void IPAIPU3::parseStatistics(unsigned int frame,\n>>          setControls(frame);\n>>   \n>>          /* \\todo Use VBlank value calculated from each frame exposure. */\n>> -       int64_t frameDuration = (defVBlank_ + sensorInfo_.outputSize.height) * lineDuration_.get<std::micro>();\n>> +       int64_t frameDuration = (defVBlank_ + sensorInfo_.outputSize.height) * lineDuration;\n>>          ctrls.set(controls::FrameDuration, frameDuration);\n>>   \n>>          ctrls.set(controls::AnalogueGain, context_.frameContext.sensor.gain);\n>>   \n>>          ctrls.set(controls::ColourTemperature, context_.frameContext.awb.temperatureK);\n>>   \n>> -       ctrls.set(controls::ExposureTime, context_.frameContext.sensor.exposure * lineDuration_.get<std::micro>());\n>> +       ctrls.set(controls::ExposureTime, context_.frameContext.sensor.exposure * lineDuration);\n>>   \n>>          /*\n>>           * \\todo The Metadata provides a path to getting extended data\n>> -- \n>> 2.32.0\n>>","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 DEAC8BE08A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 11 Mar 2022 13:50:05 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 299FB632E4;\n\tFri, 11 Mar 2022 14:50:05 +0100 (CET)","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 8DDF8604E8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 11 Mar 2022 14:50:03 +0100 (CET)","from [192.168.1.106] (unknown [103.251.226.65])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id F3874482;\n\tFri, 11 Mar 2022 14:50:01 +0100 (CET)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1647006605;\n\tbh=+7az1bt0ka0aKw9MQIHzEBmuA3C42l2ZdvWivmVkJH0=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=G43qwr4Ge8NZ/ddSX/3SwJeRbdFUi4TCSBSTY/bYbTwqfo8yeEVL9js6N8dk3pYx1\n\tD8kThFv+dJ1XGc/gM9Wk3G8EkV/ZpUaI29X2DQtbHRTPsN5Ff8U4obtYSJ6kM0Kjgi\n\tpWlswYZAIbCooOQPIBYIncOVe+lMeG8mwKLpxQxk0qbD/V7X6bhZLNLvLq+B+rF74m\n\tSe0OqMYrRGOz/1K28vUPYyjAyqVwox3f5MZet3mxbMC869CC7URsoT5jhbYtJAr5G8\n\tmsDp2XMjVldBt/NXhypJm/otIUoBZLFLY/EM+qW0cu3xJ6x+7tGokJP9HbBGd4L0e+\n\t+nggYQ+RiWHAQ==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1647006603;\n\tbh=+7az1bt0ka0aKw9MQIHzEBmuA3C42l2ZdvWivmVkJH0=;\n\th=Date:Subject:To:References:From:In-Reply-To:From;\n\tb=m3XoxrMiVUOnz+OgkIiYigiQJhmuVf27eKlJjbwe9FQKf9oe5wooofix3e/WCtIG6\n\t5J9LL43iM9q7lGlOddftLjdHQVroNG1MC61Ks4jCUZOafXZuGox5DVELd+A3g+cbem\n\t983nfC+YkR51Ey8jbiWK7EQvgGYakyIO6a68V08c="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"m3XoxrMi\"; dkim-atps=neutral","Message-ID":"<51fd85af-489e-6379-8bde-ce58a7092972@ideasonboard.com>","Date":"Fri, 11 Mar 2022 19:19:57 +0530","MIME-Version":"1.0","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101\n\tThunderbird/91.4.1","Content-Language":"en-US","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>,\n\tJean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20220224151113.109858-1-jeanmichel.hautbois@ideasonboard.com>\n\t<20220224151113.109858-4-jeanmichel.hautbois@ideasonboard.com>\n\t<164605863371.2189824.2623563457141987020@Monstersaurus>","In-Reply-To":"<164605863371.2189824.2623563457141987020@Monstersaurus>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"8bit","Subject":"Re: [libcamera-devel] [PATCH v4 3/4] ipa: ipu3: agc: Introduce\n\tlineDuration in IPASessionConfiguration","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>","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>"}}]