Patch Detail
Show a patch.
GET /api/patches/1355/?format=api
{ "id": 1355, "url": "https://patchwork.libcamera.org/api/patches/1355/?format=api", "web_url": "https://patchwork.libcamera.org/patch/1355/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/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": "<20190605005316.4835-8-paul.elder@ideasonboard.com>", "date": "2019-06-05T00:53:13", "name": "[libcamera-devel,v3,07/10] libcamera: ipa_manager: implement class for managing IPA modules", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "148f8ddf40eb7527827b0b3a822df2f22365dfdf", "submitter": { "id": 17, "url": "https://patchwork.libcamera.org/api/people/17/?format=api", "name": "Paul Elder", "email": "paul.elder@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/1355/mbox/", "series": [ { "id": 336, "url": "https://patchwork.libcamera.org/api/series/336/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=336", "date": "2019-06-05T00:53:06", "name": "Add IPAManager and IPAInterface", "version": 3, "mbox": "https://patchwork.libcamera.org/series/336/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/1355/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/1355/checks/", "tags": {}, "headers": { "Return-Path": "<paul.elder@ideasonboard.com>", "Received": [ "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DCC226472A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 5 Jun 2019 02:53:32 +0200 (CEST)", "from localhost.localdomain (unknown [96.44.9.117])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 36358321;\n\tWed, 5 Jun 2019 02:53:32 +0200 (CEST)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1559696012;\n\tbh=uKAEFI4mBSLI5wq4nHzo2wU6t3yS0PtFIQyUZY05y8Y=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=fZkTHM0lrPF7jFb39ou39Hup9ioN2ptfCYOUWq7ZOMk6NM98DEbFXEvZY4bs4u8Tu\n\tmsVRMiVevr4+1Rld2lJeJV0Mj22ahRSBE1v+3+wd+z7E30J+FBmqkoVc9NdJ+t3OlT\n\tgg6OUvXOLE1Jg9Yd41/YJjXzp2ba6OVWd/xdN1l4=", "From": "Paul Elder <paul.elder@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Tue, 4 Jun 2019 20:53:13 -0400", "Message-Id": "<20190605005316.4835-8-paul.elder@ideasonboard.com>", "X-Mailer": "git-send-email 2.20.1", "In-Reply-To": "<20190605005316.4835-1-paul.elder@ideasonboard.com>", "References": "<20190605005316.4835-1-paul.elder@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v3 07/10] libcamera: ipa_manager:\n\timplement class for managing IPA modules", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.23", "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>", "X-List-Received-Date": "Wed, 05 Jun 2019 00:53:33 -0000" }, "content": "IPAManager is a class that will search in given directories for IPA\nmodules, and will load them into a list. It also provides an interface\nfor pipeline handlers to acquire an IPA.\n\nA meson build file for the IPAs is added, which also specifies a\nhard-coded path for where to load the IPAs from in the installation\ndirectory. More paths can be specified with the environment variable\nLIBCAMERA_IPA_MODULE_PATH, with the same syntax as the regular PATH\nenvironment variable. Make the test framework set this environment\nvariable.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\nChanges in v3:\n- createIPA() now inputs an acceptable version range to find an\n IPAModule, as opposed to taking the version of the input pipeline\n handler\n- fix strtok (and C++ize it)\n- rename environment variable from IPA_MODULE_PATH to\n LIBCAMERA_IPA_MODULE_PATH\n\nChanges in v2:\n- make addDir private, and called from constructor\n- add hard-coded IPA modules path from meson\n- read environment variable for additional IPA module paths\n- move match to IPAModule\n- make addDir return value more sensible\n- add the build IPA directory to the IPA module path for all tests\n\n src/ipa/meson.build | 2 +\n src/libcamera/include/ipa_manager.h | 40 ++++++++\n src/libcamera/ipa_manager.cpp | 149 ++++++++++++++++++++++++++++\n src/libcamera/meson.build | 2 +\n src/meson.build | 1 +\n test/libtest/test.cpp | 6 ++\n 6 files changed, 200 insertions(+)\n create mode 100644 src/ipa/meson.build\n create mode 100644 src/libcamera/include/ipa_manager.h\n create mode 100644 src/libcamera/ipa_manager.cpp", "diff": "diff --git a/src/ipa/meson.build b/src/ipa/meson.build\nnew file mode 100644\nindex 0000000..be4f954\n--- /dev/null\n+++ b/src/ipa/meson.build\n@@ -0,0 +1,2 @@\n+config_h.set('IPA_MODULE_DIR',\n+ '\"' + join_paths(get_option('prefix'), get_option('libdir'), 'libcamera') + '\"')\ndiff --git a/src/libcamera/include/ipa_manager.h b/src/libcamera/include/ipa_manager.h\nnew file mode 100644\nindex 0000000..310ce7c\n--- /dev/null\n+++ b/src/libcamera/include/ipa_manager.h\n@@ -0,0 +1,40 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * ipa_manager.h - Image Processing Algorithm module manager\n+ */\n+#ifndef __LIBCAMERA_IPA_MANAGER_H__\n+#define __LIBCAMERA_IPA_MANAGER_H__\n+\n+#include <vector>\n+\n+#include <libcamera/ipa/ipa_interface.h>\n+#include <libcamera/ipa/ipa_module_info.h>\n+\n+#include \"ipa_module.h\"\n+#include \"pipeline_handler.h\"\n+\n+namespace libcamera {\n+\n+class IPAManager\n+{\n+public:\n+\tstatic IPAManager *instance();\n+\n+\tstd::unique_ptr<IPAInterface> createIPA(PipelineHandler *pipe,\n+\t\t\t\t\t\tuint32_t maxVersion,\n+\t\t\t\t\t\tuint32_t minVersion);\n+\n+private:\n+\tstd::vector<IPAModule *> modules_;\n+\n+\tIPAManager();\n+\t~IPAManager();\n+\n+\tint addDir(const char *libDir);\n+};\n+\n+} /* namespace libcamera */\n+\n+#endif /* __LIBCAMERA_IPA_MANAGER_H__ */\ndiff --git a/src/libcamera/ipa_manager.cpp b/src/libcamera/ipa_manager.cpp\nnew file mode 100644\nindex 0000000..f689aa6\n--- /dev/null\n+++ b/src/libcamera/ipa_manager.cpp\n@@ -0,0 +1,149 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * ipa_manager.cpp - Image Processing Algorithm module manager\n+ */\n+\n+#include \"ipa_manager.h\"\n+\n+#include <dirent.h>\n+#include <string.h>\n+#include <sys/types.h>\n+\n+#include \"ipa_module.h\"\n+#include \"log.h\"\n+#include \"pipeline_handler.h\"\n+#include \"utils.h\"\n+\n+/**\n+ * \\file ipa_manager.h\n+ * \\brief Image Processing Algorithm module manager\n+ */\n+\n+namespace libcamera {\n+\n+LOG_DEFINE_CATEGORY(IPAManager)\n+\n+/**\n+ * \\class IPAManager\n+ * \\brief Manager for IPA modules\n+ */\n+\n+IPAManager::IPAManager()\n+{\n+\taddDir(IPA_MODULE_DIR);\n+\n+\tstd::string modulePaths = utils::secure_getenv(\"LIBCAMERA_IPA_MODULE_PATH\");\n+\tif (modulePaths.empty())\n+\t\treturn;\n+\n+\tfor (size_t pos = 0, delim = 0; delim != std::string::npos;\n+\t pos = delim + 1) {\n+\t\tdelim = modulePaths.find(':', pos);\n+\t\tsize_t count = delim == std::string::npos ? delim : delim - pos;\n+\t\tstd::string path = modulePaths.substr(pos, count);\n+\t\tif (path.empty())\n+\t\t\tcontinue;\n+\n+\t\taddDir(path.c_str());\n+\t}\n+}\n+\n+IPAManager::~IPAManager()\n+{\n+\tfor (IPAModule *module : modules_)\n+\t\tdelete module;\n+}\n+\n+/**\n+ * \\brief Retrieve the IPA manager instance\n+ *\n+ * The IPAManager is a singleton and can't be constructed manually. This\n+ * function shall instead be used to retrieve the single global instance of the\n+ * manager.\n+ *\n+ * \\return The IPA manager instance\n+ */\n+IPAManager *IPAManager::instance()\n+{\n+\tstatic IPAManager ipaManager;\n+\treturn &ipaManager;\n+}\n+\n+/**\n+ * \\brief Load IPA modules from a directory\n+ * \\param[in] libDir directory to search for IPA modules\n+ *\n+ * This method tries to create an IPAModule instance for every shared object\n+ * found in \\a libDir, and skips invalid IPA modules.\n+ *\n+ * \\return Number of modules loaded by this call, or a negative error code\n+ * otherwise\n+ */\n+int IPAManager::addDir(const char *libDir)\n+{\n+\tstruct dirent *ent;\n+\tDIR *dir;\n+\n+\tdir = opendir(libDir);\n+\tif (!dir) {\n+\t\tint ret = -errno;\n+\t\tLOG(IPAManager, Error)\n+\t\t\t<< \"Invalid path \" << libDir << \" for IPA modules: \"\n+\t\t\t<< strerror(-ret);\n+\t\treturn ret;\n+\t}\n+\n+\tunsigned int count = 0;\n+\twhile ((ent = readdir(dir)) != nullptr) {\n+\t\tint offset = strlen(ent->d_name) - 3;\n+\t\tif (offset < 0)\n+\t\t\tcontinue;\n+\t\tif (strcmp(&ent->d_name[offset], \".so\"))\n+\t\t\tcontinue;\n+\n+\t\tIPAModule *ipaModule = new IPAModule(std::string(libDir) +\n+\t\t\t\t\t\t \"/\" + ent->d_name);\n+\t\tif (!ipaModule->isValid()) {\n+\t\t\tdelete ipaModule;\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tmodules_.push_back(ipaModule);\n+\t\tcount++;\n+\t}\n+\n+\tclosedir(dir);\n+\treturn count;\n+}\n+\n+/**\n+ * \\brief Create an IPA interface that matches a given pipeline handler\n+ * \\param[in] pipe The pipeline handler that wants a matching IPA interface\n+ * \\param[in] minVersion Minimum acceptable version of IPA module\n+ * \\param[in] maxVersion Maximum acceptable version of IPA module\n+ *\n+ * \\return A newly created IPA interface, or nullptr if no matching\n+ * IPA module is found\n+ */\n+std::unique_ptr<IPAInterface> IPAManager::createIPA(PipelineHandler *pipe,\n+\t\t\t\t\t\t uint32_t maxVersion,\n+\t\t\t\t\t\t uint32_t minVersion)\n+{\n+\tIPAModule *m = nullptr;\n+\n+\tfor (IPAModule *module : modules_) {\n+\t\tif (module->match(pipe, minVersion, maxVersion)) {\n+\t\t\tm = module;\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\n+\tif (!m || !m->load())\n+\t\treturn nullptr;\n+\n+\treturn m->createInstance();\n+}\n+\n+} /* namespace libcamera */\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex 32f7da4..0889b0d 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -11,6 +11,7 @@ libcamera_sources = files([\n 'formats.cpp',\n 'geometry.cpp',\n 'ipa_interface.cpp',\n+ 'ipa_manager.cpp',\n 'ipa_module.cpp',\n 'log.cpp',\n 'media_device.cpp',\n@@ -33,6 +34,7 @@ libcamera_headers = files([\n 'include/device_enumerator_udev.h',\n 'include/event_dispatcher_poll.h',\n 'include/formats.h',\n+ 'include/ipa_manager.h',\n 'include/ipa_module.h',\n 'include/log.h',\n 'include/media_device.h',\ndiff --git a/src/meson.build b/src/meson.build\nindex 4e41fd3..628e7a7 100644\n--- a/src/meson.build\n+++ b/src/meson.build\n@@ -1,3 +1,4 @@\n subdir('libcamera')\n+subdir('ipa')\n subdir('cam')\n subdir('qcam')\ndiff --git a/test/libtest/test.cpp b/test/libtest/test.cpp\nindex 9d537ea..b119cf1 100644\n--- a/test/libtest/test.cpp\n+++ b/test/libtest/test.cpp\n@@ -5,6 +5,8 @@\n * test.cpp - libcamera test base class\n */\n \n+#include <stdlib.h>\n+\n #include \"test.h\"\n \n Test::Test()\n@@ -19,6 +21,10 @@ int Test::execute()\n {\n \tint ret;\n \n+\tret = setenv(\"LIBCAMERA_IPA_MODULE_PATH\", \"src/ipa\", 1);\n+\tif (ret)\n+\t\treturn errno;\n+\n \tret = init();\n \tif (ret)\n \t\treturn ret;\n", "prefixes": [ "libcamera-devel", "v3", "07/10" ] }