From patchwork Thu Jul 14 15:24:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 16632 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 65254BD1F1 for ; Thu, 14 Jul 2022 15:24:24 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id EC19C63318; Thu, 14 Jul 2022 17:24:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1657812264; 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=r3Roaz0AAgrmRcu5OuaM6sS3jIHGI5Ee436M0cx4q4s2ltCTXJ9LcMx9AFqpNEXKb zvdOcsMvQJu/5vqKlfx1rQYhDU8WGQFlluzkcmfPRX6QE53S/Se3W6oxP/33zOmdkA mdilYMO28LojngkMcqwrUYdk2a6ISSCnJe7QNWxeQFvIr3KanTXfbRqhUnK1w9KG21 XDA4mbyxeWngqrY7v724Dym30jD/6Wm3IrgldY0Y670NmhtoBis+tkR6YTKXh0z1kc jPq4xs49qlf3JFsZCqfaSoaUgzpgVesjaVtNiMHT3KeAAexWWPNqg+msbe8iWPyMK+ OPume9Kv11wTA== Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 41FFA6331B for ; Thu, 14 Jul 2022 17:24:21 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="V2a6D+8K"; dkim-atps=neutral Received: by mail-wm1-x334.google.com with SMTP id h14-20020a1ccc0e000000b0039eff745c53so1413070wmb.5 for ; Thu, 14 Jul 2022 08:24:21 -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=V2a6D+8KpWMGSE8Uq8p7uhpQIiRg56SwTWkcdr2CWsazmRIW4x0ZxJmILBb7I1R3sN HyQedpItII3113/LlUIqS8h9/tdaZCgZoeYvFcbiTEMJEgpnInkWJcxsoBuoHIBTJ5q1 xN2EAL8UE8uyPwTdc+TyrcGGjkIT7No5Sgug5mhyNP3PmSsYB5bJhLzXI7mnYMi1qMiH V3Fg/fk7Mgern+bNOrkrFV4wuxCy0tVfMqYuA5guaRlvlbVfx2JzKbzT0wRx1rVndxxu qs5NAkK3nP23WoUWC59D3SqihjR5X5/mfFgouUKCCxfr+9wHTSYazc2wo3DSHlGcpvIU nB7g== 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=LOgUP/pl1BYyTVgQZN42e7bZQ9XRzxtuOj2XDtTJ/vXZ1pLOnAPlxa7IxUM2+fnTbO nAKAFmWlZOKpMO1X77iJ2ZZcfHBmSfjYeFR8n/CG7rn0x/cyUsiZ24gGEzo/WaLS1kkB yWBX2pSOXAGqsPl0dPtlhBlY2DzH/XBY4YuVMvqVAyH5ktdP7A1gOQVup329brqkpQy/ eRJDKERJGOKTStbPCXsUu7O40n0q/1AWJKi5eOVImBC15hhH1vkhnhpWyQlYlaN0y4ak wPWJwcEIitgeaAhKGDaPAJGES4WijMihjHKOECMSHOYCnL1KHeHPJ362rRShwd6PRlYY fDGg== X-Gm-Message-State: AJIora/NB2W+RM+1kVHNGQ/G8AepBFV5X4OjsrfNBJV4rAkkVtdD6HCb 10Ti05h81f3ym4FM7NJ0423C9+AKymeE0A== X-Google-Smtp-Source: AGRyM1udZ+A/u281glbJycngRbbcLVS0AwvmCUHv7IggwrEkJfNXg2IaVy0rsRO7CyWIntHNDnyLCA== X-Received: by 2002:a05:600c:22d2:b0:3a2:eb34:d1f1 with SMTP id 18-20020a05600c22d200b003a2eb34d1f1mr16167375wmg.193.1657812260607; Thu, 14 Jul 2022 08:24:20 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id h14-20020a1ccc0e000000b003a2e7c13a3asm2322476wmb.42.2022.07.14.08.24.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 08:24:19 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 14 Jul 2022 16:24:06 +0100 Message-Id: <20220714152409.9780-6-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220714152409.9780-1-naush@raspberrypi.com> References: <20220714152409.9780-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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_;