[{"id":34888,"web_url":"https://patchwork.libcamera.org/comment/34888/","msgid":"<7c379b17-a3ae-4036-b6f5-9426e7166beb@ideasonboard.com>","date":"2025-07-14T13:50:25","subject":"Re: [PATCH v13 04/12] config: Look up rpi configuration in the\n\tconfiguration file","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/people/216/","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"content":"Hi\n\n2025. 07. 11. 22:12 keltezéssel, Milan Zamazal írta:\n> Let's make rpi configuration available in the global configuration file.\n> It may be arguable whether pipeline specific configurations belong to\n> the global configuration file.  But:\n> \n> - Having a single configuration file is generally easier for the user.\n> - The original configuration via environment variables can be already\n>    considered global.\n> - This option points to other configuration files and it makes little\n>    sense to add another configuration file to the chain.\n> \n> The rpi configuration is currently placed in a separate file, specified\n> by LIBCAMERA_RPI_CONFIG_FILE environment variable.  Let's support the\n> content of the file in the global configuration file.  `version' field\n> is omitted as the global configuration file has its own version and the\n> required version in the original file has been 1.0 anyway.\n> \n> The configuration snippet:\n> \n>    configuration:\n>      pipeline:\n>        rpi:\n>          bcm2835:\n>            pipeline_handler:\n>              ...\n>          pisp:\n>            pipeline_handler:\n>              ...\n> \n> To not break current user setups, LIBCAMERA_RPI_CONFIG_FILE environment\n> variable is still supported and works as before, pointing to a separate\n> configuration file.  Just the duplicate check for the configuration file\n> version in platformPipelineConfigure methods is removed.\n> \n> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>\n> ---\n>   .../pipeline/rpi/common/pipeline_base.cpp     | 62 ++++++++++++-------\n>   .../pipeline/rpi/common/pipeline_base.h       |  3 +-\n>   src/libcamera/pipeline/rpi/pisp/pisp.cpp      | 26 +++-----\n>   src/libcamera/pipeline/rpi/vc4/vc4.cpp        | 26 +++-----\n>   4 files changed, 59 insertions(+), 58 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> index eafe94427..0eea242de 100644\n> --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> @@ -20,8 +20,10 @@\n>   #include <libcamera/property_ids.h>\n> \n>   #include \"libcamera/internal/camera_lens.h\"\n> +#include \"libcamera/internal/global_configuration.h\"\n>   #include \"libcamera/internal/ipa_manager.h\"\n>   #include \"libcamera/internal/v4l2_subdevice.h\"\n> +#include \"libcamera/internal/yaml_parser.h\"\n> \n>   using namespace std::chrono_literals;\n> \n> @@ -1091,35 +1093,46 @@ int CameraData::loadPipelineConfiguration()\n>   \t/* Initial configuration of the platform, in case no config file is present */\n>   \tplatformPipelineConfigure({});\n> \n> +\tstd::unique_ptr<YamlObject> root;\n>   \tchar const *configFromEnv = utils::secure_getenv(\"LIBCAMERA_RPI_CONFIG_FILE\");\n> -\tif (!configFromEnv || *configFromEnv == '\\0')\n> -\t\treturn 0;\n> -\n> -\tstd::string filename = std::string(configFromEnv);\n> -\tFile file(filename);\n> +\tif (configFromEnv && *configFromEnv != '\\0') {\n> +\t\tstd::string filename = std::string(configFromEnv);\n> +\t\tFile file(filename);\n> +\n> +\t\tif (!file.open(File::OpenModeFlag::ReadOnly)) {\n> +\t\t\tLOG(RPI, Warning) << \"Failed to open configuration file '\" << filename << \"'\"\n> +\t\t\t\t\t  << \", using defaults\";\n> +\t\t\treturn 0;\n> +\t\t}\n> \n> -\tif (!file.open(File::OpenModeFlag::ReadOnly)) {\n> -\t\tLOG(RPI, Warning) << \"Failed to open configuration file '\" << filename << \"'\"\n> -\t\t\t\t  << \", using defaults\";\n> -\t\treturn 0;\n> -\t}\n> +\t\tLOG(RPI, Info) << \"Using configuration file '\" << filename << \"'\";\n> \n> -\tLOG(RPI, Info) << \"Using configuration file '\" << filename << \"'\";\n> +\t\troot = YamlParser::parse(file);\n> +\t\tif (!root) {\n> +\t\t\tLOG(RPI, Warning) << \"Failed to parse configuration file, using defaults\";\n> +\t\t\treturn 0;\n> +\t\t}\n> \n> -\tstd::unique_ptr<YamlObject> root = YamlParser::parse(file);\n> -\tif (!root) {\n> -\t\tLOG(RPI, Warning) << \"Failed to parse configuration file, using defaults\";\n> -\t\treturn 0;\n> -\t}\n> +\t\tstd::optional<double> ver = (*root)[\"version\"].get<double>();\n> +\t\tif (!ver || *ver != 1.0) {\n> +\t\t\tLOG(RPI, Warning) << \"Unexpected configuration file version reported: \"\n> +\t\t\t\t\t  << *ver;\n> +\t\t\treturn 0;\n> +\t\t}\n> \n> -\tstd::optional<double> ver = (*root)[\"version\"].get<double>();\n> -\tif (!ver || *ver != 1.0) {\n> -\t\tLOG(RPI, Warning) << \"Unexpected configuration file version reported: \"\n> -\t\t\t\t  << *ver;\n> -\t\treturn 0;\n> +\t\tstd::optional<std::string> t = (*root)[\"target\"].get<std::string>();\n> +\t\tif (t != target()) {\n> +\t\t\tLOG(RPI, Error) << \"Unexpected target reported: expected \\\"\"\n> +\t\t\t\t\t<< target() << \"\\\", got \" << (t ? t->c_str() : \"(unknown)\");\n> +\t\t\treturn -EINVAL;\n> +\t\t}\n>   \t}\n> \n> -\tconst YamlObject &phConfig = (*root)[\"pipeline_handler\"];\n> +\tGlobalConfiguration::Configuration config =\n> +\t\tpipe()->cameraManager()->_d()->configuration().configuration()[\"pipeline\"][\"rpi\"];\n> +\tconst YamlObject &phConfig = (root\n> +\t\t\t\t\t      ? (*root)[\"pipeline_handler\"]\n> +\t\t\t\t\t      : config[target()][\"pipeline_handler\"]);\n> \n>   \tif (phConfig.contains(\"disable_startup_frame_drops\"))\n>   \t\tLOG(RPI, Warning)\n> @@ -1135,7 +1148,10 @@ int CameraData::loadPipelineConfiguration()\n>   \t\tfrontendDevice()->setDequeueTimeout(config_.cameraTimeoutValue * 1ms);\n>   \t}\n> \n> -\treturn platformPipelineConfigure(root);\n> +\tstd::optional<std::string> expectedTarget = (root\n> +\t\t\t\t\t\t\t     ? (*root)[\"target\"].get<std::string>()\n> +\t\t\t\t\t\t\t     : target());\n\n`expectedTarget` is no longer need as far as I can see.\n\n\nRegards,\nBarnabás Pőcze\n\n> +\treturn platformPipelineConfigure(phConfig);\n>   }\n> \n>   int CameraData::loadIPA(ipa::RPi::InitResult *result)\n> [...]","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 3BB7FC3237\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 14 Jul 2025 13:50:31 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7E80668F45;\n\tMon, 14 Jul 2025 15:50:30 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 892576186C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 14 Jul 2025 15:50:29 +0200 (CEST)","from [192.168.33.16] (185.221.140.39.nat.pool.zt.hu\n\t[185.221.140.39])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 36710166D;\n\tMon, 14 Jul 2025 15:49:57 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"wP6+/2HJ\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1752500997;\n\tbh=KQV5ZCpx5gMyVdGovVnM5TFEqTM8IyT1SrfoMWHFJHA=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=wP6+/2HJnvkrhxxbHzG/cvKEDiohQmayJozpSSsaWxcJ35Qj02WUZnEObKMYWNrHn\n\t7Q88vI1GCSxk0NR3GUStoTu4sdUQ1uLW+NAiAV5YQR5ujaHRVPyghj4e/cy7q35ROQ\n\tqmcW4TvNozhBYUHnaRbvjNiZjNuxWFwO9RFaUxtg=","Message-ID":"<7c379b17-a3ae-4036-b6f5-9426e7166beb@ideasonboard.com>","Date":"Mon, 14 Jul 2025 15:50:25 +0200","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v13 04/12] config: Look up rpi configuration in the\n\tconfiguration file","To":"Milan Zamazal <mzamazal@redhat.com>, libcamera-devel@lists.libcamera.org","Cc":"Kieran Bingham <kieran.bingham@ideasonboard.com>, =?utf-8?q?Barnab?=\n\t=?utf-8?b?w6FzIFDFkWN6ZQ==?= <barnabas.pocze@ideasonboard.com>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>","References":"<20250711201232.129264-1-mzamazal@redhat.com>\n\t<oAvG8JnJcmBe6p8Ctd-c9QqKJYWP9kZ93C3CS4xwQwlX62Xm8HsfgXu3Q_JeTtL6O088sYKws8ArtcHIZ1iYSg==@protonmail.internalid>\n\t<20250711201232.129264-5-mzamazal@redhat.com>","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Content-Language":"en-US, hu-HU","In-Reply-To":"<20250711201232.129264-5-mzamazal@redhat.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"8bit","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]