[{"id":35778,"web_url":"https://patchwork.libcamera.org/comment/35778/","msgid":"<175758896156.2127323.1177078537253547434@neptunite.rasen.tech>","date":"2025-09-11T11:09:21","subject":"Re: [PATCH v17 04/12] pipeline: rpi: Look up rpi configuration in\n\tthe configuration file","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"content":"Hi Milan,\n\nThanks for the patch.\n\nQuoting Milan Zamazal (2025-09-11 18:29:34)\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>     pipelines:\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\nLooks good to me.\n\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n> ---\n>  .../pipeline/rpi/common/pipeline_base.cpp     | 59 +++++++++++--------\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, 56 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 c209aa596..a4a018268 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> @@ -1093,35 +1095,46 @@ int CameraData::loadPipelineConfiguration()\n>         /* Initial configuration of the platform, in case no config file is present */\n>         platformPipelineConfigure({});\n>  \n> +       std::unique_ptr<YamlObject> root;\n>         char const *configFromEnv = utils::secure_getenv(\"LIBCAMERA_RPI_CONFIG_FILE\");\n> -       if (!configFromEnv || *configFromEnv == '\\0')\n> -               return 0;\n> -\n> -       std::string filename = std::string(configFromEnv);\n> -       File file(filename);\n> +       if (configFromEnv && *configFromEnv != '\\0') {\n> +               std::string filename = std::string(configFromEnv);\n> +               File file(filename);\n> +\n> +               if (!file.open(File::OpenModeFlag::ReadOnly)) {\n> +                       LOG(RPI, Warning) << \"Failed to open configuration file '\" << filename << \"'\"\n> +                                         << \", using defaults\";\n> +                       return 0;\n> +               }\n>  \n> -       if (!file.open(File::OpenModeFlag::ReadOnly)) {\n> -               LOG(RPI, Warning) << \"Failed to open configuration file '\" << filename << \"'\"\n> -                                 << \", using defaults\";\n> -               return 0;\n> -       }\n> +               LOG(RPI, Info) << \"Using configuration file '\" << filename << \"'\";\n>  \n> -       LOG(RPI, Info) << \"Using configuration file '\" << filename << \"'\";\n> +               root = YamlParser::parse(file);\n> +               if (!root) {\n> +                       LOG(RPI, Warning) << \"Failed to parse configuration file, using defaults\";\n> +                       return 0;\n> +               }\n>  \n> -       std::unique_ptr<YamlObject> root = YamlParser::parse(file);\n> -       if (!root) {\n> -               LOG(RPI, Warning) << \"Failed to parse configuration file, using defaults\";\n> -               return 0;\n> -       }\n> +               std::optional<double> ver = (*root)[\"version\"].get<double>();\n> +               if (!ver || *ver != 1.0) {\n> +                       LOG(RPI, Warning) << \"Unexpected configuration file version reported: \"\n> +                                         << *ver;\n> +                       return 0;\n> +               }\n>  \n> -       std::optional<double> ver = (*root)[\"version\"].get<double>();\n> -       if (!ver || *ver != 1.0) {\n> -               LOG(RPI, Warning) << \"Unexpected configuration file version reported: \"\n> -                                 << *ver;\n> -               return 0;\n> +               std::optional<std::string> t = (*root)[\"target\"].get<std::string>();\n> +               if (t != target()) {\n> +                       LOG(RPI, Error) << \"Unexpected target reported: expected \\\"\"\n> +                                       << target() << \"\\\", got \" << (t ? t->c_str() : \"(unknown)\");\n> +                       return -EINVAL;\n> +               }\n>         }\n>  \n> -       const YamlObject &phConfig = (*root)[\"pipeline_handler\"];\n> +       GlobalConfiguration::Configuration config =\n> +               pipe()->cameraManager()->_d()->configuration().configuration()[\"pipelines\"][\"rpi\"];\n> +       const YamlObject &phConfig = (root\n> +                                             ? (*root)[\"pipeline_handler\"]\n> +                                             : config[target()][\"pipeline_handler\"]);\n>  \n>         if (phConfig.contains(\"disable_startup_frame_drops\"))\n>                 LOG(RPI, Warning)\n> @@ -1137,7 +1150,7 @@ int CameraData::loadPipelineConfiguration()\n>                 frontendDevice()->setDequeueTimeout(config_.cameraTimeoutValue * 1ms);\n>         }\n>  \n> -       return platformPipelineConfigure(root);\n> +       return platformPipelineConfigure(phConfig);\n>  }\n>  \n>  int CameraData::loadIPA(ipa::RPi::InitResult *result)\n> diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.h b/src/libcamera/pipeline/rpi/common/pipeline_base.h\n> index 4bce4ec4f..ffbede798 100644\n> --- a/src/libcamera/pipeline/rpi/common/pipeline_base.h\n> +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.h\n> @@ -95,8 +95,9 @@ public:\n>         virtual V4L2VideoDevice::Formats ispFormats() const = 0;\n>         virtual V4L2VideoDevice::Formats rawFormats() const = 0;\n>         virtual V4L2VideoDevice *frontendDevice() = 0;\n> +       virtual const std::string &target() const = 0;\n>  \n> -       virtual int platformPipelineConfigure(const std::unique_ptr<YamlObject> &root) = 0;\n> +       virtual int platformPipelineConfigure(const YamlObject &phConfig) = 0;\n>  \n>         std::unique_ptr<ipa::RPi::IPAProxyRPi> ipa_;\n>  \n> diff --git a/src/libcamera/pipeline/rpi/pisp/pisp.cpp b/src/libcamera/pipeline/rpi/pisp/pisp.cpp\n> index 082724c5a..0fb7c3fe8 100644\n> --- a/src/libcamera/pipeline/rpi/pisp/pisp.cpp\n> +++ b/src/libcamera/pipeline/rpi/pisp/pisp.cpp\n> @@ -740,10 +740,16 @@ public:\n>                 return cfe_[Cfe::Output0].dev();\n>         }\n>  \n> +       const std::string &target() const override\n> +       {\n> +               static const std::string target = \"pisp\";\n> +               return target;\n> +       }\n> +\n>         CameraConfiguration::Status\n>         platformValidate(RPi::RPiCameraConfiguration *rpiConfig) const override;\n>  \n> -       int platformPipelineConfigure(const std::unique_ptr<YamlObject> &root) override;\n> +       int platformPipelineConfigure(const YamlObject &phConfig) override;\n>  \n>         void platformStart() override;\n>         void platformStop() override;\n> @@ -1331,7 +1337,7 @@ PiSPCameraData::platformValidate(RPi::RPiCameraConfiguration *rpiConfig) const\n>         return status;\n>  }\n>  \n> -int PiSPCameraData::platformPipelineConfigure(const std::unique_ptr<YamlObject> &root)\n> +int PiSPCameraData::platformPipelineConfigure(const YamlObject &phConfig)\n>  {\n>         config_ = {\n>                 .numCfeConfigStatsBuffers = 12,\n> @@ -1340,23 +1346,9 @@ int PiSPCameraData::platformPipelineConfigure(const std::unique_ptr<YamlObject>\n>                 .disableHdr = false,\n>         };\n>  \n> -       if (!root)\n> +       if (!phConfig)\n>                 return 0;\n>  \n> -       std::optional<double> ver = (*root)[\"version\"].get<double>();\n> -       if (!ver || *ver != 1.0) {\n> -               LOG(RPI, Error) << \"Unexpected configuration file version reported\";\n> -               return -EINVAL;\n> -       }\n> -\n> -       std::optional<std::string> target = (*root)[\"target\"].get<std::string>();\n> -       if (target != \"pisp\") {\n> -               LOG(RPI, Error) << \"Unexpected target reported: expected \\\"pisp\\\", got \"\n> -                               << (target ? target->c_str() : \"(unknown)\");\n> -               return -EINVAL;\n> -       }\n> -\n> -       const YamlObject &phConfig = (*root)[\"pipeline_handler\"];\n>         config_.numCfeConfigStatsBuffers =\n>                 phConfig[\"num_cfe_config_stats_buffers\"].get<unsigned int>(config_.numCfeConfigStatsBuffers);\n>         config_.numCfeConfigQueue =\n> diff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n> index 99d43bd0a..71c425373 100644\n> --- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n> +++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n> @@ -61,13 +61,19 @@ public:\n>                 return unicam_[Unicam::Image].dev();\n>         }\n>  \n> +       const std::string &target() const override\n> +       {\n> +               static const std::string target = \"bcm2835\";\n> +               return target;\n> +       }\n> +\n>         void platformFreeBuffers() override\n>         {\n>         }\n>  \n>         CameraConfiguration::Status platformValidate(RPi::RPiCameraConfiguration *rpiConfig) const override;\n>  \n> -       int platformPipelineConfigure(const std::unique_ptr<YamlObject> &root) override;\n> +       int platformPipelineConfigure(const YamlObject &phConfig) override;\n>  \n>         void platformStart() override;\n>         void platformStop() override;\n> @@ -493,30 +499,16 @@ CameraConfiguration::Status Vc4CameraData::platformValidate(RPi::RPiCameraConfig\n>         return status;\n>  }\n>  \n> -int Vc4CameraData::platformPipelineConfigure(const std::unique_ptr<YamlObject> &root)\n> +int Vc4CameraData::platformPipelineConfigure(const YamlObject &phConfig)\n>  {\n>         config_ = {\n>                 .minUnicamBuffers = 2,\n>                 .minTotalUnicamBuffers = 4,\n>         };\n>  \n> -       if (!root)\n> +       if (!phConfig)\n>                 return 0;\n>  \n> -       std::optional<double> ver = (*root)[\"version\"].get<double>();\n> -       if (!ver || *ver != 1.0) {\n> -               LOG(RPI, Error) << \"Unexpected configuration file version reported\";\n> -               return -EINVAL;\n> -       }\n> -\n> -       std::optional<std::string> target = (*root)[\"target\"].get<std::string>();\n> -       if (target != \"bcm2835\") {\n> -               LOG(RPI, Error) << \"Unexpected target reported: expected \\\"bcm2835\\\", got \"\n> -                               << (target ? target->c_str() : \"(unknown)\");\n> -               return -EINVAL;\n> -       }\n> -\n> -       const YamlObject &phConfig = (*root)[\"pipeline_handler\"];\n>         config_.minUnicamBuffers =\n>                 phConfig[\"min_unicam_buffers\"].get<unsigned int>(config_.minUnicamBuffers);\n>         config_.minTotalUnicamBuffers =\n> -- \n> 2.51.0\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 08CA8BDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 11 Sep 2025 11:09:31 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2B3A669372;\n\tThu, 11 Sep 2025 13:09: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 1F57A69367\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 11 Sep 2025 13:09:29 +0200 (CEST)","from neptunite.rasen.tech (unknown\n\t[IPv6:2404:7a81:160:2100:5e49:1615:2276:f31c])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id B92B8520;\n\tThu, 11 Sep 2025 13:08:13 +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=\"EbBV9jWx\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1757588894;\n\tbh=c4BFHB0rccDNM3XuQNbO98CdBQ6HWM2ZfxINpx1Yg5o=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=EbBV9jWx5YCk4IJ+29TrF0+9yzDwGXZz8tRtuKv+wRnBhsqKi5OLEEKEXCDtVaLhz\n\t5eQYc4QrXRlDT2K0lZTEWeboLtPhmWo26Z8KS/MIqBh7mshvFMAqYWb9cY2FZXRlSC\n\tln46SxUwKF1umcV48rRQTSL5ntktl4uGgYWINAPQ=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250911092945.16517-5-mzamazal@redhat.com>","References":"<20250911092945.16517-1-mzamazal@redhat.com>\n\t<20250911092945.16517-5-mzamazal@redhat.com>","Subject":"Re: [PATCH v17 04/12] pipeline: rpi: Look up rpi configuration in\n\tthe configuration file","From":"Paul Elder <paul.elder@ideasonboard.com>","Cc":"Milan Zamazal <mzamazal@redhat.com>, Kieran Bingham\n\t<kieran.bingham@ideasonboard.com>, =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?=\n\t<barnabas.pocze@ideasonboard.com>, Laurent Pinchart\n\t<laurent.pinchart@ideasonboard.com>","To":"Milan Zamazal <mzamazal@redhat.com>, libcamera-devel@lists.libcamera.org","Date":"Thu, 11 Sep 2025 20:09:21 +0900","Message-ID":"<175758896156.2127323.1177078537253547434@neptunite.rasen.tech>","User-Agent":"alot/0.0.0","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>"}}]