[{"id":20341,"web_url":"https://patchwork.libcamera.org/comment/20341/","msgid":"<YXDJ6aFs5Yu+RI3j@pendragon.ideasonboard.com>","date":"2021-10-21T02:01:13","subject":"Re: [libcamera-devel] [PATCH v2 02/13] ipa: ipu3: set frameContext\n\tbefore controls","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jean-Michel,\n\nThank you for the patch.\n\nOn Wed, Oct 20, 2021 at 05:45:56PM +0200, Jean-Michel Hautbois wrote:\n> The AGC frame context needs to be initialised correctly for the first\n> iteration.\n> \n> Set the gain and exposure appropriately to the current values known to\n> the IPA.\n\nThis patch has changed a lot compared to v1, the commit message needs to\nbe updated to explain what you're now doing.\n\n> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> ---\n>  src/ipa/ipu3/algorithms/agc.cpp |  8 ++++-\n>  src/ipa/ipu3/ipa_context.h      |  9 +++++\n>  src/ipa/ipu3/ipu3.cpp           | 64 +++++++++++++++++++++++++++++----\n>  3 files changed, 73 insertions(+), 8 deletions(-)\n> \n> diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp\n> index 970ec424..a001e349 100644\n> --- a/src/ipa/ipu3/algorithms/agc.cpp\n> +++ b/src/ipa/ipu3/algorithms/agc.cpp\n> @@ -60,7 +60,13 @@ int Agc::configure(IPAContext &context, const IPAConfigInfo &configInfo)\n>  \n>  \tlineDuration_ = configInfo.sensorInfo.lineLength * 1.0s\n>  \t\t      / configInfo.sensorInfo.pixelRate;\n> -\tmaxExposureTime_ = kMaxExposure * lineDuration_;\n> +\tmaxExposureTime_ = context.configuration.agc.maxShutterSpeed;\n> +\n> +\t/* Configure the default exposure and gain */\n\ns/gain/gain./\n\n> +\tcontext.frameContext.agc.gain =\n> +\t\tcontext.configuration.agc.minAnalogueGain;\n> +\tcontext.frameContext.agc.exposure =\n> +\t\tcontext.configuration.agc.minShutterSpeed / lineDuration_;\n>  \n>  \treturn 0;\n>  }\n> diff --git a/src/ipa/ipu3/ipa_context.h b/src/ipa/ipu3/ipa_context.h\n> index 5bab684c..847c03fe 100644\n> --- a/src/ipa/ipu3/ipa_context.h\n> +++ b/src/ipa/ipu3/ipa_context.h\n> @@ -10,6 +10,8 @@\n>  \n>  #include <linux/intel-ipu3.h>\n>  \n> +#include <libcamera/base/utils.h>\n> +\n>  #include <libcamera/geometry.h>\n>  \n>  namespace libcamera {\n> @@ -22,6 +24,13 @@ struct IPASessionConfiguration {\n>  \t\tSize bdsOutputSize;\n>  \t\tuint32_t stride;\n>  \t} grid;\n> +\n> +\tstruct {\n> +\t\tutils::Duration minShutterSpeed;\n> +\t\tutils::Duration maxShutterSpeed;\n> +\t\tdouble minAnalogueGain;\n> +\t\tdouble maxAnalogueGain;\n> +\t} agc;\n>  };\n>  \n>  struct IPAFrameContext {\n> diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp\n> index 388f1902..36ca83f5 100644\n> --- a/src/ipa/ipu3/ipu3.cpp\n> +++ b/src/ipa/ipu3/ipu3.cpp\n> @@ -97,6 +97,23 @@\n>   * \\brief Number of cells on one line including the ImgU padding\n>   */\n>  \n> +/**\n> + * \\struct IPASessionConfiguration::agc\n> + * \\brief AGC parameters configuration of the IPA\n> + *\n> + * \\var IPASessionConfiguration::agc::minShutterSpeed\n> + * \\brief Minimum shutter speed supported with the configured sensor\n> + *\n> + * \\var IPASessionConfiguration::grid::maxShutterSpeed\n> + * \\brief Maximum shutter speed supported with the configured sensor\n> + *\n> + * \\var IPASessionConfiguration::grid::minAnalogueGain\n> + * \\brief Minimum analogue gain supported with the configured sensor\n> + *\n> + * \\var IPASessionConfiguration::grid::maxAnalogueGain\n> + * \\brief Maximum analogue gain supported with the configured sensor\n> + */\n> +\n>  /**\n>   * \\struct IPAFrameContext::agc\n>   * \\brief Context for the Automatic Gain Control algorithm\n> @@ -158,6 +175,8 @@ namespace libcamera {\n>  \n>  LOG_DEFINE_CATEGORY(IPAIPU3)\n>  \n> +using namespace std::literals::chrono_literals;\n> +\n>  namespace ipa::ipu3 {\n>  \n>  class IPAIPU3 : public IPAIPU3Interface\n> @@ -182,6 +201,8 @@ private:\n>  \tvoid updateControls(const IPACameraSensorInfo &sensorInfo,\n>  \t\t\t    const ControlInfoMap &sensorControls,\n>  \t\t\t    ControlInfoMap *ipaControls);\n> +\tvoid updateSessionConfiguration(const IPACameraSensorInfo &sensorInfo,\n> +\t\t\t\t\tconst ControlInfoMap &sensorControls);\n>  \tvoid processControls(unsigned int frame, const ControlList &controls);\n>  \tvoid fillParams(unsigned int frame, ipu3_uapi_params *params);\n>  \tvoid parseStatistics(unsigned int frame,\n> @@ -216,6 +237,36 @@ private:\n>  \tstruct IPAContext context_;\n>  };\n>  \n> +/*\n> + * Compute IPASessionConfiguration using the sensor information and the sensor\n> + * v4l2 controls.\n> + */\n> +void IPAIPU3::updateSessionConfiguration(const IPACameraSensorInfo &sensorInfo,\n> +\t\t\t\t\t const ControlInfoMap &sensorControls)\n> +{\n> +\tconst ControlInfo &v4l2Exposure = sensorControls.find(V4L2_CID_EXPOSURE)->second;\n> +\tint32_t minExposure = v4l2Exposure.min().get<int32_t>();\n> +\tint32_t maxExposure = v4l2Exposure.max().get<int32_t>();\n> +\n> +\tutils::Duration lineDuration = sensorInfo.lineLength * 1.0s\n> +\t\t\t\t     / sensorInfo.pixelRate;\n> +\n> +\tconst ControlInfo &v4l2Gain = sensorControls.find(V4L2_CID_ANALOGUE_GAIN)->second;\n> +\tint32_t minGain = v4l2Gain.min().get<int32_t>();\n> +\tint32_t maxGain = v4l2Gain.max().get<int32_t>();\n> +\n> +\t/*\n> +\t * When the AGC computes the new exposure values for a frame, it needs\n> +\t * to know the limits for shutter speed and analogue gain.\n> +\t * As it depends on the sensor, update it with the controls.\n> +\t *\n> +\t * \\todo take VBLANK into account for maximum shutter speed\n> +\t */\n> +\tcontext_.configuration.agc.minShutterSpeed = minExposure * lineDuration;\n> +\tcontext_.configuration.agc.maxShutterSpeed = maxExposure * lineDuration;\n> +\tcontext_.configuration.agc.minAnalogueGain = camHelper_->gain(minGain);\n> +\tcontext_.configuration.agc.maxAnalogueGain = camHelper_->gain(maxGain);\n> +}\n>  \n>  /*\n>   * Compute camera controls using the sensor information and the sensor\n> @@ -436,15 +487,18 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo,\n>  \n>  \tcalculateBdsGrid(configInfo.bdsOutputSize);\n>  \n> +\t/* Update the camera controls using the new sensor settings. */\n> +\tupdateControls(sensorInfo_, ctrls_, ipaControls);\n> +\n> +\t/* Update the IPASessionConfiguration using the sensor settings */\n\ns/settings/settings./\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> +\tupdateSessionConfiguration(sensorInfo_, ctrls_);\n> +\n>  \tfor (auto const &algo : algorithms_) {\n>  \t\tint ret = algo->configure(context_, configInfo);\n>  \t\tif (ret)\n>  \t\t\treturn ret;\n>  \t}\n>  \n> -\t/* Update the camera controls using the new sensor settings. */\n> -\tupdateControls(sensorInfo_, ctrls_, ipaControls);\n> -\n>  \treturn 0;\n>  }\n>  \n> @@ -543,10 +597,6 @@ void IPAIPU3::parseStatistics(unsigned int frame,\n>  {\n>  \tControlList ctrls(controls::controls);\n>  \n> -\t/* \\todo These fields should not be written by the IPAIPU3 layer */\n> -\tcontext_.frameContext.agc.gain = camHelper_->gain(gain_);\n> -\tcontext_.frameContext.agc.exposure = exposure_;\n> -\n>  \tfor (auto const &algo : algorithms_)\n>  \t\talgo->process(context_, stats);\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 7638CBF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 21 Oct 2021 02:01:34 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D786A68F63;\n\tThu, 21 Oct 2021 04:01:33 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 276FB68F5B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 21 Oct 2021 04:01:33 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 94C8E93;\n\tThu, 21 Oct 2021 04:01:32 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"ho7G0cSR\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1634781692;\n\tbh=EsmS/zqdqaJlUZm/kZTwom/Xt2uy3zEhqPEnfl6X8qM=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=ho7G0cSR2F/RoqYfRfcIOVOKmpHCZekSvrWTwlUm042nbAL552U2pBb884r/07dDl\n\tM7vN5jdNoGLu8i8uXwM3ZixzA51h9Q73Qy98tixtklSTzBAOH3PUTGG12DVP3ibyXr\n\tZKr721tKK5Rr91wm51WTvczgrEWHLuw5o1EAKU5Q=","Date":"Thu, 21 Oct 2021 05:01:13 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>","Message-ID":"<YXDJ6aFs5Yu+RI3j@pendragon.ideasonboard.com>","References":"<20211020154607.180161-1-jeanmichel.hautbois@ideasonboard.com>\n\t<20211020154607.180161-3-jeanmichel.hautbois@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20211020154607.180161-3-jeanmichel.hautbois@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v2 02/13] ipa: ipu3: set frameContext\n\tbefore controls","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>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]