From patchwork Wed Jul 13 09:21:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 16615 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 73EF9BD1F1 for ; Wed, 13 Jul 2022 09:22:25 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1265163319; Wed, 13 Jul 2022 11:22:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1657704145; bh=YI7BM4sT/ZSFYVkbfWj4074LOQTRgQCuu4wZilU/Vws=; 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=2oazOmlKhjTmIzgvjGnG/4Mz4TZjjIj+V0qToneuiysrxBBsiLV3i1cpGESh15tpP 0Z4RzhuFSyB92op+tGDz7Zudimi0UcpbUG3Kf+cvQEkLnzNC5zSI4PD3PrQ2lP52Ys qdTiN3KaH9FF8qzBazcIscsR/ZcOsc+Xrhwkj6BAfQ3VQ2AU2CGuMkByXd6Rf9XALT nec29gqPlUAbgLYnyIVhI+ajyZIJsmEs5Wa2/1KTMPsyIN3Z/cV/Ird70KuiD+A39r dex+temIqFlLBatL5doPLp5Rk8KqO+F5HCQVDJlNfPSlsT9ZTgy5HJD68bo2GnyanU Gp6C8rK8CgL2A== Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D81C763311 for ; Wed, 13 Jul 2022 11:22:18 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="BBtNQfRP"; dkim-atps=neutral Received: by mail-wr1-x432.google.com with SMTP id q9so14612937wrd.8 for ; Wed, 13 Jul 2022 02:22:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zF0UqHd97naQVI/PN/cm7tNAF00UwIi5w7xlYtIKTk8=; b=BBtNQfRPXOcjBdS82psMt3g0mHQL8HXRYx0Q73Xuqk0P0oOkRAiAUErBCXXk5j7+P8 TPDCRb6o1fxnOG9gyyUcNQ/0zvXeAPfObtr36FD3x0K2w4uHolIO5nIClEEbPBQJoydF 2SD1CmovstXCU91VT3rXVFdqKimsgHreMqiPX3FNASkZ6jBVAF/w/WB510ctZ23seNRK XDTUSAB5WgeWvMmduSy0vwVcvYnjEYKqay+ScGX0mqxUOLlOv6X6j5KKZEqECwnKu+pb TZ/44LVLQzucY7Qpasikgrgn3sLzXmPGJJVxpBceOK2BvcZb6abBguP8jedAdcwIWjHF MgLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zF0UqHd97naQVI/PN/cm7tNAF00UwIi5w7xlYtIKTk8=; b=y/PEsfeDiUOg7J1J5nz6TZmEAPX26Ar2O439BZILHMiE6xj0OSjSGJP6sqIF0VN8HR BcpJRO/4GcNuCxdjzs01J8FtrPBHbYZMQ5HBPu+n+O7GsbepaBuNkZ+WfTwxmu0Mt8/F TZJe9ts89AQMtOhroCEGtOP1plBJDmKWYf5jYDPov+Sj1kHHlObqBLoh9XOYaVM/395E t1l7PqXs5xcK0jMrNJS94PQ/DmhbtdhU4X2EDolfNwp0L2enDmJ/sbCuzj75UN+/QHrN lkzru345E4Uh04W1GOksdWkeAlxG2vcGTU2tekVse8mDLTj2roJoS8mD8NMAN1KofmX2 dg9A== X-Gm-Message-State: AJIora8SGD7n6GjN4q6J5lCUqualVf3GBUqMjEu+UIegNfh7kURRyg9n EqCsadjBmw26FpRZuRYBzuG6rlDflznzSQ== X-Google-Smtp-Source: AGRyM1v00rdmB1R4U9gNjwKETxhK6KYveZDwmYawigIaM890g5CTyfPn7kmmICuLfBSC0qhBN21W6g== X-Received: by 2002:a5d:6b4b:0:b0:21d:7854:7755 with SMTP id x11-20020a5d6b4b000000b0021d78547755mr2251873wrw.437.1657704138303; Wed, 13 Jul 2022 02:22:18 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id bd20-20020a05600c1f1400b0039747cf8354sm1514778wmb.39.2022.07.13.02.22.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 02:22:17 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 13 Jul 2022 10:21:56 +0100 Message-Id: <20220713092159.9014-6-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220713092159.9014-1-naush@raspberrypi.com> References: <20220713092159.9014-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 5/8] 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: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The existing tuning file format (version 1.0) requires the controller algorithms to run in the same order as listied 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. Additionally, 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. 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 --- src/ipa/raspberrypi/controller/controller.cpp | 42 +++++++++++++------ src/ipa/raspberrypi/controller/controller.hpp | 4 +- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/ipa/raspberrypi/controller/controller.cpp b/src/ipa/raspberrypi/controller/controller.cpp index 67d650ef0c1b..9a2a3fb01793 100644 --- a/src/ipa/raspberrypi/controller/controller.cpp +++ b/src/ipa/raspberrypi/controller/controller.cpp @@ -42,22 +42,40 @@ void Controller::Read(char const *filename) } std::unique_ptr root = YamlParser::parse(file); - - for (auto const &[key, value] : root->asDict()) { - Algorithm *algo = CreateAlgorithm(key.c_str()); - if (algo) { - algo->Read(value); - algorithms_.push_back(AlgorithmPtr(algo)); - } else - LOG(RPiController, Warning) - << "No algorithm found for \"" << key << "\""; + double version = (*root)["version"].get(1.0); + 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()) { + if (!key.compare("version")) + continue; + CreateAlgorithm(key, value); + } + } else { + if (!root->contains("algorithms")) { + LOG(RPiController, Fatal) + << "Tuning file " << filename + << " does not have an \"algorithms\" list!"; + return; + } + for (auto const &rootAlgo : (*root)["algorithms"].asList()) + for (auto const &[key, value] : rootAlgo.asDict()) + CreateAlgorithm(key, value); } } -Algorithm *Controller::CreateAlgorithm(char const *name) +void 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; + } + Algorithm *algo = (*it->second)(this); + algo->Read(params); + algorithms_.push_back(AlgorithmPtr(algo)); } void Controller::Initialise() diff --git a/src/ipa/raspberrypi/controller/controller.hpp b/src/ipa/raspberrypi/controller/controller.hpp index 3b50ae770d11..9091deac5feb 100644 --- a/src/ipa/raspberrypi/controller/controller.hpp +++ b/src/ipa/raspberrypi/controller/controller.hpp @@ -15,6 +15,8 @@ #include +#include "libcamera/internal/yaml_parser.h" + #include "camera_mode.h" #include "device_status.h" #include "metadata.hpp" @@ -36,7 +38,6 @@ public: Controller(); Controller(char const *json_filename); ~Controller(); - Algorithm *CreateAlgorithm(char const *name); void Read(char const *filename); void Initialise(); void SwitchMode(CameraMode const &camera_mode, Metadata *metadata); @@ -46,6 +47,7 @@ public: Algorithm *GetAlgorithm(std::string const &name) const; protected: + void CreateAlgorithm(const std::string &name, const libcamera::YamlObject ¶ms); Metadata global_metadata_; std::vector algorithms_; bool switch_mode_called_;