[libcamera-devel] [RFC PATCH 8/8] libcamera: camera_sensor: Parse configuration properties
Kieran Bingham
kieran.bingham at ideasonboard.com
Mon Nov 23 17:43:19 CET 2020
Search for a camera_sensor.json configuration file specific to libcamera
and parse it to see if any properties specific to this CameraSensor are
applicable.
Signed-off-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
---
include/libcamera/internal/camera_sensor.h | 1 +
src/libcamera/camera_sensor.cpp | 50 ++++++++++++++++++++++
2 files changed, 51 insertions(+)
diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h
index b9eba89f00fb..646f24a966bd 100644
--- a/include/libcamera/internal/camera_sensor.h
+++ b/include/libcamera/internal/camera_sensor.h
@@ -69,6 +69,7 @@ protected:
private:
int generateId();
+ int parseConfigurationFile();
const MediaEntity *entity_;
std::unique_ptr<V4L2Subdevice> subdev_;
diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp
index 935de528c496..5a1bda483b9d 100644
--- a/src/libcamera/camera_sensor.cpp
+++ b/src/libcamera/camera_sensor.cpp
@@ -17,6 +17,7 @@
#include <libcamera/property_ids.h>
+#include "libcamera/internal/configuration.h"
#include "libcamera/internal/formats.h"
#include "libcamera/internal/sysfs.h"
#include "libcamera/internal/utils.h"
@@ -251,6 +252,12 @@ int CameraSensor::init()
propertyValue = 0;
properties_.set(properties::Rotation, propertyValue);
+ /*
+ * Properties are pulled from a configuration file on a best effort.
+ * If the file doesn't exist, or has no properties there is no failure.
+ */
+ parseConfigurationFile();
+
/* Enumerate, sort and cache media bus codes and sizes. */
formats_ = subdev_->formats(pad_);
if (formats_.empty()) {
@@ -584,4 +591,47 @@ int CameraSensor::generateId()
return -EINVAL;
}
+int CameraSensor::parseConfigurationFile()
+{
+ Configuration c;
+
+ int ret = c.open("camera_sensor.json");
+ if (ret) {
+ LOG(CameraSensor, Debug) << "No configuration file available";
+ return -ENODATA;
+ }
+
+ /* Find properties based on the Camera model_ */
+ /* Todo: Spilt parsing out for multiple paths. */
+
+ /* Find properties based around the Camera Sensor ID */
+ json::iterator it = c.data().find(id_);
+ if (it == c.data().end())
+ return -ENOENT;
+
+ json j = *it;
+ it = j.find("properties");
+ if (it == j.end())
+ return -ENOENT;
+
+ json deviceProperties = *it;
+
+ for (auto &[key, value] : deviceProperties.items()) {
+ LOG(CameraSensor, Debug) << "Key: " << key << " Value: " << value;
+
+ if (!value.is_number()) {
+ LOG(CameraSensor, Debug) << "Not a number: " << value;
+ continue;
+ }
+
+ if (key == "Rotation")
+ properties_.set(properties::Rotation, value);
+
+ if (key == "Location")
+ properties_.set(properties::Location, value);
+ }
+
+ return 0;
+}
+
} /* namespace libcamera */
--
2.25.1
More information about the libcamera-devel
mailing list