Show a patch.

GET /api/patches/23929/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 23929,
    "url": "https://patchwork.libcamera.org/api/patches/23929/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/23929/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20250724103834.54611-2-mzamazal@redhat.com>",
    "date": "2025-07-24T10:38:21",
    "name": "[v15,01/12] config: Introduce global runtime configuration",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "b58cd7fecf2cb6c55c1bae7e6c1959ae2c0d0510",
    "submitter": {
        "id": 177,
        "url": "https://patchwork.libcamera.org/api/people/177/?format=api",
        "name": "Milan Zamazal",
        "email": "mzamazal@redhat.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/23929/mbox/",
    "series": [
        {
            "id": 5320,
            "url": "https://patchwork.libcamera.org/api/series/5320/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5320",
            "date": "2025-07-24T10:38:20",
            "name": "Add global configuration file",
            "version": 15,
            "mbox": "https://patchwork.libcamera.org/series/5320/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/23929/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/23929/checks/",
    "tags": {},
    "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 0358DBDCC1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 24 Jul 2025 10:38:58 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5CE3B690E5;\n\tThu, 24 Jul 2025 12:38:57 +0200 (CEST)",
            "from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.133.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B5C7D690DA\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 24 Jul 2025 12:38:54 +0200 (CEST)",
            "from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com\n\t(ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63])\n\tby relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n\tcipher=TLS_AES_256_GCM_SHA384) id us-mta-544-aE7qDE8FPlmuU5kBkX1FFw-1;\n\tThu, 24 Jul 2025 06:38:52 -0400",
            "from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com\n\t(mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com\n\t[10.30.177.17])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\tkey-exchange X25519 server-signature RSA-PSS (2048 bits)\n\tserver-digest SHA256) (No client certificate requested)\n\tby mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTPS id 33C45195608B; Thu, 24 Jul 2025 10:38:51 +0000 (UTC)",
            "from mzamazal-thinkpadp1gen7.tpbc.com (unknown [10.44.32.255])\n\tby mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTP id 3711719560A3; Thu, 24 Jul 2025 10:38:48 +0000 (UTC)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"T2YOjtxp\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1753353533;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tcontent-transfer-encoding:content-transfer-encoding:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=0H4BUC87svpD/bg2VHPgtIpWTDHBmdYdn7oq7DBqhEU=;\n\tb=T2YOjtxptT8yZC6Sp0ti8YnvoRFVww3L8069kJ18ntGowLNOR4p5wZlwdi5e1tbfKaBNKG\n\t7gU9sKYumL1z7ffmCTUlz/HrsQWSwLskmiIS0GkpT+AGU3ivbDL1ZPHtFwb4VxoBA8rKPd\n\tvJf346RtP0ltJ09IrX0ENeAFhSZUwGo=",
        "X-MC-Unique": "aE7qDE8FPlmuU5kBkX1FFw-1",
        "X-Mimecast-MFC-AGG-ID": "aE7qDE8FPlmuU5kBkX1FFw_1753353531",
        "From": "Milan Zamazal <mzamazal@redhat.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "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>",
        "Subject": "[PATCH v15 01/12] config: Introduce global runtime configuration",
        "Date": "Thu, 24 Jul 2025 12:38:21 +0200",
        "Message-ID": "<20250724103834.54611-2-mzamazal@redhat.com>",
        "In-Reply-To": "<20250724103834.54611-1-mzamazal@redhat.com>",
        "References": "<20250724103834.54611-1-mzamazal@redhat.com>",
        "MIME-Version": "1.0",
        "X-Scanned-By": "MIMEDefang 3.0 on 10.30.177.17",
        "X-Mimecast-Spam-Score": "0",
        "X-Mimecast-MFC-PROC-ID": "Oa5CFEaUNSPhKWK18F5SWyGKxw1ulbLISUFYmyOcqc8_1753353531",
        "X-Mimecast-Originator": "redhat.com",
        "Content-Transfer-Encoding": "8bit",
        "content-type": "text/plain; charset=\"US-ASCII\"; x-default=true",
        "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>"
    },
    "content": "Currently, libcamera can be configured in runtime using several\nenvironment variables.  With introducing more and more variables, this\nmechanism reaches its limits.  It would be simpler and more flexible if\nit was possible to configure libcamera in a single file.\n\nFor example, there was a request to define pipeline precedence in\nruntime.  We want to compile in multiple pipelines, in order to have\nthem accessible within single packages in distributions.  And then being\nable to select among the pipelines manually as needed based on the\nparticular hardware or operating system environment.  Having the\nconfiguration file then allows easy switching between hardware, GPU or\nCPU IPAs.  The configuration file can also be used to enable or disable\nexperimental features and avoid the need to track local patches changing\nconfiguration options hard-wired in the code when working on new\nfeatures.\n\nThis patch introduces basic support for configuration files.\nGlobalConfiguration class reads, stores and accesses the configuration.\nGlobalConfiguration instances are meant to be stored to and accessed\nfrom instances of another class, preferably from a single instance.\n\nlibcamera configuration can be specified using a system-wide\nconfiguration file or a user configuration file.  The user configuration\nfile takes precedence if present.  There is currently no way to merge\nmultiple configuration files, the one found is used as the only\nconfiguration file.  If no configuration file is present, nothing\nchanges to the current libcamera behavior (except for some log\nmessages related to configuration file lookup).\n\nThe configuration file is a YAML file.  We already have a mechanism for\nhandling YAML configuration files in libcamera and the given\ninfrastructure can be reused for the purpose.  However, the\nconfiguration type is abstracted to make contingent future change of the\nunderlying class easier while retaining (most of) the original API.\n\nThe configuration is versioned.  This has currently no particular\nmeaning but is likely to have its purpose in future, especially once\nconfiguration validation is introduced.\n\nThe configuration YAML file looks as follows:\n\n  ---\n  version: 1\n  configuration:\n    WHATEVER CONFIGURATION NEEDED\n\nThis patch introduces just the basic idea.  Actually using the\nconfiguration in the corresponding places (everything what is currently\nconfigurable via environment variables should be configurable in the\nfile configuration) and other enhancements are implemented in the\nfollowup patches.\n\nSigned-off-by: Milan Zamazal <mzamazal@redhat.com>\n---\n .../libcamera/internal/global_configuration.h |  34 +++++\n include/libcamera/internal/meson.build        |   1 +\n src/libcamera/global_configuration.cpp        | 144 ++++++++++++++++++\n src/libcamera/meson.build                     |   1 +\n 4 files changed, 180 insertions(+)\n create mode 100644 include/libcamera/internal/global_configuration.h\n create mode 100644 src/libcamera/global_configuration.cpp",
    "diff": "diff --git a/include/libcamera/internal/global_configuration.h b/include/libcamera/internal/global_configuration.h\nnew file mode 100644\nindex 000000000..f695498c4\n--- /dev/null\n+++ b/include/libcamera/internal/global_configuration.h\n@@ -0,0 +1,34 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2024-2025 Red Hat, inc.\n+ *\n+ * Global configuration handling\n+ */\n+\n+#pragma once\n+\n+#include <filesystem>\n+\n+#include \"libcamera/internal/yaml_parser.h\"\n+\n+namespace libcamera {\n+\n+class GlobalConfiguration\n+{\n+public:\n+\tusing Configuration = const YamlObject &;\n+\n+\tGlobalConfiguration();\n+\n+\tunsigned int version() const;\n+\tConfiguration configuration() const;\n+\n+private:\n+\tbool loadFile(const std::filesystem::path &fileName);\n+\tvoid load();\n+\n+\tstd::unique_ptr<YamlObject> yamlConfiguration_ =\n+\t\tstd::make_unique<YamlObject>();\n+};\n+\n+} /* namespace libcamera */\ndiff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build\nindex 5c80a28c4..45c299f6a 100644\n--- a/include/libcamera/internal/meson.build\n+++ b/include/libcamera/internal/meson.build\n@@ -23,6 +23,7 @@ libcamera_internal_headers = files([\n     'dma_buf_allocator.h',\n     'formats.h',\n     'framebuffer.h',\n+    'global_configuration.h',\n     'ipa_data_serializer.h',\n     'ipa_manager.h',\n     'ipa_module.h',\ndiff --git a/src/libcamera/global_configuration.cpp b/src/libcamera/global_configuration.cpp\nnew file mode 100644\nindex 000000000..50756b859\n--- /dev/null\n+++ b/src/libcamera/global_configuration.cpp\n@@ -0,0 +1,144 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2024-2025 Red Hat, inc.\n+ *\n+ * Global configuration handling\n+ */\n+\n+#include \"libcamera/internal/global_configuration.h\"\n+\n+#include <filesystem>\n+#include <string_view>\n+#include <sys/types.h>\n+\n+#include <libcamera/base/file.h>\n+#include <libcamera/base/log.h>\n+#include <libcamera/base/utils.h>\n+\n+#include \"libcamera/internal/yaml_parser.h\"\n+\n+namespace libcamera {\n+\n+namespace {\n+const std::vector<std::filesystem::path> globalConfigurationFiles = {\n+\tstd::filesystem::path(LIBCAMERA_SYSCONF_DIR) / \"configuration.yaml\",\n+\tstd::filesystem::path(LIBCAMERA_DATA_DIR) / \"configuration.yaml\",\n+};\n+}\n+\n+LOG_DEFINE_CATEGORY(Configuration)\n+\n+/**\n+ * \\class GlobalConfiguration\n+ * \\brief Support for global libcamera configuration\n+ *\n+ * The configuration file is a YAML file and the configuration itself is stored\n+ * under `configuration' top-level item.\n+ *\n+ * The configuration file is looked up in user's home directory first and if it\n+ * is not found then in system-wide configuration directories. If multiple\n+ * configuration files exist then only the first one found is used and no\n+ * configuration merging is performed.\n+ */\n+\n+bool GlobalConfiguration::loadFile(const std::filesystem::path &fileName)\n+{\n+\tFile file(fileName);\n+\tif (!file.open(File::OpenModeFlag::ReadOnly)) {\n+\t\tif (file.error() == -ENOENT)\n+\t\t\treturn false;\n+\n+\t\tLOG(Configuration, Error)\n+\t\t\t<< \"Failed to open configuration file \" << fileName;\n+\t\treturn true;\n+\t}\n+\n+\tstd::unique_ptr<YamlObject> configuration = YamlParser::parse(file);\n+\tif (!configuration) {\n+\t\tLOG(Configuration, Error)\n+\t\t\t<< \"Failed to parse configuration file \" << fileName;\n+\t\treturn true;\n+\t}\n+\n+\tyamlConfiguration_ = std::move(configuration);\n+\treturn true;\n+}\n+\n+void GlobalConfiguration::load()\n+{\n+\tstd::filesystem::path userConfigurationDirectory;\n+\tconst char *xdgConfigHome = utils::secure_getenv(\"XDG_CONFIG_HOME\");\n+\tif (xdgConfigHome) {\n+\t\tuserConfigurationDirectory = xdgConfigHome;\n+\t} else {\n+\t\tconst char *home = utils::secure_getenv(\"HOME\");\n+\t\tif (home)\n+\t\t\tuserConfigurationDirectory =\n+\t\t\t\tstd::filesystem::path(home) / \".config\";\n+\t}\n+\n+\tif (!userConfigurationDirectory.empty()) {\n+\t\tstd::filesystem::path user_configuration_file =\n+\t\t\tuserConfigurationDirectory / \"libcamera\" / \"configuration.yaml\";\n+\t\tif (loadFile(user_configuration_file))\n+\t\t\treturn;\n+\t}\n+\n+\tfor (const auto &path : globalConfigurationFiles) {\n+\t\tif (loadFile(path))\n+\t\t\treturn;\n+\t}\n+}\n+\n+/**\n+ * \\brief Initialize the global configuration\n+ */\n+GlobalConfiguration::GlobalConfiguration()\n+{\n+\tload();\n+}\n+\n+/**\n+ * \\typedef GlobalConfiguration::Configuration\n+ * \\brief Type representing global libcamera configuration\n+ *\n+ * All code outside GlobalConfiguration must use this type declaration and not\n+ * the underlying type.\n+ */\n+\n+/**\n+ * \\brief Return configuration version\n+ *\n+ * The version is (optionally) declared in the configuration file in the\n+ * top-level section `version', alongside `configuration'. This has currently no\n+ * real use but may be needed in future if configuration incompatibilities\n+ * occur.\n+ *\n+ * \\return Configuration version as declared in the configuration file or 0 if\n+ * no version is declared there\n+ */\n+unsigned int GlobalConfiguration::version() const\n+{\n+\treturn (*yamlConfiguration_)[\"version\"].get<unsigned int>().value_or(0);\n+}\n+\n+/**\n+ * \\brief Return libcamera global configuration\n+ *\n+ * This returns the whole configuration stored in the top-level section\n+ * `configuration' of the YAML configuration file.\n+ *\n+ * The requested part of the configuration can be accessed using \\a YamlObject\n+ * methods.\n+ *\n+ * \\note \\a YamlObject type itself shouldn't be used in type declarations to\n+ * avoid trouble if we decide to change the underlying data objects in future.\n+ *\n+ * \\return The whole configuration section\n+ */\n+GlobalConfiguration::Configuration GlobalConfiguration::configuration() const\n+{\n+\treturn (*yamlConfiguration_)[\"configuration\"];\n+}\n+\n+} /* namespace libcamera */\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex de1eb99b2..275cf5a4b 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -31,6 +31,7 @@ libcamera_internal_sources = files([\n     'device_enumerator_sysfs.cpp',\n     'dma_buf_allocator.cpp',\n     'formats.cpp',\n+    'global_configuration.cpp',\n     'ipa_controls.cpp',\n     'ipa_data_serializer.cpp',\n     'ipa_interface.cpp',\n",
    "prefixes": [
        "v15",
        "01/12"
    ]
}