{"id":25985,"url":"https://patchwork.libcamera.org/api/1.1/patches/25985/?format=json","web_url":"https://patchwork.libcamera.org/patch/25985/","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":"<20260128074956.760538-2-paul.elder@ideasonboard.com>","date":"2026-01-28T07:49:49","name":"[v5,1/8] libcamera: ipa_manager: Factor out .so file searching","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"e989c30a48858bc46894252c4c9b8629297220c9","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/25985/mbox/","series":[{"id":5747,"url":"https://patchwork.libcamera.org/api/1.1/series/5747/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5747","date":"2026-01-28T07:49:48","name":"Add Layers support","version":5,"mbox":"https://patchwork.libcamera.org/series/5747/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/25985/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/25985/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 84C36C3200\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 28 Jan 2026 07:50:14 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 47F3C61FCF;\n\tWed, 28 Jan 2026 08:50:14 +0100 (CET)","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 4D27E61A35\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 28 Jan 2026 08:50:10 +0100 (CET)","from neptunite.hamster-moth.ts.net (unknown\n\t[IPv6:2404:7a81:160:2100:508d:7983:72a6:2eeb])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 90E9AC6F;\n\tWed, 28 Jan 2026 08:49:32 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"MsF6DmAv\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1769586573;\n\tbh=NI7nfFoKNZxIJ5lFsGWDEIdGS/KLsyCvoZ7z6PZ35wU=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=MsF6DmAvcYievEn7E6//BkwsHtBS57XQph93f1bzUnUjlA0ItVNUqrpPSBSrvTtwO\n\tQDJf56A1iDmFmxMUDJK2JjysSQCADyClmsr1THUkNsz9pMxZYmkjhReKN3CBaGl3Bm\n\tz+mvXmNlZF6rAD4lAAPEymjQoObt3oMq0a9CzdhY=","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Paul Elder <paul.elder@ideasonboard.com>","Subject":"[PATCH v5 1/8] libcamera: ipa_manager: Factor out .so file searching","Date":"Wed, 28 Jan 2026 16:49:49 +0900","Message-ID":"<20260128074956.760538-2-paul.elder@ideasonboard.com>","X-Mailer":"git-send-email 2.47.2","In-Reply-To":"<20260128074956.760538-1-paul.elder@ideasonboard.com>","References":"<20260128074956.760538-1-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"In the near future we will add support for layers/shoes on top of\nlibcamera, which will need to search for shared object files similar to\nhow IPAManager does. To avoid code duplication, move this code out of\nIPAManager into internal utils.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\n\n---\nNo change in v4\n\nChanges in v3:\n- rename addDir to findSharedObjects\n- make parseDir static\n\nNo change in v2\n---\n include/libcamera/internal/ipa_manager.h |   4 -\n include/libcamera/internal/meson.build   |   1 +\n include/libcamera/internal/utils.h       |  23 +++++\n src/libcamera/ipa_manager.cpp            | 107 ++++-------------------\n src/libcamera/meson.build                |   1 +\n src/libcamera/utils.cpp                  | 107 +++++++++++++++++++++++\n 6 files changed, 151 insertions(+), 92 deletions(-)\n create mode 100644 include/libcamera/internal/utils.h\n create mode 100644 src/libcamera/utils.cpp","diff":"diff --git a/include/libcamera/internal/ipa_manager.h b/include/libcamera/internal/ipa_manager.h\nindex f8ce780169e6..dcfcf8d69da5 100644\n--- a/include/libcamera/internal/ipa_manager.h\n+++ b/include/libcamera/internal/ipa_manager.h\n@@ -68,10 +68,6 @@ public:\n #endif\n \n private:\n-\tvoid parseDir(const char *libDir, unsigned int maxDepth,\n-\t\t      std::vector<std::string> &files);\n-\tunsigned int addDir(const char *libDir, unsigned int maxDepth = 0);\n-\n \tIPAModule *module(PipelineHandler *pipe, uint32_t minVersion,\n \t\t\t  uint32_t maxVersion);\n \ndiff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build\nindex 4d2a09bd7041..ed145a6dd7cd 100644\n--- a/include/libcamera/internal/meson.build\n+++ b/include/libcamera/internal/meson.build\n@@ -43,6 +43,7 @@ libcamera_internal_headers = files([\n     'shared_mem_object.h',\n     'source_paths.h',\n     'sysfs.h',\n+    'utils.h',\n     'v4l2_device.h',\n     'v4l2_pixelformat.h',\n     'v4l2_request.h',\ndiff --git a/include/libcamera/internal/utils.h b/include/libcamera/internal/utils.h\nnew file mode 100644\nindex 000000000000..5b7957b5d77e\n--- /dev/null\n+++ b/include/libcamera/internal/utils.h\n@@ -0,0 +1,23 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2018, Google Inc.\n+ *\n+ * Miscellaneous utility functions\n+ */\n+\n+#pragma once\n+\n+#include <functional>\n+#include <string>\n+#include <vector>\n+\n+namespace libcamera {\n+\n+namespace utils {\n+\n+unsigned int findSharedObjects(const char *libDir, unsigned int maxDepth,\n+\t\t\t       std::function<int(const std::string &)> func);\n+\n+} /* namespace utils */\n+\n+} /* namespace libcamera */\ndiff --git a/src/libcamera/ipa_manager.cpp b/src/libcamera/ipa_manager.cpp\nindex 35171d097136..244a8ee67f05 100644\n--- a/src/libcamera/ipa_manager.cpp\n+++ b/src/libcamera/ipa_manager.cpp\n@@ -8,7 +8,7 @@\n #include \"libcamera/internal/ipa_manager.h\"\n \n #include <algorithm>\n-#include <dirent.h>\n+#include <functional>\n #include <string.h>\n #include <string>\n #include <sys/types.h>\n@@ -22,6 +22,7 @@\n #include \"libcamera/internal/ipa_module.h\"\n #include \"libcamera/internal/ipa_proxy.h\"\n #include \"libcamera/internal/pipeline_handler.h\"\n+#include \"libcamera/internal/utils.h\"\n \n /**\n  * \\file ipa_manager.h\n@@ -118,6 +119,20 @@ IPAManager::IPAManager(const GlobalConfiguration &configuration)\n \n \tunsigned int ipaCount = 0;\n \n+\tauto &modules = modules_;\n+\tstd::function<int(const std::string &)> soHandler =\n+\t[&modules](const std::string &file) {\n+\t\tauto ipaModule = std::make_unique<IPAModule>(file);\n+\t\tif (!ipaModule->isValid())\n+\t\t\treturn 0;\n+\n+\t\tLOG(IPAManager, Debug) << \"Loaded IPA module '\" << file << \"'\";\n+\n+\t\tmodules.push_back(std::move(ipaModule));\n+\n+\t\treturn 1;\n+\t};\n+\n \t/* User-specified paths take precedence. */\n \tconst auto modulePaths =\n \t\tconfiguration.envListOption(\n@@ -127,7 +142,7 @@ IPAManager::IPAManager(const GlobalConfiguration &configuration)\n \t\tif (dir.empty())\n \t\t\tcontinue;\n \n-\t\tipaCount += addDir(dir.c_str());\n+\t\tipaCount += utils::findSharedObjects(dir.c_str(), 0, soHandler);\n \t}\n \n \tif (!modulePaths.empty() && !ipaCount)\n@@ -148,11 +163,11 @@ IPAManager::IPAManager(const GlobalConfiguration &configuration)\n \t\t\t<< \"libcamera is not installed. Adding '\"\n \t\t\t<< ipaBuildPath << \"' to the IPA search path\";\n \n-\t\tipaCount += addDir(ipaBuildPath.c_str(), maxDepth);\n+\t\tipaCount += utils::findSharedObjects(ipaBuildPath.c_str(), maxDepth, soHandler);\n \t}\n \n \t/* Finally try to load IPAs from the installed system path. */\n-\tipaCount += addDir(IPA_MODULE_DIR);\n+\tipaCount += utils::findSharedObjects(IPA_MODULE_DIR, 0, soHandler);\n \n \tif (!ipaCount)\n \t\tLOG(IPAManager, Warning)\n@@ -161,90 +176,6 @@ IPAManager::IPAManager(const GlobalConfiguration &configuration)\n \n IPAManager::~IPAManager() = default;\n \n-/**\n- * \\brief Identify shared library objects within a directory\n- * \\param[in] libDir The directory to search for shared objects\n- * \\param[in] maxDepth The maximum depth of sub-directories to parse\n- * \\param[out] files A vector of paths to shared object library files\n- *\n- * Search a directory for .so files, allowing recursion down to sub-directories\n- * no further than the depth specified by \\a maxDepth.\n- *\n- * Discovered shared objects are added to the \\a files vector.\n- */\n-void IPAManager::parseDir(const char *libDir, unsigned int maxDepth,\n-\t\t\t  std::vector<std::string> &files)\n-{\n-\tstruct dirent *ent;\n-\tDIR *dir;\n-\n-\tdir = opendir(libDir);\n-\tif (!dir)\n-\t\treturn;\n-\n-\twhile ((ent = readdir(dir)) != nullptr) {\n-\t\tif (ent->d_type == DT_DIR && maxDepth) {\n-\t\t\tif (strcmp(ent->d_name, \".\") == 0 ||\n-\t\t\t    strcmp(ent->d_name, \"..\") == 0)\n-\t\t\t\tcontinue;\n-\n-\t\t\tstd::string subdir = std::string(libDir) + \"/\" + ent->d_name;\n-\n-\t\t\t/* Recursion is limited to maxDepth. */\n-\t\t\tparseDir(subdir.c_str(), maxDepth - 1, files);\n-\n-\t\t\tcontinue;\n-\t\t}\n-\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\tfiles.push_back(std::string(libDir) + \"/\" + ent->d_name);\n-\t}\n-\n-\tclosedir(dir);\n-}\n-\n-/**\n- * \\brief Load IPA modules from a directory\n- * \\param[in] libDir The directory to search for IPA modules\n- * \\param[in] maxDepth The maximum depth of sub-directories to search\n- *\n- * This function tries to create an IPAModule instance for every shared object\n- * found in \\a libDir, and skips invalid IPA modules.\n- *\n- * Sub-directories are searched up to a depth of \\a maxDepth. A \\a maxDepth\n- * value of 0 only searches the directory specified in \\a libDir.\n- *\n- * \\return Number of modules loaded by this call\n- */\n-unsigned int IPAManager::addDir(const char *libDir, unsigned int maxDepth)\n-{\n-\tstd::vector<std::string> files;\n-\n-\tparseDir(libDir, maxDepth, files);\n-\n-\t/* Ensure a stable ordering of modules. */\n-\tstd::sort(files.begin(), files.end());\n-\n-\tunsigned int count = 0;\n-\tfor (const std::string &file : files) {\n-\t\tauto ipaModule = std::make_unique<IPAModule>(file);\n-\t\tif (!ipaModule->isValid())\n-\t\t\tcontinue;\n-\n-\t\tLOG(IPAManager, Debug) << \"Loaded IPA module '\" << file << \"'\";\n-\n-\t\tmodules_.push_back(std::move(ipaModule));\n-\t\tcount++;\n-\t}\n-\n-\treturn count;\n-}\n-\n /**\n  * \\brief Retrieve an IPA module that matches a given pipeline handler\n  * \\param[in] pipe The pipeline handler\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex d15943586300..186d5c48ccd5 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -52,6 +52,7 @@ libcamera_internal_sources = files([\n     'shared_mem_object.cpp',\n     'source_paths.cpp',\n     'sysfs.cpp',\n+    'utils.cpp',\n     'v4l2_device.cpp',\n     'v4l2_pixelformat.cpp',\n     'v4l2_request.cpp',\ndiff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp\nnew file mode 100644\nindex 000000000000..2ce62f236cea\n--- /dev/null\n+++ b/src/libcamera/utils.cpp\n@@ -0,0 +1,107 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * Miscellaneous utility functions (internal)\n+ */\n+\n+#include \"libcamera/internal/utils.h\"\n+\n+#include <algorithm>\n+#include <dirent.h>\n+#include <functional>\n+#include <string.h>\n+#include <string>\n+#include <sys/types.h>\n+#include <vector>\n+\n+/**\n+ * \\file internal/utils.h\n+ * \\brief Miscellaneous utility functions (internal)\n+ */\n+\n+namespace libcamera {\n+\n+namespace utils {\n+\n+/**\n+ * \\brief Identify shared library objects within a directory\n+ * \\param[in] libDir The directory to search for shared objects\n+ * \\param[in] maxDepth The maximum depth of sub-directories to parse\n+ * \\param[out] files A vector of paths to shared object library files\n+ *\n+ * Search a directory for .so files, allowing recursion down to sub-directories\n+ * no further than the depth specified by \\a maxDepth.\n+ *\n+ * Discovered shared objects are added to the \\a files vector.\n+ */\n+static void parseDir(const char *libDir, unsigned int maxDepth,\n+\t\t     std::vector<std::string> &files)\n+{\n+\tstruct dirent *ent;\n+\tDIR *dir;\n+\n+\tdir = opendir(libDir);\n+\tif (!dir)\n+\t\treturn;\n+\n+\twhile ((ent = readdir(dir)) != nullptr) {\n+\t\tif (ent->d_type == DT_DIR && maxDepth) {\n+\t\t\tif (strcmp(ent->d_name, \".\") == 0 ||\n+\t\t\t    strcmp(ent->d_name, \"..\") == 0)\n+\t\t\t\tcontinue;\n+\n+\t\t\tstd::string subdir = std::string(libDir) + \"/\" + ent->d_name;\n+\n+\t\t\t/* Recursion is limited to maxDepth. */\n+\t\t\tparseDir(subdir.c_str(), maxDepth - 1, files);\n+\n+\t\t\tcontinue;\n+\t\t}\n+\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\tfiles.push_back(std::string(libDir) + \"/\" + ent->d_name);\n+\t}\n+\n+\tclosedir(dir);\n+}\n+\n+/**\n+ * \\brief Execute some function on shared object files from a directory\n+ * \\param[in] libDir The directory to search for shared objects\n+ * \\param[in] maxDepth The maximum depth of sub-directories to search\n+ * \\param[in] func The function to execute on every shared object\n+ *\n+ * This function tries to execute the given function \\a func for every shared\n+ * object found in \\a libDir.\n+ *\n+ * Sub-directories are searched up to a depth of \\a maxDepth. A \\a maxDepth\n+ * value of 0 only searches the directory specified in \\a libDir.\n+ *\n+ * \\return Number of shared objects loaded by this call\n+ */\n+unsigned int findSharedObjects(const char *libDir, unsigned int maxDepth,\n+\t\t\t       std::function<int(const std::string &)> func)\n+{\n+\tstd::vector<std::string> files;\n+\n+\tparseDir(libDir, maxDepth, files);\n+\n+\t/* Ensure a stable ordering of modules. */\n+\tstd::sort(files.begin(), files.end());\n+\n+\tunsigned int count = 0;\n+\tfor (const std::string &file : files)\n+\t\tcount += func(file);\n+\n+\treturn count;\n+}\n+\n+} /* namespace utils */\n+\n+} /* namespace libcamera */\n","prefixes":["v5","1/8"]}