Patch Detail
Show a patch.
GET /api/1.1/patches/1341/?format=api
{ "id": 1341, "url": "https://patchwork.libcamera.org/api/1.1/patches/1341/?format=api", "web_url": "https://patchwork.libcamera.org/patch/1341/", "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": "<20190603231637.28554-5-paul.elder@ideasonboard.com>", "date": "2019-06-03T23:16:31", "name": "[libcamera-devel,v2,04/10] libcamera: ipa_module: allow instantiation of IPAInterface", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "a6ab738cac5e480dae488a7989e5a7c3efbe5532", "submitter": { "id": 17, "url": "https://patchwork.libcamera.org/api/1.1/people/17/?format=api", "name": "Paul Elder", "email": "paul.elder@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/1341/mbox/", "series": [ { "id": 335, "url": "https://patchwork.libcamera.org/api/1.1/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/1341/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/1341/checks/", "tags": {}, "headers": { "Return-Path": "<paul.elder@ideasonboard.com>", "Received": [ "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 07EAD618FD\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 4 Jun 2019 01:16:50 +0200 (CEST)", "from localhost.localdomain (unknown [96.44.9.117])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 61A4C530;\n\tTue, 4 Jun 2019 01:16:49 +0200 (CEST)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1559603809;\n\tbh=UOsv0TgC+jo2hmcdz8tvv/XPHbWwu29iW6WxYLw/Mgg=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=LjBS3FVAd/yjxKBQA5ct57WnN404ehtrSxu/cLcZGQjSOXsQfD9oYLIg0IdXf+LdL\n\tL5pSYeBmG/fvk+aD7/pDtyvnP6t1PMx8temRUhpssRS0TGipX2I3mVRYPquklnvXGa\n\tNSUF4OGldUURKJHgblu9e9gsg4rsZsJJxJ9L8kpQ=", "From": "Paul Elder <paul.elder@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Mon, 3 Jun 2019 19:16:31 -0400", "Message-Id": "<20190603231637.28554-5-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 04/10] libcamera: ipa_module: allow\n\tinstantiation of IPAInterface", "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:50 -0000" }, "content": "Add functions for loading the IPAInterface factory function from an IPA\nmodule shared object, and for creating an instance of an IPAInterface.\nThese functions will be used by IPAManager, from which a PipelineHandler\nwill request an IPAInterface.\n\nAlso update meson to add the \"-ldl\" linker argument, to allow loading of\nthe factory function from a shared object.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\n---\nChanges in v2:\n- mostly just documentation\n\n src/libcamera/include/ipa_module.h | 12 +++++\n src/libcamera/ipa_module.cpp | 83 ++++++++++++++++++++++++++++--\n src/libcamera/meson.build | 3 +-\n 3 files changed, 94 insertions(+), 4 deletions(-)", "diff": "diff --git a/src/libcamera/include/ipa_module.h b/src/libcamera/include/ipa_module.h\nindex a4c6dbd..557435c 100644\n--- a/src/libcamera/include/ipa_module.h\n+++ b/src/libcamera/include/ipa_module.h\n@@ -7,8 +7,10 @@\n #ifndef __LIBCAMERA_IPA_MODULE_H__\n #define __LIBCAMERA_IPA_MODULE_H__\n \n+#include <memory>\n #include <string>\n \n+#include <libcamera/ipa/ipa_interface.h>\n #include <libcamera/ipa/ipa_module_info.h>\n \n namespace libcamera {\n@@ -17,16 +19,26 @@ class IPAModule\n {\n public:\n \texplicit IPAModule(const std::string &libPath);\n+\t~IPAModule();\n \n \tbool isValid() const;\n \n \tconst struct IPAModuleInfo &info() const;\n \n+\tbool load();\n+\n+\tstd::unique_ptr<IPAInterface> createInstance();\n+\n private:\n \tstruct IPAModuleInfo info_;\n \n \tstd::string libPath_;\n \tbool valid_;\n+\tbool loaded_;\n+\n+\tvoid *dlHandle_;\n+\ttypedef IPAInterface *(*ipaIntfFactory)(void);\n+\tipaIntfFactory ipaCreate_;\n \n \tint loadIPAModuleInfo();\n };\ndiff --git a/src/libcamera/ipa_module.cpp b/src/libcamera/ipa_module.cpp\nindex 067f868..91d97ae 100644\n--- a/src/libcamera/ipa_module.cpp\n+++ b/src/libcamera/ipa_module.cpp\n@@ -7,6 +7,7 @@\n \n #include \"ipa_module.h\"\n \n+#include <dlfcn.h>\n #include <elf.h>\n #include <errno.h>\n #include <fcntl.h>\n@@ -257,13 +258,12 @@ int elfLoadSymbol(void *dst, size_t size, void *map, size_t soSize,\n * The IPA module shared object file must be of the same endianness and\n * bitness as libcamera.\n *\n- * \\todo load funtions from the IPA to be used by pipelines\n- *\n * The caller shall call the isValid() method after constructing an\n * IPAModule instance to verify the validity of the IPAModule.\n */\n IPAModule::IPAModule(const std::string &libPath)\n-\t: libPath_(libPath), valid_(false)\n+\t: libPath_(libPath), valid_(false), loaded_(false),\n+\t dlHandle_(nullptr), ipaCreate_(nullptr)\n {\n \tif (loadIPAModuleInfo() < 0)\n \t\treturn;\n@@ -271,6 +271,12 @@ IPAModule::IPAModule(const std::string &libPath)\n \tvalid_ = true;\n }\n \n+IPAModule::~IPAModule()\n+{\n+\tif (dlHandle_)\n+\t\tdlclose(dlHandle_);\n+}\n+\n int IPAModule::loadIPAModuleInfo()\n {\n \tint fd = open(libPath_.c_str(), O_RDONLY);\n@@ -340,4 +346,75 @@ const struct IPAModuleInfo &IPAModule::info() const\n \treturn info_;\n }\n \n+/**\n+ * \\brief Load the IPA implementation factory from the shared object\n+ *\n+ * The IPA module shared object implements an IPAInterface class to be used\n+ * by pipeline handlers. This function loads the factory function from the\n+ * shared object. Later, createInstance() can be called to instantiate the\n+ * IPAInterface.\n+ *\n+ * This method only needs to be called successfully once, after which\n+ * createInstance can be called as many times as IPAInterface instances are\n+ * needed.\n+ *\n+ * Calling this function on an invalid module (as returned by isValid()) is\n+ * an error.\n+ *\n+ * \\return true if load was successful, or already loaded, and false otherwise\n+ */\n+bool IPAModule::load()\n+{\n+\tif (!valid_)\n+\t\treturn false;\n+\n+\tif (loaded_)\n+\t\treturn true;\n+\n+\tdlHandle_ = dlopen(libPath_.c_str(), RTLD_LAZY);\n+\tif (!dlHandle_) {\n+\t\tLOG(IPAModule, Error)\n+\t\t\t<< \"Failed to open IPA module shared object \"\n+\t\t\t<< dlerror();\n+\t\treturn false;\n+\t}\n+\n+\tvoid *symbol = dlsym(dlHandle_, \"ipaCreate\");\n+\tif (!symbol) {\n+\t\tLOG(IPAModule, Error)\n+\t\t\t<< \"Failed to load ipaCreate() from IPA module shared object \"\n+\t\t\t<< dlerror();\n+\t\tdlclose(dlHandle_);\n+\t\tdlHandle_ = nullptr;\n+\t\treturn false;\n+\t}\n+\n+\tipaCreate_ = (ipaIntfFactory)symbol;\n+\n+\tloaded_ = true;\n+\n+\treturn true;\n+}\n+\n+/**\n+ * \\brief Instantiate an IPAInterface\n+ *\n+ * After loading the IPA module with load(), this method creates an\n+ * instance of the IPA module interface.\n+ *\n+ * Calling this function on a module that has not yet been loaded, or an\n+ * invalid module (as returned by load() and isValid(), respectively) is\n+ * an error.\n+ *\n+ * \\return the IPA implementation as a new IPAInterface instance on success,\n+ * or nullptr on error\n+ */\n+std::unique_ptr<IPAInterface> IPAModule::createInstance()\n+{\n+\tif (!valid_ || !loaded_)\n+\t\treturn nullptr;\n+\n+\treturn std::unique_ptr<IPAInterface>(ipaCreate_());\n+}\n+\n } /* namespace libcamera */\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex 07335e5..32f7da4 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -65,7 +65,8 @@ libcamera = shared_library('camera',\n libcamera_sources,\n install : true,\n include_directories : includes,\n- dependencies : libudev)\n+ dependencies : libudev,\n+ link_args : '-ldl')\n \n libcamera_dep = declare_dependency(sources : [libcamera_api, libcamera_h],\n include_directories : libcamera_includes,\n", "prefixes": [ "libcamera-devel", "v2", "04/10" ] }