From patchwork Mon Jun 20 01:43:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16280 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 B7239BE173 for ; Mon, 20 Jun 2022 01:43:39 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 68E3665649; Mon, 20 Jun 2022 03:43:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655689419; bh=cxWIUnrRlxP3K/1kfvgY5SFRsC7hk7Y0HgKsXMiv6hc=; 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=VgDWoH2hIUhC35KbxYQh3Wm04Gge88UE6VCbgJBgCawziCUWV14ZQdnc20ux7dEIZ BBAqNje8LN3bnZ32eG14LWxvgIwswjrIG4WEHAIkjmP6PmZnVIQYrLLTy3NhNrYRMe aBH0yE6L74W5YFeu7djfJtepjxmmvznxQ6s1c7WJouJk2so5Nfi4JH8ooFAzFOUwvj DJJ9v6M0Oqthd+GR07YQCuE66nh5Vs/k8FVueQehBAd1TzZrr1Ezh2pQZLiBhu61JD lPirOaihmKPb1dbxxudiGDrLPfeItnGROOT+q2EDMyLtTqiN7wWUF8CrLHSWHjU0aS oMVWbK0vyN2xg== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3912665647 for ; Mon, 20 Jun 2022 03:43:29 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="JJyQ/eb4"; 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 B9087929; Mon, 20 Jun 2022 03:43:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1655689409; bh=cxWIUnrRlxP3K/1kfvgY5SFRsC7hk7Y0HgKsXMiv6hc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JJyQ/eb4+Hx3EkkTer2ctvVuYn2kaKFj95G3p4iBe490C+2Yjf2ELSN52/DK2Kl7I rcZBDRCfTJuBMZA2rqwhb0lGCxadx/pNpG9/kxld6gKAtBnbd6PxLkiMyUfXjZ7btA eJg0yoo7cu6DLzldUNmND4SxrrckBaCh3AlPo+5c= To: libcamera-devel@lists.libcamera.org Date: Mon, 20 Jun 2022 04:43:02 +0300 Message-Id: <20220620014305.26778-10-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 09/12] ipa: rkisp1: 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" From: Florian Sylvestre Retrieve root node in YAML tuning file and provide to each algorithm this YamlObject to allow them to grab their default parameters by calling init() function. Signed-off-by: Florian Sylvestre Reviewed-by: Laurent Pinchart Reviewed-by: Paul Elder Signed-off-by: Laurent Pinchart --- Changes since v3: - Instantiate algorithms dynamically from tuning file --- src/ipa/rkisp1/rkisp1.cpp | 54 ++++++++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp index 61a3bab90ccf..d052954e75b5 100644 --- a/src/ipa/rkisp1/rkisp1.cpp +++ b/src/ipa/rkisp1/rkisp1.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #include @@ -24,6 +25,7 @@ #include #include "libcamera/internal/mapped_framebuffer.h" +#include "libcamera/internal/yaml_parser.h" #include "algorithms/agc.h" #include "algorithms/algorithm.h" @@ -41,7 +43,7 @@ using namespace std::literals::chrono_literals; namespace ipa::rkisp1 { -class IPARkISP1 : public IPARkISP1Interface +class IPARkISP1 : public IPARkISP1Interface, public Module { public: int init(const IPASettings &settings, unsigned int hwRevision) override; @@ -58,6 +60,10 @@ public: void fillParamsBuffer(const uint32_t frame, const uint32_t bufferId) override; void processStatsBuffer(const uint32_t frame, const uint32_t bufferId, const ControlList &sensorControls) override; + +protected: + std::string logPrefix() const override; + private: void setControls(unsigned int frame); void prepareMetadata(unsigned int frame, unsigned int aeState); @@ -81,11 +87,13 @@ private: /* Local parameter storage */ struct IPAContext context_; - - /* Maintain the algorithms used by the IPA */ - std::list> algorithms_; }; +std::string IPARkISP1::logPrefix() const +{ + return "rkisp1"; +} + int IPARkISP1::init(const IPASettings &settings, unsigned int hwRevision) { /* \todo Add support for other revisions */ @@ -121,12 +129,34 @@ int IPARkISP1::init(const IPASettings &settings, unsigned int hwRevision) return -ENODEV; } - /* Construct our Algorithms */ - 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(IPARkISP1, Error) + << "Failed to open configuration file " + << settings.configurationFile << ": " << strerror(-ret); + return ret; + } - return 0; + std::unique_ptr data = YamlParser::parse(file); + if (!data) + return -EINVAL; + + unsigned int version = (*data)["version"].get(0); + if (version != 1) { + LOG(IPARkISP1, Error) + << "Invalid tuning file version " << version; + return -EINVAL; + } + + if (!data->contains("algorithms")) { + LOG(IPARkISP1, Error) + << "Tuning file doesn't contain any algorithm"; + return -EINVAL; + } + + return createAlgorithms(context_, (*data)["algorithms"]); } int IPARkISP1::start() @@ -197,7 +227,7 @@ int IPARkISP1::configure([[maybe_unused]] const IPACameraSensorInfo &info, context_.frameContext.frameCount = 0; - for (auto const &algo : algorithms_) { + for (auto const &algo : algorithms()) { int ret = algo->configure(context_, info); if (ret) return ret; @@ -251,7 +281,7 @@ void IPARkISP1::fillParamsBuffer(const uint32_t frame, const uint32_t bufferId) /* Prepare parameters buffer. */ memset(params, 0, sizeof(*params)); - for (auto const &algo : algorithms_) + for (auto const &algo : algorithms()) algo->prepare(context_, params); paramsBufferReady.emit(frame); @@ -272,7 +302,7 @@ void IPARkISP1::processStatsBuffer(const uint32_t frame, const uint32_t bufferId unsigned int aeState = 0; - for (auto const &algo : algorithms_) + for (auto const &algo : algorithms()) algo->process(context_, nullptr, stats); setControls(frame);