[libcamera-devel] [PATCH v4 3/7] libcamera: v4l2_subdevice: Implement getSelection()

Laurent Pinchart laurent.pinchart at ideasonboard.com
Tue Apr 28 03:39:11 CEST 2020


Hi Jacopo,

Thank you for the patch.

On Mon, Apr 27, 2020 at 11:32:32PM +0200, Jacopo Mondi wrote:
> Implement V4L2Subdevice::getSelection() to support retrieving selection
> rectangles from the v4l2 subdevice.

s/v4l2/V4L2/

> 
> Signed-off-by: Jacopo Mondi <jacopo at jmondi.org>

Reviewed-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>

> ---
>  src/libcamera/include/v4l2_subdevice.h |  2 ++
>  src/libcamera/v4l2_subdevice.cpp       | 33 ++++++++++++++++++++++++++
>  2 files changed, 35 insertions(+)
> 
> diff --git a/src/libcamera/include/v4l2_subdevice.h b/src/libcamera/include/v4l2_subdevice.h
> index 9a5c812db9b6..27ba5b17f61e 100644
> --- a/src/libcamera/include/v4l2_subdevice.h
> +++ b/src/libcamera/include/v4l2_subdevice.h
> @@ -46,6 +46,8 @@ public:
>  
>  	const MediaEntity *entity() const { return entity_; }
>  
> +	int getSelection(unsigned int pad, unsigned int target,
> +			 Rectangle *rect);
>  	int setSelection(unsigned int pad, unsigned int target,
>  			 Rectangle *rect);
>  
> diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp
> index 432e89eacbd3..74788ce7cf4f 100644
> --- a/src/libcamera/v4l2_subdevice.cpp
> +++ b/src/libcamera/v4l2_subdevice.cpp
> @@ -133,6 +133,39 @@ int V4L2Subdevice::open()
>   * \return The subdevice's associated media entity.
>   */
>  
> +/**
> + * \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
> + * \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

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list