public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Yunke Cao <yunkec@google.com>
Cc: Hans Verkuil <hverkuil-cisco@xs4all.nl>,
	Daniel Scally <dan.scally@ideasonboard.com>,
	Tomasz Figa <tfiga@chromium.org>,
	Sergey Senozhatsky <senozhatsky@chromium.org>,
	Ricardo Ribalda <ribalda@chromium.org>,
	linux-media@vger.kernel.org
Subject: Re: [PATCH v14 08/11] media: uvcvideo: support V4L2_CTRL_WHICH_MIN/MAX_VAL
Date: Fri, 8 Dec 2023 17:26:20 +0200	[thread overview]
Message-ID: <20231208152620.GI25616@pendragon.ideasonboard.com> (raw)
In-Reply-To: <20231201071907.3080126-9-yunkec@google.com>

Hi Yunke,

Thank you for the patch.

On Fri, Dec 01, 2023 at 04:18:59PM +0900, Yunke Cao wrote:
> Add support for V4L2_CTRL_WHICH_MIN/MAX_VAL in uvc driver.
> It is useful for the V4L2_CID_UVC_REGION_OF_INTEREST_RECT control.
> 
> Reviewed-by: Ricardo Ribalda <ribalda@chromium.org>
> Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org>
> Signed-off-by: Yunke Cao <yunkec@google.com>
> ---
> Changelog since v11:
> - No change.
> Changelog since v10:
> - Added Reviewed-by from Sergey.
> Changelog since v9:
> - Revert a change in v7 that causes v4l2-compliance failure:
> - In uvc_ioctl_g_ext_ctrls(), when v4l2_which is not V4L2_CTRL_WHICH_*_VAL,
> - treat it the same as cur instead of returning EINVAL. This is the existing
> - behavior.
> - The change in v7 of returning EINVAL fails the check in
> - v4l2-compliance/v4l2-test-controls.cpp#L834.
> Changelog since v8:
> - No change.
> Changelog since v7:
> - Address some comments.
> 
>  drivers/media/usb/uvc/uvc_ctrl.c | 64 +++++++++++++++++++++++++++-----
>  drivers/media/usb/uvc/uvc_v4l2.c |  7 +++-
>  drivers/media/usb/uvc/uvcvideo.h |  3 +-
>  3 files changed, 61 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c
> index aae2480496b7..c073c2a02102 100644
> --- a/drivers/media/usb/uvc/uvc_ctrl.c
> +++ b/drivers/media/usb/uvc/uvc_ctrl.c
> @@ -1247,11 +1247,18 @@ int uvc_ctrl_is_accessible(struct uvc_video_chain *chain, u32 v4l2_id,
>  	if (!ctrl)
>  		return -EINVAL;
>  
> -	if (!(ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR) && read)
> -		return -EACCES;
> -
> -	if (!(ctrl->info.flags & UVC_CTRL_FLAG_SET_CUR) && !read)
> -		return -EACCES;
> +	if (read) {
> +		if (ctrls->which == V4L2_CTRL_WHICH_MIN_VAL ||
> +		    ctrls->which == V4L2_CTRL_WHICH_MAX_VAL) {
> +			if (!(ctrl->info.flags & UVC_CTRL_FLAG_GET_MIN) ||
> +			    !(ctrl->info.flags & UVC_CTRL_FLAG_GET_MAX))
> +				return -EINVAL;

Shouldn't this be

		if (ctrls->which == V4L2_CTRL_WHICH_MIN_VAL &&
		    !(ctrl->info.flags & UVC_CTRL_FLAG_GET_MIN))
			return -EINVAL;

		if (ctrls->which == V4L2_CTRL_WHICH_MAX_VAL &&
		    !(ctrl->info.flags & UVC_CTRL_FLAG_GET_MAX))
			return -EINVAL;

> +		} else if (!(ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR))
> +			return -EACCES;

		if (ctrls->which == V4L2_CTRL_WHICH_CUR_VAL &&
		    !(ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR))
			return -EACCES;

> +	} else {
> +		if (!(ctrl->info.flags & UVC_CTRL_FLAG_SET_CUR))
> +			return -EACCES;
> +	}
>  
>  	if (ioctl != VIDIOC_S_EXT_CTRLS || !mapping->master_id)
>  		return 0;
> @@ -1332,6 +1339,9 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain,
>  		v4l2_ctrl->flags |= V4L2_CTRL_FLAG_WRITE_ONLY;
>  	if (!(ctrl->info.flags & UVC_CTRL_FLAG_SET_CUR))
>  		v4l2_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
> +	if ((ctrl->info.flags & UVC_CTRL_FLAG_GET_MAX) &&
> +	    (ctrl->info.flags & UVC_CTRL_FLAG_GET_MIN))
> +		v4l2_ctrl->flags |= V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX;
>  
>  	if (mapping->master_id)
>  		__uvc_find_control(ctrl->entity, mapping->master_id,
> @@ -1981,6 +1991,7 @@ int uvc_ctrl_get(struct uvc_video_chain *chain,
>  static int __uvc_ctrl_get_boundary_std(struct uvc_video_chain *chain,
>  				       struct uvc_control *ctrl,
>  				       struct uvc_control_mapping *mapping,
> +				       u32 v4l2_which,
>  				       struct v4l2_ext_control *xctrl)
>  {
>  	struct v4l2_queryctrl qc = { .id = xctrl->id };
> @@ -1990,28 +2001,59 @@ static int __uvc_ctrl_get_boundary_std(struct uvc_video_chain *chain,
>  	if (ret < 0)
>  		return ret;
>  
> -	xctrl->value = qc.default_value;
> +	switch (v4l2_which) {
> +	case V4L2_CTRL_WHICH_DEF_VAL:
> +		xctrl->value = qc.default_value;
> +		break;
> +	case V4L2_CTRL_WHICH_MIN_VAL:
> +		xctrl->value = qc.minimum;
> +		break;
> +	case V4L2_CTRL_WHICH_MAX_VAL:
> +		xctrl->value = qc.maximum;
> +		break;
> +	}
> +
>  	return 0;
>  }
>  
>  static int __uvc_ctrl_get_boundary_compound(struct uvc_video_chain *chain,
>  					    struct uvc_control *ctrl,
>  					    struct uvc_control_mapping *mapping,
> +					    u32 v4l2_which,
>  					    struct v4l2_ext_control *xctrl)
>  {
> +	u32 flag, id;
>  	int ret;
>  
> +	switch (v4l2_which) {
> +	case V4L2_CTRL_WHICH_DEF_VAL:
> +		flag = UVC_CTRL_FLAG_GET_DEF;
> +		id = UVC_CTRL_DATA_DEF;
> +		break;
> +	case V4L2_CTRL_WHICH_MIN_VAL:
> +		flag = UVC_CTRL_FLAG_GET_MIN;
> +		id = UVC_CTRL_DATA_MIN;
> +		break;
> +	case V4L2_CTRL_WHICH_MAX_VAL:
> +		flag = UVC_CTRL_FLAG_GET_MAX;
> +		id = UVC_CTRL_DATA_MAX;
> +		break;
> +	}
> +
> +	if (!(ctrl->info.flags & flag) && flag != UVC_CTRL_FLAG_GET_DEF)
> +		return -EINVAL;
> +
>  	if (!ctrl->cached) {
>  		ret = uvc_ctrl_populate_cache(chain, ctrl);
>  		if (ret < 0)
>  			return ret;
>  	}
>  
> -	return __uvc_ctrl_get_compound(mapping, ctrl, UVC_CTRL_DATA_DEF, xctrl);
> +	return __uvc_ctrl_get_compound(mapping, ctrl, id, xctrl);
>  }
>  
>  int uvc_ctrl_get_boundary(struct uvc_video_chain *chain,
> -			  struct v4l2_ext_control *xctrl)
> +			  struct v4l2_ext_control *xctrl, u32 v4l2_which)
>  {
>  	struct uvc_control *ctrl;
>  	struct uvc_control_mapping *mapping;
> @@ -2028,9 +2070,11 @@ int uvc_ctrl_get_boundary(struct uvc_video_chain *chain,
>  
>  	if (uvc_ctrl_mapping_is_compound(mapping))
>  		ret = __uvc_ctrl_get_boundary_compound(chain, ctrl, mapping,
> -						       xctrl);
> +						       v4l2_which, xctrl);
>  	else
> -		ret = __uvc_ctrl_get_boundary_std(chain, ctrl, mapping, xctrl);
> +		ret = __uvc_ctrl_get_boundary_std(chain, ctrl, mapping,
> +						  v4l2_which, xctrl);
> +
>  
>  done:
>  	mutex_unlock(&chain->ctrl_mutex);
> diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c
> index ff72caf7bc9e..352f62ef02f2 100644
> --- a/drivers/media/usb/uvc/uvc_v4l2.c
> +++ b/drivers/media/usb/uvc/uvc_v4l2.c
> @@ -1094,9 +1094,12 @@ static int uvc_ioctl_g_ext_ctrls(struct file *file, void *fh,
>  	if (ret < 0)
>  		return ret;
>  
> -	if (ctrls->which == V4L2_CTRL_WHICH_DEF_VAL) {
> +	switch (ctrls->which) {
> +	case V4L2_CTRL_WHICH_DEF_VAL:
> +	case V4L2_CTRL_WHICH_MIN_VAL:
> +	case V4L2_CTRL_WHICH_MAX_VAL:
>  		for (i = 0; i < ctrls->count; ++ctrl, ++i) {
> -			ret = uvc_ctrl_get_boundary(chain, ctrl);
> +			ret = uvc_ctrl_get_boundary(chain, ctrl, ctrls->which);
>  			if (ret < 0) {
>  				ctrls->error_idx = i;
>  				return ret;
> diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h
> index 11805b729c22..6fda40919e7f 100644
> --- a/drivers/media/usb/uvc/uvcvideo.h
> +++ b/drivers/media/usb/uvc/uvcvideo.h
> @@ -790,7 +790,8 @@ static inline int uvc_ctrl_rollback(struct uvc_fh *handle)
>  
>  int uvc_ctrl_get(struct uvc_video_chain *chain, struct v4l2_ext_control *xctrl);
>  int uvc_ctrl_get_boundary(struct uvc_video_chain *chain,
> -			  struct v4l2_ext_control *xctrl);
> +			  struct v4l2_ext_control *xctrl,
> +			  u32 v4l2_which);
>  int uvc_ctrl_set(struct uvc_fh *handle, struct v4l2_ext_control *xctrl);
>  int uvc_ctrl_is_accessible(struct uvc_video_chain *chain, u32 v4l2_id,
>  			   const struct v4l2_ext_controls *ctrls,

-- 
Regards,

Laurent Pinchart

  reply	other threads:[~2023-12-08 15:26 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-01  7:18 [PATCH v14 00/11] Implement UVC v1.5 ROI Yunke Cao
2023-12-01  7:18 ` [PATCH v14 01/11] media: v4l2_ctrl: Add V4L2_CTRL_TYPE_RECT Yunke Cao
2023-12-01  8:35   ` Hans Verkuil
2023-12-08 13:41     ` Laurent Pinchart
2023-12-12  1:33       ` Yunke Cao
2023-12-12  1:37         ` Laurent Pinchart
2023-12-01  7:18 ` [PATCH v14 02/11] media: uvcvideo: add uvc_ctrl_get_boundary for getting default value Yunke Cao
2023-12-08 15:13   ` Laurent Pinchart
2023-12-01  7:18 ` [PATCH v14 03/11] media: uvcvideo: introduce __uvc_ctrl_get_std() Yunke Cao
2023-12-08 15:12   ` Laurent Pinchart
2023-12-01  7:18 ` [PATCH v14 04/11] media: uvcvideo: Split uvc_control_mapping.size to v4l2 and data size Yunke Cao
2023-12-08 14:15   ` Laurent Pinchart
2023-12-12  7:59     ` Yunke Cao
2023-12-18  3:17       ` Laurent Pinchart
2023-12-01  7:18 ` [PATCH v14 05/11] media: uvcvideo: Add support for compound controls Yunke Cao
2023-12-06  5:45   ` Dan Carpenter
2023-12-08 15:07   ` Laurent Pinchart
2023-12-13  7:38     ` Yunke Cao
2023-12-18  3:27       ` Laurent Pinchart
2023-12-20  2:28         ` Yunke Cao
2023-12-01  7:18 ` [PATCH v14 06/11] v4l2-ctrls: add support for V4L2_CTRL_WHICH_MIN/MAX_VAL Yunke Cao
2023-12-01  8:32   ` Hans Verkuil
2023-12-05 22:30   ` kernel test robot
2023-12-06  4:34   ` kernel test robot
2023-12-06  5:59   ` kernel test robot
2023-12-08 15:20   ` Laurent Pinchart
2023-12-13  4:06     ` Yunke Cao
2023-12-14 17:34   ` kernel test robot
2023-12-01  7:18 ` [PATCH v14 07/11] media: vivid: Add an rectangle control Yunke Cao
2023-12-01  7:18 ` [PATCH v14 08/11] media: uvcvideo: support V4L2_CTRL_WHICH_MIN/MAX_VAL Yunke Cao
2023-12-08 15:26   ` Laurent Pinchart [this message]
2023-12-01  7:19 ` [PATCH v14 09/11] media: uvcvideo: implement UVC v1.5 ROI Yunke Cao
2023-12-08 15:43   ` Laurent Pinchart
2024-03-14 13:24   ` Gergo Koteles
2023-12-01  7:19 ` [PATCH v14 10/11] media: uvcvideo: initilaize ROI control to default value Yunke Cao
2023-12-08 15:50   ` Laurent Pinchart
2023-12-01  7:19 ` [PATCH v14 11/11] media: uvcvideo: document UVC v1.5 ROI Yunke Cao
2023-12-08 16:00   ` Laurent Pinchart
2023-12-12  4:45     ` Yunke Cao
2023-12-18  3:44       ` Laurent Pinchart

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231208152620.GI25616@pendragon.ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=dan.scally@ideasonboard.com \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=linux-media@vger.kernel.org \
    --cc=ribalda@chromium.org \
    --cc=senozhatsky@chromium.org \
    --cc=tfiga@chromium.org \
    --cc=yunkec@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox