summaryrefslogtreecommitdiff
path: root/src/libcamera/v4l2_subdevice.cpp
diff options
context:
space:
mode:
authorJacopo Mondi <jacopo@jmondi.org>2020-04-22 09:46:05 +0200
committerJacopo Mondi <jacopo@jmondi.org>2020-04-28 22:25:21 +0200
commit0e36d26dad1143877d2cccb588e630271b3bc9b4 (patch)
tree0034cbea5ea32a10d3db9edd8369c886f8357530 /src/libcamera/v4l2_subdevice.cpp
parentb8728b76a6e45543b8a316ab5d9633e52b55e425 (diff)
libcamera: v4l2_subdevice: Implement getSelection()
Implement V4L2Subdevice::getSelection() to support retrieving selection rectangles from the V4L2 subdevice. Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Diffstat (limited to 'src/libcamera/v4l2_subdevice.cpp')
-rw-r--r--src/libcamera/v4l2_subdevice.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp
index e8623d58..06bc430f 100644
--- a/src/libcamera/v4l2_subdevice.cpp
+++ b/src/libcamera/v4l2_subdevice.cpp
@@ -134,6 +134,42 @@ int V4L2Subdevice::open()
*/
/**
+ * \brief Get selection rectangle \a rect for \a target
+ * \param[in] pad The 0-indexed pad number the rectangle is retrieved from
+ * \param[in] target The selection target defined by the V4L2_SEL_TGT_* flags
+ * \param[out] rect The retrieved selection rectangle
+ *
+ * \todo Define a V4L2SelectionTarget enum for the selection target
+ *
+ * \return 0 on success or a negative error code otherwise
+ */
+int V4L2Subdevice::getSelection(unsigned int pad, unsigned int target,
+ Rectangle *rect)
+{
+ struct v4l2_subdev_selection sel = {};
+
+ sel.which = V4L2_SUBDEV_FORMAT_ACTIVE;
+ sel.pad = pad;
+ sel.target = target;
+ sel.flags = 0;
+
+ int ret = ioctl(VIDIOC_SUBDEV_G_SELECTION, &sel);
+ if (ret < 0) {
+ LOG(V4L2, Error)
+ << "Unable to get rectangle " << target << " on pad "
+ << pad << ": " << strerror(-ret);
+ return ret;
+ }
+
+ rect->x = sel.r.left;
+ rect->y = sel.r.top;
+ rect->width = sel.r.width;
+ rect->height = sel.r.height;
+
+ return 0;
+}
+
+/**
* \brief Set selection rectangle \a rect for \a target
* \param[in] pad The 0-indexed pad number the rectangle is to be applied to
* \param[in] target The selection target defined by the V4L2_SEL_TGT_* flags