From patchwork Thu Feb 6 16:15:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 22746 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 596D9C32EF for ; Thu, 6 Feb 2025 16:16:20 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3A8EC685E4; Thu, 6 Feb 2025 17:16:19 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="EPgask1j"; 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 2E24D6053F for ; Thu, 6 Feb 2025 17:16:18 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738858577; 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; bh=nw0K93QMPis/Id6NwwVC5PP3Ciu9fJuoKLE5FFZ7AlE=; b=EPgask1j+EZEvJ3WTRmtITbiPEOkAv5STekr0tEFkZmWFUefM4T0vPc+Ofpfah9RyIvA1D +TVL9S89JEPdZMq4v5nkM9lmqY9QPimuEMpgaxcvaPLCRnfDDNl2ZuWrhLeMrIpc20s9Cg TLruClAsTKHkf3YQtkkGzeqM5AL+ar4= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-463-UH2OPRgQNi20GtIEdG2gCQ-1; Thu, 06 Feb 2025 11:16:14 -0500 X-MC-Unique: UH2OPRgQNi20GtIEdG2gCQ-1 X-Mimecast-MFC-AGG-ID: UH2OPRgQNi20GtIEdG2gCQ Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0F14519560B1; Thu, 6 Feb 2025 16:16:13 +0000 (UTC) Received: from mzamazal-thinkpadp1gen3.tpbc.com (unknown [10.43.17.31]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2194D18004A7; Thu, 6 Feb 2025 16:16:10 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal , Kieran Bingham , Naushir Patuck , =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= , Laurent Pinchart Subject: [PATCH v7 00/15] Add global configuration file Date: Thu, 6 Feb 2025 17:15:51 +0100 Message-ID: <20250206161607.50738-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: z4xJCuGIpPJAGVPrlqmXC234S8hCY-FLkCTXzwwnlMU_1738858573 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 series introduces global configuration file for libcamera, to provide runtime configuration means other than environment variables. Instead of, or in addition to, the growing list of configuration environment variables, the whole configuration can be specified in a single configuration file. This is both simpler and more flexible. This is not a replacement for specific configuration files already present in libcamera. The patches implement what is needed to introduce a configuration file that can handle the current environment variables and software ISP TODOs. They demonstrate how to deal with the key points that must be considered. See commit messages for more details. The configuration file is a YAML file. It is looked up in user’s home directory or, if not present, in system-wide libcamera directories. Both the directories and file name of the configuration file can be overridden using newly introduced environment variables. The current configuration environment variables are still supported and take precedence, if defined, over the corresponding entries in the YAML file. This patch series is not exhaustive, there can be future enhancements, most notably configuration file validation to avoid confusions caused by typos etc. Not everything has been tested because some of the patches are related to specific hardware. Also, not everything is necessarily C++ elegant, suggestions for improvements are welcome. Note that there is an obstacle in that configuration initialization may call logging and logging queries configuration, as explained in the commit messages. This complicates transparent encapsulation. Changes in v7: - Rebased on current master. - Tuning file path configuration updated for recent changes. A significant change is that the tuning file configuration is no longer sensor dependent as there is apparently no access to the sensor info in the IPA proxy. - Minor improvements of some commit messages. Changes in v6: - Rebased on master. - File names from file header descriptions removed. - Indentation fix in moved code as requested by checkstyle.py. - Unneeded const_cast's removed. - Using GlobalConfiguration namespace rather than a class. - Path configuration options are defined as sequences in YAML. - A patch introducing LIBCAMERA_CONFIG_NAME added. - A patch introducing LIBCAMERA_CONFIG_DIR added. - Miscellaneous minor code changes suggested by Barnabás. Changes in v5: - A pointer is used to store the global configuration singleton rather than a static variable. This makes the things more robust and fixes the problem with re-entrancy on logging and a failing camera_reconfigure test. - In relation to the change above, a new initialization method GlobalConfiguration::initialize() was introduced that replaces the initialization calls in CameraManager and IPAManager. - Logging YAML errors when reading the configuration was also fixed. - Global configuration is placed to base directly, without an intermediate patch. - An `optional' value comparison simplified. - A temporary typo in a comment fixed. - Unused stdint.h include removed. Changes in v4: - Rebased on current master. - Configuration option for LIBCAMERA_IPA_PROXY_PATH added. - Added a patch to include stdlib.h instead of cstdlib in yaml_parser.cpp. Changes in v3: - Added a configuration item for the newly introduced LIBCAMERA_PIPELINES_MATCH_LIST variable. - A minor indentation fix. - Fixed `pipelines.' x `pipeline.' configuration item naming mismatch. - Tuning files are looked up now by particular cameras attached rather than being specified for the whole pipeline. - Helpers use std::string& instead of char* for confPath arguments. - Protection against returning YamlObject::empty as a regular value (the problem has been probably exposed by addition of LIBCAMERA_PIPELINES_MATCH_LIST). Changes in v2: - Rebased on master. - Various cleanups, documentation improvements and minor fixes. - Configuration option for LIBCAMERA_RPI_TUNING_FILE added (Naush). - Two more patches for software ISP configuration added. Milan Zamazal (15): yaml: Move yaml_parser.cpp to base config: Introduce global runtime configuration config: Look up logging levels in the configuration file config: Add configuration retrieval helpers config: Look up log file in configuration file config: Look up log color configuration in configuration file config: Look up rpi config path in configuration file config: Look up IPA configurables in configuration file config: Look up pipelines match list in configuration file config: Allow enabling software ISP in runtime config: Add global configuration file documentation libcamera: software_isp: Make input buffer copying configurable libcamera: software_isp: Make measurement configurable config: Make configuration file configurable config: Make configuration directories configurable Documentation/documentation-contents.rst | 2 +- Documentation/index.rst | 2 +- Documentation/meson.build | 2 +- ...ariables.rst => runtime_configuration.rst} | 133 +++++++- .../libcamera/internal/global_configuration.h | 60 ++++ include/libcamera/internal/meson.build | 1 + src/libcamera/base/global_configuration.cpp | 289 ++++++++++++++++++ src/libcamera/base/log.cpp | 24 +- src/libcamera/base/meson.build | 15 + src/libcamera/{ => base}/yaml_parser.cpp | 13 +- src/libcamera/camera_manager.cpp | 10 +- src/libcamera/ipa_manager.cpp | 35 ++- src/libcamera/ipa_proxy.cpp | 65 ++-- src/libcamera/meson.build | 14 - .../pipeline/rpi/common/pipeline_base.cpp | 8 +- src/libcamera/pipeline/simple/simple.cpp | 12 + src/libcamera/process.cpp | 11 +- src/libcamera/software_isp/TODO | 36 --- src/libcamera/software_isp/debayer_cpu.cpp | 30 +- src/libcamera/software_isp/debayer_cpu.h | 7 +- 20 files changed, 625 insertions(+), 144 deletions(-) rename Documentation/{environment_variables.rst => runtime_configuration.rst} (58%) create mode 100644 include/libcamera/internal/global_configuration.h create mode 100644 src/libcamera/base/global_configuration.cpp rename src/libcamera/{ => base}/yaml_parser.cpp (98%)