[libcamera-devel] [PATCH 4/5] libcamera: v4l2_subdevice: Add G_SELECTION ioctl support

Niklas Söderlund niklas.soderlund at ragnatech.se
Sat Aug 17 17:58:04 CEST 2019


Hi Jacopo,

Thanks for your work.

On 2019-08-17 12:59:36 +0200, Jacopo Mondi wrote:
> Add a private operation to perform G_SELECTION ioctl on the v4l2
> subdevice and create two public methods to retrieve the crop bound
> rectangle and the subdevice native area size.
> 
> Signed-off-by: Jacopo Mondi <jacopo at jmondi.org>

Reviewed-by: Niklas Söderlund <niklas.soderlund at ragnatech.se>

> ---
>  src/libcamera/include/v4l2_subdevice.h |  4 +++
>  src/libcamera/v4l2_subdevice.cpp       | 48 ++++++++++++++++++++++++++
>  2 files changed, 52 insertions(+)
> 
> diff --git a/src/libcamera/include/v4l2_subdevice.h b/src/libcamera/include/v4l2_subdevice.h
> index 9c077674f997..5316617c6873 100644
> --- a/src/libcamera/include/v4l2_subdevice.h
> +++ b/src/libcamera/include/v4l2_subdevice.h
> @@ -43,6 +43,8 @@ public:
>  
>  	int setCrop(unsigned int pad, Rectangle *rect);
>  	int setCompose(unsigned int pad, Rectangle *rect);
> +	int getCropBounds(unsigned int pad, Rectangle *rect);
> +	int getNativeSize(unsigned int pad, Rectangle *rect);
>  
>  	ImageFormats formats(unsigned int pad);
>  
> @@ -62,6 +64,8 @@ private:
>  
>  	int setSelection(unsigned int pad, unsigned int target,
>  			 Rectangle *rect);
> +	int getSelection(unsigned int pad, unsigned int target,
> +			 Rectangle *rect);
>  
>  	const MediaEntity *entity_;
>  };
> diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp
> index a188298de34c..5e661e2ef1fc 100644
> --- a/src/libcamera/v4l2_subdevice.cpp
> +++ b/src/libcamera/v4l2_subdevice.cpp
> @@ -148,6 +148,28 @@ int V4L2Subdevice::setCompose(unsigned int pad, Rectangle *rect)
>  	return setSelection(pad, V4L2_SEL_TGT_COMPOSE, rect);
>  }
>  
> +/**
> + * \brief Get the crop bounds rectangle on one of the V4L2 subdevice pads
> + * \param[in] pad The 0-indexed pad number the rectangle is retrived from
> + * \param[out] rect The rectangle describing the crop bounds area
> + * \return 0 on success or a negative error code otherwise
> + */
> +int V4L2Subdevice::getCropBounds(unsigned int pad, Rectangle *rect)
> +{
> +	return getSelection(pad, V4L2_SEL_TGT_CROP_BOUNDS, rect);
> +}
> +
> +/**
> + * \brief Get the native area size on one of the V4L2 subdevice pads
> + * \param[in] pad The 0-indexed pad number the native area is retrieved from
> + * \param[out] rect The rectangle describing the native size area
> + * \return 0 on success or a negative error code otherwise
> + */
> +int V4L2Subdevice::getNativeSize(unsigned int pad, Rectangle *rect)
> +{
> +	return getSelection(pad, V4L2_SEL_TGT_NATIVE_SIZE, rect);
> +}
> +
>  /**
>   * \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
> @@ -360,4 +382,30 @@ int V4L2Subdevice::setSelection(unsigned int pad, unsigned int target,
>  	return 0;
>  }
>  
> +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->w = sel.r.width;
> +	rect->h = sel.r.height;
> +
> +	return 0;
> +}
> +
>  } /* namespace libcamera */
> -- 
> 2.22.0
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel at lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

-- 
Regards,
Niklas Söderlund


More information about the libcamera-devel mailing list