[{"id":31625,"web_url":"https://patchwork.libcamera.org/comment/31625/","msgid":"<172840386905.532453.4314595509191306021@ping.linuxembedded.co.uk>","date":"2024-10-08T16:11:09","subject":"Re: [PATCH v3 7/7] [DNI] ipa: Add debug controls to the agc\n\talgorithm","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Stefan Klug (2024-10-08 16:29:45)\n> Add a few (arbitrary) debug metadata to the agc algorithm. This shows\n> how easy it is to add debug metadata to an ipa even for classes that\n> don't have direct access to the metadata list or the context like\n> AgcMeanLuminance. The control_ids_debug.yaml was autogenerated by\n> calling utils/gen-debug-controls.py\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> \n> ---\n> Update in v2:\n> - Break too long line in agc.cpp\n> ---\n>  src/ipa/libipa/agc_mean_luminance.cpp |  8 ++++++++\n>  src/ipa/libipa/agc_mean_luminance.h   |  4 ++++\n>  src/ipa/rkisp1/algorithms/agc.cpp     | 10 ++++++++++\n>  src/libcamera/control_ids_debug.yaml  | 21 ++++++++++++++++++++-\n>  4 files changed, 42 insertions(+), 1 deletion(-)\n> \n> diff --git a/src/ipa/libipa/agc_mean_luminance.cpp b/src/ipa/libipa/agc_mean_luminance.cpp\n> index f97ef11771c4..bd0f85afcd2e 100644\n> --- a/src/ipa/libipa/agc_mean_luminance.cpp\n> +++ b/src/ipa/libipa/agc_mean_luminance.cpp\n> @@ -133,6 +133,11 @@ static constexpr double kDefaultRelativeLuminanceTarget = 0.16;\n>   * values.\n>   */\n>  \n> +/**\n> + * \\var AgcMeanLuminance::debugMeta_\n> + * \\brief DebugMetadata helper\n> + */\n> +\n>  AgcMeanLuminance::AgcMeanLuminance()\n>         : frameCount_(0), filteredExposure_(0s), relativeLuminanceTarget_(0)\n>  {\n> @@ -541,8 +546,11 @@ AgcMeanLuminance::calculateNewEv(uint32_t constraintModeIndex,\n>                 exposureModeHelpers_.at(exposureModeIndex);\n>  \n>         double gain = estimateInitialGain();\n> +       debugMeta_.set<float>(controls::debug::AgcInitialGain, static_cast<float>(gain));\n>         gain = constraintClampGain(constraintModeIndex, yHist, gain);\n>  \n> +       debugMeta_.set<float>(controls::debug::AgcNewGain, static_cast<float>(gain));\n> +\n>         /*\n>          * We don't check whether we're already close to the target, because\n>          * even if the effective exposure value is the same as the last frame's\n> diff --git a/src/ipa/libipa/agc_mean_luminance.h b/src/ipa/libipa/agc_mean_luminance.h\n> index 576d28be8eb0..428465a11a36 100644\n> --- a/src/ipa/libipa/agc_mean_luminance.h\n> +++ b/src/ipa/libipa/agc_mean_luminance.h\n> @@ -16,6 +16,7 @@\n>  \n>  #include <libcamera/controls.h>\n>  \n> +#include \"libcamera/internal/debug_controls.h\"\n>  #include \"libcamera/internal/yaml_parser.h\"\n>  \n>  #include \"exposure_mode_helper.h\"\n> @@ -71,6 +72,9 @@ public:\n>                 frameCount_ = 0;\n>         }\n>  \n> +protected:\n> +       DebugMetadata debugMeta_;\n> +\n>  private:\n>         virtual double estimateLuminance(const double gain) const = 0;\n>  \n> diff --git a/src/ipa/rkisp1/algorithms/agc.cpp b/src/ipa/rkisp1/algorithms/agc.cpp\n> index 17d074d9c03e..6668db942042 100644\n> --- a/src/ipa/rkisp1/algorithms/agc.cpp\n> +++ b/src/ipa/rkisp1/algorithms/agc.cpp\n> @@ -139,6 +139,8 @@ int Agc::init(IPAContext &context, const YamlObject &tuningData)\n>  {\n>         int ret;\n>  \n> +       debugMeta_.setParent(&context.debugMetadata);\n> +\n>         ret = parseTuningData(tuningData);\n>         if (ret)\n>                 return ret;\n> @@ -444,6 +446,14 @@ void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame,\n>                                frameContext.agc.exposureMode,\n>                                hist, effectiveExposureValue);\n>  \n> +       debugMeta_.set<float>(controls::debug::AgcAnalogGain, aGain);\n> +       debugMeta_.set<float>(controls::debug::AgcDigitalGain, dGain);\n> +\n> +       const Span<const uint64_t> orig = hist.data();\n> +       const Span<const int64_t> data{ reinterpret_cast<const int64_t *>(&orig[0]),\n> +                                       orig.size() };\n> +       debugMeta_.set<Span<const int64_t>>(controls::debug::AgcHistogram, data);\n> +\n>         LOG(RkISP1Agc, Debug)\n>                 << \"Divided up shutter, analogue gain and digital gain are \"\n>                 << shutterTime << \", \" << aGain << \" and \" << dGain;\n> diff --git a/src/libcamera/control_ids_debug.yaml b/src/libcamera/control_ids_debug.yaml\n> index 797532712099..356eea627f0f 100644\n> --- a/src/libcamera/control_ids_debug.yaml\n> +++ b/src/libcamera/control_ids_debug.yaml\n> @@ -1,6 +1,25 @@\n>  # SPDX-License-Identifier: LGPL-2.1-or-later\n>  #\n> +# This file was generated by utils/gen-debug-controls.py\n> +#\n>  %YAML 1.1\n>  ---\n>  vendor: debug\n> -controls: []\n> +controls:\n> +- AgcAnalogGain:\n> +    type: float\n> +    description: Debug control AgcAnalogGain found in src/ipa/rkisp1/algorithms/agc.cpp:448\n> +- AgcDigitalGain:\n> +    type: float\n> +    description: Debug control AgcDigitalGain found in src/ipa/rkisp1/algorithms/agc.cpp:449\n> +- AgcHistogram:\n> +    type: int64_t\n> +    description: Debug control AgcHistogram found in src/ipa/rkisp1/algorithms/agc.cpp:454\n> +    size: '[n]'\n> +- AgcInitialGain:\n> +    type: float\n> +    description: Debug control AgcInitialGain found in src/ipa/libipa/agc_mean_luminance.cpp:548\n> +- AgcNewGain:\n> +    type: float\n> +    description: Debug control AgcNewGain found in src/ipa/libipa/agc_mean_luminance.cpp:551\n\nCuriosity hits me here.\n\nWhat happens if two places try to set the same control? Perhaps in two\nIPA modules? Or is this undefined behaviour/not permitted?\n\n--\nKieran\n\n\n> +\n> -- \n> 2.43.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 DBB8EBE080\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  8 Oct 2024 16:11:14 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D6964618C9;\n\tTue,  8 Oct 2024 18:11:13 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D09C7618C9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  8 Oct 2024 18:11:11 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id EDDF1514;\n\tTue,  8 Oct 2024 18:09:34 +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=\"crARFzRw\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1728403775;\n\tbh=ErNluqXnVcaOmvZBCEH+D4pqJQmjbhWUFvMWY/CfkDg=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=crARFzRw671jixWlxJhjs2yZkxnZqrAS/yiONAxgKolnj8W/u9GCpwAiien5TTtS1\n\toPDkL4/PZ1MG/7t/6uhaOniMe8w+buRhLpUlZi71tha4vHkBbSx1yFW6iD5zhAfCCQ\n\twnbBj0tDhsS42MUjjIb8Xwf9vt26Sec6JE4trLGY=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20241008153031.429906-8-stefan.klug@ideasonboard.com>","References":"<20241008153031.429906-1-stefan.klug@ideasonboard.com>\n\t<20241008153031.429906-8-stefan.klug@ideasonboard.com>","Subject":"Re: [PATCH v3 7/7] [DNI] ipa: Add debug controls to the agc\n\talgorithm","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Tue, 08 Oct 2024 17:11:09 +0100","Message-ID":"<172840386905.532453.4314595509191306021@ping.linuxembedded.co.uk>","User-Agent":"alot/0.10","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>"}}]