ipa: libipa: Introduce a Module class template

libipa defines an abstract Algorithm class template that is specialized
by IPA modules. IPA modules then instantiate and manage algorithms
internally, without help from libipa. With ongoing work on tuning data
support for the RkISP1, and future similar work for the IPU3, more code
duplication for algorithms management is expected.

To address this and share code between multiple IPA modules, introduce a
new Module class template that will define and manage top-level concepts
for the IPA module.

The Module class template needs to be specialized with the same types as
the Algorithm class. To avoid manual specialization of both classes,
store the types in the Module class, and replace the template arguments
of the Algorithm class with a single Module argument from which the
other types are retrieved.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
This commit is contained in:
Laurent Pinchart 2022-06-20 00:12:00 +03:00
parent 9dacde0d65
commit 83df785493
9 changed files with 183 additions and 31 deletions

View file

@ -7,19 +7,15 @@
#pragma once #pragma once
#include <libcamera/ipa/ipu3_ipa_interface.h>
#include <libipa/algorithm.h> #include <libipa/algorithm.h>
#include "ipa_context.h" #include "module.h"
namespace libcamera { namespace libcamera {
namespace ipa::ipu3 { namespace ipa::ipu3 {
using Algorithm = libcamera::ipa::Algorithm<IPAContext, IPAFrameContext, using Algorithm = libcamera::ipa::Algorithm<Module>;
IPAConfigInfo, ipu3_uapi_params,
ipu3_uapi_stats_3a>;
} /* namespace ipa::ipu3 */ } /* namespace ipa::ipu3 */

27
src/ipa/ipu3/module.h Normal file
View file

@ -0,0 +1,27 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2022, Ideas On Board
*
* module.h - IPU3 IPA Module
*/
#pragma once
#include <linux/intel-ipu3.h>
#include <libcamera/ipa/ipu3_ipa_interface.h>
#include <libipa/module.h>
#include "ipa_context.h"
namespace libcamera {
namespace ipa::ipu3 {
using Module = ipa::Module<IPAContext, IPAFrameContext, IPAConfigInfo,
ipu3_uapi_params, ipu3_uapi_stats_3a>;
} /* namespace ipa::ipu3 */
} /* namespace libcamera*/

View file

@ -19,14 +19,17 @@ namespace ipa {
/** /**
* \class Algorithm * \class Algorithm
* \brief The base class for all IPA algorithms * \brief The base class for all IPA algorithms
* \tparam Context The type of shared IPA context * \tparam Module The IPA module type for this class of algorithms
* \tparam Config The type of the IPA configuration data
* \tparam Params The type of the ISP specific parameters
* \tparam Stats The type of the IPA statistics and ISP results
* *
* The Algorithm class defines a standard interface for IPA algorithms. By * The Algorithm class defines a standard interface for IPA algorithms
* abstracting algorithms, it makes possible the implementation of generic code * compatible with the \a Module. By abstracting algorithms, it makes possible
* to manage algorithms regardless of their specific type. * the implementation of generic code to manage algorithms regardless of their
* specific type.
*
* To specialize the Algorithm class template, an IPA module shall specialize
* the Module class template with module-specific context and configuration
* types, and pass the specialized Module class as the \a Module template
* argument.
*/ */
/** /**

View file

@ -10,27 +10,26 @@ namespace libcamera {
namespace ipa { namespace ipa {
template<typename Context, typename FrameContext, typename Config, template<typename Module>
typename Params, typename Stats>
class Algorithm class Algorithm
{ {
public: public:
virtual ~Algorithm() {} virtual ~Algorithm() {}
virtual int configure([[maybe_unused]] Context &context, virtual int configure([[maybe_unused]] typename Module::Context &context,
[[maybe_unused]] const Config &configInfo) [[maybe_unused]] const typename Module::Config &configInfo)
{ {
return 0; return 0;
} }
virtual void prepare([[maybe_unused]] Context &context, virtual void prepare([[maybe_unused]] typename Module::Context &context,
[[maybe_unused]] Params *params) [[maybe_unused]] typename Module::Params *params)
{ {
} }
virtual void process([[maybe_unused]] Context &context, virtual void process([[maybe_unused]] typename Module::Context &context,
[[maybe_unused]] FrameContext *frameContext, [[maybe_unused]] typename Module::FrameContext *frameContext,
[[maybe_unused]] const Stats *stats) [[maybe_unused]] const typename Module::Stats *stats)
{ {
} }
}; };

View file

@ -3,13 +3,16 @@
libipa_headers = files([ libipa_headers = files([
'algorithm.h', 'algorithm.h',
'camera_sensor_helper.h', 'camera_sensor_helper.h',
'histogram.h' 'histogram.h',
'module.h',
]) ])
libipa_sources = files([ libipa_sources = files([
'algorithm.cpp',
'camera_sensor_helper.cpp', 'camera_sensor_helper.cpp',
'histogram.cpp', 'histogram.cpp',
'libipa.cpp', 'libipa.cpp',
'module.cpp',
]) ])
libipa_includes = include_directories('..') libipa_includes = include_directories('..')

73
src/ipa/libipa/module.cpp Normal file
View file

@ -0,0 +1,73 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2022, Ideas On Board
*
* module.cpp - IPA Module
*/
#include "module.h"
/**
* \file module.h
* \brief IPA Module common interface
*/
namespace libcamera {
namespace ipa {
/**
* \class Module
* \brief The base class for all IPA modules
* \tparam Context The type of the shared IPA context
* \tparam FrameContext The type of the frame context
* \tparam Config The type of the IPA configuration data
* \tparam Params The type of the ISP specific parameters
* \tparam Stats The type of the IPA statistics and ISP results
*
* The Module class template defines a standard internal interface between IPA
* modules and libipa.
*
* While IPA modules are platform-specific, many of their internal functions are
* conceptually similar, even if they take different types of platform-specifc
* parameters. For instance, IPA modules could share code that instantiates,
* initializes and run algorithms if it wasn't for the fact that the the format
* of ISP parameters or statistics passed to the related functions is
* device-dependent.
*
* To enable a shared implementation of those common tasks in libipa, the Module
* class template defines a standard internal interface between IPA modules and
* libipa. The template parameters specify the types of module-dependent data.
* IPA modules shall create a specialization of the Module class template in
* their namespace, and use it to specialize other classes of libipa, such as
* the Algorithm class.
*/
/**
* \typedef Module::Context
* \brief The type of the shared IPA context
*/
/**
* \typedef Module::FrameContext
* \brief The type of the frame context
*/
/**
* \typedef Module::Config
* \brief The type of the IPA configuration data
*/
/**
* \typedef Module::Params
* \brief The type of the ISP specific parameters
*/
/**
* \typedef Module::Stats
* \brief The type of the IPA statistics and ISP results
*/
} /* namespace ipa */
} /* namespace libcamera */

30
src/ipa/libipa/module.h Normal file
View file

@ -0,0 +1,30 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2022, Ideas On Board
*
* module.h - IPA module
*/
#pragma once
namespace libcamera {
namespace ipa {
template<typename _Context, typename _FrameContext, typename _Config,
typename _Params, typename _Stats>
class Module
{
public:
using Context = _Context;
using FrameContext = _FrameContext;
using Config = _Config;
using Params = _Params;
using Stats = _Stats;
virtual ~Module() {}
};
} /* namespace ipa */
} /* namespace libcamera */

View file

@ -7,21 +7,15 @@
#pragma once #pragma once
#include <linux/rkisp1-config.h>
#include <libcamera/ipa/rkisp1_ipa_interface.h>
#include <libipa/algorithm.h> #include <libipa/algorithm.h>
#include "ipa_context.h" #include "module.h"
namespace libcamera { namespace libcamera {
namespace ipa::rkisp1 { namespace ipa::rkisp1 {
using Algorithm = libcamera::ipa::Algorithm<IPAContext, IPAFrameContext, using Algorithm = libcamera::ipa::Algorithm<Module>;
IPACameraSensorInfo, rkisp1_params_cfg,
rkisp1_stat_buffer>;
} /* namespace ipa::rkisp1 */ } /* namespace ipa::rkisp1 */

27
src/ipa/rkisp1/module.h Normal file
View file

@ -0,0 +1,27 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2022, Ideas On Board
*
* module.h - RkISP1 IPA Module
*/
#pragma once
#include <linux/rkisp1-config.h>
#include <libcamera/ipa/rkisp1_ipa_interface.h>
#include <libipa/module.h>
#include "ipa_context.h"
namespace libcamera {
namespace ipa::rkisp1 {
using Module = ipa::Module<IPAContext, IPAFrameContext, IPACameraSensorInfo,
rkisp1_params_cfg, rkisp1_stat_buffer>;
} /* namespace ipa::rkisp1 */
} /* namespace libcamera*/