[v2,07/13] config: Look up rpi paths in configuration file
diff mbox series

Message ID 20240423103034.364150-8-mzamazal@redhat.com
State Superseded
Headers show
Series
  • Add global configuration file
Related show

Commit Message

Milan Zamazal April 23, 2024, 10:30 a.m. UTC
It may be arguable whether pipeline specific configurations belong to
the global configuration file.  But:

- Having a single configuration file is generally easier for the user.
- The original configuration via environment variables can be already
  considered global.
- These options point to other configuration files and it makes little
  sense to add another configuration file to the chain.

The configuration snippet:

  configuration:
    pipeline:
      rpi:
        config_file: FILENAME
        tuning_file: FILENAME

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
---
 .../pipeline/rpi/common/pipeline_base.cpp        | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

Patch
diff mbox series

diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp
index 7e420b3f..eb6e030f 100644
--- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp
+++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp
@@ -20,6 +20,7 @@ 
 #include <libcamera/property_ids.h>
 
 #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<std::string> 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;
 
@@ -1145,14 +1151,16 @@  int CameraData::loadIPA(ipa::RPi::InitResult *result)
 	 * the environment variable overrides it.
 	 */
 	std::string configurationFile;
-	char const *configFromEnv = utils::secure_getenv("LIBCAMERA_RPI_TUNING_FILE");
-	if (!configFromEnv || *configFromEnv == '\0') {
+	std::optional<std::string> configFromEnv =
+		GlobalConfiguration::envOption("LIBCAMERA_RPI_TUNING_FILE",
+					       "pipeline.rpi.tuning_file");
+	if (!configFromEnv.has_value() || configFromEnv.value().empty()) {
 		std::string model = sensor_->model();
 		if (isMonoSensor(sensor_))
 			model += "_mono";
 		configurationFile = ipa_->configurationFile(model + ".json");
 	} else {
-		configurationFile = std::string(configFromEnv);
+		configurationFile = configFromEnv.value();
 	}
 
 	IPASettings settings(configurationFile, sensor_->model());