From patchwork Mon Jun 20 01:42:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16271 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 82CE4BE173 for ; Mon, 20 Jun 2022 01:43:29 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 906CC65643; Mon, 20 Jun 2022 03:43:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655689408; bh=Vd+XJWO6S5AqcMr1huCj18B9BE1RIuOG/mFoRE3RFXE=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=jrN4UROenJrMc8Yk1Kp7AEXmAC7mmnXZidF44yQ8BHUgdPav7PzoZxY6l7GoQV4zP B2EZHsq5k2N81q/l/Uv+sEUkn4pIOT1gjzndiAKTyJ2tT1NWdw6idUfpCIkV/EZSOB BNXqSZu9BccJUwMu363S+zhMoia1ndoKG+BA13VWN+v5WrKM9l94jCVBzukw8oGzVr TKukD3DyRIfQRkHNxh20yohSybMxNRZ0y6HKo9CReQswDLTXd7jgsfcyYdPk9mYn9G 2KH7h/qUfLkY4JPINyh8f2Sl1VkWAhBX/gKLswXafQ6jPeaW/MzfTU8IQgXAgL9LY3 iUaMYcHV7OhWQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 771ED601F1 for ; Mon, 20 Jun 2022 03:43:25 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="CTh1xJc3"; dkim-atps=neutral Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D31D4883; Mon, 20 Jun 2022 03:43:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1655689405; bh=Vd+XJWO6S5AqcMr1huCj18B9BE1RIuOG/mFoRE3RFXE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CTh1xJc3MlmTiuRP6JyJk/KZW/YgDx5mxCdfryUfDa4CCbKyAKV+5Zc3/BqRWhjC2 set2OfjXS6GUyOzFvUyUckNsh4TvzRmf6Faqx6FL2fCnN5Ahn2acqCsW4uFsn5VSqW KxKX3enzYTrpIRCh/80WUjdd4LnM4vLaINYfvfRo= To: libcamera-devel@lists.libcamera.org Date: Mon, 20 Jun 2022 04:42:54 +0300 Message-Id: <20220620014305.26778-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220620014305.26778-1-laurent.pinchart@ideasonboard.com> References: <20220620014305.26778-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 01/12] ipa: libipa: Introduce a Module class template X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" 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 Reviewed-by: Paul Elder --- src/ipa/ipu3/algorithms/algorithm.h | 8 +-- src/ipa/ipu3/module.h | 27 ++++++++++ src/ipa/libipa/algorithm.cpp | 17 ++++--- src/ipa/libipa/algorithm.h | 17 +++---- src/ipa/libipa/meson.build | 5 +- src/ipa/libipa/module.cpp | 73 +++++++++++++++++++++++++++ src/ipa/libipa/module.h | 30 +++++++++++ src/ipa/rkisp1/algorithms/algorithm.h | 10 +--- src/ipa/rkisp1/module.h | 27 ++++++++++ 9 files changed, 183 insertions(+), 31 deletions(-) create mode 100644 src/ipa/ipu3/module.h create mode 100644 src/ipa/libipa/module.cpp create mode 100644 src/ipa/libipa/module.h create mode 100644 src/ipa/rkisp1/module.h diff --git a/src/ipa/ipu3/algorithms/algorithm.h b/src/ipa/ipu3/algorithms/algorithm.h index 234b2bd77f72..ae134a9404fe 100644 --- a/src/ipa/ipu3/algorithms/algorithm.h +++ b/src/ipa/ipu3/algorithms/algorithm.h @@ -7,19 +7,15 @@ #pragma once -#include - #include -#include "ipa_context.h" +#include "module.h" namespace libcamera { namespace ipa::ipu3 { -using Algorithm = libcamera::ipa::Algorithm; +using Algorithm = libcamera::ipa::Algorithm; } /* namespace ipa::ipu3 */ diff --git a/src/ipa/ipu3/module.h b/src/ipa/ipu3/module.h new file mode 100644 index 000000000000..d94fc4594871 --- /dev/null +++ b/src/ipa/ipu3/module.h @@ -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 + +#include + +#include + +#include "ipa_context.h" + +namespace libcamera { + +namespace ipa::ipu3 { + +using Module = ipa::Module; + +} /* namespace ipa::ipu3 */ + +} /* namespace libcamera*/ diff --git a/src/ipa/libipa/algorithm.cpp b/src/ipa/libipa/algorithm.cpp index cce2ed62986d..2df91e5d8fed 100644 --- a/src/ipa/libipa/algorithm.cpp +++ b/src/ipa/libipa/algorithm.cpp @@ -19,14 +19,17 @@ namespace ipa { /** * \class Algorithm * \brief The base class for all IPA algorithms - * \tparam Context The type of shared IPA 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 + * \tparam Module The IPA module type for this class of algorithms * - * The Algorithm class defines a standard interface for IPA algorithms. By - * abstracting algorithms, it makes possible the implementation of generic code - * to manage algorithms regardless of their specific type. + * The Algorithm class defines a standard interface for IPA algorithms + * compatible with the \a Module. By abstracting algorithms, it makes possible + * 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. */ /** diff --git a/src/ipa/libipa/algorithm.h b/src/ipa/libipa/algorithm.h index 032a05b56635..fd2ffcfbc900 100644 --- a/src/ipa/libipa/algorithm.h +++ b/src/ipa/libipa/algorithm.h @@ -10,27 +10,26 @@ namespace libcamera { namespace ipa { -template +template class Algorithm { public: virtual ~Algorithm() {} - virtual int configure([[maybe_unused]] Context &context, - [[maybe_unused]] const Config &configInfo) + virtual int configure([[maybe_unused]] typename Module::Context &context, + [[maybe_unused]] const typename Module::Config &configInfo) { return 0; } - virtual void prepare([[maybe_unused]] Context &context, - [[maybe_unused]] Params *params) + virtual void prepare([[maybe_unused]] typename Module::Context &context, + [[maybe_unused]] typename Module::Params *params) { } - virtual void process([[maybe_unused]] Context &context, - [[maybe_unused]] FrameContext *frameContext, - [[maybe_unused]] const Stats *stats) + virtual void process([[maybe_unused]] typename Module::Context &context, + [[maybe_unused]] typename Module::FrameContext *frameContext, + [[maybe_unused]] const typename Module::Stats *stats) { } }; diff --git a/src/ipa/libipa/meson.build b/src/ipa/libipa/meson.build index 161cc5a1f0d0..465cf7d6c4a7 100644 --- a/src/ipa/libipa/meson.build +++ b/src/ipa/libipa/meson.build @@ -3,13 +3,16 @@ libipa_headers = files([ 'algorithm.h', 'camera_sensor_helper.h', - 'histogram.h' + 'histogram.h', + 'module.h', ]) libipa_sources = files([ + 'algorithm.cpp', 'camera_sensor_helper.cpp', 'histogram.cpp', 'libipa.cpp', + 'module.cpp', ]) libipa_includes = include_directories('..') diff --git a/src/ipa/libipa/module.cpp b/src/ipa/libipa/module.cpp new file mode 100644 index 000000000000..5a6f49a80e6d --- /dev/null +++ b/src/ipa/libipa/module.cpp @@ -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 */ diff --git a/src/ipa/libipa/module.h b/src/ipa/libipa/module.h new file mode 100644 index 000000000000..c4d778120408 --- /dev/null +++ b/src/ipa/libipa/module.h @@ -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 +class Module +{ +public: + using Context = _Context; + using FrameContext = _FrameContext; + using Config = _Config; + using Params = _Params; + using Stats = _Stats; + + virtual ~Module() {} +}; + +} /* namespace ipa */ + +} /* namespace libcamera */ diff --git a/src/ipa/rkisp1/algorithms/algorithm.h b/src/ipa/rkisp1/algorithms/algorithm.h index 68e3a44e19b4..c3212cff76fe 100644 --- a/src/ipa/rkisp1/algorithms/algorithm.h +++ b/src/ipa/rkisp1/algorithms/algorithm.h @@ -7,21 +7,15 @@ #pragma once -#include - -#include - #include -#include "ipa_context.h" +#include "module.h" namespace libcamera { namespace ipa::rkisp1 { -using Algorithm = libcamera::ipa::Algorithm; +using Algorithm = libcamera::ipa::Algorithm; } /* namespace ipa::rkisp1 */ diff --git a/src/ipa/rkisp1/module.h b/src/ipa/rkisp1/module.h new file mode 100644 index 000000000000..89f83208a75c --- /dev/null +++ b/src/ipa/rkisp1/module.h @@ -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 + +#include + +#include + +#include "ipa_context.h" + +namespace libcamera { + +namespace ipa::rkisp1 { + +using Module = ipa::Module; + +} /* namespace ipa::rkisp1 */ + +} /* namespace libcamera*/