{"id":13403,"url":"https://patchwork.libcamera.org/api/patches/13403/?format=json","web_url":"https://patchwork.libcamera.org/patch/13403/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20210819145759.184192-10-jeanmichel.hautbois@ideasonboard.com>","date":"2021-08-19T14:57:59","name":"[libcamera-devel,v4,9/9] ipa: ipu3: Move IPU3 agc into algorithms","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"3fbf5a2bc4ae1524f50cdd7fb9d3e81a53034e7b","submitter":{"id":75,"url":"https://patchwork.libcamera.org/api/people/75/?format=json","name":"Jean-Michel Hautbois","email":"jeanmichel.hautbois@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/13403/mbox/","series":[{"id":2372,"url":"https://patchwork.libcamera.org/api/series/2372/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2372","date":"2021-08-19T14:57:50","name":"IPU3: Introduce modularity for algorithms","version":4,"mbox":"https://patchwork.libcamera.org/series/2372/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/13403/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/13403/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id A2327C3245\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 19 Aug 2021 14:58:12 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 642FE68933;\n\tThu, 19 Aug 2021 16:58:12 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 045D068886\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 19 Aug 2021 16:58:05 +0200 (CEST)","from tatooine.ideasonboard.com (unknown\n\t[IPv6:2a01:e0a:169:7140:d68d:3cb6:f3c7:c19c])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id A67ADDD;\n\tThu, 19 Aug 2021 16:58:04 +0200 (CEST)"],"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=\"F0cQLQM/\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1629385084;\n\tbh=9Hmr8XoLnoxV3BzWJY5Eub3v9NioH7Qflxa2lJ77Wew=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=F0cQLQM/TXM1cDrivFkEthyR3w1xsH9jx0Ul6rW2J2DOGe1nBpi2/cJtQvvS+U6Xl\n\tQVeCFOVbJxrq9/jo/uWT8AiFXKAaQ643nuGtBH9a6cdf0KjsEV4hNQ2ChSHbwFwpKq\n\tU8hJv0Ud9IXJjDAm5Czs3X/k9DTEvmhVT4hG3MLI=","From":"Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Thu, 19 Aug 2021 16:57:59 +0200","Message-Id":"<20210819145759.184192-10-jeanmichel.hautbois@ideasonboard.com>","X-Mailer":"git-send-email 2.30.2","In-Reply-To":"<20210819145759.184192-1-jeanmichel.hautbois@ideasonboard.com>","References":"<20210819145759.184192-1-jeanmichel.hautbois@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v4 9/9] ipa: ipu3: Move IPU3 agc into\n\talgorithms","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>"},"content":"Now that the interface is properly used by the AGC class, move it into\nipa::ipu3::algorithms and let the loops do the calls.\nAs we need to exchange the exposure_ and gain_ by passing them through the\nFrameContext, use the calculated values in setControls() function to\nease the reading.\n\nSigned-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n .../ipu3/{ipu3_agc.cpp => algorithms/agc.cpp} | 18 ++++++++---------\n src/ipa/ipu3/{ipu3_agc.h => algorithms/agc.h} | 20 +++++++++----------\n src/ipa/ipu3/algorithms/meson.build           |  1 +\n src/ipa/ipu3/ipu3.cpp                         | 20 ++++++++-----------\n src/ipa/ipu3/meson.build                      |  1 -\n 5 files changed, 28 insertions(+), 32 deletions(-)\n rename src/ipa/ipu3/{ipu3_agc.cpp => algorithms/agc.cpp} (94%)\n rename src/ipa/ipu3/{ipu3_agc.h => algorithms/agc.h} (73%)","diff":"diff --git a/src/ipa/ipu3/ipu3_agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp\nsimilarity index 94%\nrename from src/ipa/ipu3/ipu3_agc.cpp\nrename to src/ipa/ipu3/algorithms/agc.cpp\nindex 30888e10..db333509 100644\n--- a/src/ipa/ipu3/ipu3_agc.cpp\n+++ b/src/ipa/ipu3/algorithms/agc.cpp\n@@ -5,7 +5,7 @@\n  * ipu3_agc.cpp - AGC/AEC control algorithm\n  */\n \n-#include \"ipu3_agc.h\"\n+#include \"agc.h\"\n \n #include <algorithm>\n #include <chrono>\n@@ -21,7 +21,7 @@ namespace libcamera {\n \n using namespace std::literals::chrono_literals;\n \n-namespace ipa::ipu3 {\n+namespace ipa::ipu3::algorithms {\n \n LOG_DEFINE_CATEGORY(IPU3Agc)\n \n@@ -50,14 +50,14 @@ static constexpr double kEvGainTarget = 0.5;\n /* A cell is 8 bytes and contains averages for RGB values and saturation ratio */\n static constexpr uint8_t kCellSize = 8;\n \n-IPU3Agc::IPU3Agc()\n+Agc::Agc()\n \t: frameCount_(0), lastFrame_(0), iqMean_(0.0), lineDuration_(0s),\n \t  maxExposureTime_(0s), prevExposure_(0s), prevExposureNoDg_(0s),\n \t  currentExposure_(0s), currentExposureNoDg_(0s)\n {\n }\n \n-int IPU3Agc::configure(IPAContext &context, const IPAConfigInfo &configInfo)\n+int Agc::configure(IPAContext &context, const IPAConfigInfo &configInfo)\n {\n \taeGrid_ = context.configuration.grid.bdsGrid;\n \n@@ -68,7 +68,7 @@ int IPU3Agc::configure(IPAContext &context, const IPAConfigInfo &configInfo)\n \treturn 0;\n }\n \n-void IPU3Agc::processBrightness(const ipu3_uapi_stats_3a *stats)\n+void Agc::processBrightness(const ipu3_uapi_stats_3a *stats)\n {\n \tconst struct ipu3_uapi_grid_config statsAeGrid = stats->stats_4a_config.awb_config.grid;\n \tRectangle aeRegion = { statsAeGrid.x_start,\n@@ -109,7 +109,7 @@ void IPU3Agc::processBrightness(const ipu3_uapi_stats_3a *stats)\n \tiqMean_ = Histogram(Span<uint32_t>(hist)).interQuantileMean(0.98, 1.0);\n }\n \n-void IPU3Agc::filterExposure()\n+void Agc::filterExposure()\n {\n \tdouble speed = 0.2;\n \tif (prevExposure_ == 0s) {\n@@ -143,7 +143,7 @@ void IPU3Agc::filterExposure()\n \tLOG(IPU3Agc, Debug) << \"After filtering, total_exposure \" << prevExposure_;\n }\n \n-void IPU3Agc::lockExposureGain(uint32_t &exposure, double &gain)\n+void Agc::lockExposureGain(uint32_t &exposure, double &gain)\n {\n \t/* Algorithm initialization should wait for first valid frames */\n \t/* \\todo - have a number of frames given by DelayedControls ?\n@@ -186,7 +186,7 @@ void IPU3Agc::lockExposureGain(uint32_t &exposure, double &gain)\n \tlastFrame_ = frameCount_;\n }\n \n-void IPU3Agc::process(IPAContext &context, const ipu3_uapi_stats_3a *&stats)\n+void Agc::process(IPAContext &context, const ipu3_uapi_stats_3a *&stats)\n {\n \tuint32_t &exposure = context.frameContext.agc.exposure;\n \tdouble &gain = context.frameContext.agc.gain;\n@@ -195,6 +195,6 @@ void IPU3Agc::process(IPAContext &context, const ipu3_uapi_stats_3a *&stats)\n \tframeCount_++;\n }\n \n-} /* namespace ipa::ipu3 */\n+} /* namespace ipa::ipu3::algorithms */\n \n } /* namespace libcamera */\ndiff --git a/src/ipa/ipu3/ipu3_agc.h b/src/ipa/ipu3/algorithms/agc.h\nsimilarity index 73%\nrename from src/ipa/ipu3/ipu3_agc.h\nrename to src/ipa/ipu3/algorithms/agc.h\nindex 0bd70021..80ce5fa5 100644\n--- a/src/ipa/ipu3/ipu3_agc.h\n+++ b/src/ipa/ipu3/algorithms/agc.h\n@@ -2,10 +2,10 @@\n /*\n  * Copyright (C) 2021, Ideas On Board\n  *\n- * ipu3_agc.h - IPU3 AGC/AEC control algorithm\n+ * agc.h - IPU3 AGC/AEC control algorithm\n  */\n-#ifndef __LIBCAMERA_IPU3_AGC_H__\n-#define __LIBCAMERA_IPU3_AGC_H__\n+#ifndef __LIBCAMERA_IPU3_ALGORITHMS_AGC_H__\n+#define __LIBCAMERA_IPU3_ALGORITHMS_AGC_H__\n \n #include <linux/intel-ipu3.h>\n \n@@ -13,21 +13,21 @@\n \n #include <libcamera/geometry.h>\n \n-#include \"algorithms/algorithm.h\"\n+#include \"algorithm.h\"\n \n namespace libcamera {\n \n struct IPACameraSensorInfo;\n \n-namespace ipa::ipu3 {\n+namespace ipa::ipu3::algorithms {\n \n using utils::Duration;\n \n-class IPU3Agc : public Algorithm\n+class Agc : public Algorithm\n {\n public:\n-\tIPU3Agc();\n-\t~IPU3Agc() = default;\n+\tAgc();\n+\t~Agc() = default;\n \n \tint configure(IPAContext &context, const IPAConfigInfo &configInfo) override;\n \tvoid process(IPAContext &context, const ipu3_uapi_stats_3a *&stats) override;\n@@ -53,8 +53,8 @@ private:\n \tDuration currentExposureNoDg_;\n };\n \n-} /* namespace ipa::ipu3 */\n+} /* namespace ipa::ipu3::algorithms */\n \n } /* namespace libcamera */\n \n-#endif /* __LIBCAMERA_IPU3_AGC_H__ */\n+#endif /* __LIBCAMERA_IPU3_ALGORITHMS_AGC_H__ */\ndiff --git a/src/ipa/ipu3/algorithms/meson.build b/src/ipa/ipu3/algorithms/meson.build\nindex fa004df4..deae225b 100644\n--- a/src/ipa/ipu3/algorithms/meson.build\n+++ b/src/ipa/ipu3/algorithms/meson.build\n@@ -1,6 +1,7 @@\n # SPDX-License-Identifier: CC0-1.0\n \n ipu3_ipa_algorithms = files([\n+    'agc.cpp',\n     'algorithm.cpp',\n     'awb.cpp',\n     'tone_mapping.cpp',\ndiff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp\nindex c124ce31..822959fe 100644\n--- a/src/ipa/ipu3/ipu3.cpp\n+++ b/src/ipa/ipu3/ipu3.cpp\n@@ -29,10 +29,10 @@\n \n #include \"libcamera/internal/mapped_framebuffer.h\"\n \n+#include \"algorithms/agc.h\"\n #include \"algorithms/algorithm.h\"\n #include \"algorithms/awb.h\"\n #include \"algorithms/tone_mapping.h\"\n-#include \"ipu3_agc.h\"\n #include \"libipa/camera_sensor_helper.h\"\n \n static constexpr uint32_t kMaxCellWidthPerSet = 160;\n@@ -187,8 +187,6 @@ private:\n \tuint32_t minGain_;\n \tuint32_t maxGain_;\n \n-\t/* Interface to the AEC/AGC algorithm */\n-\tstd::unique_ptr<IPU3Agc> agcAlgo_;\n \t/* Interface to the Camera Helper */\n \tstd::unique_ptr<CameraSensorHelper> camHelper_;\n \n@@ -269,6 +267,7 @@ int IPAIPU3::init(const IPASettings &settings,\n \t*ipaControls = ControlInfoMap(std::move(controls), controls::controls);\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 \talgorithms_.push_back(std::make_unique<algorithms::ToneMapping>());\n \n@@ -388,9 +387,6 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo)\n \t\t\treturn ret;\n \t}\n \n-\tagcAlgo_ = std::make_unique<IPU3Agc>();\n-\tagcAlgo_->configure(context_, configInfo);\n-\n \treturn 0;\n }\n \n@@ -480,15 +476,12 @@ void IPAIPU3::parseStatistics(unsigned int frame,\n {\n \tControlList ctrls(controls::controls);\n \n-\tfor (auto const &algo : algorithms_)\n-\t\talgo->process(context_, stats);\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-\tagcAlgo_->process(context_, stats);\n-\texposure_ = context_.frameContext.agc.exposure;\n-\tgain_ = camHelper_->gainCode(context_.frameContext.agc.gain);\n+\n+\tfor (auto const &algo : algorithms_)\n+\t\talgo->process(context_, stats);\n \n \tsetControls(frame);\n \n@@ -509,6 +502,9 @@ void IPAIPU3::setControls(unsigned int frame)\n \tIPU3Action op;\n \top.op = ActionSetSensorControls;\n \n+\texposure_ = context_.frameContext.agc.exposure;\n+\tgain_ = camHelper_->gainCode(context_.frameContext.agc.gain);\n+\n \tControlList ctrls(ctrls_);\n \tctrls.set(V4L2_CID_EXPOSURE, static_cast<int32_t>(exposure_));\n \tctrls.set(V4L2_CID_ANALOGUE_GAIN, static_cast<int32_t>(gain_));\ndiff --git a/src/ipa/ipu3/meson.build b/src/ipa/ipu3/meson.build\nindex d1126947..39320980 100644\n--- a/src/ipa/ipu3/meson.build\n+++ b/src/ipa/ipu3/meson.build\n@@ -6,7 +6,6 @@ ipa_name = 'ipa_ipu3'\n \n ipu3_ipa_sources = files([\n     'ipu3.cpp',\n-    'ipu3_agc.cpp',\n ])\n \n ipu3_ipa_sources += ipu3_ipa_algorithms\n","prefixes":["libcamera-devel","v4","9/9"]}