Patch Detail
Show a patch.
GET /api/1.1/patches/11168/?format=api
{ "id": 11168, "url": "https://patchwork.libcamera.org/api/1.1/patches/11168/?format=api", "web_url": "https://patchwork.libcamera.org/patch/11168/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20210204232613.494121-7-niklas.soderlund@ragnatech.se>", "date": "2021-02-04T23:26:08", "name": "[libcamera-devel,v4,06/11] libcamera: ipa: ipu3: Add an IPA skeleton for the IPU3 pipeline", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "a6d9c62ca207261825386cc2552508b97e1372cd", "submitter": { "id": 5, "url": "https://patchwork.libcamera.org/api/1.1/people/5/?format=api", "name": "Niklas Söderlund", "email": "niklas.soderlund@ragnatech.se" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/11168/mbox/", "series": [ { "id": 1656, "url": "https://patchwork.libcamera.org/api/1.1/series/1656/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1656", "date": "2021-02-04T23:26:02", "name": "libcamera: ipu3: Attach to an skeleton IPA", "version": 4, "mbox": "https://patchwork.libcamera.org/series/1656/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/11168/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/11168/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 A7A77BD163\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 4 Feb 2021 23:27:13 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 81A41614A3;\n\tFri, 5 Feb 2021 00:27:13 +0100 (CET)", "from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net\n\t[195.74.38.228])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D0A436149E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 5 Feb 2021 00:27:11 +0100 (CET)", "from bismarck.berto.se (p4fca2458.dip0.t-ipconnect.de\n\t[79.202.36.88])\n\tby bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA\n\tid 8107d0e1-6740-11eb-b73f-0050569116f7;\n\tFri, 05 Feb 2021 00:27:10 +0100 (CET)" ], "X-Halon-ID": "8107d0e1-6740-11eb-b73f-0050569116f7", "Authorized-sender": "niklas.soderlund@fsdn.se", "From": "=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Fri, 5 Feb 2021 00:26:08 +0100", "Message-Id": "<20210204232613.494121-7-niklas.soderlund@ragnatech.se>", "X-Mailer": "git-send-email 2.30.0", "In-Reply-To": "<20210204232613.494121-1-niklas.soderlund@ragnatech.se>", "References": "<20210204232613.494121-1-niklas.soderlund@ragnatech.se>", "MIME-Version": "1.0", "Subject": "[libcamera-devel] [PATCH v4 06/11] libcamera: ipa: ipu3: Add an IPA\n\tskeleton for the IPU3 pipeline", "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>", "Content-Type": "text/plain; charset=\"utf-8\"", "Content-Transfer-Encoding": "base64", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "Add an empty IPA skeleton for the IPU3 pipeline. The skeleton IPA\nhandles the flow of parameter and statistic buffers but does not read or\nwrite anything in the buffers. It also allows the IPA to set sensor\ncontrols but does not implement any logic to set optimal values and\ninstead sets the V4L2 exposure and gain controls to max and keeps them\nat that setting.\n\nThis IPA is meant as a base to allow the pipeline handler to be wired up\nto an IPA. The image algorithms can then later be added to the IPA\nindependently from also having to add plumbing to the pipeline handler.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n* Changes since v1\n- Updated commit message.\n- Rename IPU3_IPA_EVENT_PARSE_STAT to IPU3_IPA_EVENT_PARSE_STAT.\n- Sort and drop unused headers.\n- Fix style issue in meson.build and add dependency on libatomic.\n- Switch to MappedFrameBuffer interface.\n- Add result of IPA configuration status.\n\n* Changes since v2\n- Include stdint.h\n- s/std::max<uint32_t>/std::max/\n- Erase iterator instead of id in unmapBuffers()\n\n* Changes since v3\n- Add a new interface to be able to process controls separate from\n filling the parameters buffer.\n---\n include/libcamera/ipa/ipu3.h | 23 ++++\n src/ipa/ipu3/ipu3.cpp | 242 +++++++++++++++++++++++++++++++++++\n src/ipa/ipu3/meson.build | 21 +++\n src/ipa/meson.build | 2 +-\n 4 files changed, 287 insertions(+), 1 deletion(-)\n create mode 100644 include/libcamera/ipa/ipu3.h\n create mode 100644 src/ipa/ipu3/ipu3.cpp\n create mode 100644 src/ipa/ipu3/meson.build", "diff": "diff --git a/include/libcamera/ipa/ipu3.h b/include/libcamera/ipa/ipu3.h\nnew file mode 100644\nindex 0000000000000000..cbaaef04417b701b\n--- /dev/null\n+++ b/include/libcamera/ipa/ipu3.h\n@@ -0,0 +1,23 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2020, Google Inc.\n+ *\n+ * ipu3.h - Image Processing Algorithm interface for IPU3\n+ */\n+#ifndef __LIBCAMERA_IPA_INTERFACE_IPU3_H__\n+#define __LIBCAMERA_IPA_INTERFACE_IPU3_H__\n+\n+#ifndef __DOXYGEN__\n+\n+enum IPU3Operations {\n+\tIPU3_IPA_ACTION_SET_SENSOR_CONTROLS = 1,\n+\tIPU3_IPA_ACTION_PARAM_FILLED = 2,\n+\tIPU3_IPA_ACTION_METADATA_READY = 3,\n+\tIPU3_IPA_EVENT_PROCESS_CONTROLS = 4,\n+\tIPU3_IPA_EVENT_STAT_READY = 5,\n+\tIPU3_IPA_EVENT_FILL_PARAMS = 6,\n+};\n+\n+#endif /* __DOXYGEN__ */\n+\n+#endif /* __LIBCAMERA_IPA_INTERFACE_IPU3_H__ */\ndiff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp\nnew file mode 100644\nindex 0000000000000000..b11b03efa6ceb666\n--- /dev/null\n+++ b/src/ipa/ipu3/ipu3.cpp\n@@ -0,0 +1,242 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2020, Google Inc.\n+ *\n+ * ipu3.cpp - IPU3 Image Processing Algorithms\n+ */\n+\n+#include <libcamera/ipa/ipu3.h>\n+\n+#include <stdint.h>\n+#include <sys/mman.h>\n+\n+#include <linux/intel-ipu3.h>\n+#include <linux/v4l2-controls.h>\n+\n+#include <libcamera/buffer.h>\n+#include <libcamera/control_ids.h>\n+#include <libcamera/ipa/ipa_interface.h>\n+#include <libcamera/ipa/ipa_module_info.h>\n+#include <libcamera/request.h>\n+\n+#include <libipa/ipa_interface_wrapper.h>\n+\n+#include \"libcamera/internal/buffer.h\"\n+#include \"libcamera/internal/log.h\"\n+\n+namespace libcamera {\n+\n+LOG_DEFINE_CATEGORY(IPAIPU3)\n+\n+class IPAIPU3 : public IPAInterface\n+{\n+public:\n+\tint init([[maybe_unused]] const IPASettings &settings) override\n+\t{\n+\t\treturn 0;\n+\t}\n+\tint start([[maybe_unused]] const IPAOperationData &data,\n+\t\t [[maybe_unused]] IPAOperationData *result) override { return 0; }\n+\tvoid stop() override {}\n+\n+\tvoid configure(const CameraSensorInfo &info,\n+\t\t const std::map<unsigned int, IPAStream> &streamConfig,\n+\t\t const std::map<unsigned int, const ControlInfoMap &> &entityControls,\n+\t\t const IPAOperationData &ipaConfig,\n+\t\t IPAOperationData *response) override;\n+\tvoid mapBuffers(const std::vector<IPABuffer> &buffers) override;\n+\tvoid unmapBuffers(const std::vector<unsigned int> &ids) override;\n+\tvoid processEvent(const IPAOperationData &event) override;\n+\n+private:\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+\t\t\t const ipu3_uapi_stats_3a *stats);\n+\n+\tvoid setControls(unsigned int frame);\n+\n+\tstd::map<unsigned int, MappedFrameBuffer> buffers_;\n+\n+\tControlInfoMap ctrls_;\n+\n+\t/* Camera sensor controls. */\n+\tuint32_t exposure_;\n+\tuint32_t minExposure_;\n+\tuint32_t maxExposure_;\n+\tuint32_t gain_;\n+\tuint32_t minGain_;\n+\tuint32_t maxGain_;\n+};\n+\n+void IPAIPU3::configure([[maybe_unused]] const CameraSensorInfo &info,\n+\t\t\t[[maybe_unused]] const std::map<unsigned int, IPAStream> &streamConfig,\n+\t\t\tconst std::map<unsigned int, const ControlInfoMap &> &entityControls,\n+\t\t\t[[maybe_unused]] const IPAOperationData &ipaConfig,\n+\t\t\t[[maybe_unused]] IPAOperationData *result)\n+{\n+\tif (entityControls.empty())\n+\t\treturn;\n+\n+\tctrls_ = entityControls.at(0);\n+\n+\tconst auto itExp = ctrls_.find(V4L2_CID_EXPOSURE);\n+\tif (itExp == ctrls_.end()) {\n+\t\tLOG(IPAIPU3, Error) << \"Can't find exposure control\";\n+\t\treturn;\n+\t}\n+\n+\tconst auto itGain = ctrls_.find(V4L2_CID_ANALOGUE_GAIN);\n+\tif (itGain == ctrls_.end()) {\n+\t\tLOG(IPAIPU3, Error) << \"Can't find gain control\";\n+\t\treturn;\n+\t}\n+\n+\tminExposure_ = std::max(itExp->second.min().get<int32_t>(), 1);\n+\tmaxExposure_ = itExp->second.max().get<int32_t>();\n+\texposure_ = maxExposure_;\n+\n+\tminGain_ = std::max(itGain->second.min().get<int32_t>(), 1);\n+\tmaxGain_ = itGain->second.max().get<int32_t>();\n+\tgain_ = maxGain_;\n+\n+\tsetControls(0);\n+}\n+\n+void IPAIPU3::mapBuffers(const std::vector<IPABuffer> &buffers)\n+{\n+\tfor (const IPABuffer &buffer : buffers) {\n+\t\tconst FrameBuffer fb(buffer.planes);\n+\t\tbuffers_.emplace(buffer.id,\n+\t\t\t\t MappedFrameBuffer(&fb, PROT_READ | PROT_WRITE));\n+\t}\n+}\n+\n+void IPAIPU3::unmapBuffers(const std::vector<unsigned int> &ids)\n+{\n+\tfor (unsigned int id : ids) {\n+\t\tauto it = buffers_.find(id);\n+\t\tif (it == buffers_.end())\n+\t\t\tcontinue;\n+\n+\t\tbuffers_.erase(it);\n+\t}\n+}\n+\n+void IPAIPU3::processEvent(const IPAOperationData &event)\n+{\n+\tswitch (event.operation) {\n+\tcase IPU3_IPA_EVENT_PROCESS_CONTROLS: {\n+\t\tunsigned int frame = event.data[0];\n+\t\tprocessControls(frame, event.controls[0]);\n+\t\tbreak;\n+\t}\n+\tcase IPU3_IPA_EVENT_STAT_READY: {\n+\t\tunsigned int frame = event.data[0];\n+\t\tunsigned int bufferId = event.data[1];\n+\n+\t\tauto it = buffers_.find(bufferId);\n+\t\tif (it == buffers_.end()) {\n+\t\t\tLOG(IPAIPU3, Error) << \"Could not find stats buffer!\";\n+\t\t\treturn;\n+\t\t}\n+\n+\t\tSpan<uint8_t> mem = it->second.maps()[0];\n+\t\tconst ipu3_uapi_stats_3a *stats =\n+\t\t\treinterpret_cast<ipu3_uapi_stats_3a *>(mem.data());\n+\n+\t\tparseStatistics(frame, stats);\n+\t\tbreak;\n+\t}\n+\tcase IPU3_IPA_EVENT_FILL_PARAMS: {\n+\t\tunsigned int frame = event.data[0];\n+\t\tunsigned int bufferId = event.data[1];\n+\n+\t\tauto it = buffers_.find(bufferId);\n+\t\tif (it == buffers_.end()) {\n+\t\t\tLOG(IPAIPU3, Error) << \"Could not find param buffer!\";\n+\t\t\treturn;\n+\t\t}\n+\n+\t\tSpan<uint8_t> mem = it->second.maps()[0];\n+\t\tipu3_uapi_params *params =\n+\t\t\treinterpret_cast<ipu3_uapi_params *>(mem.data());\n+\n+\t\tfillParams(frame, params);\n+\t\tbreak;\n+\t}\n+\tdefault:\n+\t\tLOG(IPAIPU3, Error) << \"Unknown event \" << event.operation;\n+\t\tbreak;\n+\t}\n+}\n+\n+void IPAIPU3::processControls([[maybe_unused]] unsigned int frame,\n+\t\t\t [[maybe_unused]] const ControlList &controls)\n+{\n+\t/* \\todo Start processing for 'frame' based on 'controls'. */\n+}\n+\n+void IPAIPU3::fillParams(unsigned int frame, ipu3_uapi_params *params)\n+{\n+\t/* Prepare parameters buffer. */\n+\tmemset(params, 0, sizeof(*params));\n+\n+\t/* \\todo Fill in parameters buffer. */\n+\n+\tIPAOperationData op;\n+\top.operation = IPU3_IPA_ACTION_PARAM_FILLED;\n+\n+\tqueueFrameAction.emit(frame, op);\n+\n+\t/* \\todo Calculate new values for exposure_ and gain_. */\n+\tsetControls(frame);\n+}\n+\n+void IPAIPU3::parseStatistics(unsigned int frame,\n+\t\t\t [[maybe_unused]] const ipu3_uapi_stats_3a *stats)\n+{\n+\tControlList ctrls(controls::controls);\n+\n+\t/* \\todo React to statistics and update internal state machine. */\n+\t/* \\todo Add meta-data information to ctrls. */\n+\n+\tIPAOperationData op;\n+\top.operation = IPU3_IPA_ACTION_METADATA_READY;\n+\top.controls.push_back(ctrls);\n+\n+\tqueueFrameAction.emit(frame, op);\n+}\n+\n+void IPAIPU3::setControls(unsigned int frame)\n+{\n+\tIPAOperationData op;\n+\top.operation = IPU3_IPA_ACTION_SET_SENSOR_CONTROLS;\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_));\n+\top.controls.push_back(ctrls);\n+\n+\tqueueFrameAction.emit(frame, op);\n+}\n+\n+/*\n+ * External IPA module interface\n+ */\n+\n+extern \"C\" {\n+const struct IPAModuleInfo ipaModuleInfo = {\n+\tIPA_MODULE_API_VERSION,\n+\t1,\n+\t\"PipelineHandlerIPU3\",\n+\t\"ipu3\",\n+};\n+\n+struct ipa_context *ipaCreate()\n+{\n+\treturn new IPAInterfaceWrapper(std::make_unique<IPAIPU3>());\n+}\n+}\n+\n+} /* namespace libcamera */\ndiff --git a/src/ipa/ipu3/meson.build b/src/ipa/ipu3/meson.build\nnew file mode 100644\nindex 0000000000000000..444c82453eac42ff\n--- /dev/null\n+++ b/src/ipa/ipu3/meson.build\n@@ -0,0 +1,21 @@\n+# SPDX-License-Identifier: CC0-1.0\n+\n+ipa_name = 'ipa_ipu3'\n+\n+mod = shared_module(ipa_name,\n+ 'ipu3.cpp',\n+ name_prefix : '',\n+ include_directories : [ ipa_includes, libipa_includes ],\n+ dependencies : [ libatomic, libcamera_dep ],\n+ link_with : libipa,\n+ install : true,\n+ install_dir : ipa_install_dir)\n+\n+if ipa_sign_module\n+ custom_target(ipa_name + '.so.sign',\n+ input : mod,\n+ output : ipa_name + '.so.sign',\n+ command : [ ipa_sign, ipa_priv_key, '@INPUT@', '@OUTPUT@' ],\n+ install : false,\n+ build_by_default : true)\n+endif\ndiff --git a/src/ipa/meson.build b/src/ipa/meson.build\nindex 5a5de267c1477d24..9d623f227a1f9feb 100644\n--- a/src/ipa/meson.build\n+++ b/src/ipa/meson.build\n@@ -19,7 +19,7 @@ subdir('libipa')\n \n ipa_sign = files('ipa-sign.sh')\n \n-ipas = ['raspberrypi', 'rkisp1', 'vimc']\n+ipas = ['ipu3', 'raspberrypi', 'rkisp1', 'vimc']\n ipa_names = []\n \n foreach pipeline : get_option('pipelines')\n", "prefixes": [ "libcamera-devel", "v4", "06/11" ] }