summaryrefslogtreecommitdiff
path: root/src/libcamera/v4l2_device.cpp
diff options
context:
space:
mode:
authorDavid Plowman <david.plowman@raspberrypi.com>2021-05-05 14:53:07 +0100
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-05-11 02:31:08 +0300
commit91122dea978c880b9bb03a78641ff5585e20be8c (patch)
treeb76ae8d350f1e1737ce2885afd203a2f26adca6d /src/libcamera/v4l2_device.cpp
parent45c6a7e6e8277fed743e4033d39deeb36a58a4b0 (diff)
libcamera: camera_sensor: Fix frame lengths calculated by sensorInfo()
The minimum and maximum vblanking can change when a new format is applied to the sensor subdevice, so be sure to retrieve up-to-date values. The V4L2Device acquires the new updateControlInfo() method to perform this function, and which the CameraSensor calls automatically if its setFormat method is used to update the sensor. However, not all pipeline handlers invoke the setFormat method directly, so the new method must be made publicly available for pipeline handlers to call if they need to. Signed-off-by: David Plowman <david.plowman@raspberrypi.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/libcamera/v4l2_device.cpp')
-rw-r--r--src/libcamera/v4l2_device.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
index 397029ac..515cbdfe 100644
--- a/src/libcamera/v4l2_device.cpp
+++ b/src/libcamera/v4l2_device.cpp
@@ -511,6 +511,43 @@ void V4L2Device::listControls()
controls_ = std::move(ctrls);
}
+/**
+* \brief Update the information for all device controls
+ *
+ * The V4L2Device class caches information about all controls supported by the
+ * device and exposes it through the controls() and controlInfo() functions.
+ * Control information may change at runtime, for instance when formats on a
+ * subdev are modified. When this occurs, this function can be used to refresh
+ * control information. The information is refreshed in-place, all pointers to
+ * v4l2_query_ext_ctrl instances previously returned by controlInfo() and
+ * iterators to the ControlInfoMap returned by controls() remain valid.
+ *
+ * Note that control information isn't refreshed automatically is it may be an
+ * expensive operation. The V4L2Device users are responsible for calling this
+ * function when required, based on their usage pattern of the class.
+ */
+void V4L2Device::updateControlInfo()
+{
+ for (auto &[controlId, info] : controls_) {
+ unsigned int id = controlId->id();
+
+ /*
+ * Assume controlInfo_ has a corresponding entry, as it has been
+ * generated by listControls().
+ */
+ struct v4l2_query_ext_ctrl &ctrl = controlInfo_[id];
+
+ if (ioctl(VIDIOC_QUERY_EXT_CTRL, &ctrl)) {
+ LOG(V4L2, Debug)
+ << "Could not refresh control "
+ << utils::hex(id);
+ continue;
+ }
+
+ info = V4L2ControlInfo(ctrl);
+ }
+}
+
/*
* \brief Update the value of the first \a count V4L2 controls in \a ctrls using
* values in \a v4l2Ctrls