[v2,42/42] pipeline: simple: Turn devices configuration option into dictionary
diff mbox series

Message ID 20260407153427.1825999-43-laurent.pinchart@ideasonboard.com
State New
Headers show
Series
  • libcamera: Global configuration file improvements
Related show

Commit Message

Laurent Pinchart April 7, 2026, 3:34 p.m. UTC
The pipelines.simple.devices configuration option contains a list of
devices, each of them being a dictionary with a "driver" element that
acts as a unique key to index the list. Turn it into a YAML dictionary
to ensure uniqueness of the key, and simplify access in the pipeline
handler.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
---
Changes since v1:

- Print override message only when overriding
---
This simplification will preclude indexing the list of devices with a
compound key. For instance, if we were to extend the simple pipeline
handler to match not only on a driver name but on a (driver, driver
version) pair, the current configuration file structure would allow
expressing this with

  pipelines:
    simple:
      devices:
        - driver: mxc-isi
	  driver_version: 1
	  software_isp: true
        - driver: mxc-isi
	  driver_version: 2
	  software_isp: false

The new structure would conceptually allow us to write

  pipelines:
    simple:
      devices:
        ? driver: mxc-isi
	  driver_version: 1
	: software_isp: true
        ? driver: mxc-isi
	  driver_version: 2
	: software_isp: false

For those not familiar with the explicit syntax for mappings, this would
translate to the following Python data if dict objects were hashable in
Python:

{
    'pipelines': {
        'simple': {
	    'devices': {
	        { 'driver': 'mxc-isi', 'driver_version': 1 }: {
		    'software_isp': True,
		},
	        { 'driver': 'mxc-isi', 'driver_version': 2 }: {
		    'software_isp': False,
		},
	    },
	},
    },
}

Yes, YAML can use complex data as keys in mappings. I would really not
want to have to support that in libcamera though.

Opinions will be appreciated.
---
 Documentation/runtime_configuration.rst  |  6 +++---
 src/libcamera/pipeline/simple/simple.cpp | 21 ++++++++++-----------
 2 files changed, 13 insertions(+), 14 deletions(-)

Patch
diff mbox series

diff --git a/Documentation/runtime_configuration.rst b/Documentation/runtime_configuration.rst
index 9dfa61e72ce8..6fc53131433f 100644
--- a/Documentation/runtime_configuration.rst
+++ b/Documentation/runtime_configuration.rst
@@ -44,7 +44,7 @@  file structure:
     pipelines:
       simple:
         devices:
-          - driver: # driver name, e.g. `mxc-isi`
+          # driver name, e.g. `mxc-isi`:
             software_isp: # true/false
     software_isp:
       copy_input_buffer: # true/false
@@ -79,7 +79,7 @@  Configuration file example
      pipelines:
        simple:
          devices:
-           - driver: mxc-isi
+           mxc-isi:
              software_isp: true
      software_isp:
        copy_input_buffer: false
@@ -150,7 +150,7 @@  LIBCAMERA_SOFTISP_MODE, software_isp.mode
 
    Example value: ``gpu``
 
-pipelines.simple.devices.driver, pipelines.simple.devices.software_isp
+pipelines.simple.devices.<driver>.software_isp
    Override whether software ISP is enabled for the given driver.
 
    Example `driver` value: ``mxc-isi``
diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp
index 9ae220fc8860..b10c7fc4a25e 100644
--- a/src/libcamera/pipeline/simple/simple.cpp
+++ b/src/libcamera/pipeline/simple/simple.cpp
@@ -1879,18 +1879,17 @@  bool SimplePipelineHandler::matchDevice(std::shared_ptr<MediaDevice> media,
 	}
 
 	swIspEnabled_ = info.swIspEnabled;
+
 	const GlobalConfiguration &configuration = cameraManager()->_d()->configuration();
-	for (const ValueNode &entry :
-	     configuration.configuration()["pipelines"]["simple"]["devices"]
-		     .asList()) {
-		auto name = entry["driver"].get<std::string>();
-		if (name == info.driver) {
-			swIspEnabled_ = entry["software_isp"].get<bool>().value_or(swIspEnabled_);
-			LOG(SimplePipeline, Debug)
-				<< "Configuration file overrides software ISP for "
-				<< info.driver << " to " << swIspEnabled_;
-			break;
-		}
+	const ValueNode &cfg =
+		configuration.configuration()["pipelines"]["simple"]["devices"][info.driver];
+
+	if (auto enable = cfg["software_isp"].get<bool>()) {
+		swIspEnabled_ = *enable;
+
+		LOG(SimplePipeline, Debug)
+			<< "Configuration file overrides software ISP for "
+			<< info.driver << " to " << swIspEnabled_;
 	}
 
 	/* Locate the sensors. */