{"id":13400,"url":"https://patchwork.libcamera.org/api/patches/13400/?format=json","web_url":"https://patchwork.libcamera.org/patch/13400/","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-5-jeanmichel.hautbois@ideasonboard.com>","date":"2021-08-19T14:57:54","name":"[libcamera-devel,v4,4/9] ipa: ipu3: Introduce modular algorithm","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"71aeb06003d77ff3a31a29c423af049646a0f5b4","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/13400/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/13400/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/13400/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 8F0E3C3242\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 19 Aug 2021 14:58:09 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id DA5D068909;\n\tThu, 19 Aug 2021 16:58:08 +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 E54B8688A2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 19 Aug 2021 16:58:03 +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 9FE9B2A8;\n\tThu, 19 Aug 2021 16:58:03 +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=\"Zrcw7KbX\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1629385083;\n\tbh=daMIHgYuRLl8o3fT63Gao1Z6dUHeUUR8UJkxm8BPKqM=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=Zrcw7KbXfj2Zx6VGskGrVp8cfM3AKkvOzfkSixwRN3eLQWK7xO546nf1406ubetLz\n\twhS4E4f8WvjrFNRl+0POaItEOr8SmgAepDSPC5BZVkNsxf1mp0VrWauat7+oBgD1Bn\n\tnttkizmgnntBAMjWM5gr/4Ih8b3/VqqaCIdIqBI4=","From":"Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Thu, 19 Aug 2021 16:57:54 +0200","Message-Id":"<20210819145759.184192-5-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 4/9] ipa: ipu3: Introduce modular\n\talgorithm","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":"Implement a new modular framework for algorithms with a common context\nstructure that is passed to each algorithm through a common API.\n\nThis patch:\n- removes all the local references from IPAIPU3 and uses IPAContext\n- implements the list of pointers and the loop at configure call on each\n  algorithm\n- loops in fillParams on each prepare() call on the algorithm list\n- loops in prepareStats on each process() call on the algorithm list\n\nSigned-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\n---\n src/ipa/ipu3/algorithms/algorithm.cpp |  2 +-\n src/ipa/ipu3/algorithms/algorithm.h   |  2 +-\n src/ipa/ipu3/ipa_context.h            |  6 +++\n src/ipa/ipu3/ipu3.cpp                 | 56 +++++++++++++++++++++------\n 4 files changed, 52 insertions(+), 14 deletions(-)","diff":"diff --git a/src/ipa/ipu3/algorithms/algorithm.cpp b/src/ipa/ipu3/algorithms/algorithm.cpp\nindex ec3c152e..8291fb16 100644\n--- a/src/ipa/ipu3/algorithms/algorithm.cpp\n+++ b/src/ipa/ipu3/algorithms/algorithm.cpp\n@@ -92,7 +92,7 @@ void Algorithm::prepare([[maybe_unused]] IPAContext &context, [[maybe_unused]] i\n  * Care shall be taken to ensure the ordering of access to the information\n  * such that the algorithms use up to date state as required.\n  */\n-void Algorithm::process([[maybe_unused]] IPAContext &context, [[maybe_unused]] const ipu3_uapi_stats_3a &stats)\n+void Algorithm::process([[maybe_unused]] IPAContext &context, [[maybe_unused]] const ipu3_uapi_stats_3a *&stats)\n {\n }\n \ndiff --git a/src/ipa/ipu3/algorithms/algorithm.h b/src/ipa/ipu3/algorithms/algorithm.h\nindex 89431005..df66fc8c 100644\n--- a/src/ipa/ipu3/algorithms/algorithm.h\n+++ b/src/ipa/ipu3/algorithms/algorithm.h\n@@ -23,7 +23,7 @@ public:\n \n \tvirtual void prepare(IPAContext &context, ipu3_uapi_params &params);\n \n-\tvirtual void process(IPAContext &context, const ipu3_uapi_stats_3a &stats);\n+\tvirtual void process(IPAContext &context, const ipu3_uapi_stats_3a *&stats);\n };\n \n } /* namespace ipa::ipu3 */\ndiff --git a/src/ipa/ipu3/ipa_context.h b/src/ipa/ipu3/ipa_context.h\nindex 2706d3ca..a031ab83 100644\n--- a/src/ipa/ipu3/ipa_context.h\n+++ b/src/ipa/ipu3/ipa_context.h\n@@ -10,11 +10,17 @@\n \n #include <linux/intel-ipu3.h>\n \n+#include <libcamera/geometry.h>\n+\n namespace libcamera {\n \n namespace ipa::ipu3 {\n \n struct IPASessionConfiguration {\n+\tstruct {\n+\t\tipu3_uapi_grid_config bdsGrid;\n+\t\tSize bdsOutputSize;\n+\t} grid;\n };\n \n struct IPAFrameContext {\ndiff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp\nindex a4359d3e..fa09d9f2 100644\n--- a/src/ipa/ipu3/ipu3.cpp\n+++ b/src/ipa/ipu3/ipu3.cpp\n@@ -29,6 +29,7 @@\n \n #include \"libcamera/internal/mapped_framebuffer.h\"\n \n+#include \"algorithms/algorithm.h\"\n #include \"ipu3_agc.h\"\n #include \"ipu3_awb.h\"\n #include \"libipa/camera_sensor_helper.h\"\n@@ -82,6 +83,17 @@ static constexpr uint32_t kMaxCellHeightPerSet = 56;\n  * are run. This needs to be turned into real per-frame data storage.\n  */\n \n+/**\n+ * \\struct IPASessionConfiguration::grid\n+ * \\brief Grid configuration of the IPA\n+ *\n+ * \\var IPASessionConfiguration::grid::bdsGrid\n+ * \\brief Bayer Down Scaler grid plane config used by the kernel\n+ *\n+ * \\var IPASessionConfiguration::grid::bdsOutputSize\n+ * \\brief BDS output size configured by the pipeline handler\n+ */\n+\n namespace libcamera {\n \n LOG_DEFINE_CATEGORY(IPAIPU3)\n@@ -137,10 +149,12 @@ private:\n \t/* Interface to the Camera Helper */\n \tstd::unique_ptr<CameraSensorHelper> camHelper_;\n \n+\t/* Maintain the algorithms used by the IPA */\n+\tstd::list<std::unique_ptr<ipa::ipu3::Algorithm>> algorithms_;\n+\n \t/* Local parameter storage */\n+\tstruct IPAContext context_;\n \tstruct ipu3_uapi_params params_;\n-\n-\tstruct ipu3_uapi_grid_config bdsGrid_;\n };\n \n /**\n@@ -237,7 +251,9 @@ void IPAIPU3::calculateBdsGrid(const Size &bdsOutputSize)\n \tuint32_t minError = std::numeric_limits<uint32_t>::max();\n \tSize best;\n \tSize bestLog2;\n-\tbdsGrid_ = {};\n+\n+\t/* Set the BDS output size in the IPAConfiguration structure */\n+\tcontext_.configuration.grid.bdsOutputSize = bdsOutputSize;\n \n \tfor (uint32_t widthShift = 3; widthShift <= 7; ++widthShift) {\n \t\tuint32_t width = std::min(kMaxCellWidthPerSet,\n@@ -261,14 +277,17 @@ void IPAIPU3::calculateBdsGrid(const Size &bdsOutputSize)\n \t\t}\n \t}\n \n-\tbdsGrid_.width = best.width >> bestLog2.width;\n-\tbdsGrid_.block_width_log2 = bestLog2.width;\n-\tbdsGrid_.height = best.height >> bestLog2.height;\n-\tbdsGrid_.block_height_log2 = bestLog2.height;\n+\tstruct ipu3_uapi_grid_config &bdsGrid = context_.configuration.grid.bdsGrid;\n+\tbdsGrid.x_start = 0;\n+\tbdsGrid.y_start = 0;\n+\tbdsGrid.width = best.width >> bestLog2.width;\n+\tbdsGrid.block_width_log2 = bestLog2.width;\n+\tbdsGrid.height = best.height >> bestLog2.height;\n+\tbdsGrid.block_height_log2 = bestLog2.height;\n \n \tLOG(IPAIPU3, Debug) << \"Best grid found is: (\"\n-\t\t\t    << (int)bdsGrid_.width << \" << \" << (int)bdsGrid_.block_width_log2 << \") x (\"\n-\t\t\t    << (int)bdsGrid_.height << \" << \" << (int)bdsGrid_.block_height_log2 << \")\";\n+\t\t\t    << (int)bdsGrid.width << \" << \" << (int)bdsGrid.block_width_log2 << \") x (\"\n+\t\t\t    << (int)bdsGrid.height << \" << \" << (int)bdsGrid.block_height_log2 << \")\";\n }\n \n int IPAIPU3::configure(const IPAConfigInfo &configInfo)\n@@ -310,15 +329,22 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo)\n \n \tdefVBlank_ = itVBlank->second.def().get<int32_t>();\n \n+\t/* Clean context and IPU3 parameters at configuration */\n \tparams_ = {};\n+\tcontext_ = {};\n \n \tcalculateBdsGrid(configInfo.bdsOutputSize);\n \n-\tawbAlgo_ = std::make_unique<IPU3Awb>();\n-\tawbAlgo_->initialise(params_, configInfo.bdsOutputSize, bdsGrid_);\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+\tawbAlgo_ = std::make_unique<IPU3Awb>();\n+\tawbAlgo_->initialise(params_, context_.configuration.grid.bdsOutputSize, context_.configuration.grid.bdsGrid);\n \tagcAlgo_ = std::make_unique<IPU3Agc>();\n-\tagcAlgo_->initialise(bdsGrid_, sensorInfo_);\n+\tagcAlgo_->initialise(context_.configuration.grid.bdsGrid, sensorInfo_);\n \n \treturn 0;\n }\n@@ -392,6 +418,9 @@ void IPAIPU3::processControls([[maybe_unused]] unsigned int frame,\n \n void IPAIPU3::fillParams(unsigned int frame, ipu3_uapi_params *params)\n {\n+\tfor (auto const &algo : algorithms_)\n+\t\talgo->prepare(context_, params_);\n+\n \tif (agcAlgo_->updateControls())\n \t\tawbAlgo_->updateWbParameters(params_, agcAlgo_->gamma());\n \n@@ -409,6 +438,9 @@ 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 \tdouble gain = camHelper_->gain(gain_);\n \tagcAlgo_->process(stats, exposure_, gain);\n \tgain_ = camHelper_->gainCode(gain);\n","prefixes":["libcamera-devel","v4","4/9"]}