summaryrefslogtreecommitdiff
path: root/src/libcamera/camera_sensor.cpp
diff options
context:
space:
mode:
authorJacopo Mondi <jacopo@jmondi.org>2019-08-17 11:46:54 +0200
committerJacopo Mondi <jacopo@jmondi.org>2020-02-14 16:27:42 +0100
commit2523771d7917a442cd53980b9ae88d25ae53fb38 (patch)
treed26ad0f39a076e0af0ba32aa5be05fde481750b0 /src/libcamera/camera_sensor.cpp
parent81563b55ed36bca67e4db3950d64438c3d16c0ac (diff)
libcamera: camera_sensor: Parse camera properties
Parse and collect camera sensor properties by inspecting the associated v4l2 controls. Augment the CameraSensor class with an operation to retrieve the collected properties. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Diffstat (limited to 'src/libcamera/camera_sensor.cpp')
-rw-r--r--src/libcamera/camera_sensor.cpp49
1 files changed, 48 insertions, 1 deletions
diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp
index 86f0c772..2219a430 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"
@@ -47,7 +49,7 @@ LOG_DEFINE_CATEGORY(CameraSensor);
* Once constructed the instance must be initialized with init().
*/
CameraSensor::CameraSensor(const MediaEntity *entity)
- : entity_(entity)
+ : entity_(entity), properties_(properties::properties)
{
subdev_ = new V4L2Subdevice(entity);
}
@@ -89,6 +91,45 @@ int CameraSensor::init()
if (ret < 0)
return ret;
+ /* Retrieve and store the camera sensor properties. */
+ const ControlInfoMap &controls = subdev_->controls();
+ int32_t propertyValue;
+
+ /* Camera Location: default is front location. */
+ const auto &locationControl = controls.find(V4L2_CID_CAMERA_SENSOR_LOCATION);
+ if (locationControl != controls.end()) {
+ int32_t v4l2Location =
+ locationControl->second.def().get<int32_t>();
+
+ switch (v4l2Location) {
+ default:
+ LOG(CameraSensor, Warning)
+ << "Unsupported camera location "
+ << v4l2Location << ", setting to Front";
+ /* Fall-through */
+ case V4L2_LOCATION_FRONT:
+ propertyValue = properties::CameraLocationFront;
+ break;
+ case V4L2_LOCATION_BACK:
+ propertyValue = properties::CameraLocationBack;
+ break;
+ case V4L2_LOCATION_EXTERNAL:
+ propertyValue = properties::CameraLocationExternal;
+ break;
+ }
+ } else {
+ propertyValue = properties::CameraLocationFront;
+ }
+ properties_.set(properties::Location, propertyValue);
+
+ /* Camera Rotation: default is 0 degrees. */
+ const auto &rotationControl = controls.find(V4L2_CID_CAMERA_SENSOR_ROTATION);
+ if (rotationControl != controls.end())
+ propertyValue = rotationControl->second.def().get<int32_t>();
+ else
+ propertyValue = 0;
+ properties_.set(properties::Rotation, propertyValue);
+
/* Enumerate and cache media bus codes and sizes. */
const ImageFormats formats = subdev_->formats(0);
if (formats.isEmpty()) {
@@ -285,6 +326,12 @@ int CameraSensor::getControls(ControlList *ctrls)
}
/**
+ * \fn CameraSensor::properties()
+ * \brief Retrieve the camera sensor properties
+ * \return The list of camera sensor properties
+ */
+
+/**
* \brief Write controls to the sensor
* \param[in] ctrls The list of controls to write
*