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 <laurent.pinchart@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
This commit is contained in:
parent
5f94b262da
commit
d1934c6490
5 changed files with 152 additions and 1 deletions
|
@ -6,14 +6,19 @@
|
|||
*/
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
namespace ipa {
|
||||
|
||||
template<typename Module>
|
||||
template<typename _Module>
|
||||
class Algorithm
|
||||
{
|
||||
public:
|
||||
using Module = _Module;
|
||||
|
||||
virtual ~Algorithm() {}
|
||||
|
||||
virtual int configure([[maybe_unused]] typename Module::Context &context,
|
||||
|
@ -34,6 +39,46 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
template<typename _Module>
|
||||
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<Algorithm<_Module>> create() const = 0;
|
||||
|
||||
private:
|
||||
std::string name_;
|
||||
};
|
||||
|
||||
template<typename _Algorithm>
|
||||
class AlgorithmFactory : public AlgorithmFactoryBase<typename _Algorithm::Module>
|
||||
{
|
||||
public:
|
||||
AlgorithmFactory(const char *name)
|
||||
: AlgorithmFactoryBase<typename _Algorithm::Module>(name)
|
||||
{
|
||||
}
|
||||
|
||||
~AlgorithmFactory() = default;
|
||||
|
||||
std::unique_ptr<Algorithm<typename _Algorithm::Module>> create() const override
|
||||
{
|
||||
return std::make_unique<_Algorithm>();
|
||||
}
|
||||
};
|
||||
|
||||
#define REGISTER_IPA_ALGORITHM(algorithm, name) \
|
||||
static AlgorithmFactory<algorithm> global_##algorithm##Factory(name);
|
||||
|
||||
} /* namespace ipa */
|
||||
|
||||
} /* namespace libcamera */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue