All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: Ricardo Ribalda <ribalda@chromium.org>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Ricardo Ribalda <ribalda@kernel.org>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	Hans Verkuil <hverkuil@xs4all.nl>
Cc: Yunke Cao <yunkec@chromium.org>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	Yunke Cao <yunkec@google.com>
Subject: Re: [PATCH v15 18/19] media: uvcvideo: implement UVC v1.5 ROI
Date: Mon, 9 Dec 2024 15:22:25 +0100	[thread overview]
Message-ID: <2e90c10a-71fe-4e80-9ac3-80393bc8b266@redhat.com> (raw)
In-Reply-To: <20241114-uvc-roi-v15-18-64cfeb56b6f8@chromium.org>

Hi,

On 14-Nov-24 8:10 PM, Ricardo Ribalda wrote:
> From: Yunke Cao <yunkec@google.com>
> 
> Implement support for ROI as described in UVC 1.5:
> 4.2.2.1.20 Digital Region of Interest (ROI) Control
> 
> ROI control is implemented using V4L2 control API as
> two UVC-specific controls:
> V4L2_CID_UVC_REGION_OF_INTEREST_RECT and
> V4L2_CID_UVC_REGION_OF_INTEREST_AUTO.
> 
> Reviewed-by: Ricardo Ribalda <ribalda@chromium.org>
> Signed-off-by: Yunke Cao <yunkec@google.com>
> ---
>  drivers/media/usb/uvc/uvc_ctrl.c   | 81 ++++++++++++++++++++++++++++++++++++++
>  drivers/media/usb/uvc/uvcvideo.h   |  7 ++++
>  include/uapi/linux/usb/video.h     |  1 +
>  include/uapi/linux/uvcvideo.h      | 13 ++++++
>  include/uapi/linux/v4l2-controls.h |  9 +++++
>  5 files changed, 111 insertions(+)
> 
> diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c
> index f262e05ad3a8..5b619ef40dd3 100644
> --- a/drivers/media/usb/uvc/uvc_ctrl.c
> +++ b/drivers/media/usb/uvc/uvc_ctrl.c
> @@ -358,6 +358,24 @@ static const struct uvc_control_info uvc_ctrls[] = {
>  		.flags		= UVC_CTRL_FLAG_GET_CUR
>  				| UVC_CTRL_FLAG_AUTO_UPDATE,
>  	},
> +	/*
> +	 * UVC_CTRL_FLAG_AUTO_UPDATE is needed because the RoI may get updated
> +	 * by sensors.
> +	 * "This RoI should be the same as specified in most recent SET_CUR
> +	 * except in the case where the ‘Auto Detect and Track’ and/or
> +	 * ‘Image Stabilization’ bit have been set."
> +	 * 4.2.2.1.20 Digital Region of Interest (ROI) Control
> +	 */
> +	{
> +		.entity		= UVC_GUID_UVC_CAMERA,
> +		.selector	= UVC_CT_REGION_OF_INTEREST_CONTROL,
> +		.index		= 21,
> +		.size		= 10,
> +		.flags		= UVC_CTRL_FLAG_SET_CUR | UVC_CTRL_FLAG_GET_CUR
> +				| UVC_CTRL_FLAG_GET_MIN | UVC_CTRL_FLAG_GET_MAX
> +				| UVC_CTRL_FLAG_GET_DEF
> +				| UVC_CTRL_FLAG_AUTO_UPDATE,
> +	},
>  };
>  
>  static const u32 uvc_control_classes[] = {
> @@ -603,6 +621,44 @@ static const struct uvc_control_mapping *uvc_ctrl_filter_plf_mapping(
>  	return out_mapping;
>  }
>  
> +static int uvc_get_rect(struct uvc_control_mapping *mapping, u8 query,
> +			const void *uvc_in, size_t v4l2_size, void *v4l2_out)
> +{
> +	const struct uvc_rect *uvc_rect = uvc_in;
> +	struct v4l2_rect *v4l2_rect = v4l2_out;
> +
> +	if (WARN_ON(v4l2_size != sizeof(struct v4l2_rect)))
> +		return -EINVAL;
> +
> +	if (uvc_rect->left > uvc_rect->right ||
> +	    uvc_rect->top > uvc_rect->bottom)
> +		return -EIO;
> +
> +	v4l2_rect->top = uvc_rect->top;
> +	v4l2_rect->left = uvc_rect->left;
> +	v4l2_rect->height = uvc_rect->bottom - uvc_rect->top + 1;
> +	v4l2_rect->width = uvc_rect->right - uvc_rect->left + 1;
> +
> +	return 0;
> +}
> +
> +static int uvc_set_rect(struct uvc_control_mapping *mapping, size_t v4l2_size,
> +			const void *v4l2_in, void *uvc_out)
> +{
> +	struct uvc_rect *uvc_rect = uvc_out;
> +	const struct v4l2_rect *v4l2_rect = v4l2_in;
> +
> +	if (WARN_ON(v4l2_size != sizeof(struct v4l2_rect)))
> +		return -EINVAL;
> +
> +	uvc_rect->top = max(0xffff, v4l2_rect->top);
> +	uvc_rect->left = max(0xffff, v4l2_rect->left);
> +	uvc_rect->bottom = max(0xffff, v4l2_rect->height + v4l2_rect->top - 1);
> +	uvc_rect->right = max(0xffff, v4l2_rect->width + v4l2_rect->left - 1);

As already remarked all 4 lines should be min() not max()

Also this might just be me, but I have a preference for writing top + height
for the bottom rather then writing height + top, since the window starts with
skippig top pixels and then has height pixels filled in. And same for
calculating rect->width. IOW I have a preference for writing this as:

	uvc_rect->bottom = min(0xffff, v4l2_rect->top + v4l2_rect->height - 1);
	uvc_rect->right = min(0xffff, v4l2_rect->left + v4l2_rect->width - 1);

As I said this might just be me, but to me the above reads more naturally.




> +
> +	return 0;
> +}
> +
>  static const struct uvc_control_mapping uvc_ctrl_mappings[] = {
>  	{
>  		.id		= V4L2_CID_BRIGHTNESS,
> @@ -897,6 +953,28 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = {
>  		.selector	= UVC_PU_POWER_LINE_FREQUENCY_CONTROL,
>  		.filter_mapping	= uvc_ctrl_filter_plf_mapping,
>  	},
> +	{
> +		.id		= V4L2_CID_UVC_REGION_OF_INTEREST_RECT,
> +		.entity		= UVC_GUID_UVC_CAMERA,
> +		.selector	= UVC_CT_REGION_OF_INTEREST_CONTROL,
> +		.size		= sizeof(struct uvc_rect) * 8,
> +		.offset		= 0,
> +		.v4l2_type	= V4L2_CTRL_TYPE_RECT,
> +		.data_type	= UVC_CTRL_DATA_TYPE_RECT,
> +		.get		= uvc_get_rect,
> +		.set		= uvc_set_rect,
> +		.name		= "Region Of Interest Rectangle",
> +	},
> +	{
> +		.id		= V4L2_CID_UVC_REGION_OF_INTEREST_AUTO,
> +		.entity		= UVC_GUID_UVC_CAMERA,
> +		.selector	= UVC_CT_REGION_OF_INTEREST_CONTROL,
> +		.size		= 16,
> +		.offset		= 64,
> +		.v4l2_type	= V4L2_CTRL_TYPE_BITMASK,
> +		.data_type	= UVC_CTRL_DATA_TYPE_BITMASK,
> +		.name		= "Region Of Interest Auto Controls",
> +	},
>  };
>  
>  /* ------------------------------------------------------------------------
> @@ -1465,6 +1543,9 @@ static int __uvc_queryctrl_boundaries(struct uvc_video_chain *chain,
>  
>  static size_t uvc_mapping_v4l2_size(struct uvc_control_mapping *mapping)
>  {
> +	if (mapping->v4l2_type == V4L2_CTRL_TYPE_RECT)
> +		return sizeof(struct v4l2_rect);
> +
>  	if (uvc_ctrl_mapping_is_compound(mapping))
>  		return DIV_ROUND_UP(mapping->size, 8);
>  
> diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h
> index 8aca1a2fe587..d910a5e5b514 100644
> --- a/drivers/media/usb/uvc/uvcvideo.h
> +++ b/drivers/media/usb/uvc/uvcvideo.h
> @@ -294,6 +294,13 @@ struct uvc_streaming_header {
>  	u8 bTriggerUsage;
>  };
>  
> +struct uvc_rect {
> +	u16 top;
> +	u16 left;
> +	u16 bottom;
> +	u16 right;
> +} __packed;
> +

This should probably be grouped togather with uvc_status_* structs which are
also marked __packed because they represent hw API rather then just host
in memory structures.

>  enum uvc_buffer_state {
>  	UVC_BUF_STATE_IDLE	= 0,
>  	UVC_BUF_STATE_QUEUED	= 1,
> diff --git a/include/uapi/linux/usb/video.h b/include/uapi/linux/usb/video.h
> index 2ff0e8a3a683..2afb4420e6c4 100644
> --- a/include/uapi/linux/usb/video.h
> +++ b/include/uapi/linux/usb/video.h
> @@ -104,6 +104,7 @@
>  #define UVC_CT_ROLL_ABSOLUTE_CONTROL			0x0f
>  #define UVC_CT_ROLL_RELATIVE_CONTROL			0x10
>  #define UVC_CT_PRIVACY_CONTROL				0x11
> +#define UVC_CT_REGION_OF_INTEREST_CONTROL		0x14
>  
>  /* A.9.5. Processing Unit Control Selectors */
>  #define UVC_PU_CONTROL_UNDEFINED			0x00
> diff --git a/include/uapi/linux/uvcvideo.h b/include/uapi/linux/uvcvideo.h
> index f86185456dc5..cbe15bca9569 100644
> --- a/include/uapi/linux/uvcvideo.h
> +++ b/include/uapi/linux/uvcvideo.h
> @@ -16,6 +16,7 @@
>  #define UVC_CTRL_DATA_TYPE_BOOLEAN	3
>  #define UVC_CTRL_DATA_TYPE_ENUM		4
>  #define UVC_CTRL_DATA_TYPE_BITMASK	5
> +#define UVC_CTRL_DATA_TYPE_RECT		6
>  
>  /* Control flags */
>  #define UVC_CTRL_FLAG_SET_CUR		(1 << 0)
> @@ -38,6 +39,18 @@
>  
>  #define UVC_MENU_NAME_LEN 32
>  
> +/* V4L2 driver-specific controls */
> +#define V4L2_CID_UVC_REGION_OF_INTEREST_RECT	(V4L2_CID_USER_UVC_BASE + 1)
> +#define V4L2_CID_UVC_REGION_OF_INTEREST_AUTO	(V4L2_CID_USER_UVC_BASE + 2)
> +#define V4L2_UVC_REGION_OF_INTEREST_AUTO_EXPOSURE		(1 << 0)
> +#define V4L2_UVC_REGION_OF_INTEREST_AUTO_IRIS			(1 << 1)
> +#define V4L2_UVC_REGION_OF_INTEREST_AUTO_WHITE_BALANCE		(1 << 2)
> +#define V4L2_UVC_REGION_OF_INTEREST_AUTO_FOCUS			(1 << 3)
> +#define V4L2_UVC_REGION_OF_INTEREST_AUTO_FACE_DETECT		(1 << 4)
> +#define V4L2_UVC_REGION_OF_INTEREST_AUTO_DETECT_AND_TRACK	(1 << 5)
> +#define V4L2_UVC_REGION_OF_INTEREST_AUTO_IMAGE_STABILIZATION	(1 << 6)
> +#define V4L2_UVC_REGION_OF_INTEREST_AUTO_HIGHER_QUALITY		(1 << 7)
> +

Hmm, shoudn't these be standardized. At least the ROI rect control seems like
something which could be standardized ?

Was using driver specific CIDs for this discussed with Hans Verkuil ?

>  struct uvc_menu_info {
>  	__u32 value;
>  	__u8 name[UVC_MENU_NAME_LEN];
> diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h
> index 974fd254e573..6c91d6fa4708 100644
> --- a/include/uapi/linux/v4l2-controls.h
> +++ b/include/uapi/linux/v4l2-controls.h
> @@ -215,6 +215,13 @@ enum v4l2_colorfx {
>   */
>  #define V4L2_CID_USER_THP7312_BASE		(V4L2_CID_USER_BASE + 0x11c0)
>  
> +/*
> + * The base for the uvc driver controls.
> + * See linux/uvcvideo.h for the list of controls.
> + * We reserve 64 controls for this driver.
> + */
> +#define V4L2_CID_USER_UVC_BASE			(V4L2_CID_USER_BASE + 0x11e0)
> +
>  /* MPEG-class control IDs */
>  /* The MPEG controls are applicable to all codec controls
>   * and the 'MPEG' part of the define is historical */
> @@ -1089,6 +1096,8 @@ enum v4l2_auto_focus_range {
>  
>  #define V4L2_CID_HDR_SENSOR_MODE		(V4L2_CID_CAMERA_CLASS_BASE+36)
>  
> +/* CAMERA-class private control IDs */
> +
>  /* FM Modulator class control IDs */
>  
>  #define V4L2_CID_FM_TX_CLASS_BASE		(V4L2_CTRL_CLASS_FM_TX | 0x900)
> 


Regards,

Hans



  parent reply	other threads:[~2024-12-09 14:22 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-14 19:10 [PATCH v15 00/19] media: uvcvideo: Implement UVC v1.5 ROI Ricardo Ribalda
2024-11-14 19:10 ` [PATCH v15 01/19] media: uvcvideo: Fix event flags in uvc_ctrl_send_events Ricardo Ribalda
2024-11-14 19:10 ` [PATCH v15 02/19] media: v4l2_ctrl: Add V4L2_CTRL_TYPE_RECT Ricardo Ribalda
2024-11-14 19:10 ` [PATCH v15 03/19] media: v4l2-ctrls: add support for V4L2_CTRL_WHICH_MIN/MAX_VAL Ricardo Ribalda
2024-11-14 19:10 ` [PATCH v15 04/19] media: vivid: Add a rectangle control Ricardo Ribalda
2024-11-14 19:10 ` [PATCH v15 05/19] media: uvcvideo: Handle uvc menu translation inside uvc_get_le_value Ricardo Ribalda
2024-11-25 15:50   ` Hans de Goede
2024-11-14 19:10 ` [PATCH v15 06/19] media: uvcvideo: Handle uvc menu translation inside uvc_set_le_value Ricardo Ribalda
2024-11-25 15:58   ` Hans de Goede
2024-11-14 19:10 ` [PATCH v15 07/19] media: uvcvideo: refactor uvc_ioctl_g_ext_ctrls Ricardo Ribalda
2024-11-25 16:01   ` Hans de Goede
2024-11-14 19:10 ` [PATCH v15 08/19] media: uvcvideo: uvc_ioctl_(g|s)_ext_ctrls: handle NoP case Ricardo Ribalda
2024-11-25 16:01   ` Hans de Goede
2024-11-14 19:10 ` [PATCH v15 09/19] media: uvcvideo: Support any size for mapping get/set Ricardo Ribalda
2024-12-09  8:56   ` Yunke Cao
2024-12-09 12:49   ` Hans de Goede
2024-11-14 19:10 ` [PATCH v15 10/19] media: uvcvideo: Factor out clamping from uvc_ctrl_set Ricardo Ribalda
2024-12-09  8:50   ` Yunke Cao
2024-12-09 12:57   ` Hans de Goede
2024-11-14 19:10 ` [PATCH v15 11/19] media: uvcvideo: add support for compound controls Ricardo Ribalda
2024-12-09 13:35   ` Hans de Goede
2024-12-09 13:58   ` Hans de Goede
2024-11-14 19:10 ` [PATCH v15 12/19] media: uvcvideo: Factor out query_boundaries from query_ctrl Ricardo Ribalda
2024-12-09  8:50   ` Yunke Cao
2024-12-09 13:38   ` Hans de Goede
2024-11-14 19:10 ` [PATCH v15 13/19] media: uvcvideo: support V4L2_CTRL_WHICH_MIN/MAX_VAL Ricardo Ribalda
2024-12-09 13:47   ` Hans de Goede
2024-11-14 19:10 ` [PATCH v15 14/19] media: uvcvideo: Use the camera to clamp compound controls Ricardo Ribalda
2024-12-09 14:05   ` Hans de Goede
2024-12-09 14:46     ` Ricardo Ribalda
2024-11-14 19:10 ` [PATCH v15 15/19] media: uvcvideo: let v4l2_query_v4l2_ctrl() work with v4l2_query_ext_ctrl Ricardo Ribalda
2024-12-09  8:50   ` Yunke Cao
2024-12-09 14:08   ` Hans de Goede
2024-12-09 14:12     ` Ricardo Ribalda
2024-11-14 19:10 ` [PATCH v15 16/19] media: uvcvideo: Introduce uvc_mapping_v4l2_size Ricardo Ribalda
2024-12-09  8:51   ` Yunke Cao
2024-12-09 14:09   ` Hans de Goede
2024-11-14 19:10 ` [PATCH v15 17/19] media: uvcvideo: Add sanity check to uvc_ioctl_xu_ctrl_map Ricardo Ribalda
2024-11-29  8:15   ` Ricardo Ribalda
2024-12-09 14:11   ` Hans de Goede
2024-12-09 14:15     ` Ricardo Ribalda
2024-11-14 19:10 ` [PATCH v15 18/19] media: uvcvideo: implement UVC v1.5 ROI Ricardo Ribalda
2024-11-14 19:53   ` Gergo Koteles
2024-11-14 20:03     ` Ricardo Ribalda
2024-11-14 20:16       ` Gergo Koteles
2024-11-14 20:28         ` Ricardo Ribalda
2024-11-15  0:04           ` Gergo Koteles
2024-11-15  8:22             ` Ricardo Ribalda
2024-11-18 15:59       ` Hans de Goede
2024-11-18 16:16         ` Ricardo Ribalda Delgado
2024-11-25 14:27           ` Hans de Goede
2024-12-02  8:02   ` Yunke Cao
2024-12-02  9:26     ` Ricardo Ribalda
2024-12-06  7:50       ` Yunke Cao
2024-12-09 14:22   ` Hans de Goede [this message]
2024-12-09 15:23     ` Ricardo Ribalda
2024-12-09 15:28       ` Hans de Goede
2024-11-14 19:10 ` [PATCH v15 19/19] media: uvcvideo: document " Ricardo Ribalda
2024-12-09 14:36   ` Hans de Goede
2024-12-09 15:22     ` Ricardo Ribalda
2024-12-09 15:31       ` Hans de Goede
2024-12-09  8:53 ` [PATCH v15 00/19] media: uvcvideo: Implement " Yunke Cao

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=2e90c10a-71fe-4e80-9ac3-80393bc8b266@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=hverkuil@xs4all.nl \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=ribalda@chromium.org \
    --cc=ribalda@kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    --cc=yunkec@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.