[libcamera-devel] [RFC 6/6] libcamera: camera_sensor: Collect camera properties
Jacopo Mondi
jacopo at jmondi.org
Tue Nov 19 17:44:21 CET 2019
Store the camera sensor location and rotation by parsing the
associated V4L2 controls.
Signed-off-by: Jacopo Mondi <jacopo at jmondi.org>
---
src/libcamera/camera_sensor.cpp | 32 +++++++++++++++++++++++++++
src/libcamera/include/camera_sensor.h | 3 +++
2 files changed, 35 insertions(+)
diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp
index 86f0c772861b..857853f4fcf9 100644
--- a/src/libcamera/camera_sensor.cpp
+++ b/src/libcamera/camera_sensor.cpp
@@ -13,6 +13,8 @@
#include <limits.h>
#include <math.h>
+#include <libcamera/property_ids.h>
+
#include "formats.h"
#include "utils.h"
#include "v4l2_subdevice.h"
@@ -89,6 +91,36 @@ int CameraSensor::init()
if (ret < 0)
return ret;
+ /* Retrieve and store the camera sensor properties. */
+ const ControlInfoMap &controls = subdev_->controls();
+ int32_t controlValue = V4L2_LOCATION_EXTERNAL;
+
+ const auto &locationControl = controls.find(V4L2_CID_CAMERA_SENSOR_LOCATION);
+ if (locationControl != controls.end())
+ controlValue = locationControl->second.defaultValue().get<int32_t>();
+
+ switch (controlValue) {
+ case V4L2_LOCATION_EXTERNAL:
+ location_ = CAMERA_LOCATION_EXTERNAL;
+ break;
+ case V4L2_LOCATION_FRONT:
+ location_ = CAMERA_LOCATION_FRONT;
+ break;
+ case V4L2_LOCATION_BACK:
+ location_ = CAMERA_LOCATION_BACK;
+ break;
+ default:
+ LOG(CameraSensor, Error)
+ << "Unsupported camera location: " << controlValue;
+ return -EINVAL;
+ }
+
+ controlValue = 0;
+ const auto &rotationControl = controls.find(V4L2_CID_CAMERA_SENSOR_ROTATION);
+ if (rotationControl != controls.end())
+ controlValue = rotationControl->second.defaultValue().get<int32_t>();
+ rotation_ = controlValue;
+
/* Enumerate and cache media bus codes and sizes. */
const ImageFormats formats = subdev_->formats(0);
if (formats.isEmpty()) {
diff --git a/src/libcamera/include/camera_sensor.h b/src/libcamera/include/camera_sensor.h
index 1fb36a4f4951..ee26ca20ac20 100644
--- a/src/libcamera/include/camera_sensor.h
+++ b/src/libcamera/include/camera_sensor.h
@@ -56,6 +56,9 @@ private:
std::vector<unsigned int> mbusCodes_;
std::vector<Size> sizes_;
+
+ unsigned int location_;
+ unsigned int rotation_;
};
} /* namespace libcamera */
--
2.23.0
More information about the libcamera-devel
mailing list