From patchwork Mon Jul 18 08:15:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 16671 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 1E9B7BD1F1 for ; Mon, 18 Jul 2022 08:16:14 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C8EF863317; Mon, 18 Jul 2022 10:16:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1658132173; bh=HLUs42uFbD7cMb9yZy5swV03CaFsS+iH1xxvF7Oa/lE=; 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=bA74/dVHCBT/iH7vmCjf/8I4nEBJTB/yst2zpFlAmYLLaAH38oo4MxtPTM1bdqRCs bNUGCR/DRxe5cDZCLXt1wawYFKoVLUC81de3J9WydaEmzw7SmiNOcMRCkNAGRwo5QZ Oo8vhsfGDWemcNUwTgZGiHUGckWMwukspqbC5ZgPZrkYwdG2ltK9rkObWzThxjFr6U lP6Xe3n9fxWdsPSp9G8a6Y4SKZ9hjbghMZV8pK5zh8Dt3y8Wp9PaJMuH2m4PSw7eGc ptBTKDa1y/OAXZTg39z7JFaGzmRFLY8OoIOr0QELxbg8efB+0+0BuCaSTxGNLRQ2My EzO1EX8mva8rg== Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5866763313 for ; Mon, 18 Jul 2022 10:16:10 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="GogST6hM"; dkim-atps=neutral Received: by mail-wm1-x32d.google.com with SMTP id o8so6649436wms.2 for ; Mon, 18 Jul 2022 01:16:10 -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=XtlLy1tZ90SLNUA/xVA9z1V4OdXjkWqfFZp8JsW2GDU=; b=GogST6hM2jKmA8Pl7cUcTK/Ua5crd8paPh+Ptcwu+mq21aF5JUu8GJlISzTuH9zGe9 0r/p3Hdmbf1YxI2io+bqjFrkqbsCNEvODQTo/9nQw7Rn/NRo0eZlKmqYJcYWfnUtmUwp 0MKNLk4PDN15jFfaNCB4S/dmuKpm824uXPRLgXVxUhZ6v6NZhFKtlA28VcensiY4eFI4 RlH+uKTCguKTcIE4TWjUHgNX3mT1BiuYRfIBp/RbgAzf3Kgvc31u6wY3NvFLSEoBWOVQ LnhKbcGkarZuMb79SBo5udTrs75DTCZ+0sbCai48qvbd0EqEJnuKM1Ip5W/re6ZzKvzp /0lg== 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=XtlLy1tZ90SLNUA/xVA9z1V4OdXjkWqfFZp8JsW2GDU=; b=CksL4URYJXr/Oo9M5XdFaQLy0eGz0wZ6LbKzHXUp3zgGlKmHYtMRP2xmZQUCyWJ2LU ptM3cQmFsdibCOgi1Y5e1tRzpHsGj/ZOKJXP+Ze6+1XPFR+H8i/kFiQzAAFzhOeqthHc IEpD6ALPUwTdkvGrXdZLds5XYr6wyUSefl6nRwxtkI1gu3ELDGnlpp40R1B6g4eeEtL3 HsDQwgkhROXijCULTfdU0CQzmPhHRlTOp0jsSkD0YYMxc8Jf1yBRyOywH2wEfSh8GtxA KDfuuEQamWCEgNxT+kDsjFi/d4C0Dwbs+qrOVJa9laAi1CmaKo56MRWl5/JGjG0pEusw 9RUA== X-Gm-Message-State: AJIora9ieVQbqhF9ati/5J1YN+NJvigS0Rb0CRo7uMNxO1Brz5UaVa9W cUzwIU898/G7BQka5XQoLBiGYAh1wddVwg== X-Google-Smtp-Source: AGRyM1sjfNHVM2+UDg56jdYB5b5Qz67xu+9wisA1G74fM8DOIUEyPghI1rKst39j9oAZISmk0Ohhcw== X-Received: by 2002:a05:600c:4e0d:b0:3a3:bc7:e9ec with SMTP id b13-20020a05600c4e0d00b003a30bc7e9ecmr14675124wmq.167.1658132169730; Mon, 18 Jul 2022 01:16:09 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id a15-20020adffb8f000000b0021dbac444a7sm10206795wrr.59.2022.07.18.01.16.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jul 2022 01:16:09 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 18 Jul 2022 09:15:59 +0100 Message-Id: <20220718081602.32535-6-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220718081602.32535-1-naush@raspberrypi.com> References: <20220718081602.32535-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 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 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 --- src/ipa/raspberrypi/controller/controller.cpp | 43 +++++++++++++------ src/ipa/raspberrypi/controller/controller.hpp | 4 +- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/ipa/raspberrypi/controller/controller.cpp b/src/ipa/raspberrypi/controller/controller.cpp index 67d650ef0c1b..b22a17f18f8e 100644 --- a/src/ipa/raspberrypi/controller/controller.cpp +++ b/src/ipa/raspberrypi/controller/controller.cpp @@ -42,22 +42,41 @@ 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()) + CreateAlgorithm(key, value); + } else if (version < 3.0) { + 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); + } else { + LOG(RPiController, Fatal) + << "Unrecognised version " << version + << " for the tuning file " << filename; } } -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_;