Patch Detail
Show a patch.
GET /api/patches/1343/?format=api
{ "id": 1343, "url": "https://patchwork.libcamera.org/api/patches/1343/?format=api", "web_url": "https://patchwork.libcamera.org/patch/1343/", "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": "<20190603231637.28554-7-paul.elder@ideasonboard.com>", "date": "2019-06-03T23:16:33", "name": "[libcamera-devel,v2,06/10] libcamera: ipa_manager: implement class for managing IPA modules", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "ac8c4e6cd93f7c6baf60767d3dcb90e84261ad23", "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/1343/mbox/", "series": [ { "id": 335, "url": "https://patchwork.libcamera.org/api/series/335/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=335", "date": "2019-06-03T23:16:27", "name": "Add IPAManager and IPAInterface", "version": 2, "mbox": "https://patchwork.libcamera.org/series/335/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/1343/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/1343/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 59CF460BD7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 4 Jun 2019 01:16:51 +0200 (CEST)", "from localhost.localdomain (unknown [96.44.9.117])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B129F51C;\n\tTue, 4 Jun 2019 01:16:50 +0200 (CEST)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1559603811;\n\tbh=gXMLYxF7voHAjC0JxKIFD6nWjuPImrEQSEJMSG3acvA=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=QiKCoyiOKdcTPtlizypVN83VcZnz/WkhwJW0N6Gmoa51pX3N+zNezJIspJIrlY8Z8\n\tDT2xNHwQ5cFN3UJ5rUul7zbRHFvAAwpmqwho2mpYfQ8YoMlIzNQYWV8mKhExs0Lpoq\n\tuja6kHl4uQbVn7nHHVD0HaF6q2Eys/zMm79hMkig=", "From": "Paul Elder <paul.elder@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Mon, 3 Jun 2019 19:16:33 -0400", "Message-Id": "<20190603231637.28554-7-paul.elder@ideasonboard.com>", "X-Mailer": "git-send-email 2.20.1", "In-Reply-To": "<20190603231637.28554-1-paul.elder@ideasonboard.com>", "References": "<20190603231637.28554-1-paul.elder@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v2 06/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": "Mon, 03 Jun 2019 23:16:51 -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 aquire 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\nIPA_MODULE_PATH, with the same syntax as the regular PATH environment\nvariable. Make the test framework populate this environment variable.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\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 | 39 ++++++++\n src/libcamera/ipa_manager.cpp | 141 ++++++++++++++++++++++++++++\n src/libcamera/meson.build | 2 +\n src/meson.build | 1 +\n test/libtest/test.cpp | 6 ++\n 6 files changed, 191 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..694df64\n--- /dev/null\n+++ b/src/libcamera/include/ipa_manager.h\n@@ -0,0 +1,39 @@\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 <list>\n+#include <string>\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+\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..6a946a2\n--- /dev/null\n+++ b/src/libcamera/ipa_manager.cpp\n@@ -0,0 +1,141 @@\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 <dlfcn.h>\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+\tchar *modulePaths = utils::secure_getenv(\"IPA_MODULE_PATH\");\n+\tif (!modulePaths)\n+\t\treturn;\n+\n+\tchar *saveptr;\n+\tchar *dir;\n+\tif ((dir = strtok_r(modulePaths, \":\", &saveptr)))\n+\t\taddDir(dir);\n+\twhile ((dir = strtok_r(nullptr, \":\", &saveptr)))\n+\t\taddDir(dir);\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 found\n+ * shared object 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+\tint count = 0;\n+\twhile ((ent = readdir(dir)) != nullptr) {\n+\t\tif (strlen(ent->d_name) < 3)\n+\t\t\tcontinue;\n+\t\tint offset = strlen(ent->d_name) - 3;\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+ *\n+ * \\return IPA interface, or nullptr if no matching IPA module is found\n+ */\n+std::unique_ptr<IPAInterface> IPAManager::createIPA(PipelineHandler *pipe)\n+{\n+\tIPAModule *m = nullptr;\n+\n+\tfor (IPAModule *module : modules_) {\n+\t\tif (module->match(pipe)) {\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..451c111 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(\"IPA_MODULE_PATH\", \"test/ipa\", 1);\n+\tif (ret)\n+\t\treturn errno;\n+\n \tret = init();\n \tif (ret)\n \t\treturn ret;\n", "prefixes": [ "libcamera-devel", "v2", "06/10" ] }