{"id":14653,"url":"https://patchwork.libcamera.org/api/1.1/patches/14653/?format=json","web_url":"https://patchwork.libcamera.org/patch/14653/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20211119111654.68445-5-jeanmichel.hautbois@ideasonboard.com>","date":"2021-11-19T11:16:50","name":"[libcamera-devel,v1,4/8] ipa: ipu3: Introduce the Algorithm class","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"1d229e77d0c0e94a126d2e9ed49272a9a1b3c8df","submitter":{"id":75,"url":"https://patchwork.libcamera.org/api/1.1/people/75/?format=json","name":"Jean-Michel Hautbois","email":"jeanmichel.hautbois@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/14653/mbox/","series":[{"id":2735,"url":"https://patchwork.libcamera.org/api/1.1/series/2735/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2735","date":"2021-11-19T11:16:46","name":"Introduce AGC for RkISP1","version":1,"mbox":"https://patchwork.libcamera.org/series/2735/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/14653/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/14653/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 9CC9AC3250\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 19 Nov 2021 11:17:06 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 32DE960398;\n\tFri, 19 Nov 2021 12:17:06 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0F66760376\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 19 Nov 2021 12:17:00 +0100 (CET)","from tatooine.ideasonboard.com (unknown\n\t[IPv6:2a01:e0a:169:7140:db30:8e54:a96:9838])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id C8FCA1C19;\n\tFri, 19 Nov 2021 12:16:59 +0100 (CET)"],"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=\"NKluxxcX\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1637320619;\n\tbh=yNkIRJjs4v/QIzrtbu+rfR1PqWvSXqCB6KGEhxbNeGs=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=NKluxxcX4vG4JJL/ehDTnbex87VLBFfZQ5nomWhTA1Mu1KLNCEmb+ScsVbFlqtxEs\n\tltlshwtPLsl+E1L/M7VQAHIB3vspGVFvPjDIclP5ZUjM3wJwsRrdQLBRKWofBWGlrm\n\tip03voOisQCHbzkycZYwthfeZxtXjarUwUAHbqv8=","From":"Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Fri, 19 Nov 2021 12:16:50 +0100","Message-Id":"<20211119111654.68445-5-jeanmichel.hautbois@ideasonboard.com>","X-Mailer":"git-send-email 2.32.0","In-Reply-To":"<20211119111654.68445-1-jeanmichel.hautbois@ideasonboard.com>","References":"<20211119111654.68445-1-jeanmichel.hautbois@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v1 4/8] ipa: ipu3: Introduce the Algorithm\n\tclass","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 everything is in place, introduce the Algorithm class and\ndeclare it in IPA::RkISP1. There is no functional change yet.\n\nSigned-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\n---\n src/ipa/rkisp1/algorithms/algorithm.cpp | 101 ++++++++++++++++++++++++\n src/ipa/rkisp1/algorithms/algorithm.h   |  32 ++++++++\n src/ipa/rkisp1/algorithms/meson.build   |   5 ++\n src/ipa/rkisp1/meson.build              |   3 +\n src/ipa/rkisp1/rkisp1.cpp               |   5 +-\n 5 files changed, 145 insertions(+), 1 deletion(-)\n create mode 100644 src/ipa/rkisp1/algorithms/algorithm.cpp\n create mode 100644 src/ipa/rkisp1/algorithms/algorithm.h\n create mode 100644 src/ipa/rkisp1/algorithms/meson.build","diff":"diff --git a/src/ipa/rkisp1/algorithms/algorithm.cpp b/src/ipa/rkisp1/algorithms/algorithm.cpp\nnew file mode 100644\nindex 00000000..be3cd9f6\n--- /dev/null\n+++ b/src/ipa/rkisp1/algorithms/algorithm.cpp\n@@ -0,0 +1,101 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2021, Ideas On Board\n+ *\n+ * algorithm.cpp - RkISP1 control algorithm interface\n+ */\n+\n+#include \"algorithm.h\"\n+\n+/**\n+ * \\file algorithm.h\n+ * \\brief Algorithm common interface\n+ */\n+\n+namespace libcamera {\n+\n+namespace ipa::rkisp1 {\n+\n+/**\n+ * \\class Algorithm\n+ * \\brief The base class for all RkISP1 algorithms\n+ *\n+ * The Algorithm class defines a standard interface for IPA algorithms. By\n+ * abstracting algorithms, it makes possible the implementation of generic code\n+ * to manage algorithms regardless of their specific type.\n+ */\n+\n+/**\n+ * \\brief Configure the Algorithm given an IPAConfigInfo\n+ * \\param[in] context The shared IPA context\n+ * \\param[in] IPACameraSensorInfo The IPA configuration data, received from the\n+ * pipeline handler\n+ *\n+ * Algorithms may implement a configure operation to pre-calculate\n+ * parameters prior to commencing streaming.\n+ *\n+ * Configuration state may be stored in the IPASessionConfiguration structure of\n+ * the IPAContext.\n+ *\n+ * \\return 0 if successful, an error code otherwise\n+ */\n+int Algorithm::configure([[maybe_unused]] IPAContext &context,\n+\t\t\t [[maybe_unused]] const IPACameraSensorInfo &configInfo)\n+{\n+\treturn 0;\n+}\n+\n+/**\n+ * \\brief Fill the \\a params buffer with ISP processing parameters for a frame\n+ * \\param[in] context The shared IPA context\n+ * \\param[out] params The RkISP1 specific parameters.\n+ *\n+ * This function is called for every frame when the camera is running before it\n+ * is processed by the ImgU to prepare the ImgU processing parameters for that\n+ * frame.\n+ *\n+ * Algorithms shall fill in the parameter structure fields appropriately to\n+ * configure the ImgU processing blocks that they are responsible for. This\n+ * includes setting fields and flags that enable those processing blocks.\n+ */\n+void Algorithm::prepare([[maybe_unused]] IPAContext &context,\n+\t\t\t[[maybe_unused]] rkisp1_params_cfg *params)\n+{\n+}\n+\n+/**\n+ * \\brief Process ISP statistics, and run algorithm operations\n+ * \\param[in] context The shared IPA context\n+ * \\param[in] stats The RkISP1 statistics and ISP results\n+ *\n+ * This function is called while camera is running for every frame processed by\n+ * the ImgU, to process statistics generated from that frame by the ImgU.\n+ * Algorithms shall use this data to run calculations and update their state\n+ * accordingly.\n+ *\n+ * Processing shall not take an undue amount of time, and any extended or\n+ * computationally expensive calculations or operations must be handled\n+ * asynchronously in a separate thread.\n+ *\n+ * Algorithms can store state in their respective IPAFrameContext structures,\n+ * and reference state from the IPAFrameContext of other algorithms.\n+ *\n+ * \\todo Historical data may be required as part of the processing.\n+ * Either the previous frame, or the IPAFrameContext state of the frame\n+ * that generated the statistics for this operation may be required for\n+ * some advanced algorithms to prevent oscillations or support control\n+ * loops correctly. Only a single IPAFrameContext is available currently,\n+ * and so any data stored may represent the results of the previously\n+ * completed operations.\n+ *\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,\n+\t\t\t[[maybe_unused]] const rkisp1_stat_buffer *stats)\n+{\n+}\n+\n+} /* namespace ipa::rkisp1 */\n+\n+} /* namespace libcamera */\ndiff --git a/src/ipa/rkisp1/algorithms/algorithm.h b/src/ipa/rkisp1/algorithms/algorithm.h\nnew file mode 100644\nindex 00000000..5365a860\n--- /dev/null\n+++ b/src/ipa/rkisp1/algorithms/algorithm.h\n@@ -0,0 +1,32 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2021, Ideas On Board\n+ *\n+ * algorithm.h - RkISP1 control algorithm interface\n+ */\n+#ifndef __LIBCAMERA_IPA_RKISP1_ALGORITHM_H__\n+#define __LIBCAMERA_IPA_RKISP1_ALGORITHM_H__\n+\n+#include <libcamera/ipa/rkisp1_ipa_interface.h>\n+\n+#include \"ipa_context.h\"\n+\n+namespace libcamera {\n+\n+namespace ipa::rkisp1 {\n+\n+class Algorithm\n+{\n+public:\n+\tvirtual ~Algorithm() {}\n+\n+\tvirtual int configure(IPAContext &context, const IPACameraSensorInfo &configInfo);\n+\tvirtual void prepare(IPAContext &context, rkisp1_params_cfg *params);\n+\tvirtual void process(IPAContext &context, const rkisp1_stat_buffer *stats);\n+};\n+\n+} /* namespace ipa::rkisp1 */\n+\n+} /* namespace libcamera */\n+\n+#endif /* __LIBCAMERA_IPA_RKISP1_ALGORITHM_H__ */\ndiff --git a/src/ipa/rkisp1/algorithms/meson.build b/src/ipa/rkisp1/algorithms/meson.build\nnew file mode 100644\nindex 00000000..d98f77e2\n--- /dev/null\n+++ b/src/ipa/rkisp1/algorithms/meson.build\n@@ -0,0 +1,5 @@\n+# SPDX-License-Identifier: CC0-1.0\n+\n+rkisp1_ipa_algorithms = files([\n+    'algorithm.cpp',\n+])\ndiff --git a/src/ipa/rkisp1/meson.build b/src/ipa/rkisp1/meson.build\nindex 3683c922..a6a4856e 100644\n--- a/src/ipa/rkisp1/meson.build\n+++ b/src/ipa/rkisp1/meson.build\n@@ -1,4 +1,5 @@\n # SPDX-License-Identifier: CC0-1.0\n+subdir('algorithms')\n \n ipa_name = 'ipa_rkisp1'\n \n@@ -7,6 +8,8 @@ rkisp1_ipa_sources = files([\n     'rkisp1.cpp',\n ])\n \n+rkisp1_ipa_sources += rkisp1_ipa_algorithms\n+\n mod = shared_module(ipa_name,\n                     [rkisp1_ipa_sources, libcamera_generated_ipa_headers],\n                     name_prefix : '',\ndiff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp\nindex e0933e22..ddddd52d 100644\n--- a/src/ipa/rkisp1/rkisp1.cpp\n+++ b/src/ipa/rkisp1/rkisp1.cpp\n@@ -25,7 +25,7 @@\n \n #include <libcamera/internal/mapped_framebuffer.h>\n \n-#include \"ipa_context.h\"\n+#include \"algorithms/algorithm.h\"\n #include \"libipa/camera_sensor_helper.h\"\n \n namespace libcamera {\n@@ -82,6 +82,9 @@ private:\n \n \t/* Local parameter storage */\n \tstruct IPAContext context_;\n+\n+\t/* Maintain the algorithms used by the IPA */\n+\tstd::list<std::unique_ptr<ipa::rkisp1::Algorithm>> algorithms_;\n };\n \n int IPARkISP1::init([[maybe_unused]] const IPASettings &settings,\n","prefixes":["libcamera-devel","v1","4/8"]}