From patchwork Mon Aug 9 09:20:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Michel Hautbois X-Patchwork-Id: 13253 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 81230BD87D for ; Mon, 9 Aug 2021 09:20:20 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3FE1E68864; Mon, 9 Aug 2021 11:20:20 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="CaWiKM0b"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3770A68826 for ; Mon, 9 Aug 2021 11:20:16 +0200 (CEST) Received: from tatooine.ideasonboard.com (unknown [IPv6:2a01:e0a:169:7140:14c5:c0eb:b1fb:db22]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D74B94A1; Mon, 9 Aug 2021 11:20:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1628500815; bh=A3Lt+YMe0FeKiiDBhL7+1hPAh1k7tHbw8GSzNrytY5c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CaWiKM0bC+JMvISK4KZZJEVIylBsVLmltRO0ZDWs/V4SKuS4moBPEeWqoPnSR2V1i qVqz8SMJkJCmk32Ls5kvRAlctJiIxW1yE+uVDPJSP/r+bt42cyMzD0D8angMhv9aNz E9ko74O96oe3VIgv/uEF2A7cpE4wD60MHf0C2PcY= From: Jean-Michel Hautbois To: libcamera-devel@lists.libcamera.org Date: Mon, 9 Aug 2021 11:20:04 +0200 Message-Id: <20210809092007.79067-3-jeanmichel.hautbois@ideasonboard.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210809092007.79067-1-jeanmichel.hautbois@ideasonboard.com> References: <20210809092007.79067-1-jeanmichel.hautbois@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 2/5] ipa: ipu3: Introduce modular algorithms 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Provide a modular IPU3 specific algorithm, and frame context structure so that algorithms can be built for the IPU3 in a component based structure. Signed-off-by: Kieran Bingham Signed-off-by: Jean-Michel Hautbois --- src/ipa/ipu3/algorithms/algorithm.h | 30 ++++++++++++++++++ src/ipa/ipu3/algorithms/meson.build | 4 +++ src/ipa/ipu3/ipu3.cpp | 47 +++++++++++++++++++++++++++++ src/ipa/ipu3/ipu3_agc.h | 3 +- src/ipa/ipu3/ipu3_awb.h | 3 +- src/ipa/ipu3/meson.build | 4 +++ 6 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 src/ipa/ipu3/algorithms/algorithm.h create mode 100644 src/ipa/ipu3/algorithms/meson.build diff --git a/src/ipa/ipu3/algorithms/algorithm.h b/src/ipa/ipu3/algorithms/algorithm.h new file mode 100644 index 00000000..bac82b7c --- /dev/null +++ b/src/ipa/ipu3/algorithms/algorithm.h @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021, Ideas On Board + * + * algorithm.h - IPU3 control algorithm interface + */ +#ifndef __LIBCAMERA_IPA_IPU3_ALGORITHM_H__ +#define __LIBCAMERA_IPA_IPU3_ALGORITHM_H__ + +#include + +namespace libcamera { + +namespace ipa::ipu3 { + +class Algorithm +{ +public: + virtual ~Algorithm() {} + + virtual int initialise([[maybe_unused]] IPAContext &context) { return 0; } + virtual int configure([[maybe_unused]] IPAContext &context) { return 0; } + virtual void process([[maybe_unused]] IPAContext &context) {} +}; + +} /* namespace ipa::ipu3 */ + +} /* namespace libcamera */ + +#endif /* __LIBCAMERA_IPA_IPU3_ALGORITHM_H__ */ diff --git a/src/ipa/ipu3/algorithms/meson.build b/src/ipa/ipu3/algorithms/meson.build new file mode 100644 index 00000000..67148333 --- /dev/null +++ b/src/ipa/ipu3/algorithms/meson.build @@ -0,0 +1,4 @@ +# SPDX-License-Identifier: CC0-1.0 + +ipu3_ipa_algorithms = files([ +]) diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp index a714af85..55c4da72 100644 --- a/src/ipa/ipu3/ipu3.cpp +++ b/src/ipa/ipu3/ipu3.cpp @@ -22,6 +22,7 @@ #include "libcamera/internal/framebuffer.h" +#include "algorithms/algorithm.h" #include "ipa_context.h" #include "ipu3_agc.h" @@ -53,6 +54,10 @@ public: private: void processControls(unsigned int frame, const ControlList &controls); void fillParams(unsigned int frame, ipu3_uapi_params *params); + + int initialiseAlgorithms(); + int configureAlgorithms(); + void processAlgorithms(const ipu3_uapi_stats_3a *stats); void parseStatistics(unsigned int frame, int64_t frameTimestamp, const ipu3_uapi_stats_3a *stats); @@ -82,6 +87,9 @@ private: /* Interface to the Camera Helper */ std::unique_ptr camHelper_; + /* Maintain the algorithms used by the IPA */ + std::list> algorithms_; + /* Local parameter storage */ struct ipu3_uapi_grid_config bdsGrid_; struct IPAContext context_; @@ -98,6 +106,8 @@ int IPAIPU3::init(const IPASettings &settings) /* Reset all the hardware settings */ context_.params = {}; + initialiseAlgorithms(); + return 0; } @@ -199,6 +209,8 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo) calculateBdsGrid(configInfo.bdsOutputSize); + configureAlgorithms(); + awbAlgo_ = std::make_unique(); awbAlgo_->initialise(context_.params, configInfo.bdsOutputSize, bdsGrid_); @@ -288,12 +300,47 @@ void IPAIPU3::fillParams(unsigned int frame, ipu3_uapi_params *params) queueFrameAction.emit(frame, op); } +int IPAIPU3::initialiseAlgorithms() +{ + for (auto const &algo : algorithms_) { + int ret = algo->initialise(context_); + if (ret) + return ret; + } + + return 0; +} + +int IPAIPU3::configureAlgorithms() +{ + for (auto const &algo : algorithms_) { + int ret = algo->configure(context_); + if (ret) + return ret; + } + + return 0; +} + +void IPAIPU3::processAlgorithms(const ipu3_uapi_stats_3a *stats) +{ + /* It might be better to pass the stats in as a parameter to process() ? */ + context_.stats = stats; + + for (auto const &algo : algorithms_) { + algo->process(context_); + } +} + void IPAIPU3::parseStatistics(unsigned int frame, [[maybe_unused]] int64_t frameTimestamp, [[maybe_unused]] const ipu3_uapi_stats_3a *stats) { ControlList ctrls(controls::controls); + /* Run the process for each algorithm on the stats */ + processAlgorithms(stats); + double gain = camHelper_->gain(gain_); agcAlgo_->process(stats, exposure_, gain); gain_ = camHelper_->gainCode(gain); diff --git a/src/ipa/ipu3/ipu3_agc.h b/src/ipa/ipu3/ipu3_agc.h index 3deca3ae..e3e1d28b 100644 --- a/src/ipa/ipu3/ipu3_agc.h +++ b/src/ipa/ipu3/ipu3_agc.h @@ -16,6 +16,7 @@ #include +#include "algorithms/algorithm.h" #include "libipa/algorithm.h" namespace libcamera { @@ -26,7 +27,7 @@ namespace ipa::ipu3 { using utils::Duration; -class IPU3Agc : public Algorithm +class IPU3Agc : public ipa::Algorithm { public: IPU3Agc(); diff --git a/src/ipa/ipu3/ipu3_awb.h b/src/ipa/ipu3/ipu3_awb.h index 122cf68c..284e3844 100644 --- a/src/ipa/ipu3/ipu3_awb.h +++ b/src/ipa/ipu3/ipu3_awb.h @@ -13,6 +13,7 @@ #include +#include "algorithms/algorithm.h" #include "libipa/algorithm.h" namespace libcamera { @@ -23,7 +24,7 @@ namespace ipa::ipu3 { static constexpr uint32_t kAwbStatsSizeX = 16; static constexpr uint32_t kAwbStatsSizeY = 12; -class IPU3Awb : public Algorithm +class IPU3Awb : public ipa::Algorithm { public: IPU3Awb(); diff --git a/src/ipa/ipu3/meson.build b/src/ipa/ipu3/meson.build index b6364190..fcb27d68 100644 --- a/src/ipa/ipu3/meson.build +++ b/src/ipa/ipu3/meson.build @@ -1,5 +1,7 @@ # SPDX-License-Identifier: CC0-1.0 +subdir('algorithms') + ipa_name = 'ipa_ipu3' ipu3_ipa_sources = files([ @@ -8,6 +10,8 @@ ipu3_ipa_sources = files([ 'ipu3_awb.cpp', ]) +ipu3_ipa_sources += ipu3_ipa_algorithms + mod = shared_module(ipa_name, [ipu3_ipa_sources, libcamera_generated_ipa_headers], name_prefix : '',