From patchwork Tue Aug 9 14:46:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 17046 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 49261C3275 for ; Tue, 9 Aug 2022 14:46:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0726E63328; Tue, 9 Aug 2022 16:46:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1660056396; bh=5tLNzpV1RqRYJ0NUMR8N1xeVEQv0hHXKB2bxVhlVEoo=; 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=RjdJaX3K5F83/QpvPDRE9PP1Fp3RKI2w19lng8c9PfTpD9zCEPmwcurtMxKap3nKg 8WU+MW9PtJyvaYB04xvW0MXXOW8abz0W1IkRYmUq1/yTPGUxFRgEHwRO5Dg8PMivJs A5JMUf5O/budkdQm3rRNKHQKa/7crHTD+pkiEh5Hm7mODmwhShskMoJMP4m86Pr9w9 eQU7Rw1ARIYyy1Yck0NOY/EJdzvpieUk3sOuPBJPCYZRBq6D/yySyk7JDb1/uXbIch OZ4xOUmt04ebOV1Oru0mEu9dyDX8Zg42ZxZySTu0awHWbsGlvt5L9LVixdNohbPVlS 8xRHBESOOx30w== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 921CA63328 for ; Tue, 9 Aug 2022 16:46:34 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="idyZ9tMU"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 2B822481 for ; Tue, 9 Aug 2022 16:46:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1660056394; bh=5tLNzpV1RqRYJ0NUMR8N1xeVEQv0hHXKB2bxVhlVEoo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=idyZ9tMUdEbv6xHDTbsFvmeFbVYw+5pMPpB4UrouycjS3rhto+eoG/78IXDBHjrZv uxwoWpsQtD6BMNt6pRm0DliKkppbZXdvX8xLAGP5CWdYNSrhHLp+KPU+S5VjlOOAOf f3CtQ/dKAMzp5/i7owPtITa9h9Oh/ZCoiHze+aa8= To: libcamera-devel@lists.libcamera.org Date: Tue, 9 Aug 2022 17:46:17 +0300 Message-Id: <20220809144617.27983-5-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220809144617.27983-1-laurent.pinchart@ideasonboard.com> References: <20220809144617.27983-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 4/4] ipa: ipu3: Add YAML tuning file support 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" Replace the manual instantiation of algorithms with an automatic mechanism based on a tuning data file, provided by the Module base class. This brings the IPU3 IPA module in line with the RkISP1 IPA module. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/ipa/ipu3/ipu3.cpp | 70 ++++++++++++++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 18 deletions(-) diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp index 2f6bb672f7bb..e37b2fa0f30e 100644 --- a/src/ipa/ipu3/ipu3.cpp +++ b/src/ipa/ipu3/ipu3.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -29,6 +30,7 @@ #include #include "libcamera/internal/mapped_framebuffer.h" +#include "libcamera/internal/yaml_parser.h" #include "algorithms/af.h" #include "algorithms/agc.h" @@ -71,7 +73,7 @@ namespace ipa::ipu3 { * * At initialisation time, a CameraSensorHelper is instantiated to support * camera-specific calculations, while the default controls are computed, and - * the algorithms are constructed and placed in an ordered list. + * the algorithms are instantiated from the tuning data file. * * The IPU3 ImgU operates with a grid layout to divide the overall frame into * rectangular cells of pixels. When the IPA is configured, we determine the @@ -92,12 +94,14 @@ namespace ipa::ipu3 { * fillParamsBuffer() call. * * The individual algorithms are split into modular components that are called - * iteratively to allow them to process statistics from the ImgU in a defined - * order. + * iteratively to allow them to process statistics from the ImgU in the order + * defined in the tuning data file. * - * The current implementation supports three core algorithms: - * - Automatic white balance (AWB) + * The current implementation supports five core algorithms: + * + * - Auto focus (AF) * - Automatic gain and exposure control (AGC) + * - Automatic white balance (AWB) * - Black level correction (BLC) * - Tone mapping (Gamma) * @@ -128,7 +132,7 @@ namespace ipa::ipu3 { * sensor-specific tuning to adapt for Black Level compensation (BLC), Lens * shading correction (SHD) and Color correction (CCM). */ -class IPAIPU3 : public IPAIPU3Interface +class IPAIPU3 : public IPAIPU3Interface, public Module { public: int init(const IPASettings &settings, @@ -150,6 +154,10 @@ public: void processStatsBuffer(const uint32_t frame, const int64_t frameTimestamp, const uint32_t bufferId, const ControlList &sensorControls) override; + +protected: + std::string logPrefix() const override; + private: void updateControls(const IPACameraSensorInfo &sensorInfo, const ControlInfoMap &sensorControls, @@ -171,13 +179,15 @@ private: /* Interface to the Camera Helper */ std::unique_ptr camHelper_; - /* Maintain the algorithms used by the IPA */ - std::list> algorithms_; - /* Local parameter storage */ struct IPAContext context_; }; +std::string IPAIPU3::logPrefix() const +{ + return "ipu3"; +} + /** * \brief Compute IPASessionConfiguration using the sensor information and the * sensor V4L2 controls @@ -316,12 +326,36 @@ int IPAIPU3::init(const IPASettings &settings, context_.configuration = {}; context_.configuration.sensor.lineDuration = sensorInfo.lineLength * 1.0s / sensorInfo.pixelRate; - /* Construct our Algorithms */ - algorithms_.push_back(std::make_unique()); - algorithms_.push_back(std::make_unique()); - algorithms_.push_back(std::make_unique()); - algorithms_.push_back(std::make_unique()); - algorithms_.push_back(std::make_unique()); + /* Load the tuning data file. */ + File file(settings.configurationFile.c_str()); + if (!file.open(File::OpenModeFlag::ReadOnly)) { + int ret = file.error(); + LOG(IPAIPU3, Error) + << "Failed to open configuration file " + << settings.configurationFile << ": " << strerror(-ret); + return ret; + } + + std::unique_ptr data = YamlParser::parse(file); + if (!data) + return -EINVAL; + + unsigned int version = (*data)["version"].get(0); + if (version != 1) { + LOG(IPAIPU3, Error) + << "Invalid tuning file version " << version; + return -EINVAL; + } + + if (!data->contains("algorithms")) { + LOG(IPAIPU3, Error) + << "Tuning file doesn't contain any algorithm"; + return -EINVAL; + } + + int ret = createAlgorithms(context_, (*data)["algorithms"]); + if (ret) + return ret; /* Initialize controls. */ updateControls(sensorInfo, sensorControls, ipaControls); @@ -470,7 +504,7 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo, /* Update the IPASessionConfiguration using the sensor settings. */ updateSessionConfiguration(sensorCtrls_); - for (auto const &algo : algorithms_) { + for (auto const &algo : algorithms()) { int ret = algo->configure(context_, configInfo); if (ret) return ret; @@ -538,7 +572,7 @@ void IPAIPU3::fillParamsBuffer(const uint32_t frame, const uint32_t bufferId) */ params->use = {}; - for (auto const &algo : algorithms_) + for (auto const &algo : algorithms()) algo->prepare(context_, params); paramsBufferReady.emit(frame); @@ -581,7 +615,7 @@ void IPAIPU3::processStatsBuffer(const uint32_t frame, int32_t vBlank = context_.configuration.sensor.defVBlank; ControlList ctrls(controls::controls); - for (auto const &algo : algorithms_) + for (auto const &algo : algorithms()) algo->process(context_, &frameContext, stats); setControls(frame);