ipa: camera_sensor_helper: Implement factories through class templates
The REGISTER_CAMERA_SENSOR_HELPER() macro defines a class type that inherits from the CameraSensorHelperFactory class, and implements a constructor and createInstance() function. Replace the code generation through macro with the C++ equivalent, a class template, as done by the Algorithm factory. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Xavier Roumegue <xavier.roumegue@oss.nxp.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
This commit is contained in:
parent
9d9481188f
commit
014698cba1
4 changed files with 72 additions and 52 deletions
|
@ -326,7 +326,7 @@ int IPAIPU3::init(const IPASettings &settings,
|
||||||
const ControlInfoMap &sensorControls,
|
const ControlInfoMap &sensorControls,
|
||||||
ControlInfoMap *ipaControls)
|
ControlInfoMap *ipaControls)
|
||||||
{
|
{
|
||||||
camHelper_ = CameraSensorHelperFactory::create(settings.sensorModel);
|
camHelper_ = CameraSensorHelperFactoryBase::create(settings.sensorModel);
|
||||||
if (camHelper_ == nullptr) {
|
if (camHelper_ == nullptr) {
|
||||||
LOG(IPAIPU3, Error)
|
LOG(IPAIPU3, Error)
|
||||||
<< "Failed to create camera sensor helper for "
|
<< "Failed to create camera sensor helper for "
|
||||||
|
|
|
@ -43,7 +43,8 @@ namespace ipa {
|
||||||
* \brief Construct a CameraSensorHelper instance
|
* \brief Construct a CameraSensorHelper instance
|
||||||
*
|
*
|
||||||
* CameraSensorHelper derived class instances shall never be constructed
|
* CameraSensorHelper derived class instances shall never be constructed
|
||||||
* manually but always through the CameraSensorHelperFactory::create() function.
|
* manually but always through the CameraSensorHelperFactoryBase::create()
|
||||||
|
* function.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -217,27 +218,25 @@ double CameraSensorHelper::gain(uint32_t gainCode) const
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \class CameraSensorHelperFactory
|
* \class CameraSensorHelperFactoryBase
|
||||||
* \brief Registration of CameraSensorHelperFactory classes and creation of instances
|
* \brief Base class for camera sensor helper factories
|
||||||
*
|
*
|
||||||
* To facilitate discovery and instantiation of CameraSensorHelper classes, the
|
* The CameraSensorHelperFactoryBase class is the base of all specializations of
|
||||||
* CameraSensorHelperFactory class maintains a registry of camera sensor helper
|
* the CameraSensorHelperFactory class template. It implements the factory
|
||||||
* sub-classes. Each CameraSensorHelper subclass shall register itself using the
|
* registration, maintains a registry of factories, and provides access to the
|
||||||
* REGISTER_CAMERA_SENSOR_HELPER() macro, which will create a corresponding
|
* registered factories.
|
||||||
* instance of a CameraSensorHelperFactory subclass and register it with the
|
|
||||||
* static list of factories.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Construct a camera sensor helper factory
|
* \brief Construct a camera sensor helper factory base
|
||||||
* \param[in] name Name of the camera sensor helper class
|
* \param[in] name Name of the camera sensor helper class
|
||||||
*
|
*
|
||||||
* Creating an instance of the factory registers it with the global list of
|
* Creating an instance of the factory base registers it with the global list of
|
||||||
* factories, accessible through the factories() function.
|
* factories, accessible through the factories() function.
|
||||||
*
|
*
|
||||||
* The factory \a name is used for debug purpose and shall be unique.
|
* The factory \a name is used to look up factories and shall be unique.
|
||||||
*/
|
*/
|
||||||
CameraSensorHelperFactory::CameraSensorHelperFactory(const std::string name)
|
CameraSensorHelperFactoryBase::CameraSensorHelperFactoryBase(const std::string name)
|
||||||
: name_(name)
|
: name_(name)
|
||||||
{
|
{
|
||||||
registerType(this);
|
registerType(this);
|
||||||
|
@ -252,12 +251,12 @@ CameraSensorHelperFactory::CameraSensorHelperFactory(const std::string name)
|
||||||
* corresponding to the named factory or a null pointer if no such factory
|
* corresponding to the named factory or a null pointer if no such factory
|
||||||
* exists
|
* exists
|
||||||
*/
|
*/
|
||||||
std::unique_ptr<CameraSensorHelper> CameraSensorHelperFactory::create(const std::string &name)
|
std::unique_ptr<CameraSensorHelper> CameraSensorHelperFactoryBase::create(const std::string &name)
|
||||||
{
|
{
|
||||||
const std::vector<CameraSensorHelperFactory *> &factories =
|
const std::vector<CameraSensorHelperFactoryBase *> &factories =
|
||||||
CameraSensorHelperFactory::factories();
|
CameraSensorHelperFactoryBase::factories();
|
||||||
|
|
||||||
for (const CameraSensorHelperFactory *factory : factories) {
|
for (const CameraSensorHelperFactoryBase *factory : factories) {
|
||||||
if (name != factory->name_)
|
if (name != factory->name_)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -274,10 +273,10 @@ std::unique_ptr<CameraSensorHelper> CameraSensorHelperFactory::create(const std:
|
||||||
* The caller is responsible to guarantee the uniqueness of the camera sensor
|
* The caller is responsible to guarantee the uniqueness of the camera sensor
|
||||||
* helper name.
|
* helper name.
|
||||||
*/
|
*/
|
||||||
void CameraSensorHelperFactory::registerType(CameraSensorHelperFactory *factory)
|
void CameraSensorHelperFactoryBase::registerType(CameraSensorHelperFactoryBase *factory)
|
||||||
{
|
{
|
||||||
std::vector<CameraSensorHelperFactory *> &factories =
|
std::vector<CameraSensorHelperFactoryBase *> &factories =
|
||||||
CameraSensorHelperFactory::factories();
|
CameraSensorHelperFactoryBase::factories();
|
||||||
|
|
||||||
factories.push_back(factory);
|
factories.push_back(factory);
|
||||||
}
|
}
|
||||||
|
@ -286,35 +285,51 @@ void CameraSensorHelperFactory::registerType(CameraSensorHelperFactory *factory)
|
||||||
* \brief Retrieve the list of all camera sensor helper factories
|
* \brief Retrieve the list of all camera sensor helper factories
|
||||||
* \return The list of camera sensor helper factories
|
* \return The list of camera sensor helper factories
|
||||||
*/
|
*/
|
||||||
std::vector<CameraSensorHelperFactory *> &CameraSensorHelperFactory::factories()
|
std::vector<CameraSensorHelperFactoryBase *> &CameraSensorHelperFactoryBase::factories()
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* The static factories map is defined inside the function to ensure
|
* The static factories map is defined inside the function to ensure
|
||||||
* it gets initialized on first use, without any dependency on link
|
* it gets initialized on first use, without any dependency on link
|
||||||
* order.
|
* order.
|
||||||
*/
|
*/
|
||||||
static std::vector<CameraSensorHelperFactory *> factories;
|
static std::vector<CameraSensorHelperFactoryBase *> factories;
|
||||||
return factories;
|
return factories;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \class CameraSensorHelperFactory
|
||||||
|
* \brief Registration of CameraSensorHelperFactory classes and creation of instances
|
||||||
|
* \tparam _Helper The camera sensor helper class type for this factory
|
||||||
|
*
|
||||||
|
* To facilitate discovery and instantiation of CameraSensorHelper classes, the
|
||||||
|
* CameraSensorHelperFactory class implements auto-registration of camera sensor
|
||||||
|
* helpers. Each CameraSensorHelper subclass shall register itself using the
|
||||||
|
* REGISTER_CAMERA_SENSOR_HELPER() macro, which will create a corresponding
|
||||||
|
* instance of a CameraSensorHelperFactory subclass and register it with the
|
||||||
|
* static list of factories.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \fn CameraSensorHelperFactory::CameraSensorHelperFactory(const char *name)
|
||||||
|
* \brief Construct a camera sensor helper factory
|
||||||
|
* \param[in] name Name of the camera sensor helper class
|
||||||
|
*
|
||||||
|
* Creating an instance of the factory registers it with the global list of
|
||||||
|
* factories, accessible through the CameraSensorHelperFactoryBase::factories()
|
||||||
|
* function.
|
||||||
|
*
|
||||||
|
* The factory \a name is used to look up factories and shall be unique.
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \fn CameraSensorHelperFactory::createInstance() const
|
* \fn CameraSensorHelperFactory::createInstance() const
|
||||||
* \brief Create an instance of the CameraSensorHelper corresponding to the
|
* \brief Create an instance of the CameraSensorHelper corresponding to the
|
||||||
* factory
|
* factory
|
||||||
*
|
*
|
||||||
* This virtual function is implemented by the REGISTER_CAMERA_SENSOR_HELPER()
|
|
||||||
* macro. It creates a camera sensor helper instance associated with the camera
|
|
||||||
* sensor model.
|
|
||||||
*
|
|
||||||
* \return A unique pointer to a newly constructed instance of the
|
* \return A unique pointer to a newly constructed instance of the
|
||||||
* CameraSensorHelper subclass corresponding to the factory
|
* CameraSensorHelper subclass corresponding to the factory
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* \var CameraSensorHelperFactory::name_
|
|
||||||
* \brief The name of the factory
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \def REGISTER_CAMERA_SENSOR_HELPER
|
* \def REGISTER_CAMERA_SENSOR_HELPER
|
||||||
* \brief Register a camera sensor helper with the camera sensor helper factory
|
* \brief Register a camera sensor helper with the camera sensor helper factory
|
||||||
|
|
|
@ -58,39 +58,44 @@ private:
|
||||||
LIBCAMERA_DISABLE_COPY_AND_MOVE(CameraSensorHelper)
|
LIBCAMERA_DISABLE_COPY_AND_MOVE(CameraSensorHelper)
|
||||||
};
|
};
|
||||||
|
|
||||||
class CameraSensorHelperFactory
|
class CameraSensorHelperFactoryBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CameraSensorHelperFactory(const std::string name);
|
CameraSensorHelperFactoryBase(const std::string name);
|
||||||
virtual ~CameraSensorHelperFactory() = default;
|
virtual ~CameraSensorHelperFactoryBase() = default;
|
||||||
|
|
||||||
static std::unique_ptr<CameraSensorHelper> create(const std::string &name);
|
static std::unique_ptr<CameraSensorHelper> create(const std::string &name);
|
||||||
|
|
||||||
static std::vector<CameraSensorHelperFactory *> &factories();
|
static std::vector<CameraSensorHelperFactoryBase *> &factories();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LIBCAMERA_DISABLE_COPY_AND_MOVE(CameraSensorHelperFactory)
|
LIBCAMERA_DISABLE_COPY_AND_MOVE(CameraSensorHelperFactoryBase)
|
||||||
|
|
||||||
static void registerType(CameraSensorHelperFactory *factory);
|
static void registerType(CameraSensorHelperFactoryBase *factory);
|
||||||
|
|
||||||
virtual std::unique_ptr<CameraSensorHelper> createInstance() const = 0;
|
virtual std::unique_ptr<CameraSensorHelper> createInstance() const = 0;
|
||||||
|
|
||||||
std::string name_;
|
std::string name_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define REGISTER_CAMERA_SENSOR_HELPER(name, helper) \
|
template<typename _Helper>
|
||||||
class helper##Factory final : public CameraSensorHelperFactory \
|
class CameraSensorHelperFactory final : public CameraSensorHelperFactoryBase
|
||||||
{ \
|
{
|
||||||
public: \
|
public:
|
||||||
helper##Factory() : CameraSensorHelperFactory(name) {} \
|
CameraSensorHelperFactory(const char *name)
|
||||||
\
|
: CameraSensorHelperFactoryBase(name)
|
||||||
private: \
|
{
|
||||||
std::unique_ptr<CameraSensorHelper> createInstance() const \
|
}
|
||||||
{ \
|
|
||||||
return std::make_unique<helper>(); \
|
private:
|
||||||
} \
|
std::unique_ptr<CameraSensorHelper> createInstance() const
|
||||||
}; \
|
{
|
||||||
static helper##Factory global_##helper##Factory;
|
return std::make_unique<_Helper>();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#define REGISTER_CAMERA_SENSOR_HELPER(name, helper) \
|
||||||
|
static CameraSensorHelperFactory<helper> global_##helper##Factory(name);
|
||||||
|
|
||||||
} /* namespace ipa */
|
} /* namespace ipa */
|
||||||
|
|
||||||
|
|
|
@ -142,7 +142,7 @@ int IPARkISP1::init(const IPASettings &settings, unsigned int hwRevision,
|
||||||
/* Cache the value to set it in configure. */
|
/* Cache the value to set it in configure. */
|
||||||
hwRevision_ = static_cast<rkisp1_cif_isp_version>(hwRevision);
|
hwRevision_ = static_cast<rkisp1_cif_isp_version>(hwRevision);
|
||||||
|
|
||||||
camHelper_ = CameraSensorHelperFactory::create(settings.sensorModel);
|
camHelper_ = CameraSensorHelperFactoryBase::create(settings.sensorModel);
|
||||||
if (!camHelper_) {
|
if (!camHelper_) {
|
||||||
LOG(IPARkISP1, Error)
|
LOG(IPARkISP1, Error)
|
||||||
<< "Failed to create camera sensor helper for "
|
<< "Failed to create camera sensor helper for "
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue