diff options
Diffstat (limited to 'src/ipa/libipa/module.h')
-rw-r--r-- | src/ipa/libipa/module.h | 71 |
1 files changed, 66 insertions, 5 deletions
diff --git a/src/ipa/libipa/module.h b/src/ipa/libipa/module.h index 05f39801..addae067 100644 --- a/src/ipa/libipa/module.h +++ b/src/ipa/libipa/module.h @@ -7,14 +7,22 @@ #pragma once +#include <list> #include <memory> #include <string> #include <vector> +#include <libcamera/base/log.h> +#include <libcamera/base/utils.h> + +#include "libcamera/internal/yaml_parser.h" + #include "algorithm.h" namespace libcamera { +LOG_DECLARE_CATEGORY(IPAModuleAlgo) + namespace ipa { template<typename _Context, typename _FrameContext, typename _Config, @@ -30,14 +38,31 @@ public: virtual ~Module() {} - static std::unique_ptr<Algorithm<Module>> createAlgorithm(const std::string &name) + const std::list<std::unique_ptr<Algorithm<Module>>> &algorithms() const { - for (const AlgorithmFactoryBase<Module> *factory : factories()) { - if (factory->name() == name) - return factory->create(); + return algorithms_; + } + + int createAlgorithms(Context &context, const YamlObject &algorithms) + { + const auto &list = algorithms.asList(); + + for (const auto &[i, algo] : utils::enumerate(list)) { + if (!algo.isDictionary()) { + LOG(IPAModuleAlgo, Error) + << "Invalid YAML syntax for algorithm " << i; + algorithms_.clear(); + return -EINVAL; + } + + int ret = createAlgorithm(context, algo); + if (ret) { + algorithms_.clear(); + return ret; + } } - return nullptr; + return 0; } static void registerAlgorithm(AlgorithmFactoryBase<Module> *factory) @@ -46,6 +71,40 @@ public: } private: + int createAlgorithm(Context &context, const YamlObject &data) + { + const auto &[name, algoData] = *data.asDict().begin(); + std::unique_ptr<Algorithm<Module>> algo = createAlgorithm(name); + if (!algo) { + LOG(IPAModuleAlgo, Error) + << "Algorithm '" << name << "' not found"; + return -EINVAL; + } + + int ret = algo->init(context, algoData); + if (ret) { + LOG(IPAModuleAlgo, Error) + << "Algorithm '" << name << "' failed to initialize"; + return ret; + } + + LOG(IPAModuleAlgo, Debug) + << "Instantiated algorithm '" << name << "'"; + + algorithms_.push_back(std::move(algo)); + return 0; + } + + static std::unique_ptr<Algorithm<Module>> createAlgorithm(const std::string &name) + { + for (const AlgorithmFactoryBase<Module> *factory : factories()) { + if (factory->name() == name) + return factory->create(); + } + + return nullptr; + } + static std::vector<AlgorithmFactoryBase<Module> *> &factories() { /* @@ -56,6 +115,8 @@ private: static std::vector<AlgorithmFactoryBase<Module> *> factories; return factories; } + + std::list<std::unique_ptr<Algorithm<Module>>> algorithms_; }; } /* namespace ipa */ |