new file mode 100644
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2019, Google Inc.
+ *
+ * ipa_manager.h - Image Processing Algorithm module manager
+ */
+#ifndef __LIBCAMERA_IPA_MANAGER_H__
+#define __LIBCAMERA_IPA_MANAGER_H__
+
+#include <libcamera/ipa/ipa_module_info.h>
+#include <list>
+#include <string>
+
+#include "ipa_module.h"
+#include "pipeline_handler.h"
+
+namespace libcamera {
+
+class IPAManager
+{
+public:
+ static std::unique_ptr<IPAManager> create();
+
+ int addDir(const std::string &libDir);
+
+ const IPAModule *acquireIPA(const struct IPAModuleInfo &info) const;
+
+private:
+ std::string libDir_;
+
+ std::list<IPAModule *> modules_;
+
+ bool match(const IPAModule *ipa, const struct IPAModuleInfo &info) const;
+};
+
+} /* namespace libcamera */
+
+#endif /* __LIBCAMERA_IPA_MANAGER_H__ */
new file mode 100644
@@ -0,0 +1,102 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2019, Google Inc.
+ *
+ * ipa_manager.cpp - Image Processing Algorithm module manager
+ */
+
+#include "ipa_manager.h"
+#include "ipa_module.h"
+#include "pipeline_handler.h"
+#include "utils.h"
+
+#include <dirent.h>
+#include <string.h>
+#include <sys/types.h>
+
+#include "log.h"
+
+/**
+ * \file ipa_manager.h
+ * \brief Image Processing Algorithm module manager
+ */
+
+namespace libcamera {
+
+LOG_DEFINE_CATEGORY(IPAManager)
+
+/**
+ * \class IPAManager
+ * \brief Manager for IPA modules
+ */
+
+std::unique_ptr<IPAManager> IPAManager::create()
+{
+ return utils::make_unique<IPAManager>();
+}
+
+/**
+ * \brief Load IPA modules from a directory
+ * \param[in] libDir directory to search for IPA modules
+ *
+ * Goes through libDir and tries to create an IPAModule instance for every
+ * found shared object. Skips invalid IPA modules.
+ */
+int IPAManager::addDir(const std::string &libDir)
+{
+ struct dirent *ent;
+ DIR *dir;
+
+ dir = opendir(libDir.c_str());
+ if (!dir) {
+ int ret = -errno;
+ LOG(IPAManager, Error) << "Invalid path for IPA modules: "
+ << strerror(ret);
+ return ret;
+ }
+
+ while ((ent = readdir(dir)) != nullptr) {
+ int offset = strlen(ent->d_name) - 3;
+ if (strncmp(&ent->d_name[offset], ".so", 3))
+ continue;
+
+ IPAModule *ipaModule = new IPAModule(libDir + "/" + ent->d_name);
+ if (ipaModule->isValid())
+ modules_.push_back(ipaModule);
+ }
+
+ closedir(dir);
+ return 0;
+}
+
+/**
+ * \brief Retrieve an IPA module for a given pipeline handler
+ *
+ * \return IPAModule
+ */
+const IPAModule
+*IPAManager::acquireIPA(const struct IPAModuleInfo &info) const
+{
+ IPAModule *m = nullptr;
+
+ for (struct IPAModule *module : modules_) {
+ if (module->acquired())
+ continue;
+
+ if (match(module, info) && module->acquire()) {
+ m = module;
+ break;
+ }
+ }
+
+ return m;
+}
+
+bool IPAManager::match(const IPAModule *ipa, const struct IPAModuleInfo &info) const
+{
+ return ipa->info().ipaAPIVersion == info.ipaAPIVersion &&
+ ipa->info().pipelineVersion <= info.pipelineVersion &&
+ !strcmp(ipa->info().pipelineName, info.pipelineName);
+}
+
+} /* namespace libcamera */
@@ -10,6 +10,7 @@ libcamera_sources = files([
'event_notifier.cpp',
'formats.cpp',
'geometry.cpp',
+ 'ipa_manager.cpp',
'ipa_module.cpp',
'log.cpp',
'media_device.cpp',
@@ -32,6 +33,7 @@ libcamera_headers = files([
'include/device_enumerator_udev.h',
'include/event_dispatcher_poll.h',
'include/formats.h',
+ 'include/ipa_manager.h',
'include/ipa_module.h',
'include/log.h',
'include/media_device.h',
IPAManager is a class that will search in given directories for IPA modules, and will load them into a list. It also provides an interface for pipelines to aquire an IPA. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> --- src/libcamera/include/ipa_manager.h | 38 +++++++++++ src/libcamera/ipa_manager.cpp | 102 ++++++++++++++++++++++++++++ src/libcamera/meson.build | 2 + 3 files changed, 142 insertions(+) create mode 100644 src/libcamera/include/ipa_manager.h create mode 100644 src/libcamera/ipa_manager.cpp