{"id":1279,"url":"https://patchwork.libcamera.org/api/1.1/patches/1279/?format=json","web_url":"https://patchwork.libcamera.org/patch/1279/","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":"<20190523164210.2105-4-paul.elder@ideasonboard.com>","date":"2019-05-23T16:42:08","name":"[libcamera-devel,RFC,v2,3/5] libcamera: ipa_manager: implement class for managing IPA modules","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"043c1169e16218fbbfc2a3bea175ffbeaa0fa1c0","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/1.1/people/17/?format=json","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/1279/mbox/","series":[{"id":324,"url":"https://patchwork.libcamera.org/api/1.1/series/324/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=324","date":"2019-05-23T16:42:05","name":"Add IPAManager","version":2,"mbox":"https://patchwork.libcamera.org/series/324/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/1279/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/1279/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 64E8F61865\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 23 May 2019 18:42:26 +0200 (CEST)","from localhost.localdomain (unknown [96.44.9.117])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B42355A9;\n\tThu, 23 May 2019 18:42:25 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1558629746;\n\tbh=Qd7YX0RbMCUS16XBJVooMOxEgPKyJXALh4GFJ8PrCjI=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=EjhgCncKLCcfPuU55mihfUcNK4qJGvQRiYeBVBOE+cbgaet1NtULrH7X+hSdrRg3C\n\tD38fTj/TpIh2g2h2t/2CZzQORwN/Wulf92e2qZ+RompXKY4EB2eyrSEy2PfJDIdqHO\n\tys4LWD5icqK6q8qqT8uxBxBpIOWcmfXLTmycaFEM=","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Thu, 23 May 2019 12:42:08 -0400","Message-Id":"<20190523164210.2105-4-paul.elder@ideasonboard.com>","X-Mailer":"git-send-email 2.20.1","In-Reply-To":"<20190523164210.2105-1-paul.elder@ideasonboard.com>","References":"<20190523164210.2105-1-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [RFC PATCH v2 3/5] 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":"Thu, 23 May 2019 16:42:26 -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 pipelines to aquire an IPA.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\n---\nChanges in v2:\n- made IPAManager into a real singleton (as opposed to my misunderstood\n  version)\n- return non-const IPAModule from IPAManager::acquireIPA()\n- made return value of addDir return the total number of modules loaded\n  - that way the caller can know if any modules were loaded at all\n    (since zero modules loaded doesn't really constitute as an error)\n\n src/libcamera/include/ipa_manager.h |  39 +++++++++\n src/libcamera/ipa_manager.cpp       | 122 ++++++++++++++++++++++++++++\n src/libcamera/meson.build           |   2 +\n 3 files changed, 163 insertions(+)\n create mode 100644 src/libcamera/include/ipa_manager.h\n create mode 100644 src/libcamera/ipa_manager.cpp","diff":"diff --git a/src/libcamera/include/ipa_manager.h b/src/libcamera/include/ipa_manager.h\nnew file mode 100644\nindex 0000000..333fec0\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 <libcamera/ipa/ipa_module_info.h>\n+#include <list>\n+#include <string>\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+\tint addDir(const std::string &libDir);\n+\n+\tIPAModule *acquireIPA(const struct IPAModuleInfo &info) const;\n+\n+private:\n+\tstd::list<IPAModule *> modules_;\n+\n+\tIPAManager();\n+\t~IPAManager();\n+\n+\tbool match(const IPAModule *ipa, const struct IPAModuleInfo &info) const;\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..3d65786\n--- /dev/null\n+++ b/src/libcamera/ipa_manager.cpp\n@@ -0,0 +1,122 @@\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+#include \"ipa_module.h\"\n+#include \"pipeline_handler.h\"\n+#include \"utils.h\"\n+\n+#include <dirent.h>\n+#include <string.h>\n+#include <sys/types.h>\n+\n+#include \"log.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+}\n+\n+IPAManager::~IPAManager()\n+{\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+ * Goes through \\a libDir and tries to create an IPAModule instance for every\n+ * found shared object. Skips invalid IPA modules.\n+ *\n+ * \\return total number of modules loaded (including modules loaded in\n+ * previous calls of this function), or negative error code\n+ */\n+int IPAManager::addDir(const std::string &libDir)\n+{\n+\tstruct dirent *ent;\n+\tDIR *dir;\n+\n+\tdir = opendir(libDir.c_str());\n+\tif (!dir) {\n+\t\tint ret = -errno;\n+\t\tLOG(IPAManager, Error) << \"Invalid path for IPA modules: \"\n+\t\t\t\t       << strerror(ret);\n+\t\treturn ret;\n+\t}\n+\n+\twhile ((ent = readdir(dir)) != nullptr) {\n+\t\tint offset = strlen(ent->d_name) - 3;\n+\t\tif (strncmp(&ent->d_name[offset], \".so\", 3))\n+\t\t\tcontinue;\n+\n+\t\tIPAModule *ipaModule = new IPAModule(libDir + \"/\" + ent->d_name);\n+\t\tif (ipaModule->isValid())\n+\t\t\tmodules_.push_back(ipaModule);\n+\t}\n+\n+\tclosedir(dir);\n+\treturn modules_.size();\n+}\n+\n+/**\n+ * \\brief Retrieve an IPA module that matches a desired IPA module info\n+ *\n+ * \\return IPA module\n+ */\n+IPAModule *IPAManager::acquireIPA(const struct IPAModuleInfo &info) const\n+{\n+\tIPAModule *m = nullptr;\n+\n+\tfor (IPAModule *module : modules_) {\n+\t\tif (module->isAcquired())\n+\t\t\tcontinue;\n+\n+\t\tif (match(module, info) && module->acquire()) {\n+\t\t\tm = module;\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\n+\treturn m;\n+}\n+\n+bool IPAManager::match(const IPAModule *ipa, const struct IPAModuleInfo &info) const\n+{\n+\treturn ipa->info().ipaAPIVersion == info.ipaAPIVersion &&\n+\t       ipa->info().pipelineVersion >= info.pipelineVersion &&\n+\t       !strcmp(ipa->info().pipelineName, info.pipelineName);\n+}\n+\n+} /* namespace libcamera */\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex e5b48f2..ee1b658 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -10,6 +10,7 @@ libcamera_sources = files([\n     'event_notifier.cpp',\n     'formats.cpp',\n     'geometry.cpp',\n+    'ipa_manager.cpp',\n     'ipa_module.cpp',\n     'log.cpp',\n     'media_device.cpp',\n@@ -32,6 +33,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',\n","prefixes":["libcamera-devel","RFC","v2","3/5"]}