summaryrefslogtreecommitdiff
path: root/src/libcamera/ipa_proxy.cpp
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-04-27 04:04:48 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-04-28 01:54:41 +0300
commit53d3f4152af5a943d84f60cb8a02d791730c99b1 (patch)
tree63c1d41d4079de1a02233df5e724878f44ca32ba /src/libcamera/ipa_proxy.cpp
parent78f685df8a5727ebd8978d05aef963533808b6f5 (diff)
libcamera: ipa_proxy: Provide suport for IPA configuration files
IPA modules may require configuration files, which may be stored in different locations in the file system. To standardize file locations between all IPAs and pipeline handlers, provide a helper function to locate a configuration file by searching in the following directories: - All directories specified in the LIBCAMERA_IPA_CONFIG_PATH environment variable ; or - 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 IPA directory. More locations, or extensions to the mechanism, may be implemented later. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'src/libcamera/ipa_proxy.cpp')
-rw-r--r--src/libcamera/ipa_proxy.cpp92
1 files changed, 90 insertions, 2 deletions
diff --git a/src/libcamera/ipa_proxy.cpp b/src/libcamera/ipa_proxy.cpp
index 43ac9afc..401ac52d 100644
--- a/src/libcamera/ipa_proxy.cpp
+++ b/src/libcamera/ipa_proxy.cpp
@@ -8,8 +8,11 @@
#include "ipa_proxy.h"
#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
#include <unistd.h>
+#include "ipa_module.h"
#include "log.h"
#include "utils.h"
@@ -34,12 +37,13 @@ LOG_DEFINE_CATEGORY(IPAProxy)
/**
* \brief Construct an IPAProxy instance
+ * \param[in] ipam The IPA module
*
* IPAProxy instances shall be constructed through the IPAProxyFactory::create()
* method implemented by the respective factories.
*/
-IPAProxy::IPAProxy()
- : valid_(false)
+IPAProxy::IPAProxy(IPAModule *ipam)
+ : valid_(false), ipam_(ipam)
{
}
@@ -58,6 +62,90 @@ IPAProxy::~IPAProxy()
*/
/**
+ * \brief Retrieve the absolute path to an IPA configuration file
+ * \param[in] name The configuration file name
+ *
+ * This function locates the configuration file for an IPA and returns its
+ * absolute path. It searches the following directories, in order:
+ *
+ * - All directories specified in the colon-separated LIBCAMERA_IPA_CONFIG_PATH
+ * environment variable ; or
+ * - If libcamera is not installed, the src/ipa/ directory within the source
+ * tree ; otherwise
+ * - The system sysconf (etc/libcamera/ipa) and the data (share/libcamera/ipa/)
+ * directories.
+ *
+ * The system directories are not searched if libcamera is not installed.
+ *
+ * Within each of those directories, the function looks for a subdirectory
+ * named after the IPA module name, as reported in IPAModuleInfo::name, and for
+ * a file named \a name within that directory. The \a name is IPA-specific.
+ *
+ * \return The full path to the IPA configuration file, or an empty string if
+ * no configuration file can be found
+ */
+std::string IPAProxy::configurationFile(const std::string &name) const
+{
+ struct stat statbuf;
+ int ret;
+
+ /*
+ * The IPA module name can be used as-is to build directory names as it
+ * has been validated when loading the module.
+ */
+ std::string ipaName = ipam_->info().name;
+
+ /* Check the environment variable first. */
+ const char *confPaths = utils::secure_getenv("LIBCAMERA_IPA_CONFIG_PATH");
+ if (confPaths) {
+ for (const auto &dir : utils::split(confPaths, ":")) {
+ if (dir.empty())
+ continue;
+
+ std::string confPath = dir + "/" + ipaName + "/" + name;
+ ret = stat(confPath.c_str(), &statbuf);
+ if (ret == 0 && (statbuf.st_mode & S_IFMT) == S_IFREG)
+ return confPath;
+ }
+ }
+
+ 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 ipaConfDir = root + "src/ipa/" + ipaName + "/data";
+
+ LOG(IPAProxy, Info)
+ << "libcamera is not installed. Loading IPA configuration from '"
+ << ipaConfDir << "'";
+
+ std::string confPath = ipaConfDir + "/" + 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. */
+ for (const auto &dir : utils::split(IPA_CONFIG_DIR, ":")) {
+ std::string confPath = dir + "/" + ipaName + "/" + name;
+ ret = stat(confPath.c_str(), &statbuf);
+ if (ret == 0 && (statbuf.st_mode & S_IFMT) == S_IFREG)
+ return confPath;
+ }
+ }
+
+ LOG(IPAProxy, Error)
+ << "Configuration file '" << name
+ << "' not found for IPA module '" << ipaName << "'";
+
+ return std::string();
+}
+
+/**
* \brief Find a valid full path for a proxy worker for a given executable name
* \param[in] file File name of proxy worker executable
*