[{"id":22127,"web_url":"https://patchwork.libcamera.org/comment/22127/","msgid":"<164424807224.1048642.17156545686308100024@Monstersaurus>","date":"2022-02-07T15:34:32","subject":"Re: [libcamera-devel] [PATCH v2 3/3] 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":"Hi JM,\n\nQuoting Jean-Michel Hautbois (2022-02-07 13:59:37)\n> Instead of having a local cached value for line duration, store it in\n> the IPASessionConfiguration::agc structure.\n\nLooking at my previous comments on this patch in\nhttps://patchwork.libcamera.org/patch/14778/, I was suggesting that I\nbelieved this line duration should be in the sensor specific structure,\nnot the AGC specific structure.\n\nI'm sorry my comment then was not clear, perhaps I should have made it\nmore direct.\n\nIs the lineDuration specific to the AGC algorithm in any way that I have\nnot seen or understood?\n\nIn rkisp1/ipa_context.h, you have:\n\nstruct IPASessionConfiguration {\n...\n\tstruct {\n\t\tutils::Duration lineDuration;\n\t} sensor;\n...\n};\n\n\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> ---\n>  src/ipa/ipu3/algorithms/agc.cpp | 25 +++++++++++++++----------\n>  src/ipa/ipu3/algorithms/agc.h   |  3 +--\n>  src/ipa/ipu3/ipa_context.cpp    |  3 +++\n>  src/ipa/ipu3/ipa_context.h      |  1 +\n>  4 files changed, 20 insertions(+), 12 deletions(-)\n> \n> diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp\n> index a929085c..137c36cf 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> @@ -85,11 +85,14 @@ Agc::Agc()\n>   */\n>  int Agc::configure(IPAContext &context, const IPAConfigInfo &configInfo)\n>  {\n> -       stride_ = context.configuration.grid.stride;\n> +       IPASessionConfiguration &configuration = context.configuration;\n> +       IPAFrameContext &frameContext = context.frameContext;\n> +\n> +       stride_ = configuration.grid.stride;\n>  \n>         /* \\todo use the IPAContext to provide the limits */\n> -       lineDuration_ = configInfo.sensorInfo.lineLength * 1.0s\n> -                     / configInfo.sensorInfo.pixelRate;\n> +       configuration.agc.lineDuration = configInfo.sensorInfo.lineLength * 1.0s\n> +                                      / configInfo.sensorInfo.pixelRate;\n\nAnd in RKISP1 this is calculated during the IPA configure, before it\ncalls configure on the algorithms. Should we do that here to align them?\n\n\n>  \n>         minShutterSpeed_ = context.configuration.agc.minShutterSpeed;\n>         maxShutterSpeed_ = std::min(context.configuration.agc.maxShutterSpeed,\n> @@ -99,8 +102,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.agc.lineDuration;\n>  \n>         return 0;\n>  }\n> @@ -182,9 +185,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 +205,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.agc.lineDuration;\n>  \n>         /*\n>          * Update the exposure value for the next computation using the values\n> @@ -247,7 +252,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.agc.lineDuration;\n>         frameContext.agc.gain = stepGain;\n>  }\n>  \n> @@ -354,7 +359,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..ace9c66f 100644\n> --- a/src/ipa/ipu3/ipa_context.cpp\n> +++ b/src/ipa/ipu3/ipa_context.cpp\n> @@ -84,6 +84,9 @@ namespace libcamera::ipa::ipu3 {\n>   *\n>   * \\var IPASessionConfiguration::agc.maxAnalogueGain\n>   * \\brief Maximum analogue gain supported with the configured sensor\n> + *\n> + * \\var IPASessionConfiguration::agc.lineDuration\n> + * \\brief Line duration in microseconds\n>   */\n>  \n>  /**\n> diff --git a/src/ipa/ipu3/ipa_context.h b/src/ipa/ipu3/ipa_context.h\n> index c6dc0814..7696fd14 100644\n> --- a/src/ipa/ipu3/ipa_context.h\n> +++ b/src/ipa/ipu3/ipa_context.h\n> @@ -30,6 +30,7 @@ struct IPASessionConfiguration {\n>                 utils::Duration maxShutterSpeed;\n>                 double minAnalogueGain;\n>                 double maxAnalogueGain;\n> +               utils::Duration lineDuration;\n>         } agc;\n>  };\n>  \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 D9307BDCBF\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  7 Feb 2022 15:34:36 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3EFCA61070;\n\tMon,  7 Feb 2022 16:34:36 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0695560E58\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  7 Feb 2022 16:34:35 +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 8BB7D499;\n\tMon,  7 Feb 2022 16:34:34 +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=\"LeCfnTC2\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1644248074;\n\tbh=wfvFel1h558b/4GvHs98t7z23wHgXIF2WIWY960sGTc=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=LeCfnTC2V7frQWjy+2QBSad6YOw7W54mY6pJdocSdkXQou0o6PHJToOMpt3UWf8Ln\n\tpF0we7x3nE/iZ+eh02t5y7XSJjrgY3kCki4agkMzsgKCh4lOeORJKD2blzGZheVY3F\n\tf+/AZg1AWD3i3NtPpe2kkrfo0MdsIdqu96ksXw4Y=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20220207135937.221226-4-jeanmichel.hautbois@ideasonboard.com>","References":"<20220207135937.221226-1-jeanmichel.hautbois@ideasonboard.com>\n\t<20220207135937.221226-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, 07 Feb 2022 15:34:32 +0000","Message-ID":"<164424807224.1048642.17156545686308100024@Monstersaurus>","User-Agent":"alot/0.10","Subject":"Re: [libcamera-devel] [PATCH v2 3/3] 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":22151,"web_url":"https://patchwork.libcamera.org/comment/22151/","msgid":"<5e41c7a5-5423-6773-2b63-da0efd9f9ac1@ideasonboard.com>","date":"2022-02-08T17:09:59","subject":"Re: [libcamera-devel] [PATCH v2 3/3] ipa: ipu3: agc: Introduce\n\tlineDuration in IPASessionConfiguration","submitter":{"id":75,"url":"https://patchwork.libcamera.org/api/people/75/","name":"Jean-Michel Hautbois","email":"jeanmichel.hautbois@ideasonboard.com"},"content":"Hi Kieran,\n\nOn 07/02/2022 16:34, Kieran Bingham wrote:\n> Hi JM,\n> \n> Quoting Jean-Michel Hautbois (2022-02-07 13:59:37)\n>> Instead of having a local cached value for line duration, store it in\n>> the IPASessionConfiguration::agc structure.\n> \n> Looking at my previous comments on this patch in\n> https://patchwork.libcamera.org/patch/14778/, I was suggesting that I\n> believed this line duration should be in the sensor specific structure,\n> not the AGC specific structure.\n> \n> I'm sorry my comment then was not clear, perhaps I should have made it\n> more direct.\n> \n> Is the lineDuration specific to the AGC algorithm in any way that I have\n> not seen or understood?\n> \n> In rkisp1/ipa_context.h, you have:\n> \n> struct IPASessionConfiguration {\n> ...\n> \tstruct {\n> \t\tutils::Duration lineDuration;\n> \t} sensor;\n> ...\n> };\n> \n> \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>> ---\n>>   src/ipa/ipu3/algorithms/agc.cpp | 25 +++++++++++++++----------\n>>   src/ipa/ipu3/algorithms/agc.h   |  3 +--\n>>   src/ipa/ipu3/ipa_context.cpp    |  3 +++\n>>   src/ipa/ipu3/ipa_context.h      |  1 +\n>>   4 files changed, 20 insertions(+), 12 deletions(-)\n>>\n>> diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp\n>> index a929085c..137c36cf 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>> @@ -85,11 +85,14 @@ Agc::Agc()\n>>    */\n>>   int Agc::configure(IPAContext &context, const IPAConfigInfo &configInfo)\n>>   {\n>> -       stride_ = context.configuration.grid.stride;\n>> +       IPASessionConfiguration &configuration = context.configuration;\n>> +       IPAFrameContext &frameContext = context.frameContext;\n>> +\n>> +       stride_ = configuration.grid.stride;\n>>   \n>>          /* \\todo use the IPAContext to provide the limits */\n>> -       lineDuration_ = configInfo.sensorInfo.lineLength * 1.0s\n>> -                     / configInfo.sensorInfo.pixelRate;\n>> +       configuration.agc.lineDuration = configInfo.sensorInfo.lineLength * 1.0s\n>> +                                      / configInfo.sensorInfo.pixelRate;\n> \n> And in RKISP1 this is calculated during the IPA configure, before it\n> calls configure on the algorithms. Should we do that here to align them?\n> \n\nI noticed that lineDuration_ is cached and used in updateControls() \nwhich is called in configure()... and in init() (so, before it is set ?)...\nWe might have an issue there ?\n\n> \n>>   \n>>          minShutterSpeed_ = context.configuration.agc.minShutterSpeed;\n>>          maxShutterSpeed_ = std::min(context.configuration.agc.maxShutterSpeed,\n>> @@ -99,8 +102,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.agc.lineDuration;\n>>   \n>>          return 0;\n>>   }\n>> @@ -182,9 +185,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 +205,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.agc.lineDuration;\n>>   \n>>          /*\n>>           * Update the exposure value for the next computation using the values\n>> @@ -247,7 +252,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.agc.lineDuration;\n>>          frameContext.agc.gain = stepGain;\n>>   }\n>>   \n>> @@ -354,7 +359,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..ace9c66f 100644\n>> --- a/src/ipa/ipu3/ipa_context.cpp\n>> +++ b/src/ipa/ipu3/ipa_context.cpp\n>> @@ -84,6 +84,9 @@ namespace libcamera::ipa::ipu3 {\n>>    *\n>>    * \\var IPASessionConfiguration::agc.maxAnalogueGain\n>>    * \\brief Maximum analogue gain supported with the configured sensor\n>> + *\n>> + * \\var IPASessionConfiguration::agc.lineDuration\n>> + * \\brief Line duration in microseconds\n>>    */\n>>   \n>>   /**\n>> diff --git a/src/ipa/ipu3/ipa_context.h b/src/ipa/ipu3/ipa_context.h\n>> index c6dc0814..7696fd14 100644\n>> --- a/src/ipa/ipu3/ipa_context.h\n>> +++ b/src/ipa/ipu3/ipa_context.h\n>> @@ -30,6 +30,7 @@ struct IPASessionConfiguration {\n>>                  utils::Duration maxShutterSpeed;\n>>                  double minAnalogueGain;\n>>                  double maxAnalogueGain;\n>> +               utils::Duration lineDuration;\n>>          } agc;\n>>   };\n>>   \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 DB1D6BF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  8 Feb 2022 17:10:04 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1B077610AD;\n\tTue,  8 Feb 2022 18:10:04 +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 A095160E58\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  8 Feb 2022 18:10:02 +0100 (CET)","from [IPV6:2a01:e0a:169:7140:b99c:2ebe:5dcf:6513] (unknown\n\t[IPv6:2a01:e0a:169:7140:b99c:2ebe:5dcf:6513])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 4443AA04;\n\tTue,  8 Feb 2022 18:10:02 +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=\"ezjPro8t\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1644340202;\n\tbh=QhJhIyVNI7qaNpRqticRokg59R0ZcjmFyGPptbACP40=;\n\th=Date:Subject:To:References:From:In-Reply-To:From;\n\tb=ezjPro8tiG1aipW8Gmkq6E6Z92yVnBmsArhib/NAAjlzffdQ/8GFjVy9tRphl/R2m\n\t/O/+zq+12eO5YjmKz+njo477IfScgSs/YvfOPJW7HFUbDyjglrsF0VWhNNcwMSk2Le\n\t8JV09nB1ppWvMhxTaDch9tJdO35xsmTHL0u93a5Y=","Message-ID":"<5e41c7a5-5423-6773-2b63-da0efd9f9ac1@ideasonboard.com>","Date":"Tue, 8 Feb 2022 18:09:59 +0100","MIME-Version":"1.0","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101\n\tThunderbird/91.5.0","Content-Language":"en-US","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20220207135937.221226-1-jeanmichel.hautbois@ideasonboard.com>\n\t<20220207135937.221226-4-jeanmichel.hautbois@ideasonboard.com>\n\t<164424807224.1048642.17156545686308100024@Monstersaurus>","From":"Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>","In-Reply-To":"<164424807224.1048642.17156545686308100024@Monstersaurus>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","Subject":"Re: [libcamera-devel] [PATCH v2 3/3] 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":22161,"web_url":"https://patchwork.libcamera.org/comment/22161/","msgid":"<164449222466.3354066.7228726429578488343@Monstersaurus>","date":"2022-02-10T11:23:44","subject":"Re: [libcamera-devel] [PATCH v2 3/3] 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-08 17:09:59)\n> Hi Kieran,\n> \n> On 07/02/2022 16:34, Kieran Bingham wrote:\n> > Hi JM,\n> > \n> > Quoting Jean-Michel Hautbois (2022-02-07 13:59:37)\n> >> Instead of having a local cached value for line duration, store it in\n> >> the IPASessionConfiguration::agc structure.\n> > \n> > Looking at my previous comments on this patch in\n> > https://patchwork.libcamera.org/patch/14778/, I was suggesting that I\n> > believed this line duration should be in the sensor specific structure,\n> > not the AGC specific structure.\n> > \n> > I'm sorry my comment then was not clear, perhaps I should have made it\n> > more direct.\n> > \n> > Is the lineDuration specific to the AGC algorithm in any way that I have\n> > not seen or understood?\n> > \n> > In rkisp1/ipa_context.h, you have:\n> > \n> > struct IPASessionConfiguration {\n> > ...\n> >       struct {\n> >               utils::Duration lineDuration;\n> >       } sensor;\n> > ...\n> > };\n> > \n> > \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> >> ---\n> >>   src/ipa/ipu3/algorithms/agc.cpp | 25 +++++++++++++++----------\n> >>   src/ipa/ipu3/algorithms/agc.h   |  3 +--\n> >>   src/ipa/ipu3/ipa_context.cpp    |  3 +++\n> >>   src/ipa/ipu3/ipa_context.h      |  1 +\n> >>   4 files changed, 20 insertions(+), 12 deletions(-)\n> >>\n> >> diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp\n> >> index a929085c..137c36cf 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> >> @@ -85,11 +85,14 @@ Agc::Agc()\n> >>    */\n> >>   int Agc::configure(IPAContext &context, const IPAConfigInfo &configInfo)\n> >>   {\n> >> -       stride_ = context.configuration.grid.stride;\n> >> +       IPASessionConfiguration &configuration = context.configuration;\n> >> +       IPAFrameContext &frameContext = context.frameContext;\n> >> +\n> >> +       stride_ = configuration.grid.stride;\n> >>   \n> >>          /* \\todo use the IPAContext to provide the limits */\n> >> -       lineDuration_ = configInfo.sensorInfo.lineLength * 1.0s\n> >> -                     / configInfo.sensorInfo.pixelRate;\n> >> +       configuration.agc.lineDuration = configInfo.sensorInfo.lineLength * 1.0s\n> >> +                                      / configInfo.sensorInfo.pixelRate;\n> > \n> > And in RKISP1 this is calculated during the IPA configure, before it\n> > calls configure on the algorithms. Should we do that here to align them?\n> > \n> \n> I noticed that lineDuration_ is cached and used in updateControls() \n> which is called in configure()... and in init() (so, before it is set ?)...\n> We might have an issue there ?\n\nOk - so we have two instances of lineDuration_ ... so they should be\nmoved to a single one in the sensor specific structure ...\n\nIt should be initialised during init() before it's used, and updated\nin configure() before any algorithms are called? Is that right?\n\n\n> >>   \n> >>          minShutterSpeed_ = context.configuration.agc.minShutterSpeed;\n> >>          maxShutterSpeed_ = std::min(context.configuration.agc.maxShutterSpeed,\n> >> @@ -99,8 +102,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.agc.lineDuration;\n> >>   \n> >>          return 0;\n> >>   }\n> >> @@ -182,9 +185,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 +205,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.agc.lineDuration;\n> >>   \n> >>          /*\n> >>           * Update the exposure value for the next computation using the values\n> >> @@ -247,7 +252,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.agc.lineDuration;\n> >>          frameContext.agc.gain = stepGain;\n> >>   }\n> >>   \n> >> @@ -354,7 +359,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..ace9c66f 100644\n> >> --- a/src/ipa/ipu3/ipa_context.cpp\n> >> +++ b/src/ipa/ipu3/ipa_context.cpp\n> >> @@ -84,6 +84,9 @@ namespace libcamera::ipa::ipu3 {\n> >>    *\n> >>    * \\var IPASessionConfiguration::agc.maxAnalogueGain\n> >>    * \\brief Maximum analogue gain supported with the configured sensor\n> >> + *\n> >> + * \\var IPASessionConfiguration::agc.lineDuration\n> >> + * \\brief Line duration in microseconds\n> >>    */\n> >>   \n> >>   /**\n> >> diff --git a/src/ipa/ipu3/ipa_context.h b/src/ipa/ipu3/ipa_context.h\n> >> index c6dc0814..7696fd14 100644\n> >> --- a/src/ipa/ipu3/ipa_context.h\n> >> +++ b/src/ipa/ipu3/ipa_context.h\n> >> @@ -30,6 +30,7 @@ struct IPASessionConfiguration {\n> >>                  utils::Duration maxShutterSpeed;\n> >>                  double minAnalogueGain;\n> >>                  double maxAnalogueGain;\n> >> +               utils::Duration lineDuration;\n> >>          } agc;\n> >>   };\n> >>   \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 17E8ABDCBF\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 10 Feb 2022 11:23:50 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5B630610A1;\n\tThu, 10 Feb 2022 12:23:49 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9974360E70\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 10 Feb 2022 12:23:47 +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 2B92D93;\n\tThu, 10 Feb 2022 12:23:47 +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=\"iXisTk4C\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1644492227;\n\tbh=tzfABD2UA5/dsizRV9Qqph3cQxNHc6UtBYW8u2S5aRs=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=iXisTk4CQF6VJaY4NDSCv74w5CoTQUVBacxnEcafV6NfEdrjDc/McUCH7O2/DKr/6\n\tErH9sPYwcMOJ3FLxJfAp4BR4s41aaxLhb7laY8H+RmO5I9ZFL9tIaXj2EsZcoDc4WT\n\tqh4hkbSG+i4wAdA80rm/9aocaeURkQMA6b3pDo7o=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<5e41c7a5-5423-6773-2b63-da0efd9f9ac1@ideasonboard.com>","References":"<20220207135937.221226-1-jeanmichel.hautbois@ideasonboard.com>\n\t<20220207135937.221226-4-jeanmichel.hautbois@ideasonboard.com>\n\t<164424807224.1048642.17156545686308100024@Monstersaurus>\n\t<5e41c7a5-5423-6773-2b63-da0efd9f9ac1@ideasonboard.com>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Thu, 10 Feb 2022 11:23:44 +0000","Message-ID":"<164449222466.3354066.7228726429578488343@Monstersaurus>","User-Agent":"alot/0.10","Subject":"Re: [libcamera-devel] [PATCH v2 3/3] 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>"}}]