From d1934c6490e335c273838a960657652bfe6d7546 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Mon, 20 Jun 2022 02:30:32 +0300 Subject: ipa: libipa: algorithm: Add an algorithm registration mechanism In order to allow dynamic instantiation of algorithms based on tuning data files, add a mechanism to register algorithms with the IPA module. The implementation relies on an AlgorithmFactory class and a registration macro, similar to the pipeline handler registration mechanism. The main difference is that the algorithm registration and instantiation are implemented in the Module class instead of the AlgorithmFactory class, making the factory an internal implementation detail. Signed-off-by: Laurent Pinchart Reviewed-by: Paul Elder --- src/ipa/libipa/module.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/ipa/libipa/module.h') diff --git a/src/ipa/libipa/module.h b/src/ipa/libipa/module.h index c4d77812..05f39801 100644 --- a/src/ipa/libipa/module.h +++ b/src/ipa/libipa/module.h @@ -7,6 +7,12 @@ #pragma once +#include +#include +#include + +#include "algorithm.h" + namespace libcamera { namespace ipa { @@ -23,6 +29,33 @@ public: using Stats = _Stats; virtual ~Module() {} + + static std::unique_ptr> createAlgorithm(const std::string &name) + { + for (const AlgorithmFactoryBase *factory : factories()) { + if (factory->name() == name) + return factory->create(); + } + + return nullptr; + } + + static void registerAlgorithm(AlgorithmFactoryBase *factory) + { + factories().push_back(factory); + } + +private: + static std::vector *> &factories() + { + /* + * The static factories map is defined inside the function to ensure + * it gets initialized on first use, without any dependency on + * link order. + */ + static std::vector *> factories; + return factories; + } }; } /* namespace ipa */ -- cgit v1.2.1