[libcamera-devel] [PATCH v1 01/10] libcamera: pipeline: Add a platform configuration file helper

Naushir Patuck naush at raspberrypi.com
Fri Oct 14 15:18:37 CEST 2022


Add a new helper function PipelineHandler::configurationFile() that returns
the full path of a named configuration file. This configuration file may be read
by pipeline handlers for platform specific configuration parameters on
initialisation.

The mechanism for searching for the configuration file is similar to the IPA
configuration file:

- In the source tree if libcamera is not installed
- Otherwise in standard system locations (etc and share directories).

When stored in the source tree, configuration files shall be located in a 'data'
subdirectory of their respective pipeline handler directory.

Signed-off-by: Naushir Patuck <naush at raspberrypi.com>
---
 include/libcamera/internal/pipeline_handler.h |  2 +
 src/libcamera/pipeline_handler.cpp            | 57 +++++++++++++++++++
 2 files changed, 59 insertions(+)

diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h
index b6139a88d421..6648975f15de 100644
--- a/include/libcamera/internal/pipeline_handler.h
+++ b/include/libcamera/internal/pipeline_handler.h
@@ -74,6 +74,8 @@ protected:
 	virtual int queueRequestDevice(Camera *camera, Request *request) = 0;
 	virtual void stopDevice(Camera *camera) = 0;
 
+	std::string configurationFile(const std::string &name) const;
+
 	CameraManager *manager_;
 
 private:
diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp
index 588a3db30e82..998dcece05f2 100644
--- a/src/libcamera/pipeline_handler.cpp
+++ b/src/libcamera/pipeline_handler.cpp
@@ -8,6 +8,7 @@
 #include "libcamera/internal/pipeline_handler.h"
 
 #include <chrono>
+#include <sys/stat.h>
 #include <sys/sysmacros.h>
 
 #include <libcamera/base/log.h>
@@ -625,6 +626,62 @@ void PipelineHandler::disconnect()
 	}
 }
 
+/**
+ * \brief Retrieve the absolute path to a platform configuration file
+ * \param[in] name The configuration file name
+ *
+ * This function locates a named platform configuration file and returns
+ * its absolute path to the pipeline handler. It searches the following
+ * directories, in order:
+ *
+ * - If libcamera is not installed, the src/libcamera/pipeline/ directory within
+ *   the source tree ; otherwise
+ * - The system data (share/libcamera/pipeline/) directory.
+ *
+ * The system directories are not searched if libcamera is not installed.
+ *
+ * \return The full path to the pipeline handler configuration file, or an empty
+ * string if no configuration file can be found
+ */
+std::string PipelineHandler::configurationFile(const std::string &name) const
+{
+	struct stat statbuf;
+	int ret;
+
+	std::string root = utils::libcameraSourcePath();
+	if (!root.empty()) {
+		/*
+		 * When libcamera is used before it is installed, load
+		 * configuration files from the source directory. The
+		 * configuration files are then located in the 'data'
+		 * subdirectory of the corresponding IPA module.
+		 */
+		std::string confDir = root + "src/libcamera/pipeline/data";
+
+		LOG(Pipeline, Info)
+			<< "libcamera is not installed. Loading platform configuration file from '"
+			<< confDir << "'";
+
+		std::string confPath = confDir + "/" + name;
+		ret = stat(confPath.c_str(), &statbuf);
+		if (ret == 0 && (statbuf.st_mode & S_IFMT) == S_IFREG)
+			return confPath;
+
+	} else {
+		/* Else look in the system locations. */
+		std::string confPath = std::string(LIBCAMERA_DATA_DIR) + "/pipeline/" + name;
+		ret = stat(confPath.c_str(), &statbuf);
+		if (ret == 0 && (statbuf.st_mode & S_IFMT) == S_IFREG)
+			return confPath;
+	}
+
+	LOG(Pipeline, Error)
+		<< "Configuration file '" << name
+		<< "' not found for pipeline handler '" << PipelineHandler::name() << "'";
+
+	return std::string();
+}
+
 /**
  * \var PipelineHandler::manager_
  * \brief The Camera manager associated with the pipeline handler
-- 
2.25.1



More information about the libcamera-devel mailing list