summaryrefslogtreecommitdiff
path: root/src/libcamera/v4l2_videodevice.cpp
diff options
context:
space:
mode:
authorNaushir Patuck <naush@raspberrypi.com>2020-02-04 11:24:44 +0000
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-02-13 22:19:07 +0200
commitea3a00bc33f950c794e8b6d8cf0201a24c0c3d0d (patch)
treeccff8ec458a47a46af89302b57164440182a8f87 /src/libcamera/v4l2_videodevice.cpp
parent5dc5fb2ac57ec7123215c82d10992cfbcddf34e9 (diff)
libcamera: v4l2_videodevice: Add crop/selection control
Add control for cropping/selection on a V4L2 video device through the VIDIOC_S_SELECTION ioctl. This is similar to the existing cropping control available on V4L2 sub-devices. Signed-off-by: Naushir Patuck <naush@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_videodevice.cpp')
-rw-r--r--src/libcamera/v4l2_videodevice.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
index b874f238..99470ce1 100644
--- a/src/libcamera/v4l2_videodevice.cpp
+++ b/src/libcamera/v4l2_videodevice.cpp
@@ -942,6 +942,54 @@ std::vector<SizeRange> V4L2VideoDevice::enumSizes(unsigned int pixelFormat)
return sizes;
}
+/**
+ * \brief Set a crop rectangle on the V4L2 video device node
+ * \param[inout] rect The rectangle describing the crop target area
+ * \return 0 on success or a negative error code otherwise
+ */
+int V4L2VideoDevice::setCrop(Rectangle *rect)
+{
+ return setSelection(V4L2_SEL_TGT_CROP, rect);
+}
+
+/**
+ * \brief Set a compose rectangle on the V4L2 video device node
+ * \param[inout] rect The rectangle describing the compose target area
+ * \return 0 on success or a negative error code otherwise
+ */
+int V4L2VideoDevice::setCompose(Rectangle *rect)
+{
+ return setSelection(V4L2_SEL_TGT_COMPOSE, rect);
+}
+
+int V4L2VideoDevice::setSelection(unsigned int target, Rectangle *rect)
+{
+ struct v4l2_selection sel = {};
+
+ sel.type = bufferType_;
+ sel.target = target;
+ sel.flags = 0;
+
+ sel.r.left = rect->x;
+ sel.r.top = rect->y;
+ sel.r.width = rect->w;
+ sel.r.height = rect->h;
+
+ int ret = ioctl(VIDIOC_S_SELECTION, &sel);
+ if (ret < 0) {
+ LOG(V4L2, Error) << "Unable to set rectangle " << target
+ << ": " << strerror(-ret);
+ return ret;
+ }
+
+ rect->x = sel.r.left;
+ rect->y = sel.r.top;
+ rect->w = sel.r.width;
+ rect->h = sel.r.height;
+
+ return 0;
+}
+
int V4L2VideoDevice::requestBuffers(unsigned int count)
{
struct v4l2_requestbuffers rb = {};