[libcamera-devel,v1,01/10] libcamera: pipeline: Add a platform configuration file helper
diff mbox series

Message ID 20221014131846.27169-2-naush@raspberrypi.com
State Superseded
Headers show
Series
  • Raspberry Pi: Platform configuration and buffer allocation improvements
Related show

Commit Message

Naushir Patuck Oct. 14, 2022, 1:18 p.m. UTC
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@raspberrypi.com>
---
 include/libcamera/internal/pipeline_handler.h |  2 +
 src/libcamera/pipeline_handler.cpp            | 57 +++++++++++++++++++
 2 files changed, 59 insertions(+)

Comments

David Plowman Nov. 1, 2022, 11:43 a.m. UTC | #1
Hi Naush

Thanks for this patch!

On Fri, 14 Oct 2022 at 14:18, Naushir Patuck via libcamera-devel
<libcamera-devel@lists.libcamera.org> wrote:
>
> 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@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)

I guess I was just wondering slightly whether this is worth checking
given that we fail with a helpful message anyway if we can't open the
file, but it's fine like this too, so probably just ignore me!

Reviewed-by: David Plowman <david.plowman@raspberrypi.com>

Thanks!
David

> +                       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
>
Naushir Patuck Nov. 29, 2022, 10:20 a.m. UTC | #2
Hi David,

Thank you for your feedback!

On Tue, 1 Nov 2022 at 11:43, David Plowman <david.plowman@raspberrypi.com>
wrote:

> Hi Naush
>
> Thanks for this patch!
>
> On Fri, 14 Oct 2022 at 14:18, Naushir Patuck via libcamera-devel
> <libcamera-devel@lists.libcamera.org> wrote:
> >
> > 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@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)
>
> I guess I was just wondering slightly whether this is worth checking
> given that we fail with a helpful message anyway if we can't open the
> file, but it's fine like this too, so probably just ignore me!
>

This function is (mostly) a duplicate of what is used for the tuning file,
so I'll probably leave this check in to be consistent.

Regards,
Naush


>
> Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
>
> Thanks!
> David
>
> > +                       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
> >
>

Patch
diff mbox series

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