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/algorithm.h | 47 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) (limited to 'src/ipa/libipa/algorithm.h') diff --git a/src/ipa/libipa/algorithm.h b/src/ipa/libipa/algorithm.h index fd2ffcfb..cfbe4ed8 100644 --- a/src/ipa/libipa/algorithm.h +++ b/src/ipa/libipa/algorithm.h @@ -6,14 +6,19 @@ */ #pragma once +#include +#include + namespace libcamera { namespace ipa { -template +template class Algorithm { public: + using Module = _Module; + virtual ~Algorithm() {} virtual int configure([[maybe_unused]] typename Module::Context &context, @@ -34,6 +39,46 @@ public: } }; +template +class AlgorithmFactoryBase +{ +public: + AlgorithmFactoryBase(const char *name) + : name_(name) + { + _Module::registerAlgorithm(this); + } + + virtual ~AlgorithmFactoryBase() = default; + + const std::string &name() const { return name_; } + + virtual std::unique_ptr> create() const = 0; + +private: + std::string name_; +}; + +template +class AlgorithmFactory : public AlgorithmFactoryBase +{ +public: + AlgorithmFactory(const char *name) + : AlgorithmFactoryBase(name) + { + } + + ~AlgorithmFactory() = default; + + std::unique_ptr> create() const override + { + return std::make_unique<_Algorithm>(); + } +}; + +#define REGISTER_IPA_ALGORITHM(algorithm, name) \ +static AlgorithmFactory global_##algorithm##Factory(name); + } /* namespace ipa */ } /* namespace libcamera */ -- cgit v1.2.1