summaryrefslogtreecommitdiff
path: root/src/libcamera/v4l2_subdevice.cpp
diff options
context:
space:
mode:
authorJacopo Mondi <jacopo@jmondi.org>2020-04-25 17:24:39 +0200
committerJacopo Mondi <jacopo@jmondi.org>2020-04-28 22:24:00 +0200
commite8d4797ef5c8133b4dbff49ba0995f3842d408b5 (patch)
treebb7caf9efee572dc67de7f9b6efd22db0ac0296e /src/libcamera/v4l2_subdevice.cpp
parent6ed463911defa512725a521f827e63517c6a6419 (diff)
libcamera: v4l2_subdevice: Expose setSelection()
Expose V4L2Subdevice::setSelection() method and drop V4L2Subdevice::setCrop() and V4L2Subdevice::setComopse() as wrapping each target with a single function does not provide any benefit. 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.cpp79
1 files changed, 33 insertions, 46 deletions
diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp
index 5a479a96..e8623d58 100644
--- a/src/libcamera/v4l2_subdevice.cpp
+++ b/src/libcamera/v4l2_subdevice.cpp
@@ -134,27 +134,45 @@ int V4L2Subdevice::open()
*/
/**
- * \brief Set a crop rectangle on one of the V4L2 subdevice pads
+ * \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[inout] rect The rectangle describing crop target area
+ * \param[in] target The selection target defined by the V4L2_SEL_TGT_* flags
+ * \param[inout] rect The selection rectangle to be applied
+ *
+ * \todo Define a V4L2SelectionTarget enum for the selection target
+ *
* \return 0 on success or a negative error code otherwise
*/
-int V4L2Subdevice::setCrop(unsigned int pad, Rectangle *rect)
+int V4L2Subdevice::setSelection(unsigned int pad, unsigned int target,
+ Rectangle *rect)
{
- return setSelection(pad, V4L2_SEL_TGT_CROP, rect);
-}
+ struct v4l2_subdev_selection sel = {};
-/**
- * \brief Set a compose rectangle on one of the V4L2 subdevice pads
- * \param[in] pad The 0-indexed pad number the rectangle is to be applied to
- * \param[inout] rect The rectangle describing the compose target area
- * \return 0 on success or a negative error code otherwise
- */
-int V4L2Subdevice::setCompose(unsigned int pad, Rectangle *rect)
-{
- return setSelection(pad, V4L2_SEL_TGT_COMPOSE, rect);
-}
+ sel.which = V4L2_SUBDEV_FORMAT_ACTIVE;
+ sel.pad = pad;
+ sel.target = target;
+ sel.flags = 0;
+
+ sel.r.left = rect->x;
+ sel.r.top = rect->y;
+ sel.r.width = rect->width;
+ sel.r.height = rect->height;
+
+ int ret = ioctl(VIDIOC_SUBDEV_S_SELECTION, &sel);
+ if (ret < 0) {
+ LOG(V4L2, Error)
+ << "Unable to set 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 Enumerate all media bus codes and frame sizes on a \a pad
* \param[in] pad The 0-indexed pad number to enumerate formats on
@@ -343,35 +361,4 @@ std::vector<SizeRange> V4L2Subdevice::enumPadSizes(unsigned int pad,
return sizes;
}
-int V4L2Subdevice::setSelection(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;
-
- sel.r.left = rect->x;
- sel.r.top = rect->y;
- sel.r.width = rect->width;
- sel.r.height = rect->height;
-
- int ret = ioctl(VIDIOC_SUBDEV_S_SELECTION, &sel);
- if (ret < 0) {
- LOG(V4L2, Error)
- << "Unable to set 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;
-}
-
} /* namespace libcamera */