From patchwork Tue Mar 26 11:24:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 19813 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 10E52C32CA for ; Tue, 26 Mar 2024 11:26:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7EE7E6336F; Tue, 26 Mar 2024 12:26:35 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="XM257og2"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9845E6331B for ; Tue, 26 Mar 2024 12:26:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711452379; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZOpqgvP0/AzliHmux1yBNzHqutaIO8zDnOdJa0JHxP8=; b=XM257og2xve+NIOw68W0FZLVtUoXumadVI7XGMEG02muqvz550kjEg1nxrp00eXOmeDb92 lJvw6Nj4vKqRQ1exbedlECwBnlfYoveTT8p/87ASzPp5J+af6L744GMVJZ48RkxmCA5qvH v9twa3Kikl9CUj1bbaV74BVC8HqCEbE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-438-9DbREjoKPSuP5Udupxeqbw-1; Tue, 26 Mar 2024 07:26:18 -0400 X-MC-Unique: 9DbREjoKPSuP5Udupxeqbw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9DA01101A526 for ; Tue, 26 Mar 2024 11:26:15 +0000 (UTC) Received: from nuthatch.brq.redhat.com (unknown [10.43.17.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 110003C22; Tue, 26 Mar 2024 11:26:14 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal Subject: [RFC PATCH 01/11] config: Introduce global runtime configuration Date: Tue, 26 Mar 2024 12:24:04 +0100 Message-ID: <20240326112419.503286-2-mzamazal@redhat.com> In-Reply-To: <20240326112419.503286-1-mzamazal@redhat.com> References: <20240326112419.503286-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Currently, libcamera can be configured in runtime using several environment variables. With introducing more and more variables, this mechanism reaches its limits. It would be simpler and more flexible if it was possible to configure libcamera in a single file. For example, there have been a request for defining pipeline precedence in runtime. We want to have support for multiple pipelines compiled in order to have single packages in distributions. And then being able to select among them as needed based on the particular hardware or operating system environment. This can for example allow easy switching between hardware, CPU or GPU IPAs. Another possible use case is tuning image output, especially with software ISP, to user liking. For example, some users may prefer higher contrast without the need to use the corresponding knobs, if present at all, in every application. This patch introduces basic support for configuration files. GlobalConfiguration class reads, stores and adds access to the configuration. Its instance is stored as a singleton and be accessed using a static method of the class. libcamera configuration can be specified using a system-wide configuration file or a user configuration file. The user configuration file take precedence if present. There is currently no way to merge multiple configuration files, the one found is used as the only configuration file. If no configuration file is present, nothing changes to the current libcamera behavior (except for some log messages). The configuration file is a YAML file, we already have a mechanism for handling YAML configuration files in libcamera and the given infrastructure can be reused for the purpose. However, the configuration type is abstracted to make contingent future change of the underlying class easier, if retaining (most of) its API. The configuration is versioned. This has currently no particular meaning but is likely to have its purpose in future, especially once configuration validation is introduced. The configuration YAML file looks as follows: --- version: 1 configuration: WHATEVER CONFIGURATION NEEDED This patch introduces just the basic idea. Actually using the configuration in the corresponding places (everything what is currently configurable via environment variables should be configurable in the file configuration), refining the mechanism (e.g. configuration file validation to avoid mistakes caused by typos) and other improvements will be addressed in followup patches. GlobalConfiguration is meant to be used as a globally accessible singleton. There is currently no reason to have more than one instance. Signed-off-by: Milan Zamazal --- .../libcamera/internal/global_configuration.h | 44 ++++++ include/libcamera/internal/meson.build | 1 + src/libcamera/global_configuration.cpp | 132 ++++++++++++++++++ src/libcamera/meson.build | 1 + 4 files changed, 178 insertions(+) create mode 100644 include/libcamera/internal/global_configuration.h create mode 100644 src/libcamera/global_configuration.cpp diff --git a/include/libcamera/internal/global_configuration.h b/include/libcamera/internal/global_configuration.h new file mode 100644 index 00000000..0a4f3c02 --- /dev/null +++ b/include/libcamera/internal/global_configuration.h @@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2024 Red Hat, inc. + * + * global_configuration.h - Global configuration handling + */ + +#pragma once + +#include +#include + +#include "libcamera/internal/yaml_parser.h" + +namespace libcamera { + +class GlobalConfiguration +{ +public: + /** + * \brief Type representing global libcamera configuration. + * + * All code outside GlobalConfiguration must use this type and not the + * underlying type. + */ + using Configuration = const YamlObject &; + + static unsigned int version(); + static Configuration configuration(); + +private: + static const std::vector globalConfigurationFiles; + + bool initialized_; + std::unique_ptr configuration_; + + GlobalConfiguration(); + bool loadFile(const std::filesystem::path &fileName); + void load(); + static const GlobalConfiguration &instance(); + static Configuration get(); +}; + +} /* namespace libcamera */ diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build index 160fdc37..640a54aa 100644 --- a/include/libcamera/internal/meson.build +++ b/include/libcamera/internal/meson.build @@ -28,6 +28,7 @@ libcamera_internal_headers = files([ 'dma_heaps.h', 'formats.h', 'framebuffer.h', + 'global_configuration.h', 'ipa_manager.h', 'ipa_module.h', 'ipa_proxy.h', diff --git a/src/libcamera/global_configuration.cpp b/src/libcamera/global_configuration.cpp new file mode 100644 index 00000000..72c3ce26 --- /dev/null +++ b/src/libcamera/global_configuration.cpp @@ -0,0 +1,132 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2024 Red Hat, inc. + * + * global_configuration.cpp - Global configuration handling + */ + +#include "libcamera/internal/global_configuration.h" + +#include +#include +#include +#include + +#include +#include + +#include "libcamera/internal/yaml_parser.h" + +#include "libcamera/base/utils.h" + +namespace libcamera { + +LOG_DEFINE_CATEGORY(Configuration) + +/** + * \class GlobalConfiguration + * \brief Support for global libcamera configuration + * + * ... + */ + +GlobalConfiguration::GlobalConfiguration() + : initialized_(false), configuration_(std::make_unique()) +{ +} + +const std::vector + GlobalConfiguration::globalConfigurationFiles = { + std::filesystem::path(LIBCAMERA_SYSCONF_DIR) / "configuration.yaml", + std::filesystem::path("/etc/libcamera/configuration.yaml"), + }; + +void GlobalConfiguration::load() +{ + std::filesystem::path userConfigurationDirectory; + char *xdgConfigHome = utils::secure_getenv("XDG_CONFIG_HOME"); + if (xdgConfigHome) { + userConfigurationDirectory = xdgConfigHome; + } else { + const char *home = utils::secure_getenv("HOME"); + if (home) + userConfigurationDirectory = + std::filesystem::path(home) / ".config"; + } + + if (!userConfigurationDirectory.empty()) { + std::filesystem::path user_configuration_file = + userConfigurationDirectory / "libcamera" / "configuration.yaml"; + if (loadFile(user_configuration_file)) + return; + } + + for (auto path : globalConfigurationFiles) + if (loadFile(path)) + return; + + initialized_ = true; + LOG(Configuration, Debug) << "No configuration file found"; +} + +bool GlobalConfiguration::loadFile(const std::filesystem::path &fileName) +{ + File file(fileName); + if (!file.exists()) { + return false; + } + + if (!file.open(File::OpenModeFlag::ReadOnly)) { + LOG(Configuration, Warning) + << "Failed to open configuration file '" << fileName << "'"; + return true; + } + + auto root = YamlParser::parse(file); + if (!root) { + LOG(Configuration, Warning) << "Failed to parse configuration file " + << fileName; + return true; + } + configuration_ = std::move(root); + initialized_ = true; + LOG(Configuration, Info) << "Configuration file " << fileName << "loaded"; + + return true; +} + +const GlobalConfiguration &GlobalConfiguration::instance() +{ + static GlobalConfiguration configuration; + if (!configuration.initialized_) { + configuration.load(); + } + return configuration; +} + +GlobalConfiguration::Configuration GlobalConfiguration::get() +{ + return (*instance().configuration_); +} + +/** + * \brief Return configuration version. + * + * ... + */ +unsigned int GlobalConfiguration::version() +{ + return get()["version"].get().value_or(0); +} + +/** + * \brief Return libcamera global configuration. + * + * ... + */ +GlobalConfiguration::Configuration GlobalConfiguration::configuration() +{ + return get()["configuration"]; +} + +} /* namespace libcamera */ diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build index a3b12bc1..b81c75b8 100644 --- a/src/libcamera/meson.build +++ b/src/libcamera/meson.build @@ -21,6 +21,7 @@ libcamera_sources = files([ 'framebuffer.cpp', 'framebuffer_allocator.cpp', 'geometry.cpp', + 'global_configuration.cpp', 'ipa_controls.cpp', 'ipa_data_serializer.cpp', 'ipa_interface.cpp', From patchwork Tue Mar 26 11:24:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 19803 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 68A31BD160 for ; Tue, 26 Mar 2024 11:26:21 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1939963334; Tue, 26 Mar 2024 12:26:21 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="PkY9D7Ws"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 69D4A63037 for ; Tue, 26 Mar 2024 12:26:19 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711452378; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Br90tOxDYLy2ge9WS76qMTdULqiTbJc5OrIYbqwZJbM=; b=PkY9D7Wsqda6HFSlUJCRG4/fwxhtIjUXVkL09iecPdB1pHrtQMz+gW2C9fmR0NvSqQte+Y A6S2Lkjz7eQrGMSm9C3tFYGB+1R6rxFBRgPg7mrF7cceq1PlFs7FIuIkNCsWKf9EcSYPnt NcX4Wsz66H5mFthCXD1a5Nelc/S0sZY= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-292-wQPZS5yUPdOkn9aWpdD-yA-1; Tue, 26 Mar 2024 07:26:16 -0400 X-MC-Unique: wQPZS5yUPdOkn9aWpdD-yA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4FA633C0D7B7 for ; Tue, 26 Mar 2024 11:26:16 +0000 (UTC) Received: from nuthatch.brq.redhat.com (unknown [10.43.17.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id D2C313C54; Tue, 26 Mar 2024 11:26:15 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal Subject: [RFC PATCH 02/11] config: Move global configuration to base Date: Tue, 26 Mar 2024 12:24:05 +0100 Message-ID: <20240326112419.503286-3-mzamazal@redhat.com> In-Reply-To: <20240326112419.503286-1-mzamazal@redhat.com> References: <20240326112419.503286-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Global configuration may be used by some components from base, most notably logging. This means the configuration must also be present in base. And YAML object and parsing too. Let's move it all there. Signed-off-by: Milan Zamazal --- src/libcamera/{ => base}/global_configuration.cpp | 0 src/libcamera/base/meson.build | 15 +++++++++++++++ src/libcamera/{ => base}/yaml_parser.cpp | 0 src/libcamera/meson.build | 15 --------------- 4 files changed, 15 insertions(+), 15 deletions(-) rename src/libcamera/{ => base}/global_configuration.cpp (100%) rename src/libcamera/{ => base}/yaml_parser.cpp (100%) diff --git a/src/libcamera/global_configuration.cpp b/src/libcamera/base/global_configuration.cpp similarity index 100% rename from src/libcamera/global_configuration.cpp rename to src/libcamera/base/global_configuration.cpp diff --git a/src/libcamera/base/meson.build b/src/libcamera/base/meson.build index 7a7fd7e4..b71d3e23 100644 --- a/src/libcamera/base/meson.build +++ b/src/libcamera/base/meson.build @@ -9,6 +9,7 @@ libcamera_base_sources = files([ 'event_notifier.cpp', 'file.cpp', 'flags.cpp', + 'global_configuration.cpp', 'log.cpp', 'message.cpp', 'mutex.cpp', @@ -20,10 +21,12 @@ libcamera_base_sources = files([ 'timer.cpp', 'unique_fd.cpp', 'utils.cpp', + 'yaml_parser.cpp', ]) libdw = dependency('libdw', required : false) libunwind = dependency('libunwind', required : false) +libyaml = dependency('yaml-0.1', required : false) if cc.has_header_symbol('execinfo.h', 'backtrace') config_h.set('HAVE_BACKTRACE', 1) @@ -37,11 +40,23 @@ if libunwind.found() config_h.set('HAVE_UNWIND', 1) endif +# Fallback to a subproject if libyaml isn't found, as it's not packaged in AOSP. +if not libyaml.found() + cmake = import('cmake') + + libyaml_vars = cmake.subproject_options() + libyaml_vars.add_cmake_defines({'CMAKE_POSITION_INDEPENDENT_CODE': 'ON'}) + libyaml_vars.append_compile_args('c', '-Wno-unused-value') + libyaml_wrap = cmake.subproject('libyaml', options : libyaml_vars) + libyaml = libyaml_wrap.dependency('yaml') +endif + libcamera_base_deps = [ libatomic, libdw, libthreads, libunwind, + libyaml, ] # Internal components must use the libcamera_base_private dependency to enable diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/base/yaml_parser.cpp similarity index 100% rename from src/libcamera/yaml_parser.cpp rename to src/libcamera/base/yaml_parser.cpp diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build index b81c75b8..fb1ce3fc 100644 --- a/src/libcamera/meson.build +++ b/src/libcamera/meson.build @@ -21,7 +21,6 @@ libcamera_sources = files([ 'framebuffer.cpp', 'framebuffer_allocator.cpp', 'geometry.cpp', - 'global_configuration.cpp', 'ipa_controls.cpp', 'ipa_data_serializer.cpp', 'ipa_interface.cpp', @@ -49,7 +48,6 @@ libcamera_sources = files([ 'v4l2_pixelformat.cpp', 'v4l2_subdevice.cpp', 'v4l2_videodevice.cpp', - 'yaml_parser.cpp', ]) libcamera_sources += libcamera_public_headers @@ -81,7 +79,6 @@ if not cc.has_function('dlopen') libdl = cc.find_library('dl') endif libudev = dependency('libudev', required : get_option('udev')) -libyaml = dependency('yaml-0.1', required : false) # Use one of gnutls or libcrypto (provided by OpenSSL), trying gnutls first. libcrypto = dependency('gnutls', required : false) @@ -117,17 +114,6 @@ if libudev.found() ]) endif -# Fallback to a subproject if libyaml isn't found, as it's not packaged in AOSP. -if not libyaml.found() - cmake = import('cmake') - - libyaml_vars = cmake.subproject_options() - libyaml_vars.add_cmake_defines({'CMAKE_POSITION_INDEPENDENT_CODE': 'ON'}) - libyaml_vars.append_compile_args('c', '-Wno-unused-value') - libyaml_wrap = cmake.subproject('libyaml', options : libyaml_vars) - libyaml = libyaml_wrap.dependency('yaml') -endif - control_sources = [] controls_mode_files = { @@ -183,7 +169,6 @@ libcamera_deps += [ libdl, liblttng, libudev, - libyaml, ] # We add '/' to the build_rpath as a 'safe' path to act as a boolean flag. From patchwork Tue Mar 26 11:24:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 19804 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 E1697C32C1 for ; Tue, 26 Mar 2024 11:26:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7D68A6331B; Tue, 26 Mar 2024 12:26:22 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="H4fS+A8J"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0604063037 for ; Tue, 26 Mar 2024 12:26:19 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711452379; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tGxlXOyKjix+rj0eDrpR96gXNd4Z7usawprtl1OpE9w=; b=H4fS+A8J63+/6lxGfii9viGuMEcAFwhS7rFXHCz07ph+CFHwzKkrsnV7yKKRsEZeUkTNAh wGkAj+UJC4iULUNdh++7ohn1GxxI4Kdyt7Tjr8/jAz2LsJQf6HbEldJmjgnmFCT8dRoEG0 twH55mujD0BRmwwK9rSqXwIGg1XYVx4= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-375-DnJ2tQljP36u1mbAjoJS3A-1; Tue, 26 Mar 2024 07:26:17 -0400 X-MC-Unique: DnJ2tQljP36u1mbAjoJS3A-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 012543C0D7B5 for ; Tue, 26 Mar 2024 11:26:17 +0000 (UTC) Received: from nuthatch.brq.redhat.com (unknown [10.43.17.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 83DB53C22; Tue, 26 Mar 2024 11:26:16 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal Subject: [RFC PATCH 03/11] config: Look up logging levels in the configuration file Date: Tue, 26 Mar 2024 12:24:06 +0100 Message-ID: <20240326112419.503286-4-mzamazal@redhat.com> In-Reply-To: <20240326112419.503286-1-mzamazal@redhat.com> References: <20240326112419.503286-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" In addition to LIBCAMERA_LOG_LEVELS environment variable, expose the same configuration in the configuration file. Because logging asks for configuration and configuration loading uses logging, extra care is needed. We must prevent calling any log function before configuration is logged. Otherwise the log function would ask for configuration, it would load the configuration files and would try to log the results, which would cause mutex deadlock due to calling logging inside logging. Not logging in configuration is not an option, at least without introducing complicated mechanism such as delayed logging, because we need to log at least errors when reading the configuration. We must also log in configuration loading only after the configuration is loaded and available (or there is an error in loading the configuration). Otherwise logging would see an empty configuration and wouldn't be configured as asked. Preventing logging before configuration is loaded is ensured by asking for configuration in CameraManager constructor and in IPAManager constructor (which is mysteriously loaded from CameraManager constructor before its body is executed). This seems to be sufficient at least for software ISP. The configuration snippet for logging looks as follows: configuration: log: levels: LIBCAMERA_LOG_LEVELS Signed-off-by: Milan Zamazal --- src/libcamera/base/global_configuration.cpp | 11 ++++++++++- src/libcamera/base/log.cpp | 12 ++++++++++-- src/libcamera/camera_manager.cpp | 9 +++++++++ src/libcamera/ipa_manager.cpp | 12 ++++++++++++ 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/libcamera/base/global_configuration.cpp b/src/libcamera/base/global_configuration.cpp index 72c3ce26..e9c44057 100644 --- a/src/libcamera/base/global_configuration.cpp +++ b/src/libcamera/base/global_configuration.cpp @@ -41,6 +41,11 @@ const std::vector std::filesystem::path("/etc/libcamera/configuration.yaml"), }; +/* + * Care is needed here to not log anything before the configuration is + * loaded otherwise the logger would be initialized with empty configuration. + */ + void GlobalConfiguration::load() { std::filesystem::path userConfigurationDirectory; @@ -71,10 +76,15 @@ void GlobalConfiguration::load() bool GlobalConfiguration::loadFile(const std::filesystem::path &fileName) { + /* + * initialized_ must be set to true before any logging is called! + */ + File file(fileName); if (!file.exists()) { return false; } + initialized_ = true; if (!file.open(File::OpenModeFlag::ReadOnly)) { LOG(Configuration, Warning) @@ -89,7 +99,6 @@ bool GlobalConfiguration::loadFile(const std::filesystem::path &fileName) return true; } configuration_ = std::move(root); - initialized_ = true; LOG(Configuration, Info) << "Configuration file " << fileName << "loaded"; return true; diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp index c8045ef7..0564306d 100644 --- a/src/libcamera/base/log.cpp +++ b/src/libcamera/base/log.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -25,6 +26,8 @@ #include #include +#include "libcamera/internal/global_configuration.h" + /** * \file base/log.h * \brief Logging infrastructure @@ -626,8 +629,13 @@ void Logger::parseLogFile() void Logger::parseLogLevels() { const char *debug = utils::secure_getenv("LIBCAMERA_LOG_LEVELS"); - if (!debug) - return; + if (!debug) { + const std::optional confDebug = + GlobalConfiguration::configuration()["log"]["levels"].get(); + if (!confDebug.has_value()) + return; + debug = confDebug.value().c_str(); + } for (const char *pair = debug; *debug != '\0'; pair = debug) { const char *comma = strchrnul(debug, ','); diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp index 355f3ada..cff8e80c 100644 --- a/src/libcamera/camera_manager.cpp +++ b/src/libcamera/camera_manager.cpp @@ -15,6 +15,7 @@ #include "libcamera/internal/camera.h" #include "libcamera/internal/device_enumerator.h" +#include "libcamera/internal/global_configuration.h" #include "libcamera/internal/pipeline_handler.h" /** @@ -37,6 +38,14 @@ LOG_DEFINE_CATEGORY(Camera) CameraManager::Private::Private() : initialized_(false) { + /* + * This is needed to initialize global configuration + * before any logging is called. Actually, IPAManager + * constructor is called before this, so the configuration + * call is superfluous here, but the initialization belongs + * here. + */ + GlobalConfiguration::configuration(); } int CameraManager::Private::start() diff --git a/src/libcamera/ipa_manager.cpp b/src/libcamera/ipa_manager.cpp index 7a4515d9..5104b930 100644 --- a/src/libcamera/ipa_manager.cpp +++ b/src/libcamera/ipa_manager.cpp @@ -16,6 +16,7 @@ #include #include +#include "libcamera/internal/global_configuration.h" #include "libcamera/internal/ipa_module.h" #include "libcamera/internal/ipa_proxy.h" #include "libcamera/internal/pipeline_handler.h" @@ -105,6 +106,17 @@ IPAManager *IPAManager::self_ = nullptr; */ IPAManager::IPAManager() { + /* + * Make sure configuration is loaded early. + * Otherwise there would be problems with mutual + * configuration-logging dependencies. + * + * This is needed to be here in addition to CameraManager constructor + * because logging is called before CameraManager constructor body is + * executed. + */ + GlobalConfiguration::configuration(); + if (self_) LOG(IPAManager, Fatal) << "Multiple IPAManager objects are not allowed"; From patchwork Tue Mar 26 11:24:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 19805 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 83957BD160 for ; Tue, 26 Mar 2024 11:26:24 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 35AD063334; Tue, 26 Mar 2024 12:26:23 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="KTivKatl"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D4D606331B for ; Tue, 26 Mar 2024 12:26:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711452379; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NGQUOluWVd3l2g+6aByZJMX68em3b48gIEq3iXmWcts=; b=KTivKatlF6Qp23Unugv4KYTWH7sRCirWGdY2VPpjY8povV97ZiY8gi9XV5OIxFXJVCBoe2 /cUdIuXzgrt2k5my4zm6qOwzhHZrmBdj7AGxcjjPH1EeLNPSLHSQm/Z2sGhE2p7ECmg1Hf ZWTTLZwZSplx3+9AvXn/98ZX0nJ4I4E= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-450-a4MzkkZcNGSRqN5bA13ezA-1; Tue, 26 Mar 2024 07:26:17 -0400 X-MC-Unique: a4MzkkZcNGSRqN5bA13ezA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id ADA7784B162 for ; Tue, 26 Mar 2024 11:26:17 +0000 (UTC) Received: from nuthatch.brq.redhat.com (unknown [10.43.17.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 357CC3C22; Tue, 26 Mar 2024 11:26:17 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal Subject: [RFC PATCH 04/11] config: Add configuration retrieval helpers Date: Tue, 26 Mar 2024 12:24:07 +0100 Message-ID: <20240326112419.503286-5-mzamazal@redhat.com> In-Reply-To: <20240326112419.503286-1-mzamazal@redhat.com> References: <20240326112419.503286-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Due to the restrictions of YamlObject class, ugly type casting dance is needed. Signed-off-by: Milan Zamazal --- .../libcamera/internal/global_configuration.h | 4 +++ src/libcamera/base/global_configuration.cpp | 28 +++++++++++++++++++ src/libcamera/base/log.cpp | 13 ++++----- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/include/libcamera/internal/global_configuration.h b/include/libcamera/internal/global_configuration.h index 0a4f3c02..41ac57cf 100644 --- a/include/libcamera/internal/global_configuration.h +++ b/include/libcamera/internal/global_configuration.h @@ -8,6 +8,7 @@ #pragma once #include +#include #include #include "libcamera/internal/yaml_parser.h" @@ -27,6 +28,9 @@ public: static unsigned int version(); static Configuration configuration(); + static std::optional option(const char *const confPath); + static std::optional envOption(const char *const envVariable, + const char *const confPath); private: static const std::vector globalConfigurationFiles; diff --git a/src/libcamera/base/global_configuration.cpp b/src/libcamera/base/global_configuration.cpp index e9c44057..b29f452b 100644 --- a/src/libcamera/base/global_configuration.cpp +++ b/src/libcamera/base/global_configuration.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -118,6 +119,33 @@ GlobalConfiguration::Configuration GlobalConfiguration::get() return (*instance().configuration_); } +/** + * \brief Retrieve string configuration identified by the given string + * ... + */ +std::optional GlobalConfiguration::option( + const char *const confPath) +{ + YamlObject *c = &const_cast(configuration()); + for (auto part : utils::details::StringSplitter(confPath, ".")) + c = &const_cast((*c)[part]); + return c->get(); +} + +/** + * \brief Retrieve string configuration from the given environment variable or configuration + * ... + */ +std::optional GlobalConfiguration::envOption( + const char *const envVariable, + const char *const confPath) +{ + const char *envValue = utils::secure_getenv(envVariable); + if (envValue) + return std::optional{ std::string{ envValue } }; + return option(confPath); +} + /** * \brief Return configuration version. * diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp index 0564306d..7e58e4f9 100644 --- a/src/libcamera/base/log.cpp +++ b/src/libcamera/base/log.cpp @@ -628,14 +628,11 @@ void Logger::parseLogFile() */ void Logger::parseLogLevels() { - const char *debug = utils::secure_getenv("LIBCAMERA_LOG_LEVELS"); - if (!debug) { - const std::optional confDebug = - GlobalConfiguration::configuration()["log"]["levels"].get(); - if (!confDebug.has_value()) - return; - debug = confDebug.value().c_str(); - } + const std::optional confDebug = + GlobalConfiguration::envOption("LIBCAMERA_LOG_LEVELS", "log.levels"); + if (!confDebug.has_value()) + return; + const char *debug = confDebug.value().c_str(); for (const char *pair = debug; *debug != '\0'; pair = debug) { const char *comma = strchrnul(debug, ','); From patchwork Tue Mar 26 11:24:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 19807 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 BC389C32C1 for ; Tue, 26 Mar 2024 11:26:28 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 333BD6332E; Tue, 26 Mar 2024 12:26:28 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="H7DObWjj"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id ABE256333B for ; Tue, 26 Mar 2024 12:26:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711452380; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+ReI+rMpjT3lfZesYrbQhHsFMUUrygKVbQtLH/oCUPY=; b=H7DObWjj2y1caL8Kw7VnZ/dj72cgcNuXTSswOAEnbntFfiixCj2LBhlqxp14H3cEZqNBlh k2zoCFl8Z+mbMAFompaPZXyynouAzAAFuTrGYfvoOciz+ptSKkI+4SWCQE286uqLteXKWH ANKYggRfat7qrp92XrJN7qggrhgvXYs= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-441-nzEwsg7hN6m3j5yZCwgYIg-1; Tue, 26 Mar 2024 07:26:18 -0400 X-MC-Unique: nzEwsg7hN6m3j5yZCwgYIg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 651D4185A784 for ; Tue, 26 Mar 2024 11:26:18 +0000 (UTC) Received: from nuthatch.brq.redhat.com (unknown [10.43.17.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id E2FC23C22; Tue, 26 Mar 2024 11:26:17 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal Subject: [RFC PATCH 05/11] config: Look up log file in configuration file Date: Tue, 26 Mar 2024 12:24:08 +0100 Message-ID: <20240326112419.503286-6-mzamazal@redhat.com> In-Reply-To: <20240326112419.503286-1-mzamazal@redhat.com> References: <20240326112419.503286-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" This requires change in LIBCAMERA_LOG_FILE interpretation so that we can disable the log file in isolated processes. If LIBCAMERA_LOG_FILE is defined but empty, it means there is no log file, even if defined in the configuration file. This should cause no compatibility trouble since opening a file with an empty name makes little sense. The configuration snippet: configuration: log: file: FILENAME Signed-off-by: Milan Zamazal --- src/libcamera/base/log.cpp | 13 +++++++++---- src/libcamera/process.cpp | 11 ++++++++--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp index 7e58e4f9..a373d38b 100644 --- a/src/libcamera/base/log.cpp +++ b/src/libcamera/base/log.cpp @@ -607,16 +607,21 @@ Logger::Logger() */ void Logger::parseLogFile() { - const char *file = utils::secure_getenv("LIBCAMERA_LOG_FILE"); - if (!file) + std::optional file = + GlobalConfiguration::envOption("LIBCAMERA_LOG_FILE", "log.file"); + if (!file.has_value()) return; - if (!strcmp(file, "syslog")) { + auto fileValue = file.value(); + if (fileValue == "") + return; + + if (fileValue != "syslog") { logSetTarget(LoggingTargetSyslog); return; } - logSetFile(file, false); + logSetFile(fileValue.c_str(), false); } /** diff --git a/src/libcamera/process.cpp b/src/libcamera/process.cpp index 86a382fb..4bfce285 100644 --- a/src/libcamera/process.cpp +++ b/src/libcamera/process.cpp @@ -12,7 +12,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -24,6 +26,8 @@ #include #include +#include "libcamera/internal/global_configuration.h" + /** * \file process.h * \brief Process object @@ -263,9 +267,10 @@ int Process::start(const std::string &path, closeAllFdsExcept(fds); - const char *file = utils::secure_getenv("LIBCAMERA_LOG_FILE"); - if (file && strcmp(file, "syslog")) - unsetenv("LIBCAMERA_LOG_FILE"); + std::optional file = + GlobalConfiguration::envOption("LIBCAMERA_LOG_FILE", "log.file"); + if (file.has_value() && file.value() != "syslog") + setenv("LIBCAMERA_LOG_FILE", "", 1); const char **argv = new const char *[args.size() + 2]; unsigned int len = args.size(); From patchwork Tue Mar 26 11:24:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 19806 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 65AB2BD160 for ; Tue, 26 Mar 2024 11:26:27 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 186DB63361; Tue, 26 Mar 2024 12:26:27 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="cCmuAYZ2"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BC7A36333E for ; Tue, 26 Mar 2024 12:26:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711452380; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wPiQFiIlDaGgBq0SquSq1dWwBimKRK9z13gS7ic6Tn4=; b=cCmuAYZ2t7L6Q8xho3G8THgU+xPjWKIXQxXCddU3oricdE/2Y6WYkqBu5PzvRRa0V0bPL0 1kQ4fK4Mi42UOY5QUwaT0jGFSKXgCCigzgQZkRTnzcBVLB+ZSDSK7fq7ehiNWOx/+U6f5w YVUihPzb41PArZM1sKwNI6h64qmG+fs= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-386-S4bfWoVfPVmddN7sH1rbYQ-1; Tue, 26 Mar 2024 07:26:19 -0400 X-MC-Unique: S4bfWoVfPVmddN7sH1rbYQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1A6B9800264 for ; Tue, 26 Mar 2024 11:26:19 +0000 (UTC) Received: from nuthatch.brq.redhat.com (unknown [10.43.17.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9AAA43C20; Tue, 26 Mar 2024 11:26:18 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal Subject: [RFC PATCH 06/11] config: Look up log color configuration in configuration file Date: Tue, 26 Mar 2024 12:24:09 +0100 Message-ID: <20240326112419.503286-7-mzamazal@redhat.com> In-Reply-To: <20240326112419.503286-1-mzamazal@redhat.com> References: <20240326112419.503286-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The configuration snippet: configuration: log: color: BOOL In order to use the global configuration access helper for a boolean value, we must make a template from it. To make the template visible, we must implement it in the header file, otherwise undefined reference error would be reported when linking. We don't implement envOption helper for boolean here, because we would have to deal with a specific value interpretation in this particular case. Signed-off-by: Milan Zamazal --- .../libcamera/internal/global_configuration.h | 17 ++++++++++++++++- src/libcamera/base/global_configuration.cpp | 17 +---------------- src/libcamera/base/log.cpp | 2 ++ 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/include/libcamera/internal/global_configuration.h b/include/libcamera/internal/global_configuration.h index 41ac57cf..67684762 100644 --- a/include/libcamera/internal/global_configuration.h +++ b/include/libcamera/internal/global_configuration.h @@ -13,6 +13,8 @@ #include "libcamera/internal/yaml_parser.h" +#include "libcamera/base/utils.h" + namespace libcamera { class GlobalConfiguration @@ -28,7 +30,20 @@ public: static unsigned int version(); static Configuration configuration(); - static std::optional option(const char *const confPath); + + /** + * \brief Retrieve string configuration identified by the given string + * ... + */ + template + static std::optional option(const char *const confPath) + { + YamlObject *c = &const_cast(configuration()); + for (auto part : utils::details::StringSplitter(confPath, ".")) + c = &const_cast((*c)[part]); + return c->get(); + } + static std::optional envOption(const char *const envVariable, const char *const confPath); diff --git a/src/libcamera/base/global_configuration.cpp b/src/libcamera/base/global_configuration.cpp index b29f452b..1e7a4caa 100644 --- a/src/libcamera/base/global_configuration.cpp +++ b/src/libcamera/base/global_configuration.cpp @@ -18,8 +18,6 @@ #include "libcamera/internal/yaml_parser.h" -#include "libcamera/base/utils.h" - namespace libcamera { LOG_DEFINE_CATEGORY(Configuration) @@ -119,19 +117,6 @@ GlobalConfiguration::Configuration GlobalConfiguration::get() return (*instance().configuration_); } -/** - * \brief Retrieve string configuration identified by the given string - * ... - */ -std::optional GlobalConfiguration::option( - const char *const confPath) -{ - YamlObject *c = &const_cast(configuration()); - for (auto part : utils::details::StringSplitter(confPath, ".")) - c = &const_cast((*c)[part]); - return c->get(); -} - /** * \brief Retrieve string configuration from the given environment variable or configuration * ... @@ -143,7 +128,7 @@ std::optional GlobalConfiguration::envOption( const char *envValue = utils::secure_getenv(envVariable); if (envValue) return std::optional{ std::string{ envValue } }; - return option(confPath); + return option(confPath); } /** diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp index a373d38b..19403378 100644 --- a/src/libcamera/base/log.cpp +++ b/src/libcamera/base/log.cpp @@ -590,6 +590,8 @@ void Logger::logSetLevel(const char *category, const char *level) Logger::Logger() { bool color = !utils::secure_getenv("LIBCAMERA_LOG_NO_COLOR"); + if (color) + color = GlobalConfiguration::option("log.color").value_or(true); logSetStream(&std::cerr, color); parseLogFile(); From patchwork Tue Mar 26 11:24:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 19808 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 D8FA2BD160 for ; Tue, 26 Mar 2024 11:26:29 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 67E9763334; Tue, 26 Mar 2024 12:26:29 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="LLsgaIEo"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4CDA163352 for ; Tue, 26 Mar 2024 12:26:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711452382; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MVGknVDHOYLDP9mCKW76NFv1VKmGr/3QBYY2Odjh9PM=; b=LLsgaIEoXduUdZy7RbIvEufoPBem6VF8ZrMfZn4iXfLYpWy8TZ0rMpWUnqtgfZWRaHFP2Q RPQZlPAEjLX+juDhNa0KtN7SAcCqVM6x9VM6N4cDdxRARvIo4NnIg4EfVhrbjJvTav31Xb mjb2V5h5y+8lT09C4u+yAOoCHk5LUaw= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-382-EsqEbmrdNmeMXwuITtns_g-1; Tue, 26 Mar 2024 07:26:20 -0400 X-MC-Unique: EsqEbmrdNmeMXwuITtns_g-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BF46E3C0D7BC for ; Tue, 26 Mar 2024 11:26:19 +0000 (UTC) Received: from nuthatch.brq.redhat.com (unknown [10.43.17.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4D5A73C54; Tue, 26 Mar 2024 11:26:19 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal Subject: [RFC PATCH 07/11] config: Look up rpi config path in configuration file Date: Tue, 26 Mar 2024 12:24:10 +0100 Message-ID: <20240326112419.503286-8-mzamazal@redhat.com> In-Reply-To: <20240326112419.503286-1-mzamazal@redhat.com> References: <20240326112419.503286-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The configuration snippet: configuration: pipeline: rpi: config_file: FILENAME Signed-off-by: Milan Zamazal --- src/libcamera/pipeline/rpi/common/pipeline_base.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp index 7e420b3f..8260a3ff 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp @@ -20,6 +20,7 @@ #include #include "libcamera/internal/camera_lens.h" +#include "libcamera/internal/global_configuration.h" #include "libcamera/internal/ipa_manager.h" #include "libcamera/internal/v4l2_subdevice.h" @@ -1086,7 +1087,12 @@ int CameraData::loadPipelineConfiguration() /* Initial configuration of the platform, in case no config file is present */ platformPipelineConfigure({}); - char const *configFromEnv = utils::secure_getenv("LIBCAMERA_RPI_CONFIG_FILE"); + std::optional configFile = + GlobalConfiguration::envOption("LIBCAMERA_RPI_CONFIG_FILE", + "pipeline.rpi.config_file"); + if (!configFile.has_value()) + return 0; + char const *configFromEnv = configFile.value().c_str(); if (!configFromEnv || *configFromEnv == '\0') return 0; From patchwork Tue Mar 26 11:24:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 19809 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 CDD1CC32C9 for ; Tue, 26 Mar 2024 11:26:30 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0C9E96336B; Tue, 26 Mar 2024 12:26:30 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="SPbWFU3d"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4D7E063354 for ; Tue, 26 Mar 2024 12:26:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711452382; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=t2TslSbFuSDyHZHcHr2C23GUF38/PcUUW1mKWTLdcAc=; b=SPbWFU3dd7KhX3FbpFp9yfD0fqI65BQEChtfFlz8MDDWMwXEsiUOXXdeNptoVFLsGyQwuW SdWakmloIORAXyaPRWpqqrYpcNU6bSQ/zDkJK8br/sRFS8zgVDWTEcu1q9sv7iF2PddFoH K3iFPqwZWD+lTV4bfQ73pImLmFksIzI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-631-8EEL8JEZPtm2q5LBuK7kmg-1; Tue, 26 Mar 2024 07:26:20 -0400 X-MC-Unique: 8EEL8JEZPtm2q5LBuK7kmg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 78AE6800265 for ; Tue, 26 Mar 2024 11:26:20 +0000 (UTC) Received: from nuthatch.brq.redhat.com (unknown [10.43.17.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 017A43C20; Tue, 26 Mar 2024 11:26:19 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal Subject: [RFC PATCH 08/11] config: Look up IPA configurables in configuration file Date: Tue, 26 Mar 2024 12:24:11 +0100 Message-ID: <20240326112419.503286-9-mzamazal@redhat.com> In-Reply-To: <20240326112419.503286-1-mzamazal@redhat.com> References: <20240326112419.503286-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The configuration snippet: configuration: ipa: config_paths: CONFIG:PATHS:... module_paths: MODULE:PATHS:... force_isolation: BOOL Signed-off-by: Milan Zamazal --- src/libcamera/ipa_manager.cpp | 11 ++++++++--- src/libcamera/ipa_proxy.cpp | 8 ++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/libcamera/ipa_manager.cpp b/src/libcamera/ipa_manager.cpp index 5104b930..02a09724 100644 --- a/src/libcamera/ipa_manager.cpp +++ b/src/libcamera/ipa_manager.cpp @@ -129,8 +129,11 @@ IPAManager::IPAManager() unsigned int ipaCount = 0; /* User-specified paths take precedence. */ - const char *modulePaths = utils::secure_getenv("LIBCAMERA_IPA_MODULE_PATH"); - if (modulePaths) { + const auto confModulePaths = + GlobalConfiguration::envOption( + "LIBCAMERA_IPA_MODULE_PATH", "ipa.module_paths"); + if (confModulePaths.has_value()) { + const char *modulePaths = confModulePaths.value().c_str(); for (const auto &dir : utils::split(modulePaths, ":")) { if (dir.empty()) continue; @@ -308,7 +311,9 @@ bool IPAManager::isSignatureValid([[maybe_unused]] IPAModule *ipa) const { #if HAVE_IPA_PUBKEY char *force = utils::secure_getenv("LIBCAMERA_IPA_FORCE_ISOLATION"); - if (force && force[0] != '\0') { + if ((force && force[0] != '\0') || + (!force && GlobalConfiguration::option("ipa.force_isolation") + .value_or(false))) { LOG(IPAManager, Debug) << "Isolation of IPA module " << ipa->path() << " forced through environment variable"; diff --git a/src/libcamera/ipa_proxy.cpp b/src/libcamera/ipa_proxy.cpp index 3f2cc6b8..368c1452 100644 --- a/src/libcamera/ipa_proxy.cpp +++ b/src/libcamera/ipa_proxy.cpp @@ -15,6 +15,7 @@ #include #include +#include "libcamera/internal/global_configuration.h" #include "libcamera/internal/ipa_module.h" /** @@ -104,8 +105,11 @@ std::string IPAProxy::configurationFile(const std::string &name) const std::string ipaName = ipam_->info().name; /* Check the environment variable first. */ - const char *confPaths = utils::secure_getenv("LIBCAMERA_IPA_CONFIG_PATH"); - if (confPaths) { + auto confConfPaths = + GlobalConfiguration::envOption( + "LIBCAMERA_IPA_CONFIG_PATH", "ipa.config_paths"); + if (confConfPaths.has_value()) { + const char *confPaths = confConfPaths.value().c_str(); for (const auto &dir : utils::split(confPaths, ":")) { if (dir.empty()) continue; From patchwork Tue Mar 26 11:24:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 19810 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 53D3BC32C1 for ; Tue, 26 Mar 2024 11:26:32 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CE68063360; Tue, 26 Mar 2024 12:26:31 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="KKkAVjjQ"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D7D166332E for ; Tue, 26 Mar 2024 12:26:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711452382; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=H5rObzSBGpbgDLgQyfdrfryihEhci/ELnlu2c5EUREA=; b=KKkAVjjQaOJXlSN2RmaSVGbuBlbWjvZRQBVt6FLdcfURMaUlA3vgWo8H5aZRDyraRCOkf1 A1h3x2Kl8wVPrKcVQMgGkjp94H8prGlGH6aFC5BpO7d5AZ9nLZjlhuWJNGflTGT1RBtRes qTzPY4aWaon7dMbEVqPHou6ToPamLPY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-499-vSLwvsv7Obq9EjtJn0BSPQ-1; Tue, 26 Mar 2024 07:26:21 -0400 X-MC-Unique: vSLwvsv7Obq9EjtJn0BSPQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 28B4F8007A3 for ; Tue, 26 Mar 2024 11:26:21 +0000 (UTC) Received: from nuthatch.brq.redhat.com (unknown [10.43.17.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id AD3CA3C20; Tue, 26 Mar 2024 11:26:20 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal Subject: [RFC PATCH 09/11] config: Look up RkISP1 tuning file in configuration file Date: Tue, 26 Mar 2024 12:24:12 +0100 Message-ID: <20240326112419.503286-10-mzamazal@redhat.com> In-Reply-To: <20240326112419.503286-1-mzamazal@redhat.com> References: <20240326112419.503286-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The configuration snippet: configuration: pipeline: rkisp1: tuning_file: FILE This environment variable has not been documented. Signed-off-by: Milan Zamazal --- src/libcamera/pipeline/rkisp1/rkisp1.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index abb21968..5be25698 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -36,6 +36,7 @@ #include "libcamera/internal/delayed_controls.h" #include "libcamera/internal/device_enumerator.h" #include "libcamera/internal/framebuffer.h" +#include "libcamera/internal/global_configuration.h" #include "libcamera/internal/ipa_manager.h" #include "libcamera/internal/media_device.h" #include "libcamera/internal/pipeline_handler.h" @@ -349,8 +350,10 @@ int RkISP1CameraData::loadIPA(unsigned int hwRevision) * environment variable overrides it. */ std::string ipaTuningFile; - char const *configFromEnv = utils::secure_getenv("LIBCAMERA_RKISP1_TUNING_FILE"); - if (!configFromEnv || *configFromEnv == '\0') { + const auto confTuningFile = + GlobalConfiguration::envOption( + "LIBCAMERA_RKISP1_TUNING_FILE", "pipeline.rkisp1.tuning_file"); + if (!confTuningFile.has_value() || confTuningFile.value() == "") { ipaTuningFile = ipa_->configurationFile(sensor_->model() + ".yaml"); /* * If the tuning file isn't found, fall back to the @@ -359,7 +362,7 @@ int RkISP1CameraData::loadIPA(unsigned int hwRevision) if (ipaTuningFile.empty()) ipaTuningFile = ipa_->configurationFile("uncalibrated.yaml"); } else { - ipaTuningFile = std::string(configFromEnv); + ipaTuningFile = confTuningFile.value(); } IPACameraSensorInfo sensorInfo{}; From patchwork Tue Mar 26 11:24:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 19811 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 F3449BD160 for ; Tue, 26 Mar 2024 11:26:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6EC5763365; Tue, 26 Mar 2024 12:26:33 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="PhY+slMV"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C58776331B for ; Tue, 26 Mar 2024 12:26:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711452383; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P9FciB58ZFfx2jfOCnb696OMwmJV8EDIJAEbqLWPV6A=; b=PhY+slMVlf6TU/od+EIEuCP0O8rZ7SPc2nV8U8O4iE2p9JX2YNgMomgBRjM5rc3QXFcix1 Yw0EsMQjc8jPUr2Eb4wHRC/t79TaCe1betCSkq/vQdwnBWyx4G6IElfkAy0eFzgYKY4vBz 814/cqFkr2FF92LpdiopbXQxc/8nx0Y= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-379-Vu89Uua8NBeuQ7bjw8crpQ-1; Tue, 26 Mar 2024 07:26:22 -0400 X-MC-Unique: Vu89Uua8NBeuQ7bjw8crpQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CD21F800265 for ; Tue, 26 Mar 2024 11:26:21 +0000 (UTC) Received: from nuthatch.brq.redhat.com (unknown [10.43.17.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5D4F53C54; Tue, 26 Mar 2024 11:26:21 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal Subject: [RFC PATCH 10/11] config: Allow enabling software ISP in runtime Date: Tue, 26 Mar 2024 12:24:13 +0100 Message-ID: <20240326112419.503286-11-mzamazal@redhat.com> In-Reply-To: <20240326112419.503286-1-mzamazal@redhat.com> References: <20240326112419.503286-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" This patch allows enabling or disabling software ISP in runtime in addition to compile time. This can be useful for software ISP testing on various platforms as well as for overriding the defaults in case the defaults don't work well (e.g. hardware ISP may or may not work on i.MX8MP depending on the kernel and libcamera patches present in the given system). The configuration is specified as follows: configuration: pipelines: simple: supportedDevices: - driver: DRIVER-NAME softwareIsp: BOOLEAN - ... For example: configuration: pipelines: simple: supportedDevices: - driver: mxc-isi softwareIsp: true The overall configuration of enabling or disabling software ISP may get dropped in future but this patch is still useful in the meantime. Signed-off-by: Milan Zamazal --- src/libcamera/pipeline/simple/simple.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp index 22639407..23e3f9da 100644 --- a/src/libcamera/pipeline/simple/simple.cpp +++ b/src/libcamera/pipeline/simple/simple.cpp @@ -32,6 +32,7 @@ #include "libcamera/internal/camera_sensor.h" #include "libcamera/internal/converter.h" #include "libcamera/internal/device_enumerator.h" +#include "libcamera/internal/global_configuration.h" #include "libcamera/internal/media_device.h" #include "libcamera/internal/pipeline_handler.h" #include "libcamera/internal/software_isp/software_isp.h" @@ -1532,6 +1533,15 @@ bool SimplePipelineHandler::match(DeviceEnumerator *enumerator) } swIspEnabled_ = info->swIspEnabled; + for (GlobalConfiguration::Configuration entry : + GlobalConfiguration::configuration()["pipelines"]["simple"]["supportedDevices"].asList()) { + auto name = entry["driver"].get(); + if (name.has_value() and !name.value().compare(info->driver)) { + swIspEnabled_ = entry["softwareIsp"].get().value_or(swIspEnabled_); + LOG(SimplePipeline, Debug) << "Overriding software ISP to " << swIspEnabled_; + break; + } + } /* Locate the sensors. */ std::vector sensors = locateSensors(); From patchwork Tue Mar 26 11:24:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 19812 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 1F5F7C32C9 for ; Tue, 26 Mar 2024 11:26:35 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A8EC363361; Tue, 26 Mar 2024 12:26:34 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="MGAXQpJI"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4758A6334D for ; Tue, 26 Mar 2024 12:26:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711452384; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZZoxr7e+9DLjwMQCQu7w3y8F5CLpNlUzgOTZZGgNfug=; b=MGAXQpJIO2PolJwjdL58shCxIQBwkVYpabZSEBwENfBzth81xGmEaF6eQ1ZCqsU4xpg5rw rwLWxaMpnD2fsMmuWCQgaAbkldPEOE56GcZVxftE6ZtsW2klMO+bh/4lHvfiqbWclwy5SO rQv3amAHmV7+d9SVXLDLcSPJqOggcr0= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-534-38tTpm7bPEOxGUbUp4-ebw-1; Tue, 26 Mar 2024 07:26:22 -0400 X-MC-Unique: 38tTpm7bPEOxGUbUp4-ebw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 85957382C462 for ; Tue, 26 Mar 2024 11:26:22 +0000 (UTC) Received: from nuthatch.brq.redhat.com (unknown [10.43.17.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 10B5B3C54; Tue, 26 Mar 2024 11:26:21 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal Subject: [RFC PATCH 11/11] config: Add global configuration documentation Date: Tue, 26 Mar 2024 12:24:14 +0100 Message-ID: <20240326112419.503286-12-mzamazal@redhat.com> In-Reply-To: <20240326112419.503286-1-mzamazal@redhat.com> References: <20240326112419.503286-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" WIP Signed-off-by: Milan Zamazal --- Documentation/index.rst | 2 +- Documentation/meson.build | 2 +- ...ariables.rst => runtime_configuration.rst} | 56 +++++++++++++++++-- 3 files changed, 54 insertions(+), 6 deletions(-) rename Documentation/{environment_variables.rst => runtime_configuration.rst} (76%) diff --git a/Documentation/index.rst b/Documentation/index.rst index 5442ae75..aa277b85 100644 --- a/Documentation/index.rst +++ b/Documentation/index.rst @@ -19,7 +19,7 @@ Pipeline Handler Writer's Guide IPA Writer's guide Tracing guide - Environment variables + Runtime configuration Sensor driver requirements Lens driver requirements Python Bindings diff --git a/Documentation/meson.build b/Documentation/meson.build index 3872e0a8..f8ca63eb 100644 --- a/Documentation/meson.build +++ b/Documentation/meson.build @@ -70,7 +70,6 @@ if sphinx.found() 'conf.py', 'contributing.rst', 'docs.rst', - 'environment_variables.rst', 'guides/application-developer.rst', 'guides/introduction.rst', 'guides/ipa.rst', @@ -79,6 +78,7 @@ if sphinx.found() 'index.rst', 'lens_driver_requirements.rst', 'python-bindings.rst', + 'runtime_configuration.rst', 'sensor_driver_requirements.rst', 'software-isp-benchmarking.rst', '../README.rst', diff --git a/Documentation/environment_variables.rst b/Documentation/runtime_configuration.rst similarity index 76% rename from Documentation/environment_variables.rst rename to Documentation/runtime_configuration.rst index a9b230bc..75bf3530 100644 --- a/Documentation/environment_variables.rst +++ b/Documentation/runtime_configuration.rst @@ -1,10 +1,58 @@ .. SPDX-License-Identifier: CC-BY-SA-4.0 -Environment variables +Runtime configuration ===================== -The libcamera behaviour can be tuned through environment variables. This -document lists all the available variables and describes their usage. +The libcamera behaviour can be tuned through a configuration file or environment +variables. This document lists all the configuration options and describes their +usage. + +General rules +------------- + +The configuration file is looked up in the following locations, in this order: + +- $XDG_CONFIG_HOME/libcamera/configuration.yaml +- LIBCAMERA_SYSCONF_DIR/configuration.yaml +- /etc/libcamera/configuration.yaml + +The first configuration file found wins, contingent configuration files in other locations are ignored. + +Settings in environment variables take precedence over settings in configuration +files. This allows overriding behaviour temporarily without the need to modify +configuration files. + +Configuration options +--------------------- + +... + +Configuration file example +-------------------------- + +:: + + --- + version: 1 + configuration: + log: + file: syslog + levels: 'IPAManager:DEBUG' + color: false + pipelines: + simple: + supportedDevices: + - driver: mxc-isi + softwareIsp: true + rpi: + config_file: /usr/local/share/libcamera/pipeline/rpi/vc4/minimal_mem.yaml + rkisp1: + tuning_file: + /home/user/.libcamera/rkisp1.yaml + ipa: + config_paths: /home/user/.libcamera/share/ipa:/opt/libcamera/vendor/share/ipa + module_paths: /home/user/.libcamera/lib:/opt/libcamera/vendor/lib + force_isolation: true List of variables ----------------- @@ -136,7 +184,7 @@ code. IPA configuration ~~~~~~~~~~~~~~~~~ -IPA modules use configuration files to store parameters. The format and +IPA modules use their own configuration files to store parameters. The format and contents of the configuration files is specific to the IPA module. They usually contain tuning parameters for the algorithms, in JSON format.