From patchwork Wed Jul 27 02:38:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16821 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 A1740BE173 for ; Wed, 27 Jul 2022 02:38:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4679863332; Wed, 27 Jul 2022 04:38:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1658889513; bh=exBJxnmOkPEWyGAfhnAEwP7yPxQEFUXRoFHvScU0fVU=; 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=3hiY3+nEhKH7xUPxHuC10cXShcolw3NHRXD9TOjqiBUGiqdu/gpbEDDY/lucw55B8 C6iHBsCpTH7zNyD0W1ky3MoEJ92ecUfsUj6/LfXPklTeal1zjLxT3TP9Dr3188wcID E52uYiP5lWLFrnv8njd63bVLnI14cCVDelwakAONWRiV4IUm8bYQJLZb9YtM4YXSPK M9Uo7DVO3p8uj0XtUO7JrFmYbnVxT+AmvOZJyTeKjfz6W6/Ju9L8P68w/nJfpyCgEv 2b9NVIxtAuPLCXEDyPqNN79eU+kskCfCFYIA55jfSdniK5jV5U2KqChDdFWgcjyCfr uOs3duNzpIs6w== 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 AD7DE6332A for ; Wed, 27 Jul 2022 04:38:28 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="oCX05xwg"; 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 4906556D; Wed, 27 Jul 2022 04:38:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1658889508; bh=exBJxnmOkPEWyGAfhnAEwP7yPxQEFUXRoFHvScU0fVU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oCX05xwgIs/cRkF0bs5eng9i6ZuLbV3PxMv2V92TwJunI5huWYODY6Q8wb9hqOcWw zebzfEEUUs1WjkUzR2BYnRAWjUucIF/6A3htv/8DhyFQfn067xVYAPWeXNTUntg/dp 09MH/+JJK7bER4ZAUpgCRLxHf9LJGrg66UHYudW4= To: libcamera-devel@lists.libcamera.org Date: Wed, 27 Jul 2022 05:38:11 +0300 Message-Id: <20220727023816.30008-10-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220727023816.30008-1-laurent.pinchart@ideasonboard.com> References: <20220727023816.30008-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v7 09/14] ipa: raspberrypi: Introduce version 2.0 format for the camera tuning file 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: Naushir Patuck The existing tuning file format (version 1.0) requires the controller algorithms to run in the same order as listed in the JSON structure. The JSON specification does not mandate any such ordering, but the Boost JSON parser would maintain this order. In order to remove this reliance on the parser to provide ordering, introduce a new version 2.0 format for the camera tuning file. In this version, the algorithms are specified in a top level list node ("algorithms"), which does require strict ordering of the elements. A "version" node is added to distinguish between the version 1.0 and 2.0 formats. The absence of the "version" node implies version 1.0. A "target" node is also added to specify the target platform for this configuration. Update the controller to support either version of the tuning file by looking at the version node. CreateAlgorithm member function to now load and configure each algorithm. Additionally, make CreateAlgorithm a private member, it does not get called externally. If a version 1.0 format tuning file is used, throw a warning message indicating it will be soon deprecated. Signed-off-by: Naushir Patuck Reviewed-by: Laurent Pinchart Signed-off-by: Laurent Pinchart --- src/ipa/raspberrypi/controller/controller.cpp | 54 +++++++++++++++---- src/ipa/raspberrypi/controller/controller.h | 5 +- 2 files changed, 47 insertions(+), 12 deletions(-) diff --git a/src/ipa/raspberrypi/controller/controller.cpp b/src/ipa/raspberrypi/controller/controller.cpp index bceb62540dbd..bbd382bce3ab 100644 --- a/src/ipa/raspberrypi/controller/controller.cpp +++ b/src/ipa/raspberrypi/controller/controller.cpp @@ -44,26 +44,58 @@ int Controller::read(char const *filename) } std::unique_ptr root = YamlParser::parse(file); + double version = (*root)["version"].get(1.0); - for (auto const &[key, value] : root->asDict()) { - Algorithm *algo = createAlgorithm(key.c_str()); - if (algo) { - int ret = algo->read(value); + if (version < 2.0) { + LOG(RPiController, Warning) + << "This format of the tuning file will be deprecated soon!" + << " Please use the convert_tuning.py utility to update to version 2.0."; + + for (auto const &[key, value] : root->asDict()) { + int ret = createAlgorithm(key, value); if (ret) return ret; - algorithms_.push_back(AlgorithmPtr(algo)); - } else - LOG(RPiController, Warning) - << "No algorithm found for \"" << key << "\""; + } + } else if (version < 3.0) { + if (!root->contains("algorithms")) { + LOG(RPiController, Error) + << "Tuning file " << filename + << " does not have an \"algorithms\" list!"; + return -EINVAL; + } + + for (auto const &rootAlgo : (*root)["algorithms"].asList()) + for (auto const &[key, value] : rootAlgo.asDict()) { + int ret = createAlgorithm(key, value); + if (ret) + return ret; + } + } else { + LOG(RPiController, Error) + << "Unrecognised version " << version + << " for the tuning file " << filename; + return -EINVAL; } return 0; } -Algorithm *Controller::createAlgorithm(char const *name) +int Controller::createAlgorithm(const std::string &name, const YamlObject ¶ms) { - auto it = getAlgorithms().find(std::string(name)); - return it != getAlgorithms().end() ? (*it->second)(this) : nullptr; + auto it = getAlgorithms().find(name); + if (it == getAlgorithms().end()) { + LOG(RPiController, Warning) + << "No algorithm found for \"" << name << "\""; + return 0; + } + + Algorithm *algo = (*it->second)(this); + int ret = algo->read(params); + if (ret) + return ret; + + algorithms_.push_back(AlgorithmPtr(algo)); + return 0; } void Controller::initialise() diff --git a/src/ipa/raspberrypi/controller/controller.h b/src/ipa/raspberrypi/controller/controller.h index 841783bb7a5c..6be1e3cfa156 100644 --- a/src/ipa/raspberrypi/controller/controller.h +++ b/src/ipa/raspberrypi/controller/controller.h @@ -17,6 +17,8 @@ #include +#include "libcamera/internal/yaml_parser.h" + #include "camera_mode.h" #include "device_status.h" #include "metadata.h" @@ -40,7 +42,6 @@ public: Controller(); Controller(char const *jsonFilename); ~Controller(); - Algorithm *createAlgorithm(char const *name); int read(char const *filename); void initialise(); void switchMode(CameraMode const &cameraMode, Metadata *metadata); @@ -50,6 +51,8 @@ public: Algorithm *getAlgorithm(std::string const &name) const; protected: + int createAlgorithm(const std::string &name, const libcamera::YamlObject ¶ms); + Metadata globalMetadata_; std::vector algorithms_; bool switchModeCalled_;