Skip to contentSkip to conversation

media: Implement UVC v1.5 ROI

PATCH Superseded Yunke Cao 3 participants 15 messages May 16, 2022 – May 20, 2022

Subsystems (6)

v2 of 14 Superseded Latest is v14 →

lore
Share & tools
lore

Yunke Cao

author
#0 lore raw

v2 cover media: Implement UVC v1.5 ROI

This patch set implements UVC v1.5 regioin of interest using V4L2 control API.

ROI control is consisted an auto control with type bitmask and a rectangle control with a newly added type V4L2_CTRL_TYPE_RECT.

V4L2_CTRL_WHICH_MIN/MAX_VAL is added to support the rectangle control.

A rectangle control is also added to the vivid test driver.

Tested on two different usb cameras using v4l2-ctl and calling ioctls.

Yunke Cao (6):
media: v4l2_ctrl: Add region of interest rectangle control
media: v4l2_ctrl: Add region of interest auto control
media: v4l2_ctrl: Add V4L2_CTRL_WHICH_MIN/MAX_VAL
media: uvcvideo: implement UVC v1.5 ROI
media: uvcvideo: Initialize roi to default value
media: vivid: Add a roi rectangle control

 .../userspace-api/media/drivers/uvcvideo.rst  |   1 +
 .../media/v4l/ext-ctrls-camera.rst            |  29 +++
 .../media/v4l/vidioc-g-ext-ctrls.rst          |  14 +-
 .../media/videodev2.h.rst.exceptions          |   3 +
 drivers/media/i2c/imx214.c                    |   4 +-
 .../media/test-drivers/vivid/vivid-ctrls.c    |  34 +++
 drivers/media/usb/uvc/uvc_ctrl.c              | 213 ++++++++++++++++--
 drivers/media/usb/uvc/uvc_v4l2.c              |  12 +-
 drivers/media/usb/uvc/uvcvideo.h              |  10 +-
 drivers/media/v4l2-core/v4l2-ctrls-api.c      |  51 ++++-
 drivers/media/v4l2-core/v4l2-ctrls-core.c     | 155 ++++++++++++-
 drivers/media/v4l2-core/v4l2-ctrls-defs.c     |   6 +
 drivers/media/v4l2-core/v4l2-ioctl.c          |   4 +-
 include/media/v4l2-ctrls.h                    |  32 ++-
 include/uapi/linux/usb/video.h                |   1 +
 include/uapi/linux/uvcvideo.h                 |   1 +
 include/uapi/linux/v4l2-controls.h            |  11 +
 include/uapi/linux/videodev2.h                |   4 +
 18 files changed, 532 insertions(+), 53 deletions(-)
Signature · 1 line
2.36.0.550.gb090851708-goog
author
#1 lore raw

PATCH v2 1/6 media: v4l2_ctrl: Add region of interest rectangle control

Including:
1. Add a control ID.
2. Add p_rect to struct v4l2_ext_control with basic support in v4l2-ctrls.

---
 .../media/v4l/ext-ctrls-camera.rst            |  4 ++++
 .../media/v4l/vidioc-g-ext-ctrls.rst          |  4 ++++
 .../media/videodev2.h.rst.exceptions          |  1 +
 drivers/media/v4l2-core/v4l2-ctrls-core.c     | 20 +++++++++++++++++++
 drivers/media/v4l2-core/v4l2-ctrls-defs.c     |  4 ++++
 include/media/v4l2-ctrls.h                    |  2 ++
 include/uapi/linux/v4l2-controls.h            |  2 ++
 include/uapi/linux/videodev2.h                |  2 ++
 8 files changed, 39 insertions(+)
Documentation/userspace-api/media/v4l/ext-ctrls-camera.rst +4 -0
index 4c5061aa9cd4..86a1f09a8a1c 100644
@@ -661,3 +661,7 @@ enum v4l2_scene_mode -
 .. [#f1]
    This control may be changed to a menu control in the future, if more
    options are required.
+
+``V4L2_CID_REGION_OF_INTEREST_RECT (struct)``
+    This control determines the region of interest. Region of interest is an
+    rectangular area represented by a struct v4l2_rect.
Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst +4 -0
index 29971a45a2d4..f4e205ead0a2 100644
@@ -189,6 +189,10 @@ still cause this situation.
       - ``p_area``
       - A pointer to a struct :c:type:`v4l2_area`. Valid if this control is
         of type ``V4L2_CTRL_TYPE_AREA``.
+    * - struct :c:type:`v4l2_rect` *
+      - ``p_area``
+      - A pointer to a struct :c:type:`v4l2_rect`. Valid if this control is
+        of type ``V4L2_CTRL_TYPE_RECT``.
     * - struct :c:type:`v4l2_ctrl_h264_sps` *
       - ``p_h264_sps``
       - A pointer to a struct :c:type:`v4l2_ctrl_h264_sps`. Valid if this control is
Documentation/userspace-api/media/videodev2.h.rst.exceptions +1 -0
index 9cbb7a0c354a..7b423475281d 100644
@@ -147,6 +147,7 @@ replace symbol V4L2_CTRL_TYPE_HEVC_SPS :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_HEVC_PPS :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_AREA :c:type:`v4l2_ctrl_type`
+replace symbol V4L2_CTRL_TYPE_RECT :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_FWHT_PARAMS :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_VP8_FRAME :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_VP9_COMPRESSED_HDR :c:type:`v4l2_ctrl_type`
drivers/media/v4l2-core/v4l2-ctrls-core.c +20 -0
index 8968cec8454e..dcde405c2713 100644
@@ -84,6 +84,11 @@ static bool std_equal(const struct v4l2_ctrl *ctrl, u32 idx,
 		return ptr1.p_u16[idx] == ptr2.p_u16[idx];
 	case V4L2_CTRL_TYPE_U32:
 		return ptr1.p_u32[idx] == ptr2.p_u32[idx];
+	case V4L2_CTRL_TYPE_RECT:
+		return ptr1.p_rect->top == ptr2.p_rect->top &&
+		       ptr1.p_rect->left == ptr2.p_rect->left &&
+		       ptr1.p_rect->height == ptr2.p_rect->height &&
+		       ptr1.p_rect->width == ptr2.p_rect->width;
 	default:
 		if (ctrl->is_int)
 			return ptr1.p_s32[idx] == ptr2.p_s32[idx];
@@ -307,6 +312,11 @@ static void std_log(const struct v4l2_ctrl *ctrl)
 	case V4L2_CTRL_TYPE_VP9_FRAME:
 		pr_cont("VP9_FRAME");
 		break;
+	case V4L2_CTRL_TYPE_RECT:
+		pr_cont("l: %d, t: %d, w: %u, h: %u",
+			ptr.p_rect->left, ptr.p_rect->top,
+			ptr.p_rect->width, ptr.p_rect->height);
+		break;
 	default:
 		pr_cont("unknown type %d", ctrl->type);
 		break;
@@ -525,6 +535,7 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx,
 	struct v4l2_ctrl_hdr10_mastering_display *p_hdr10_mastering;
 	struct v4l2_ctrl_hevc_decode_params *p_hevc_decode_params;
 	struct v4l2_area *area;
+	struct v4l2_rect *rect;
 	void *p = ptr.p + idx * ctrl->elem_size;
 	unsigned int i;
 
@@ -888,6 +899,12 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx,
 			return -EINVAL;
 		break;
 
+	case V4L2_CTRL_TYPE_RECT:
+		rect = p;
+		if (!rect->width || !rect->height)
+			return -EINVAL;
+		break;
+
 	default:
 		return -EINVAL;
 	}
@@ -1456,6 +1473,9 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
 	case V4L2_CTRL_TYPE_AREA:
 		elem_size = sizeof(struct v4l2_area);
 		break;
+	case V4L2_CTRL_TYPE_RECT:
+		elem_size = sizeof(struct v4l2_rect);
+		break;
 	default:
 		if (type < V4L2_CTRL_COMPOUND_TYPES)
 			elem_size = sizeof(s32);
drivers/media/v4l2-core/v4l2-ctrls-defs.c +4 -0
index 54ca4e6b820b..95f39a2d2ad2 100644
@@ -1042,6 +1042,7 @@ const char *v4l2_ctrl_get_name(u32 id)
 	case V4L2_CID_UNIT_CELL_SIZE:		return "Unit Cell Size";
 	case V4L2_CID_CAMERA_ORIENTATION:	return "Camera Orientation";
 	case V4L2_CID_CAMERA_SENSOR_ROTATION:	return "Camera Sensor Rotation";
+	case V4L2_CID_REGION_OF_INTEREST_RECT:  return "Region Of Interest Rectangle";
 
 	/* FM Radio Modulator controls */
 	/* Keep the order of the 'case's the same as in v4l2-controls.h! */
@@ -1524,6 +1525,9 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
 	case V4L2_CID_COLORIMETRY_HDR10_MASTERING_DISPLAY:
 		*type = V4L2_CTRL_TYPE_HDR10_MASTERING_DISPLAY;
 		break;
+	case V4L2_CID_REGION_OF_INTEREST_RECT:
+		*type = V4L2_CTRL_TYPE_RECT;
+		break;
 	default:
 		*type = V4L2_CTRL_TYPE_INTEGER;
 		break;
include/media/v4l2-ctrls.h +2 -0
index b3ce438f1329..919e104de50b 100644
@@ -58,6 +58,7 @@ struct video_device;
  * @p_hdr10_cll:		Pointer to an HDR10 Content Light Level structure.
  * @p_hdr10_mastering:		Pointer to an HDR10 Mastering Display structure.
  * @p_area:			Pointer to an area.
+ * @p_rect:			Pointer to a rectangle.
  * @p:				Pointer to a compound value.
  * @p_const:			Pointer to a constant compound value.
  */
@@ -87,6 +88,7 @@ union v4l2_ctrl_ptr {
 	struct v4l2_ctrl_hdr10_cll_info *p_hdr10_cll;
 	struct v4l2_ctrl_hdr10_mastering_display *p_hdr10_mastering;
 	struct v4l2_area *p_area;
+	struct v4l2_rect *p_rect;
 	void *p;
 	const void *p_const;
 };
include/uapi/linux/v4l2-controls.h +2 -0
index bb40129446d4..499fcddb6254 100644
@@ -1008,6 +1008,8 @@ enum v4l2_auto_focus_range {
 
 #define V4L2_CID_CAMERA_SENSOR_ROTATION		(V4L2_CID_CAMERA_CLASS_BASE+35)
 
+#define V4L2_CID_REGION_OF_INTEREST_RECT	(V4L2_CID_CAMERA_CLASS_BASE+36)
+
 /* FM Modulator class control IDs */
 
 #define V4L2_CID_FM_TX_CLASS_BASE		(V4L2_CTRL_CLASS_FM_TX | 0x900)
include/uapi/linux/videodev2.h +2 -0
index 3768a0a80830..b712412cf763 100644
@@ -1751,6 +1751,7 @@ struct v4l2_ext_control {
 		__u16 __user *p_u16;
 		__u32 __user *p_u32;
 		struct v4l2_area __user *p_area;
+		struct v4l2_rect __user *p_rect;
 		struct v4l2_ctrl_h264_sps __user *p_h264_sps;
 		struct v4l2_ctrl_h264_pps *p_h264_pps;
 		struct v4l2_ctrl_h264_scaling_matrix __user *p_h264_scaling_matrix;
@@ -1810,6 +1811,7 @@ enum v4l2_ctrl_type {
 	V4L2_CTRL_TYPE_U16	     = 0x0101,
 	V4L2_CTRL_TYPE_U32	     = 0x0102,
 	V4L2_CTRL_TYPE_AREA          = 0x0106,
+	V4L2_CTRL_TYPE_RECT	     = 0x0107,
 
 	V4L2_CTRL_TYPE_HDR10_CLL_INFO		= 0x0110,
 	V4L2_CTRL_TYPE_HDR10_MASTERING_DISPLAY	= 0x0111,
Signature · 1 line
2.36.0.550.gb090851708-goog
#2 lore raw

Re: [PATCH v2 1/6] media: v4l2_ctrl: Add region of interest rectangle control

Hi,

thanks for working on this, see my comments below ...

Le lundi 16 mai 2022 à 23:04 +0900, Yunke Cao a écrit :

Quoted 22 lines

Including:
1. Add a control ID.
2. Add p_rect to struct v4l2_ext_control with basic support in v4l2-ctrls.

---
 .../media/v4l/ext-ctrls-camera.rst            |  4 ++++
 .../media/v4l/vidioc-g-ext-ctrls.rst          |  4 ++++
 .../media/videodev2.h.rst.exceptions          |  1 +
 drivers/media/v4l2-core/v4l2-ctrls-core.c     | 20 +++++++++++++++++++
 drivers/media/v4l2-core/v4l2-ctrls-defs.c     |  4 ++++
 include/media/v4l2-ctrls.h                    |  2 ++
 include/uapi/linux/v4l2-controls.h            |  2 ++
 include/uapi/linux/videodev2.h                |  2 ++
 8 files changed, 39 insertions(+)
Documentation/userspace-api/media/v4l/ext-ctrls-camera.rst +0 -0
index 4c5061aa9cd4..86a1f09a8a1c 100644

Documentation/userspace-api/media/v4l/ext-ctrls-camera.rst enum v4l2_scene_mode - · line 667

Quoted 7 lines
Documentation/userspace-api/media/v4l/ext-ctrls-camera.rst +4 -0
@@ -661,3 +661,7 @@ enum v4l2_scene_mode -
 .. [#f1]
    This control may be changed to a menu control in the future, if more
    options are required.
+
+``V4L2_CID_REGION_OF_INTEREST_RECT (struct)``
+    This control determines the region of interest. Region of interest is an
+    rectangular area represented by a struct v4l2_rect.

This control documentation is missing some important information. Notably, what will happen if this rectangle is set ? Is there a value to unset it ?

The name is very generic and I would expect that to be usable in general. But it won't work for encoders, as you only allow 1 rectangle and it would be missing some QP delta parameter. I think I would prefer if we specialize this type of control a bit more. In your case, I'm guessing you only care about 1 ROI when taking a picture, and this ROI will be used for automatic focus. If my guess is right, perhaps a FOCUS_AERA could be a better name ?

regards,
Nicolas

Quoted 161 lines
Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst +4 -0
index 29971a45a2d4..f4e205ead0a2 100644
@@ -189,6 +189,10 @@ still cause this situation.
       - ``p_area``
       - A pointer to a struct :c:type:`v4l2_area`. Valid if this control is
         of type ``V4L2_CTRL_TYPE_AREA``.
+    * - struct :c:type:`v4l2_rect` *
+      - ``p_area``
+      - A pointer to a struct :c:type:`v4l2_rect`. Valid if this control is
+        of type ``V4L2_CTRL_TYPE_RECT``.
     * - struct :c:type:`v4l2_ctrl_h264_sps` *
       - ``p_h264_sps``
       - A pointer to a struct :c:type:`v4l2_ctrl_h264_sps`. Valid if this control is
Documentation/userspace-api/media/videodev2.h.rst.exceptions +1 -0
index 9cbb7a0c354a..7b423475281d 100644
@@ -147,6 +147,7 @@ replace symbol V4L2_CTRL_TYPE_HEVC_SPS :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_HEVC_PPS :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_AREA :c:type:`v4l2_ctrl_type`
+replace symbol V4L2_CTRL_TYPE_RECT :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_FWHT_PARAMS :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_VP8_FRAME :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_VP9_COMPRESSED_HDR :c:type:`v4l2_ctrl_type`
drivers/media/v4l2-core/v4l2-ctrls-core.c +20 -0
index 8968cec8454e..dcde405c2713 100644
@@ -84,6 +84,11 @@ static bool std_equal(const struct v4l2_ctrl *ctrl, u32 idx,
 		return ptr1.p_u16[idx] == ptr2.p_u16[idx];
 	case V4L2_CTRL_TYPE_U32:
 		return ptr1.p_u32[idx] == ptr2.p_u32[idx];
+	case V4L2_CTRL_TYPE_RECT:
+		return ptr1.p_rect->top == ptr2.p_rect->top &&
+		       ptr1.p_rect->left == ptr2.p_rect->left &&
+		       ptr1.p_rect->height == ptr2.p_rect->height &&
+		       ptr1.p_rect->width == ptr2.p_rect->width;
 	default:
 		if (ctrl->is_int)
 			return ptr1.p_s32[idx] == ptr2.p_s32[idx];
@@ -307,6 +312,11 @@ static void std_log(const struct v4l2_ctrl *ctrl)
 	case V4L2_CTRL_TYPE_VP9_FRAME:
 		pr_cont("VP9_FRAME");
 		break;
+	case V4L2_CTRL_TYPE_RECT:
+		pr_cont("l: %d, t: %d, w: %u, h: %u",
+			ptr.p_rect->left, ptr.p_rect->top,
+			ptr.p_rect->width, ptr.p_rect->height);
+		break;
 	default:
 		pr_cont("unknown type %d", ctrl->type);
 		break;
@@ -525,6 +535,7 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx,
 	struct v4l2_ctrl_hdr10_mastering_display *p_hdr10_mastering;
 	struct v4l2_ctrl_hevc_decode_params *p_hevc_decode_params;
 	struct v4l2_area *area;
+	struct v4l2_rect *rect;
 	void *p = ptr.p + idx * ctrl->elem_size;
 	unsigned int i;
 
@@ -888,6 +899,12 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx,
 			return -EINVAL;
 		break;
 
+	case V4L2_CTRL_TYPE_RECT:
+		rect = p;
+		if (!rect->width || !rect->height)
+			return -EINVAL;
+		break;
+
 	default:
 		return -EINVAL;
 	}
@@ -1456,6 +1473,9 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
 	case V4L2_CTRL_TYPE_AREA:
 		elem_size = sizeof(struct v4l2_area);
 		break;
+	case V4L2_CTRL_TYPE_RECT:
+		elem_size = sizeof(struct v4l2_rect);
+		break;
 	default:
 		if (type < V4L2_CTRL_COMPOUND_TYPES)
 			elem_size = sizeof(s32);
drivers/media/v4l2-core/v4l2-ctrls-defs.c +4 -0
index 54ca4e6b820b..95f39a2d2ad2 100644
@@ -1042,6 +1042,7 @@ const char *v4l2_ctrl_get_name(u32 id)
 	case V4L2_CID_UNIT_CELL_SIZE:		return "Unit Cell Size";
 	case V4L2_CID_CAMERA_ORIENTATION:	return "Camera Orientation";
 	case V4L2_CID_CAMERA_SENSOR_ROTATION:	return "Camera Sensor Rotation";
+	case V4L2_CID_REGION_OF_INTEREST_RECT:  return "Region Of Interest Rectangle";
 
 	/* FM Radio Modulator controls */
 	/* Keep the order of the 'case's the same as in v4l2-controls.h! */
@@ -1524,6 +1525,9 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
 	case V4L2_CID_COLORIMETRY_HDR10_MASTERING_DISPLAY:
 		*type = V4L2_CTRL_TYPE_HDR10_MASTERING_DISPLAY;
 		break;
+	case V4L2_CID_REGION_OF_INTEREST_RECT:
+		*type = V4L2_CTRL_TYPE_RECT;
+		break;
 	default:
 		*type = V4L2_CTRL_TYPE_INTEGER;
 		break;
include/media/v4l2-ctrls.h +2 -0
index b3ce438f1329..919e104de50b 100644
@@ -58,6 +58,7 @@ struct video_device;
  * @p_hdr10_cll:		Pointer to an HDR10 Content Light Level structure.
  * @p_hdr10_mastering:		Pointer to an HDR10 Mastering Display structure.
  * @p_area:			Pointer to an area.
+ * @p_rect:			Pointer to a rectangle.
  * @p:				Pointer to a compound value.
  * @p_const:			Pointer to a constant compound value.
  */
@@ -87,6 +88,7 @@ union v4l2_ctrl_ptr {
 	struct v4l2_ctrl_hdr10_cll_info *p_hdr10_cll;
 	struct v4l2_ctrl_hdr10_mastering_display *p_hdr10_mastering;
 	struct v4l2_area *p_area;
+	struct v4l2_rect *p_rect;
 	void *p;
 	const void *p_const;
 };
include/uapi/linux/v4l2-controls.h +2 -0
index bb40129446d4..499fcddb6254 100644
@@ -1008,6 +1008,8 @@ enum v4l2_auto_focus_range {
 
 #define V4L2_CID_CAMERA_SENSOR_ROTATION		(V4L2_CID_CAMERA_CLASS_BASE+35)
 
+#define V4L2_CID_REGION_OF_INTEREST_RECT	(V4L2_CID_CAMERA_CLASS_BASE+36)
+
 /* FM Modulator class control IDs */
 
 #define V4L2_CID_FM_TX_CLASS_BASE		(V4L2_CTRL_CLASS_FM_TX | 0x900)
include/uapi/linux/videodev2.h +2 -0
index 3768a0a80830..b712412cf763 100644
@@ -1751,6 +1751,7 @@ struct v4l2_ext_control {
 		__u16 __user *p_u16;
 		__u32 __user *p_u32;
 		struct v4l2_area __user *p_area;
+		struct v4l2_rect __user *p_rect;
 		struct v4l2_ctrl_h264_sps __user *p_h264_sps;
 		struct v4l2_ctrl_h264_pps *p_h264_pps;
 		struct v4l2_ctrl_h264_scaling_matrix __user *p_h264_scaling_matrix;
@@ -1810,6 +1811,7 @@ enum v4l2_ctrl_type {
 	V4L2_CTRL_TYPE_U16	     = 0x0101,
 	V4L2_CTRL_TYPE_U32	     = 0x0102,
 	V4L2_CTRL_TYPE_AREA          = 0x0106,
+	V4L2_CTRL_TYPE_RECT	     = 0x0107,
 
 	V4L2_CTRL_TYPE_HDR10_CLL_INFO		= 0x0110,
 	V4L2_CTRL_TYPE_HDR10_MASTERING_DISPLAY	= 0x0111,
author
#3 lore raw

Re: [PATCH v2 1/6] media: v4l2_ctrl: Add region of interest rectangle control

Hi Nicolas,

Thanks for the feedback. I will send v3 updating the documentation.

Yes, the current implementation only cares about 1 ROI.
For naming, my worry about using something like FOCUS_AREA is that the ROI does more than auto focus.
See the list of controls V4L2_CID_REGION_OF_INTEREST_AUTO_* in Patch 2/6. Let me know what you think.

Best,
Yunke

Quoted 211 lines · Nicolas Dufresne

Hi,

thanks for working on this, see my comments below ...

Quoted 22 lines · Yunke Cao

Including:
1. Add a control ID.
2. Add p_rect to struct v4l2_ext_control with basic support in v4l2-ctrls.

---
 .../media/v4l/ext-ctrls-camera.rst            |  4 ++++
 .../media/v4l/vidioc-g-ext-ctrls.rst          |  4 ++++
 .../media/videodev2.h.rst.exceptions          |  1 +
 drivers/media/v4l2-core/v4l2-ctrls-core.c     | 20 +++++++++++++++++++
 drivers/media/v4l2-core/v4l2-ctrls-defs.c     |  4 ++++
 include/media/v4l2-ctrls.h                    |  2 ++
 include/uapi/linux/v4l2-controls.h            |  2 ++
 include/uapi/linux/videodev2.h                |  2 ++
 8 files changed, 39 insertions(+)
Documentation/userspace-api/media/v4l/ext-ctrls-camera.rst +0 -0
index 4c5061aa9cd4..86a1f09a8a1c 100644

Documentation/userspace-api/media/v4l/ext-ctrls-camera.rst enum v4l2_scene_mode - · line 667

Quoted 7 lines
Documentation/userspace-api/media/v4l/ext-ctrls-camera.rst +4 -0
@@ -661,3 +661,7 @@ enum v4l2_scene_mode -
 .. [#f1]
    This control may be changed to a menu control in the future, if more
    options are required.
+
+``V4L2_CID_REGION_OF_INTEREST_RECT (struct)``
+    This control determines the region of interest. Region of interest is an
+    rectangular area represented by a struct v4l2_rect.

This control documentation is missing some important information. Notably, what will happen if this rectangle is set ? Is there a value to unset it ?

The name is very generic and I would expect that to be usable in general. But it won't work for encoders, as you only allow 1 rectangle and it would be missing some QP delta parameter. I think I would prefer if we specialize this type of control a bit more. In your case, I'm guessing you only care about 1 ROI when taking a picture, and this ROI will be used for automatic focus. If my guess is right, perhaps a FOCUS_AERA could be a better name ?

regards,
Nicolas

Quoted 161 lines
Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst +4 -0
index 29971a45a2d4..f4e205ead0a2 100644
@@ -189,6 +189,10 @@ still cause this situation.
       - ``p_area``
       - A pointer to a struct :c:type:`v4l2_area`. Valid if this control is
         of type ``V4L2_CTRL_TYPE_AREA``.
+    * - struct :c:type:`v4l2_rect` *
+      - ``p_area``
+      - A pointer to a struct :c:type:`v4l2_rect`. Valid if this control is
+        of type ``V4L2_CTRL_TYPE_RECT``.
     * - struct :c:type:`v4l2_ctrl_h264_sps` *
       - ``p_h264_sps``
       - A pointer to a struct :c:type:`v4l2_ctrl_h264_sps`. Valid if this control is
Documentation/userspace-api/media/videodev2.h.rst.exceptions +1 -0
index 9cbb7a0c354a..7b423475281d 100644
@@ -147,6 +147,7 @@ replace symbol V4L2_CTRL_TYPE_HEVC_SPS :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_HEVC_PPS :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_AREA :c:type:`v4l2_ctrl_type`
+replace symbol V4L2_CTRL_TYPE_RECT :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_FWHT_PARAMS :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_VP8_FRAME :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_VP9_COMPRESSED_HDR :c:type:`v4l2_ctrl_type`
drivers/media/v4l2-core/v4l2-ctrls-core.c +20 -0
index 8968cec8454e..dcde405c2713 100644
@@ -84,6 +84,11 @@ static bool std_equal(const struct v4l2_ctrl *ctrl, u32 idx,
              return ptr1.p_u16[idx] == ptr2.p_u16[idx];
      case V4L2_CTRL_TYPE_U32:
              return ptr1.p_u32[idx] == ptr2.p_u32[idx];
+     case V4L2_CTRL_TYPE_RECT:
+             return ptr1.p_rect->top == ptr2.p_rect->top &&
+                    ptr1.p_rect->left == ptr2.p_rect->left &&
+                    ptr1.p_rect->height == ptr2.p_rect->height &&
+                    ptr1.p_rect->width == ptr2.p_rect->width;
      default:
              if (ctrl->is_int)
                      return ptr1.p_s32[idx] == ptr2.p_s32[idx];
@@ -307,6 +312,11 @@ static void std_log(const struct v4l2_ctrl *ctrl)
      case V4L2_CTRL_TYPE_VP9_FRAME:
              pr_cont("VP9_FRAME");
              break;
+     case V4L2_CTRL_TYPE_RECT:
+             pr_cont("l: %d, t: %d, w: %u, h: %u",
+                     ptr.p_rect->left, ptr.p_rect->top,
+                     ptr.p_rect->width, ptr.p_rect->height);
+             break;
      default:
              pr_cont("unknown type %d", ctrl->type);
              break;
@@ -525,6 +535,7 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx,
      struct v4l2_ctrl_hdr10_mastering_display *p_hdr10_mastering;
      struct v4l2_ctrl_hevc_decode_params *p_hevc_decode_params;
      struct v4l2_area *area;
+     struct v4l2_rect *rect;
      void *p = ptr.p + idx * ctrl->elem_size;
      unsigned int i;
 
@@ -888,6 +899,12 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx,
                      return -EINVAL;
              break;
 
+     case V4L2_CTRL_TYPE_RECT:
+             rect = p;
+             if (!rect->width || !rect->height)
+                     return -EINVAL;
+             break;
+
      default:
              return -EINVAL;
      }
@@ -1456,6 +1473,9 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
      case V4L2_CTRL_TYPE_AREA:
              elem_size = sizeof(struct v4l2_area);
              break;
+     case V4L2_CTRL_TYPE_RECT:
+             elem_size = sizeof(struct v4l2_rect);
+             break;
      default:
              if (type < V4L2_CTRL_COMPOUND_TYPES)
                      elem_size = sizeof(s32);
drivers/media/v4l2-core/v4l2-ctrls-defs.c +4 -0
index 54ca4e6b820b..95f39a2d2ad2 100644
@@ -1042,6 +1042,7 @@ const char *v4l2_ctrl_get_name(u32 id)
      case V4L2_CID_UNIT_CELL_SIZE:           return "Unit Cell Size";
      case V4L2_CID_CAMERA_ORIENTATION:       return "Camera Orientation";
      case V4L2_CID_CAMERA_SENSOR_ROTATION:   return "Camera Sensor Rotation";
+     case V4L2_CID_REGION_OF_INTEREST_RECT:  return "Region Of Interest Rectangle";
 
      /* FM Radio Modulator controls */
      /* Keep the order of the 'case's the same as in v4l2-controls.h! */
@@ -1524,6 +1525,9 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
      case V4L2_CID_COLORIMETRY_HDR10_MASTERING_DISPLAY:
              *type = V4L2_CTRL_TYPE_HDR10_MASTERING_DISPLAY;
              break;
+     case V4L2_CID_REGION_OF_INTEREST_RECT:
+             *type = V4L2_CTRL_TYPE_RECT;
+             break;
      default:
              *type = V4L2_CTRL_TYPE_INTEGER;
              break;
include/media/v4l2-ctrls.h +2 -0
index b3ce438f1329..919e104de50b 100644
@@ -58,6 +58,7 @@ struct video_device;
  * @p_hdr10_cll:             Pointer to an HDR10 Content Light Level structure.
  * @p_hdr10_mastering:               Pointer to an HDR10 Mastering Display structure.
  * @p_area:                  Pointer to an area.
+ * @p_rect:                  Pointer to a rectangle.
  * @p:                               Pointer to a compound value.
  * @p_const:                 Pointer to a constant compound value.
  */
@@ -87,6 +88,7 @@ union v4l2_ctrl_ptr {
      struct v4l2_ctrl_hdr10_cll_info *p_hdr10_cll;
      struct v4l2_ctrl_hdr10_mastering_display *p_hdr10_mastering;
      struct v4l2_area *p_area;
+     struct v4l2_rect *p_rect;
      void *p;
      const void *p_const;
 };
include/uapi/linux/v4l2-controls.h +2 -0
index bb40129446d4..499fcddb6254 100644
@@ -1008,6 +1008,8 @@ enum v4l2_auto_focus_range {
 
 #define V4L2_CID_CAMERA_SENSOR_ROTATION              (V4L2_CID_CAMERA_CLASS_BASE+35)
 
+#define V4L2_CID_REGION_OF_INTEREST_RECT     (V4L2_CID_CAMERA_CLASS_BASE+36)
+
 /* FM Modulator class control IDs */
 
 #define V4L2_CID_FM_TX_CLASS_BASE            (V4L2_CTRL_CLASS_FM_TX | 0x900)
include/uapi/linux/videodev2.h +2 -0
index 3768a0a80830..b712412cf763 100644
@@ -1751,6 +1751,7 @@ struct v4l2_ext_control {
              __u16 __user *p_u16;
              __u32 __user *p_u32;
              struct v4l2_area __user *p_area;
+             struct v4l2_rect __user *p_rect;
              struct v4l2_ctrl_h264_sps __user *p_h264_sps;
              struct v4l2_ctrl_h264_pps *p_h264_pps;
              struct v4l2_ctrl_h264_scaling_matrix __user *p_h264_scaling_matrix;
@@ -1810,6 +1811,7 @@ enum v4l2_ctrl_type {
      V4L2_CTRL_TYPE_U16           = 0x0101,
      V4L2_CTRL_TYPE_U32           = 0x0102,
      V4L2_CTRL_TYPE_AREA          = 0x0106,
+     V4L2_CTRL_TYPE_RECT          = 0x0107,
 
      V4L2_CTRL_TYPE_HDR10_CLL_INFO           = 0x0110,
      V4L2_CTRL_TYPE_HDR10_MASTERING_DISPLAY  = 0x0111,
#4 lore raw

Re: [PATCH v2 1/6] media: v4l2_ctrl: Add region of interest rectangle control

In reply to Nicolas Dufresne

Hi Nicolas,

Quoted 23 lines · Nicolas Dufresne

Hi,

thanks for working on this, see my comments below ...

Quoted 17 lines · Yunke Cao

Including:
1. Add a control ID.
2. Add p_rect to struct v4l2_ext_control with basic support in v4l2-ctrls.

---
 .../media/v4l/ext-ctrls-camera.rst            |  4 ++++
 .../media/v4l/vidioc-g-ext-ctrls.rst          |  4 ++++
 .../media/videodev2.h.rst.exceptions          |  1 +
 drivers/media/v4l2-core/v4l2-ctrls-core.c     | 20 +++++++++++++++++++
 drivers/media/v4l2-core/v4l2-ctrls-defs.c     |  4 ++++
 include/media/v4l2-ctrls.h                    |  2 ++
 include/uapi/linux/v4l2-controls.h            |  2 ++
 include/uapi/linux/videodev2.h                |  2 ++
 8 files changed, 39 insertions(+)
Quoted 16 lines

Documentation/userspace-api/media/v4l/ext-ctrls-camera.rst enum v4l2_scene_mode - · line 667

Quoted 12 lines
Documentation/userspace-api/media/v4l/ext-ctrls-camera.rst +4 -0
index 4c5061aa9cd4..86a1f09a8a1c 100644
@@ -661,3 +661,7 @@ enum v4l2_scene_mode -
 .. [#f1]
    This control may be changed to a menu control in the future, if more
    options are required.
+
+``V4L2_CID_REGION_OF_INTEREST_RECT (struct)``
+    This control determines the region of interest. Region of interest is an
+    rectangular area represented by a struct v4l2_rect.

This control documentation is missing some important information. Notably, what will happen if this rectangle is set ? Is there a value to unset it ?

Thanks for the review!

In V4L2 all the controls are always set to something. There is no way to unset a control. Since controls have default values, perhaps the way to "unset" (or rather reset it to the initial configuration) is to set it to the default value?

Quoted 6 lines

The name is very generic and I would expect that to be usable in general. But it won't work for encoders, as you only allow 1 rectangle and it would be missing some QP delta parameter. I think I would prefer if we specialize this type of control a bit more. In your case, I'm guessing you only care about 1 ROI when taking a picture, and this ROI will be used for automatic focus. If my guess is right, perhaps a FOCUS_AERA could be a better name ?

I wonder if an array control is what we need here to make it flexible enough? For a UVC camera obviously we would only need 1 element, but other devices could accept more.

Best regards,
Tomasz

Quoted 166 lines

regards,
Nicolas

Quoted 161 lines
Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst +4 -0
index 29971a45a2d4..f4e205ead0a2 100644
@@ -189,6 +189,10 @@ still cause this situation.
       - ``p_area``
       - A pointer to a struct :c:type:`v4l2_area`. Valid if this control is
         of type ``V4L2_CTRL_TYPE_AREA``.
+    * - struct :c:type:`v4l2_rect` *
+      - ``p_area``
+      - A pointer to a struct :c:type:`v4l2_rect`. Valid if this control is
+        of type ``V4L2_CTRL_TYPE_RECT``.
     * - struct :c:type:`v4l2_ctrl_h264_sps` *
       - ``p_h264_sps``
       - A pointer to a struct :c:type:`v4l2_ctrl_h264_sps`. Valid if this control is
Documentation/userspace-api/media/videodev2.h.rst.exceptions +1 -0
index 9cbb7a0c354a..7b423475281d 100644
@@ -147,6 +147,7 @@ replace symbol V4L2_CTRL_TYPE_HEVC_SPS :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_HEVC_PPS :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_AREA :c:type:`v4l2_ctrl_type`
+replace symbol V4L2_CTRL_TYPE_RECT :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_FWHT_PARAMS :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_VP8_FRAME :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_VP9_COMPRESSED_HDR :c:type:`v4l2_ctrl_type`
drivers/media/v4l2-core/v4l2-ctrls-core.c +20 -0
index 8968cec8454e..dcde405c2713 100644
@@ -84,6 +84,11 @@ static bool std_equal(const struct v4l2_ctrl *ctrl, u32 idx,
              return ptr1.p_u16[idx] == ptr2.p_u16[idx];
      case V4L2_CTRL_TYPE_U32:
              return ptr1.p_u32[idx] == ptr2.p_u32[idx];
+     case V4L2_CTRL_TYPE_RECT:
+             return ptr1.p_rect->top == ptr2.p_rect->top &&
+                    ptr1.p_rect->left == ptr2.p_rect->left &&
+                    ptr1.p_rect->height == ptr2.p_rect->height &&
+                    ptr1.p_rect->width == ptr2.p_rect->width;
      default:
              if (ctrl->is_int)
                      return ptr1.p_s32[idx] == ptr2.p_s32[idx];
@@ -307,6 +312,11 @@ static void std_log(const struct v4l2_ctrl *ctrl)
      case V4L2_CTRL_TYPE_VP9_FRAME:
              pr_cont("VP9_FRAME");
              break;
+     case V4L2_CTRL_TYPE_RECT:
+             pr_cont("l: %d, t: %d, w: %u, h: %u",
+                     ptr.p_rect->left, ptr.p_rect->top,
+                     ptr.p_rect->width, ptr.p_rect->height);
+             break;
      default:
              pr_cont("unknown type %d", ctrl->type);
              break;
@@ -525,6 +535,7 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx,
      struct v4l2_ctrl_hdr10_mastering_display *p_hdr10_mastering;
      struct v4l2_ctrl_hevc_decode_params *p_hevc_decode_params;
      struct v4l2_area *area;
+     struct v4l2_rect *rect;
      void *p = ptr.p + idx * ctrl->elem_size;
      unsigned int i;
 
@@ -888,6 +899,12 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx,
                      return -EINVAL;
              break;
 
+     case V4L2_CTRL_TYPE_RECT:
+             rect = p;
+             if (!rect->width || !rect->height)
+                     return -EINVAL;
+             break;
+
      default:
              return -EINVAL;
      }
@@ -1456,6 +1473,9 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
      case V4L2_CTRL_TYPE_AREA:
              elem_size = sizeof(struct v4l2_area);
              break;
+     case V4L2_CTRL_TYPE_RECT:
+             elem_size = sizeof(struct v4l2_rect);
+             break;
      default:
              if (type < V4L2_CTRL_COMPOUND_TYPES)
                      elem_size = sizeof(s32);
drivers/media/v4l2-core/v4l2-ctrls-defs.c +4 -0
index 54ca4e6b820b..95f39a2d2ad2 100644
@@ -1042,6 +1042,7 @@ const char *v4l2_ctrl_get_name(u32 id)
      case V4L2_CID_UNIT_CELL_SIZE:           return "Unit Cell Size";
      case V4L2_CID_CAMERA_ORIENTATION:       return "Camera Orientation";
      case V4L2_CID_CAMERA_SENSOR_ROTATION:   return "Camera Sensor Rotation";
+     case V4L2_CID_REGION_OF_INTEREST_RECT:  return "Region Of Interest Rectangle";
 
      /* FM Radio Modulator controls */
      /* Keep the order of the 'case's the same as in v4l2-controls.h! */
@@ -1524,6 +1525,9 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
      case V4L2_CID_COLORIMETRY_HDR10_MASTERING_DISPLAY:
              *type = V4L2_CTRL_TYPE_HDR10_MASTERING_DISPLAY;
              break;
+     case V4L2_CID_REGION_OF_INTEREST_RECT:
+             *type = V4L2_CTRL_TYPE_RECT;
+             break;
      default:
              *type = V4L2_CTRL_TYPE_INTEGER;
              break;
include/media/v4l2-ctrls.h +2 -0
index b3ce438f1329..919e104de50b 100644
@@ -58,6 +58,7 @@ struct video_device;
  * @p_hdr10_cll:             Pointer to an HDR10 Content Light Level structure.
  * @p_hdr10_mastering:               Pointer to an HDR10 Mastering Display structure.
  * @p_area:                  Pointer to an area.
+ * @p_rect:                  Pointer to a rectangle.
  * @p:                               Pointer to a compound value.
  * @p_const:                 Pointer to a constant compound value.
  */
@@ -87,6 +88,7 @@ union v4l2_ctrl_ptr {
      struct v4l2_ctrl_hdr10_cll_info *p_hdr10_cll;
      struct v4l2_ctrl_hdr10_mastering_display *p_hdr10_mastering;
      struct v4l2_area *p_area;
+     struct v4l2_rect *p_rect;
      void *p;
      const void *p_const;
 };
include/uapi/linux/v4l2-controls.h +2 -0
index bb40129446d4..499fcddb6254 100644
@@ -1008,6 +1008,8 @@ enum v4l2_auto_focus_range {
 
 #define V4L2_CID_CAMERA_SENSOR_ROTATION              (V4L2_CID_CAMERA_CLASS_BASE+35)
 
+#define V4L2_CID_REGION_OF_INTEREST_RECT     (V4L2_CID_CAMERA_CLASS_BASE+36)
+
 /* FM Modulator class control IDs */
 
 #define V4L2_CID_FM_TX_CLASS_BASE            (V4L2_CTRL_CLASS_FM_TX | 0x900)
include/uapi/linux/videodev2.h +2 -0
index 3768a0a80830..b712412cf763 100644
@@ -1751,6 +1751,7 @@ struct v4l2_ext_control {
              __u16 __user *p_u16;
              __u32 __user *p_u32;
              struct v4l2_area __user *p_area;
+             struct v4l2_rect __user *p_rect;
              struct v4l2_ctrl_h264_sps __user *p_h264_sps;
              struct v4l2_ctrl_h264_pps *p_h264_pps;
              struct v4l2_ctrl_h264_scaling_matrix __user *p_h264_scaling_matrix;
@@ -1810,6 +1811,7 @@ enum v4l2_ctrl_type {
      V4L2_CTRL_TYPE_U16           = 0x0101,
      V4L2_CTRL_TYPE_U32           = 0x0102,
      V4L2_CTRL_TYPE_AREA          = 0x0106,
+     V4L2_CTRL_TYPE_RECT          = 0x0107,
 
      V4L2_CTRL_TYPE_HDR10_CLL_INFO           = 0x0110,
      V4L2_CTRL_TYPE_HDR10_MASTERING_DISPLAY  = 0x0111,
#5 lore raw

Re: [PATCH v2 1/6] media: v4l2_ctrl: Add region of interest rectangle control

Le mercredi 18 mai 2022 à 14:19 +0900, Tomasz Figa a écrit :

Quoted 43 lines

Hi Nicolas,

Quoted 23 lines · Nicolas Dufresne

Hi,

thanks for working on this, see my comments below ...

Quoted 17 lines · Yunke Cao

Including:
1. Add a control ID.
2. Add p_rect to struct v4l2_ext_control with basic support in v4l2-ctrls.

---
 .../media/v4l/ext-ctrls-camera.rst            |  4 ++++
 .../media/v4l/vidioc-g-ext-ctrls.rst          |  4 ++++
 .../media/videodev2.h.rst.exceptions          |  1 +
 drivers/media/v4l2-core/v4l2-ctrls-core.c     | 20 +++++++++++++++++++
 drivers/media/v4l2-core/v4l2-ctrls-defs.c     |  4 ++++
 include/media/v4l2-ctrls.h                    |  2 ++
 include/uapi/linux/v4l2-controls.h            |  2 ++
 include/uapi/linux/videodev2.h                |  2 ++
 8 files changed, 39 insertions(+)
Quoted 16 lines

Documentation/userspace-api/media/v4l/ext-ctrls-camera.rst enum v4l2_scene_mode - · line 667

Quoted 12 lines
Documentation/userspace-api/media/v4l/ext-ctrls-camera.rst +4 -0
index 4c5061aa9cd4..86a1f09a8a1c 100644
@@ -661,3 +661,7 @@ enum v4l2_scene_mode -
 .. [#f1]
    This control may be changed to a menu control in the future, if more
    options are required.
+
+``V4L2_CID_REGION_OF_INTEREST_RECT (struct)``
+    This control determines the region of interest. Region of interest is an
+    rectangular area represented by a struct v4l2_rect.

This control documentation is missing some important information. Notably, what will happen if this rectangle is set ? Is there a value to unset it ?

Quoted 6 lines

Thanks for the review!

In V4L2 all the controls are always set to something. There is no way to unset a control. Since controls have default values, perhaps the way to "unset" (or rather reset it to the initial configuration) is to set it to the default value?

That's why a lot of similar controls comes with a companion boolean control to enable/disable the feature, or an enum that specify what else is to be used, could be an "automatic" default or something.

Quoted 11 lines
Quoted 7 lines

The name is very generic and I would expect that to be usable in general. But it won't work for encoders, as you only allow 1 rectangle and it would be missing some QP delta parameter. I think I would prefer if we specialize this type of control a bit more. In your case, I'm guessing you only care about 1 ROI when taking a picture, and this ROI will be used for automatic focus. If my guess is right, perhaps a FOCUS_AERA could be a better name ?

I wonder if an array control is what we need here to make it flexible enough? For a UVC camera obviously we would only need 1 element, but other devices could accept more.

See Hans and Laurent's comment on V3. They don't believe camera region of interest is likely to exists outside of UVC, and suggested making all these control entirely UVC specific, which also allow making it 1:1 with UVC without any headache.

And this way we don't need to think about encoder ROI just yet.

Quoted 170 lines

Best regards,
Tomasz

Quoted 166 lines

regards,
Nicolas

Quoted 161 lines
Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst +4 -0
index 29971a45a2d4..f4e205ead0a2 100644
@@ -189,6 +189,10 @@ still cause this situation.
       - ``p_area``
       - A pointer to a struct :c:type:`v4l2_area`. Valid if this control is
         of type ``V4L2_CTRL_TYPE_AREA``.
+    * - struct :c:type:`v4l2_rect` *
+      - ``p_area``
+      - A pointer to a struct :c:type:`v4l2_rect`. Valid if this control is
+        of type ``V4L2_CTRL_TYPE_RECT``.
     * - struct :c:type:`v4l2_ctrl_h264_sps` *
       - ``p_h264_sps``
       - A pointer to a struct :c:type:`v4l2_ctrl_h264_sps`. Valid if this control is
Documentation/userspace-api/media/videodev2.h.rst.exceptions +1 -0
index 9cbb7a0c354a..7b423475281d 100644
@@ -147,6 +147,7 @@ replace symbol V4L2_CTRL_TYPE_HEVC_SPS :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_HEVC_PPS :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_AREA :c:type:`v4l2_ctrl_type`
+replace symbol V4L2_CTRL_TYPE_RECT :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_FWHT_PARAMS :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_VP8_FRAME :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_VP9_COMPRESSED_HDR :c:type:`v4l2_ctrl_type`
drivers/media/v4l2-core/v4l2-ctrls-core.c +20 -0
index 8968cec8454e..dcde405c2713 100644
@@ -84,6 +84,11 @@ static bool std_equal(const struct v4l2_ctrl *ctrl, u32 idx,
              return ptr1.p_u16[idx] == ptr2.p_u16[idx];
      case V4L2_CTRL_TYPE_U32:
              return ptr1.p_u32[idx] == ptr2.p_u32[idx];
+     case V4L2_CTRL_TYPE_RECT:
+             return ptr1.p_rect->top == ptr2.p_rect->top &&
+                    ptr1.p_rect->left == ptr2.p_rect->left &&
+                    ptr1.p_rect->height == ptr2.p_rect->height &&
+                    ptr1.p_rect->width == ptr2.p_rect->width;
      default:
              if (ctrl->is_int)
                      return ptr1.p_s32[idx] == ptr2.p_s32[idx];
@@ -307,6 +312,11 @@ static void std_log(const struct v4l2_ctrl *ctrl)
      case V4L2_CTRL_TYPE_VP9_FRAME:
              pr_cont("VP9_FRAME");
              break;
+     case V4L2_CTRL_TYPE_RECT:
+             pr_cont("l: %d, t: %d, w: %u, h: %u",
+                     ptr.p_rect->left, ptr.p_rect->top,
+                     ptr.p_rect->width, ptr.p_rect->height);
+             break;
      default:
              pr_cont("unknown type %d", ctrl->type);
              break;
@@ -525,6 +535,7 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx,
      struct v4l2_ctrl_hdr10_mastering_display *p_hdr10_mastering;
      struct v4l2_ctrl_hevc_decode_params *p_hevc_decode_params;
      struct v4l2_area *area;
+     struct v4l2_rect *rect;
      void *p = ptr.p + idx * ctrl->elem_size;
      unsigned int i;
 
@@ -888,6 +899,12 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx,
                      return -EINVAL;
              break;
 
+     case V4L2_CTRL_TYPE_RECT:
+             rect = p;
+             if (!rect->width || !rect->height)
+                     return -EINVAL;
+             break;
+
      default:
              return -EINVAL;
      }
@@ -1456,6 +1473,9 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
      case V4L2_CTRL_TYPE_AREA:
              elem_size = sizeof(struct v4l2_area);
              break;
+     case V4L2_CTRL_TYPE_RECT:
+             elem_size = sizeof(struct v4l2_rect);
+             break;
      default:
              if (type < V4L2_CTRL_COMPOUND_TYPES)
                      elem_size = sizeof(s32);
drivers/media/v4l2-core/v4l2-ctrls-defs.c +4 -0
index 54ca4e6b820b..95f39a2d2ad2 100644
@@ -1042,6 +1042,7 @@ const char *v4l2_ctrl_get_name(u32 id)
      case V4L2_CID_UNIT_CELL_SIZE:           return "Unit Cell Size";
      case V4L2_CID_CAMERA_ORIENTATION:       return "Camera Orientation";
      case V4L2_CID_CAMERA_SENSOR_ROTATION:   return "Camera Sensor Rotation";
+     case V4L2_CID_REGION_OF_INTEREST_RECT:  return "Region Of Interest Rectangle";
 
      /* FM Radio Modulator controls */
      /* Keep the order of the 'case's the same as in v4l2-controls.h! */
@@ -1524,6 +1525,9 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
      case V4L2_CID_COLORIMETRY_HDR10_MASTERING_DISPLAY:
              *type = V4L2_CTRL_TYPE_HDR10_MASTERING_DISPLAY;
              break;
+     case V4L2_CID_REGION_OF_INTEREST_RECT:
+             *type = V4L2_CTRL_TYPE_RECT;
+             break;
      default:
              *type = V4L2_CTRL_TYPE_INTEGER;
              break;
include/media/v4l2-ctrls.h +2 -0
index b3ce438f1329..919e104de50b 100644
@@ -58,6 +58,7 @@ struct video_device;
  * @p_hdr10_cll:             Pointer to an HDR10 Content Light Level structure.
  * @p_hdr10_mastering:               Pointer to an HDR10 Mastering Display structure.
  * @p_area:                  Pointer to an area.
+ * @p_rect:                  Pointer to a rectangle.
  * @p:                               Pointer to a compound value.
  * @p_const:                 Pointer to a constant compound value.
  */
@@ -87,6 +88,7 @@ union v4l2_ctrl_ptr {
      struct v4l2_ctrl_hdr10_cll_info *p_hdr10_cll;
      struct v4l2_ctrl_hdr10_mastering_display *p_hdr10_mastering;
      struct v4l2_area *p_area;
+     struct v4l2_rect *p_rect;
      void *p;
      const void *p_const;
 };
include/uapi/linux/v4l2-controls.h +2 -0
index bb40129446d4..499fcddb6254 100644
@@ -1008,6 +1008,8 @@ enum v4l2_auto_focus_range {
 
 #define V4L2_CID_CAMERA_SENSOR_ROTATION              (V4L2_CID_CAMERA_CLASS_BASE+35)
 
+#define V4L2_CID_REGION_OF_INTEREST_RECT     (V4L2_CID_CAMERA_CLASS_BASE+36)
+
 /* FM Modulator class control IDs */
 
 #define V4L2_CID_FM_TX_CLASS_BASE            (V4L2_CTRL_CLASS_FM_TX | 0x900)
include/uapi/linux/videodev2.h +2 -0
index 3768a0a80830..b712412cf763 100644
@@ -1751,6 +1751,7 @@ struct v4l2_ext_control {
              __u16 __user *p_u16;
              __u32 __user *p_u32;
              struct v4l2_area __user *p_area;
+             struct v4l2_rect __user *p_rect;
              struct v4l2_ctrl_h264_sps __user *p_h264_sps;
              struct v4l2_ctrl_h264_pps *p_h264_pps;
              struct v4l2_ctrl_h264_scaling_matrix __user *p_h264_scaling_matrix;
@@ -1810,6 +1811,7 @@ enum v4l2_ctrl_type {
      V4L2_CTRL_TYPE_U16           = 0x0101,
      V4L2_CTRL_TYPE_U32           = 0x0102,
      V4L2_CTRL_TYPE_AREA          = 0x0106,
+     V4L2_CTRL_TYPE_RECT          = 0x0107,
 
      V4L2_CTRL_TYPE_HDR10_CLL_INFO           = 0x0110,
      V4L2_CTRL_TYPE_HDR10_MASTERING_DISPLAY  = 0x0111,
#6 lore raw

Re: [PATCH v2 1/6] media: v4l2_ctrl: Add region of interest rectangle control

Quoted 47 lines · Nicolas Dufresne
Quoted 45 lines · Tomasz Figa

Hi Nicolas,

Quoted 23 lines · Nicolas Dufresne

Hi,

thanks for working on this, see my comments below ...

Quoted 17 lines · Yunke Cao

Including:
1. Add a control ID.
2. Add p_rect to struct v4l2_ext_control with basic support in v4l2-ctrls.

---
 .../media/v4l/ext-ctrls-camera.rst            |  4 ++++
 .../media/v4l/vidioc-g-ext-ctrls.rst          |  4 ++++
 .../media/videodev2.h.rst.exceptions          |  1 +
 drivers/media/v4l2-core/v4l2-ctrls-core.c     | 20 +++++++++++++++++++
 drivers/media/v4l2-core/v4l2-ctrls-defs.c     |  4 ++++
 include/media/v4l2-ctrls.h                    |  2 ++
 include/uapi/linux/v4l2-controls.h            |  2 ++
 include/uapi/linux/videodev2.h                |  2 ++
 8 files changed, 39 insertions(+)
Quoted 16 lines

Documentation/userspace-api/media/v4l/ext-ctrls-camera.rst enum v4l2_scene_mode - · line 667

Quoted 12 lines
Documentation/userspace-api/media/v4l/ext-ctrls-camera.rst +4 -0
index 4c5061aa9cd4..86a1f09a8a1c 100644
@@ -661,3 +661,7 @@ enum v4l2_scene_mode -
 .. [#f1]
    This control may be changed to a menu control in the future, if more
    options are required.
+
+``V4L2_CID_REGION_OF_INTEREST_RECT (struct)``
+    This control determines the region of interest. Region of interest is an
+    rectangular area represented by a struct v4l2_rect.

This control documentation is missing some important information. Notably, what will happen if this rectangle is set ? Is there a value to unset it ?

Thanks for the review!

Quoted 9 lines
Quoted 4 lines

In V4L2 all the controls are always set to something. There is no way to unset a control. Since controls have default values, perhaps the way to "unset" (or rather reset it to the initial configuration) is to set it to the default value?

That's why a lot of similar controls comes with a companion boolean control to enable/disable the feature, or an enum that specify what else is to be used, could be an "automatic" default or something.

True. I think the other bitmask control is the companion control in this case, but it indeed wouldn't work for other use cases.

Quoted 12 lines
Quoted 11 lines
Quoted 7 lines

The name is very generic and I would expect that to be usable in general. But it won't work for encoders, as you only allow 1 rectangle and it would be missing some QP delta parameter. I think I would prefer if we specialize this type of control a bit more. In your case, I'm guessing you only care about 1 ROI when taking a picture, and this ROI will be used for automatic focus. If my guess is right, perhaps a FOCUS_AERA could be a better name ?

I wonder if an array control is what we need here to make it flexible enough? For a UVC camera obviously we would only need 1 element, but other devices could accept more.

Quoted 7 lines

See Hans and Laurent's comment on V3. They don't believe camera region of interest is likely to exists outside of UVC, and suggested making all these control entirely UVC specific, which also allow making it 1:1 with UVC without any headache.

And this way we don't need to think about encoder ROI just yet.

Okay, I think that also works for us. :)

Best regards,
Tomasz

Quoted 171 lines
Quoted 170 lines

Best regards,
Tomasz

Quoted 166 lines

regards,
Nicolas

Quoted 161 lines
Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst +4 -0
index 29971a45a2d4..f4e205ead0a2 100644
@@ -189,6 +189,10 @@ still cause this situation.
       - ``p_area``
       - A pointer to a struct :c:type:`v4l2_area`. Valid if this control is
         of type ``V4L2_CTRL_TYPE_AREA``.
+    * - struct :c:type:`v4l2_rect` *
+      - ``p_area``
+      - A pointer to a struct :c:type:`v4l2_rect`. Valid if this control is
+        of type ``V4L2_CTRL_TYPE_RECT``.
     * - struct :c:type:`v4l2_ctrl_h264_sps` *
       - ``p_h264_sps``
       - A pointer to a struct :c:type:`v4l2_ctrl_h264_sps`. Valid if this control is
Documentation/userspace-api/media/videodev2.h.rst.exceptions +1 -0
index 9cbb7a0c354a..7b423475281d 100644
@@ -147,6 +147,7 @@ replace symbol V4L2_CTRL_TYPE_HEVC_SPS :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_HEVC_PPS :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_AREA :c:type:`v4l2_ctrl_type`
+replace symbol V4L2_CTRL_TYPE_RECT :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_FWHT_PARAMS :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_VP8_FRAME :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_VP9_COMPRESSED_HDR :c:type:`v4l2_ctrl_type`
drivers/media/v4l2-core/v4l2-ctrls-core.c +20 -0
index 8968cec8454e..dcde405c2713 100644
@@ -84,6 +84,11 @@ static bool std_equal(const struct v4l2_ctrl *ctrl, u32 idx,
              return ptr1.p_u16[idx] == ptr2.p_u16[idx];
      case V4L2_CTRL_TYPE_U32:
              return ptr1.p_u32[idx] == ptr2.p_u32[idx];
+     case V4L2_CTRL_TYPE_RECT:
+             return ptr1.p_rect->top == ptr2.p_rect->top &&
+                    ptr1.p_rect->left == ptr2.p_rect->left &&
+                    ptr1.p_rect->height == ptr2.p_rect->height &&
+                    ptr1.p_rect->width == ptr2.p_rect->width;
      default:
              if (ctrl->is_int)
                      return ptr1.p_s32[idx] == ptr2.p_s32[idx];
@@ -307,6 +312,11 @@ static void std_log(const struct v4l2_ctrl *ctrl)
      case V4L2_CTRL_TYPE_VP9_FRAME:
              pr_cont("VP9_FRAME");
              break;
+     case V4L2_CTRL_TYPE_RECT:
+             pr_cont("l: %d, t: %d, w: %u, h: %u",
+                     ptr.p_rect->left, ptr.p_rect->top,
+                     ptr.p_rect->width, ptr.p_rect->height);
+             break;
      default:
              pr_cont("unknown type %d", ctrl->type);
              break;
@@ -525,6 +535,7 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx,
      struct v4l2_ctrl_hdr10_mastering_display *p_hdr10_mastering;
      struct v4l2_ctrl_hevc_decode_params *p_hevc_decode_params;
      struct v4l2_area *area;
+     struct v4l2_rect *rect;
      void *p = ptr.p + idx * ctrl->elem_size;
      unsigned int i;
 
@@ -888,6 +899,12 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx,
                      return -EINVAL;
              break;
 
+     case V4L2_CTRL_TYPE_RECT:
+             rect = p;
+             if (!rect->width || !rect->height)
+                     return -EINVAL;
+             break;
+
      default:
              return -EINVAL;
      }
@@ -1456,6 +1473,9 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
      case V4L2_CTRL_TYPE_AREA:
              elem_size = sizeof(struct v4l2_area);
              break;
+     case V4L2_CTRL_TYPE_RECT:
+             elem_size = sizeof(struct v4l2_rect);
+             break;
      default:
              if (type < V4L2_CTRL_COMPOUND_TYPES)
                      elem_size = sizeof(s32);
drivers/media/v4l2-core/v4l2-ctrls-defs.c +4 -0
index 54ca4e6b820b..95f39a2d2ad2 100644
@@ -1042,6 +1042,7 @@ const char *v4l2_ctrl_get_name(u32 id)
      case V4L2_CID_UNIT_CELL_SIZE:           return "Unit Cell Size";
      case V4L2_CID_CAMERA_ORIENTATION:       return "Camera Orientation";
      case V4L2_CID_CAMERA_SENSOR_ROTATION:   return "Camera Sensor Rotation";
+     case V4L2_CID_REGION_OF_INTEREST_RECT:  return "Region Of Interest Rectangle";
 
      /* FM Radio Modulator controls */
      /* Keep the order of the 'case's the same as in v4l2-controls.h! */
@@ -1524,6 +1525,9 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
      case V4L2_CID_COLORIMETRY_HDR10_MASTERING_DISPLAY:
              *type = V4L2_CTRL_TYPE_HDR10_MASTERING_DISPLAY;
              break;
+     case V4L2_CID_REGION_OF_INTEREST_RECT:
+             *type = V4L2_CTRL_TYPE_RECT;
+             break;
      default:
              *type = V4L2_CTRL_TYPE_INTEGER;
              break;
include/media/v4l2-ctrls.h +2 -0
index b3ce438f1329..919e104de50b 100644
@@ -58,6 +58,7 @@ struct video_device;
  * @p_hdr10_cll:             Pointer to an HDR10 Content Light Level structure.
  * @p_hdr10_mastering:               Pointer to an HDR10 Mastering Display structure.
  * @p_area:                  Pointer to an area.
+ * @p_rect:                  Pointer to a rectangle.
  * @p:                               Pointer to a compound value.
  * @p_const:                 Pointer to a constant compound value.
  */
@@ -87,6 +88,7 @@ union v4l2_ctrl_ptr {
      struct v4l2_ctrl_hdr10_cll_info *p_hdr10_cll;
      struct v4l2_ctrl_hdr10_mastering_display *p_hdr10_mastering;
      struct v4l2_area *p_area;
+     struct v4l2_rect *p_rect;
      void *p;
      const void *p_const;
 };
include/uapi/linux/v4l2-controls.h +2 -0
index bb40129446d4..499fcddb6254 100644
@@ -1008,6 +1008,8 @@ enum v4l2_auto_focus_range {
 
 #define V4L2_CID_CAMERA_SENSOR_ROTATION              (V4L2_CID_CAMERA_CLASS_BASE+35)
 
+#define V4L2_CID_REGION_OF_INTEREST_RECT     (V4L2_CID_CAMERA_CLASS_BASE+36)
+
 /* FM Modulator class control IDs */
 
 #define V4L2_CID_FM_TX_CLASS_BASE            (V4L2_CTRL_CLASS_FM_TX | 0x900)
include/uapi/linux/videodev2.h +2 -0
index 3768a0a80830..b712412cf763 100644
@@ -1751,6 +1751,7 @@ struct v4l2_ext_control {
              __u16 __user *p_u16;
              __u32 __user *p_u32;
              struct v4l2_area __user *p_area;
+             struct v4l2_rect __user *p_rect;
              struct v4l2_ctrl_h264_sps __user *p_h264_sps;
              struct v4l2_ctrl_h264_pps *p_h264_pps;
              struct v4l2_ctrl_h264_scaling_matrix __user *p_h264_scaling_matrix;
@@ -1810,6 +1811,7 @@ enum v4l2_ctrl_type {
      V4L2_CTRL_TYPE_U16           = 0x0101,
      V4L2_CTRL_TYPE_U32           = 0x0102,
      V4L2_CTRL_TYPE_AREA          = 0x0106,
+     V4L2_CTRL_TYPE_RECT          = 0x0107,
 
      V4L2_CTRL_TYPE_HDR10_CLL_INFO           = 0x0110,
      V4L2_CTRL_TYPE_HDR10_MASTERING_DISPLAY  = 0x0111,
author
#7 lore raw

PATCH v2 2/6 media: v4l2_ctrl: Add region of interest auto control

In reply to Yunke Cao
---
 .../media/v4l/ext-ctrls-camera.rst            | 25 +++++++++++++++++++
 drivers/media/v4l2-core/v4l2-ctrls-defs.c     |  2 ++
 include/uapi/linux/v4l2-controls.h            |  9 +++++++
 3 files changed, 36 insertions(+)
Documentation/userspace-api/media/v4l/ext-ctrls-camera.rst +25 -0
index 86a1f09a8a1c..3da66e1e1fc7 100644
@@ -665,3 +665,28 @@ enum v4l2_scene_mode -
 ``V4L2_CID_REGION_OF_INTEREST_RECT (struct)``
     This control determines the region of interest. Region of interest is an
     rectangular area represented by a struct v4l2_rect.
+
+``V4L2_CID_REGION_OF_INTEREST_AUTO (bitmask)``
+    This determines which, if any, on board features should track to the
+    Region of Interest.
+
+.. flat-table::
+    :header-rows:  0
+    :stub-columns: 0
+
+    * - ``V4L2_CID_REGION_OF_INTEREST_AUTO_EXPOSURE``
+      - Auto Exposure.
+    * - ``V4L2_CID_REGION_OF_INTEREST_AUTO_IRIS``
+      - Auto Iris.
+    * - ``V4L2_CID_REGION_OF_INTEREST_AUTO_WHITE_BALANCE``
+      - Auto White Balance.
+    * - ``V4L2_CID_REGION_OF_INTEREST_AUTO_FOCUS``
+      - Auto Focus.
+    * - ``V4L2_CID_REGION_OF_INTEREST_AUTO_FACE_DETECT``
+      - Auto Face Detect.
+    * - ``V4L2_CID_REGION_OF_INTEREST_AUTO_DETECT_AND_TRACK``
+      - Auto Detect and Track.
+    * - ``V4L2_CID_REGION_OF_INTEREST_AUTO_IMAGE_STABILIZATION``
+      - Image Stabilization.
+    * - ``V4L2_CID_REGION_OF_INTEREST_AUTO_HIGHER_QUALITY``
+      - Higher Quality.
drivers/media/v4l2-core/v4l2-ctrls-defs.c +2 -0
index 95f39a2d2ad2..f28763bf95e9 100644
@@ -1043,6 +1043,7 @@ const char *v4l2_ctrl_get_name(u32 id)
 	case V4L2_CID_CAMERA_ORIENTATION:	return "Camera Orientation";
 	case V4L2_CID_CAMERA_SENSOR_ROTATION:	return "Camera Sensor Rotation";
 	case V4L2_CID_REGION_OF_INTEREST_RECT:  return "Region Of Interest Rectangle";
+	case V4L2_CID_REGION_OF_INTEREST_AUTO:  return "Region Of Interest Auto Controls";
 
 	/* FM Radio Modulator controls */
 	/* Keep the order of the 'case's the same as in v4l2-controls.h! */
@@ -1415,6 +1416,7 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
 	case V4L2_CID_JPEG_ACTIVE_MARKER:
 	case V4L2_CID_3A_LOCK:
 	case V4L2_CID_AUTO_FOCUS_STATUS:
+	case V4L2_CID_REGION_OF_INTEREST_AUTO:
 	case V4L2_CID_DV_TX_HOTPLUG:
 	case V4L2_CID_DV_TX_RXSENSE:
 	case V4L2_CID_DV_TX_EDID_PRESENT:
include/uapi/linux/v4l2-controls.h +9 -0
index 499fcddb6254..f6938e4de129 100644
@@ -1009,6 +1009,15 @@ enum v4l2_auto_focus_range {
 #define V4L2_CID_CAMERA_SENSOR_ROTATION		(V4L2_CID_CAMERA_CLASS_BASE+35)
 
 #define V4L2_CID_REGION_OF_INTEREST_RECT	(V4L2_CID_CAMERA_CLASS_BASE+36)
+#define V4L2_CID_REGION_OF_INTEREST_AUTO	(V4L2_CID_CAMERA_CLASS_BASE+37)
+#define V4L2_CID_REGION_OF_INTEREST_AUTO_EXPOSURE		(1 << 0)
+#define V4L2_CID_REGION_OF_INTEREST_AUTO_IRIS			(1 << 1)
+#define V4L2_CID_REGION_OF_INTEREST_AUTO_WHITE_BALANCE		(1 << 2)
+#define V4L2_CID_REGION_OF_INTEREST_AUTO_FOCUS			(1 << 3)
+#define V4L2_CID_REGION_OF_INTEREST_AUTO_FACE_DETECT		(1 << 4)
+#define V4L2_CID_REGION_OF_INTEREST_AUTO_DETECT_AND_TRACK	(1 << 5)
+#define V4L2_CID_REGION_OF_INTEREST_AUTO_IMAGE_STABILIZATION	(1 << 6)
+#define V4L2_CID_REGION_OF_INTEREST_AUTO_HIGHER_QUALITY		(1 << 7)
 
 /* FM Modulator class control IDs */
 
Signature · 1 line
2.36.0.550.gb090851708-goog
#8 lore raw

Re: [PATCH v2 2/6] media: v4l2_ctrl: Add region of interest auto control

Le lundi 16 mai 2022 à 23:04 +0900, Yunke Cao a écrit :

Quoted 30 lines
---
 .../media/v4l/ext-ctrls-camera.rst            | 25 +++++++++++++++++++
 drivers/media/v4l2-core/v4l2-ctrls-defs.c     |  2 ++
 include/uapi/linux/v4l2-controls.h            |  9 +++++++
 3 files changed, 36 insertions(+)
Documentation/userspace-api/media/v4l/ext-ctrls-camera.rst +15 -0
index 86a1f09a8a1c..3da66e1e1fc7 100644
@@ -665,3 +665,28 @@ enum v4l2_scene_mode -
 ``V4L2_CID_REGION_OF_INTEREST_RECT (struct)``
     This control determines the region of interest. Region of interest is an
     rectangular area represented by a struct v4l2_rect.
+
+``V4L2_CID_REGION_OF_INTEREST_AUTO (bitmask)``
+    This determines which, if any, on board features should track to the
+    Region of Interest.
+
+.. flat-table::
+    :header-rows:  0
+    :stub-columns: 0
+
+    * - ``V4L2_CID_REGION_OF_INTEREST_AUTO_EXPOSURE``
+      - Auto Exposure.
+    * - ``V4L2_CID_REGION_OF_INTEREST_AUTO_IRIS``
+      - Auto Iris.
+    * - ``V4L2_CID_REGION_OF_INTEREST_AUTO_WHITE_BALANCE``
+      - Auto White Balance.

Documentation/userspace-api/media/v4l/ext-ctrls-camera.rst enum v4l2_scene_mode - · line 692

Quoted 10 lines
Documentation/userspace-api/media/v4l/ext-ctrls-camera.rst +10 -0
+    * - ``V4L2_CID_REGION_OF_INTEREST_AUTO_FOCUS``
+      - Auto Focus.
+    * - ``V4L2_CID_REGION_OF_INTEREST_AUTO_FACE_DETECT``
+      - Auto Face Detect.
+    * - ``V4L2_CID_REGION_OF_INTEREST_AUTO_DETECT_AND_TRACK``
+      - Auto Detect and Track.
+    * - ``V4L2_CID_REGION_OF_INTEREST_AUTO_IMAGE_STABILIZATION``
+      - Image Stabilization.
+    * - ``V4L2_CID_REGION_OF_INTEREST_AUTO_HIGHER_QUALITY``
+      - Higher Quality.

Now I see the usage, the control is missing cross-reference and behaviour. Consider that someone may have to use or implement your feature on different HW and in different context in the future. Right now you aren't writing a specification, but barely listing things that are already encoded in the item names. For each of this, add human readable prose that explain what is expected behaviour when the bit is set. This way, future implementation can check their behaviour and cross-over with the documentation to make sure it is a fit, or if another bit need to be allocated.

I still believe REGION_OF_INTEREST is too generic of a name for the purpose, as in the context of the V4L2 API, we also support video encoders, and none of this (perhaps except QUALITY, but with encoder you have to specify a delta for that). The name really needs to be specialized to be implemented this way. Otherwise, it create confusion, and makes the V4L2 uAPI poorer over time. Naming is hard, but I need to make a suggestion, perhaps CAMERA_ROI ? We have classes, perhaps a class for the CAMERA controls is needed ?

Quoted 40 lines
drivers/media/v4l2-core/v4l2-ctrls-defs.c +2 -0
index 95f39a2d2ad2..f28763bf95e9 100644
@@ -1043,6 +1043,7 @@ const char *v4l2_ctrl_get_name(u32 id)
 	case V4L2_CID_CAMERA_ORIENTATION:	return "Camera Orientation";
 	case V4L2_CID_CAMERA_SENSOR_ROTATION:	return "Camera Sensor Rotation";
 	case V4L2_CID_REGION_OF_INTEREST_RECT:  return "Region Of Interest Rectangle";
+	case V4L2_CID_REGION_OF_INTEREST_AUTO:  return "Region Of Interest Auto Controls";
 
 	/* FM Radio Modulator controls */
 	/* Keep the order of the 'case's the same as in v4l2-controls.h! */
@@ -1415,6 +1416,7 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
 	case V4L2_CID_JPEG_ACTIVE_MARKER:
 	case V4L2_CID_3A_LOCK:
 	case V4L2_CID_AUTO_FOCUS_STATUS:
+	case V4L2_CID_REGION_OF_INTEREST_AUTO:
 	case V4L2_CID_DV_TX_HOTPLUG:
 	case V4L2_CID_DV_TX_RXSENSE:
 	case V4L2_CID_DV_TX_EDID_PRESENT:
include/uapi/linux/v4l2-controls.h +9 -0
index 499fcddb6254..f6938e4de129 100644
@@ -1009,6 +1009,15 @@ enum v4l2_auto_focus_range {
 #define V4L2_CID_CAMERA_SENSOR_ROTATION		(V4L2_CID_CAMERA_CLASS_BASE+35)
 
 #define V4L2_CID_REGION_OF_INTEREST_RECT	(V4L2_CID_CAMERA_CLASS_BASE+36)
+#define V4L2_CID_REGION_OF_INTEREST_AUTO	(V4L2_CID_CAMERA_CLASS_BASE+37)
+#define V4L2_CID_REGION_OF_INTEREST_AUTO_EXPOSURE		(1 << 0)
+#define V4L2_CID_REGION_OF_INTEREST_AUTO_IRIS			(1 << 1)
+#define V4L2_CID_REGION_OF_INTEREST_AUTO_WHITE_BALANCE		(1 << 2)
+#define V4L2_CID_REGION_OF_INTEREST_AUTO_FOCUS			(1 << 3)
+#define V4L2_CID_REGION_OF_INTEREST_AUTO_FACE_DETECT		(1 << 4)
+#define V4L2_CID_REGION_OF_INTEREST_AUTO_DETECT_AND_TRACK	(1 << 5)
+#define V4L2_CID_REGION_OF_INTEREST_AUTO_IMAGE_STABILIZATION	(1 << 6)
+#define V4L2_CID_REGION_OF_INTEREST_AUTO_HIGHER_QUALITY		(1 << 7)
 
 /* FM Modulator class control IDs */
 
author
#9 lore raw

Re: [PATCH v2 2/6] media: v4l2_ctrl: Add region of interest auto control

Thanks, I will add detailed behavior in the follow up version.

Quoted 87 lines · Nicolas Dufresne
Quoted 30 lines · Yunke Cao
---
 .../media/v4l/ext-ctrls-camera.rst            | 25 +++++++++++++++++++
 drivers/media/v4l2-core/v4l2-ctrls-defs.c     |  2 ++
 include/uapi/linux/v4l2-controls.h            |  9 +++++++
 3 files changed, 36 insertions(+)
Documentation/userspace-api/media/v4l/ext-ctrls-camera.rst +15 -0
index 86a1f09a8a1c..3da66e1e1fc7 100644
@@ -665,3 +665,28 @@ enum v4l2_scene_mode -
 ``V4L2_CID_REGION_OF_INTEREST_RECT (struct)``
     This control determines the region of interest. Region of interest is an
     rectangular area represented by a struct v4l2_rect.
+
+``V4L2_CID_REGION_OF_INTEREST_AUTO (bitmask)``
+    This determines which, if any, on board features should track to the
+    Region of Interest.
+
+.. flat-table::
+    :header-rows:  0
+    :stub-columns: 0
+
+    * - ``V4L2_CID_REGION_OF_INTEREST_AUTO_EXPOSURE``
+      - Auto Exposure.
+    * - ``V4L2_CID_REGION_OF_INTEREST_AUTO_IRIS``
+      - Auto Iris.
+    * - ``V4L2_CID_REGION_OF_INTEREST_AUTO_WHITE_BALANCE``
+      - Auto White Balance.

Documentation/userspace-api/media/v4l/ext-ctrls-camera.rst enum v4l2_scene_mode - · line 692

Quoted 10 lines
Documentation/userspace-api/media/v4l/ext-ctrls-camera.rst +10 -0
+    * - ``V4L2_CID_REGION_OF_INTEREST_AUTO_FOCUS``
+      - Auto Focus.
+    * - ``V4L2_CID_REGION_OF_INTEREST_AUTO_FACE_DETECT``
+      - Auto Face Detect.
+    * - ``V4L2_CID_REGION_OF_INTEREST_AUTO_DETECT_AND_TRACK``
+      - Auto Detect and Track.
+    * - ``V4L2_CID_REGION_OF_INTEREST_AUTO_IMAGE_STABILIZATION``
+      - Image Stabilization.
+    * - ``V4L2_CID_REGION_OF_INTEREST_AUTO_HIGHER_QUALITY``
+      - Higher Quality.

Now I see the usage, the control is missing cross-reference and behaviour. Consider that someone may have to use or implement your feature on different HW and in different context in the future. Right now you aren't writing a specification, but barely listing things that are already encoded in the item names. For each of this, add human readable prose that explain what is expected behaviour when the bit is set. This way, future implementation can check their behaviour and cross-over with the documentation to make sure it is a fit, or if another bit need to be allocated.

I still believe REGION_OF_INTEREST is too generic of a name for the purpose, as in the context of the V4L2 API, we also support video encoders, and none of this (perhaps except QUALITY, but with encoder you have to specify a delta for that). The name really needs to be specialized to be implemented this way. Otherwise, it create confusion, and makes the V4L2 uAPI poorer over time. Naming is hard, but I need to make a suggestion, perhaps CAMERA_ROI ? We have classes, perhaps a class for the CAMERA controls is needed ?

Quoted 27 lines
drivers/media/v4l2-core/v4l2-ctrls-defs.c +2 -0
index 95f39a2d2ad2..f28763bf95e9 100644
@@ -1043,6 +1043,7 @@ const char *v4l2_ctrl_get_name(u32 id)
      case V4L2_CID_CAMERA_ORIENTATION:       return "Camera Orientation";
      case V4L2_CID_CAMERA_SENSOR_ROTATION:   return "Camera Sensor Rotation";
      case V4L2_CID_REGION_OF_INTEREST_RECT:  return "Region Of Interest Rectangle";
+     case V4L2_CID_REGION_OF_INTEREST_AUTO:  return "Region Of Interest Auto Controls";
 
      /* FM Radio Modulator controls */
      /* Keep the order of the 'case's the same as in v4l2-controls.h! */
@@ -1415,6 +1416,7 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
      case V4L2_CID_JPEG_ACTIVE_MARKER:
      case V4L2_CID_3A_LOCK:
      case V4L2_CID_AUTO_FOCUS_STATUS:
+     case V4L2_CID_REGION_OF_INTEREST_AUTO:
      case V4L2_CID_DV_TX_HOTPLUG:
      case V4L2_CID_DV_TX_RXSENSE:
      case V4L2_CID_DV_TX_EDID_PRESENT:
include/uapi/linux/v4l2-controls.h +0 -0
index 499fcddb6254..f6938e4de129 100644
@@ -1009,6 +1009,15 @@ enum v4l2_auto_focus_range {
 #define V4L2_CID_CAMERA_SENSOR_ROTATION              (V4L2_CID_CAMERA_CLASS_BASE+35)
 
Quoted 2 lines

include/uapi/linux/v4l2-controls.h enum v4l2_auto_focus_range { · line 1012

Quoted 2 lines
include/uapi/linux/v4l2-controls.h +1 -0
 #define V4L2_CID_REGION_OF_INTEREST_RECT     (V4L2_CID_CAMERA_CLASS_BASE+36)
+#define V4L2_CID_REGION_OF_INTEREST_AUTO     (V4L2_CID_CAMERA_CLASS_BASE+37)

The ROI controls are in V4L2_CID_CAMERA_CLASS "(V4L2_CID_CAMERA_CLASS_BASE+36)" unless I miss anything. Correct me if I'm wrong but I don't see "CAMERA" included in the name of other camera controls.

Quoted 12 lines
Quoted 11 lines
include/uapi/linux/v4l2-controls.h +8 -0
+#define V4L2_CID_REGION_OF_INTEREST_AUTO_EXPOSURE            (1 << 0)
+#define V4L2_CID_REGION_OF_INTEREST_AUTO_IRIS                        (1 << 1)
+#define V4L2_CID_REGION_OF_INTEREST_AUTO_WHITE_BALANCE               (1 << 2)
+#define V4L2_CID_REGION_OF_INTEREST_AUTO_FOCUS                       (1 << 3)
+#define V4L2_CID_REGION_OF_INTEREST_AUTO_FACE_DETECT         (1 << 4)
+#define V4L2_CID_REGION_OF_INTEREST_AUTO_DETECT_AND_TRACK    (1 << 5)
+#define V4L2_CID_REGION_OF_INTEREST_AUTO_IMAGE_STABILIZATION (1 << 6)
+#define V4L2_CID_REGION_OF_INTEREST_AUTO_HIGHER_QUALITY              (1 << 7)
 
 /* FM Modulator class control IDs */
 
#10 lore raw

Re: [PATCH v2 2/6] media: v4l2_ctrl: Add region of interest auto control

Le mercredi 18 mai 2022 à 10:11 +0900, Yunke Cao a écrit :

Quoted 90 lines

Thanks, I will add detailed behavior in the follow up version.

Quoted 87 lines · Nicolas Dufresne
Quoted 30 lines · Yunke Cao
---
 .../media/v4l/ext-ctrls-camera.rst            | 25 +++++++++++++++++++
 drivers/media/v4l2-core/v4l2-ctrls-defs.c     |  2 ++
 include/uapi/linux/v4l2-controls.h            |  9 +++++++
 3 files changed, 36 insertions(+)
Documentation/userspace-api/media/v4l/ext-ctrls-camera.rst +15 -0
index 86a1f09a8a1c..3da66e1e1fc7 100644
@@ -665,3 +665,28 @@ enum v4l2_scene_mode -
 ``V4L2_CID_REGION_OF_INTEREST_RECT (struct)``
     This control determines the region of interest. Region of interest is an
     rectangular area represented by a struct v4l2_rect.
+
+``V4L2_CID_REGION_OF_INTEREST_AUTO (bitmask)``
+    This determines which, if any, on board features should track to the
+    Region of Interest.
+
+.. flat-table::
+    :header-rows:  0
+    :stub-columns: 0
+
+    * - ``V4L2_CID_REGION_OF_INTEREST_AUTO_EXPOSURE``
+      - Auto Exposure.
+    * - ``V4L2_CID_REGION_OF_INTEREST_AUTO_IRIS``
+      - Auto Iris.
+    * - ``V4L2_CID_REGION_OF_INTEREST_AUTO_WHITE_BALANCE``
+      - Auto White Balance.

Documentation/userspace-api/media/v4l/ext-ctrls-camera.rst enum v4l2_scene_mode - · line 692

Quoted 10 lines
Documentation/userspace-api/media/v4l/ext-ctrls-camera.rst +10 -0
+    * - ``V4L2_CID_REGION_OF_INTEREST_AUTO_FOCUS``
+      - Auto Focus.
+    * - ``V4L2_CID_REGION_OF_INTEREST_AUTO_FACE_DETECT``
+      - Auto Face Detect.
+    * - ``V4L2_CID_REGION_OF_INTEREST_AUTO_DETECT_AND_TRACK``
+      - Auto Detect and Track.
+    * - ``V4L2_CID_REGION_OF_INTEREST_AUTO_IMAGE_STABILIZATION``
+      - Image Stabilization.
+    * - ``V4L2_CID_REGION_OF_INTEREST_AUTO_HIGHER_QUALITY``
+      - Higher Quality.

Now I see the usage, the control is missing cross-reference and behaviour. Consider that someone may have to use or implement your feature on different HW and in different context in the future. Right now you aren't writing a specification, but barely listing things that are already encoded in the item names. For each of this, add human readable prose that explain what is expected behaviour when the bit is set. This way, future implementation can check their behaviour and cross-over with the documentation to make sure it is a fit, or if another bit need to be allocated.

I still believe REGION_OF_INTEREST is too generic of a name for the purpose, as in the context of the V4L2 API, we also support video encoders, and none of this (perhaps except QUALITY, but with encoder you have to specify a delta for that). The name really needs to be specialized to be implemented this way. Otherwise, it create confusion, and makes the V4L2 uAPI poorer over time. Naming is hard, but I need to make a suggestion, perhaps CAMERA_ROI ? We have classes, perhaps a class for the CAMERA controls is needed ?

Quoted 27 lines
drivers/media/v4l2-core/v4l2-ctrls-defs.c +2 -0
index 95f39a2d2ad2..f28763bf95e9 100644
@@ -1043,6 +1043,7 @@ const char *v4l2_ctrl_get_name(u32 id)
      case V4L2_CID_CAMERA_ORIENTATION:       return "Camera Orientation";
      case V4L2_CID_CAMERA_SENSOR_ROTATION:   return "Camera Sensor Rotation";
      case V4L2_CID_REGION_OF_INTEREST_RECT:  return "Region Of Interest Rectangle";
+     case V4L2_CID_REGION_OF_INTEREST_AUTO:  return "Region Of Interest Auto Controls";
 
      /* FM Radio Modulator controls */
      /* Keep the order of the 'case's the same as in v4l2-controls.h! */
@@ -1415,6 +1416,7 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
      case V4L2_CID_JPEG_ACTIVE_MARKER:
      case V4L2_CID_3A_LOCK:
      case V4L2_CID_AUTO_FOCUS_STATUS:
+     case V4L2_CID_REGION_OF_INTEREST_AUTO:
      case V4L2_CID_DV_TX_HOTPLUG:
      case V4L2_CID_DV_TX_RXSENSE:
      case V4L2_CID_DV_TX_EDID_PRESENT:
include/uapi/linux/v4l2-controls.h +0 -0
index 499fcddb6254..f6938e4de129 100644
@@ -1009,6 +1009,15 @@ enum v4l2_auto_focus_range {
 #define V4L2_CID_CAMERA_SENSOR_ROTATION              (V4L2_CID_CAMERA_CLASS_BASE+35)
 
Quoted 7 lines
Quoted 2 lines

include/uapi/linux/v4l2-controls.h enum v4l2_auto_focus_range { · line 1012

Quoted 2 lines
include/uapi/linux/v4l2-controls.h +1 -0
 #define V4L2_CID_REGION_OF_INTEREST_RECT     (V4L2_CID_CAMERA_CLASS_BASE+36)
+#define V4L2_CID_REGION_OF_INTEREST_AUTO     (V4L2_CID_CAMERA_CLASS_BASE+37)

The ROI controls are in V4L2_CID_CAMERA_CLASS "(V4L2_CID_CAMERA_CLASS_BASE+36)" unless I miss anything. Correct me if I'm wrong but I don't see "CAMERA" included in the name of other camera controls.

Namespace should be extended when its obviously going to clash with other similar concept. In this case it obviously clash with video encoder ROI.

regards,
Nicolas

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
include/uapi/linux/v4l2-controls.h +8 -0
+#define V4L2_CID_REGION_OF_INTEREST_AUTO_EXPOSURE            (1 << 0)
+#define V4L2_CID_REGION_OF_INTEREST_AUTO_IRIS                        (1 << 1)
+#define V4L2_CID_REGION_OF_INTEREST_AUTO_WHITE_BALANCE               (1 << 2)
+#define V4L2_CID_REGION_OF_INTEREST_AUTO_FOCUS                       (1 << 3)
+#define V4L2_CID_REGION_OF_INTEREST_AUTO_FACE_DETECT         (1 << 4)
+#define V4L2_CID_REGION_OF_INTEREST_AUTO_DETECT_AND_TRACK    (1 << 5)
+#define V4L2_CID_REGION_OF_INTEREST_AUTO_IMAGE_STABILIZATION (1 << 6)
+#define V4L2_CID_REGION_OF_INTEREST_AUTO_HIGHER_QUALITY              (1 << 7)
 
 /* FM Modulator class control IDs */
 
author
#11 lore raw

PATCH v2 3/6 media: v4l2_ctrl: Add V4L2_CTRL_WHICH_MIN/MAX_VAL

In reply to Yunke Cao

Added V4L2_CTRL_WHICH_MIN/MAX_VAL and basic support in v4l2-core.

Mostly reusing a previous attempt:
https://lore.kernel.org/all/[email protected]/T/#m5c83970af8b774a4b1ea5f2dca4c0a534da4ccbe

---
 .../media/v4l/vidioc-g-ext-ctrls.rst          |  10 +-
 .../media/videodev2.h.rst.exceptions          |   2 +
 drivers/media/i2c/imx214.c                    |   4 +-
 drivers/media/v4l2-core/v4l2-ctrls-api.c      |  51 +++++--
 drivers/media/v4l2-core/v4l2-ctrls-core.c     | 135 ++++++++++++++++--
 drivers/media/v4l2-core/v4l2-ioctl.c          |   4 +-
 include/media/v4l2-ctrls.h                    |  30 +++-
 include/uapi/linux/videodev2.h                |   2 +
 8 files changed, 210 insertions(+), 28 deletions(-)
Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst +7 -3
index f4e205ead0a2..11336f5d69ed 100644
@@ -284,14 +284,18 @@ still cause this situation.
       - Which value of the control to get/set/try.
     * - :cspan:`2` ``V4L2_CTRL_WHICH_CUR_VAL`` will return the current value of
 	the control, ``V4L2_CTRL_WHICH_DEF_VAL`` will return the default
-	value of the control and ``V4L2_CTRL_WHICH_REQUEST_VAL`` indicates that
+	value of the control, ``V4L2_CTRL_WHICH_MIN_VAL`` will return the minimum
+  value of the control, ``V4L2_CTRL_WHICH_MAX_VAL`` will return the maximum
+  value of the control and ``V4L2_CTRL_WHICH_REQUEST_VAL`` indicates that
 	these controls have to be retrieved from a request or tried/set for
 	a request. In the latter case the ``request_fd`` field contains the
 	file descriptor of the request that should be used. If the device
 	does not support requests, then ``EACCES`` will be returned.
 
-	When using ``V4L2_CTRL_WHICH_DEF_VAL`` be aware that you can only
-	get the default value of the control, you cannot set or try it.
+  When using ``V4L2_CTRL_WHICH_DEF_VAL``, ``V4L2_CTRL_WHICH_MIN_VAL``
+  or ``V4L2_CTRL_WHICH_MAX_VAL`` be aware that you can only
+  get the default/minimum/maximum value of the control, you cannot set
+  or try it.
 
 	For backwards compatibility you can also use a control class here
 	(see :ref:`ctrl-class`). In that case all controls have to
Documentation/userspace-api/media/videodev2.h.rst.exceptions +2 -0
index 7b423475281d..e2dde31d76df 100644
@@ -553,6 +553,8 @@ ignore define V4L2_CTRL_DRIVER_PRIV
 ignore define V4L2_CTRL_MAX_DIMS
 ignore define V4L2_CTRL_WHICH_CUR_VAL
 ignore define V4L2_CTRL_WHICH_DEF_VAL
+ignore define V4L2_CTRL_WHICH_MIN_VAL
+ignore define V4L2_CTRL_WHICH_MAX_VAL
 ignore define V4L2_CTRL_WHICH_REQUEST_VAL
 ignore define V4L2_OUT_CAP_CUSTOM_TIMINGS
 ignore define V4L2_CID_MAX_CTRLS
drivers/media/i2c/imx214.c +3 -1
index 83c1737abeec..1541a81dcd46 100644
@@ -1037,7 +1037,9 @@ static int imx214_probe(struct i2c_client *client)
 	imx214->unit_size = v4l2_ctrl_new_std_compound(&imx214->ctrls,
 				NULL,
 				V4L2_CID_UNIT_CELL_SIZE,
-				v4l2_ctrl_ptr_create((void *)&unit_size));
+				v4l2_ctrl_ptr_create((void *)&unit_size),
+				v4l2_ctrl_ptr_create(NULL),
+				v4l2_ctrl_ptr_create(NULL));
 	ret = imx214->ctrls.error;
 	if (ret) {
 		dev_err(&client->dev, "%s control init failed (%d)\n",
drivers/media/v4l2-core/v4l2-ctrls-api.c +41 -10

101 lines not on this page · raw message

drivers/media/v4l2-core/v4l2-ctrls-core.c +126 -9

213 lines not on this page · raw message

drivers/media/v4l2-core/v4l2-ioctl.c +3 -1
index 96e307fe3aab..6ed6ef87c7ff 100644
@@ -892,7 +892,9 @@ static bool check_ext_ctrls(struct v4l2_ext_controls *c, unsigned long ioctl)
 			return false;
 		break;
 	case V4L2_CTRL_WHICH_DEF_VAL:
-		/* Default value cannot be changed */
+	case V4L2_CTRL_WHICH_MIN_VAL:
+	case V4L2_CTRL_WHICH_MAX_VAL:
+		/* Default, minimum or maximum value cannot be changed */
 		if (ioctl == VIDIOC_S_EXT_CTRLS ||
 		    ioctl == VIDIOC_TRY_EXT_CTRLS) {
 			c->error_idx = c->count;
include/media/v4l2-ctrls.h +26 -4
index 919e104de50b..bd3bab55b766 100644
@@ -131,6 +131,8 @@ struct v4l2_ctrl_ops {
  *
  * @equal: return true if both values are equal.
  * @init: initialize the value.
+ * @minimum: set the value to the minimum value of the control.
+ * @maximum: set the value to the maximum value of the control.
  * @log: log the value.
  * @validate: validate the value. Return 0 on success and a negative value
  *	otherwise.
@@ -141,6 +143,10 @@ struct v4l2_ctrl_type_ops {
 		      union v4l2_ctrl_ptr ptr2);
 	void (*init)(const struct v4l2_ctrl *ctrl, u32 idx,
 		     union v4l2_ctrl_ptr ptr);
+	void (*minimum)(const struct v4l2_ctrl *ctrl, u32 idx,
+			union v4l2_ctrl_ptr ptr);
+	void (*maximum)(const struct v4l2_ctrl *ctrl, u32 idx,
+			union v4l2_ctrl_ptr ptr);
 	void (*log)(const struct v4l2_ctrl *ctrl);
 	int (*validate)(const struct v4l2_ctrl *ctrl, u32 idx,
 			union v4l2_ctrl_ptr ptr);
@@ -237,6 +243,12 @@ typedef void (*v4l2_ctrl_notify_fnc)(struct v4l2_ctrl *ctrl, void *priv);
  * @p_def:	The control's default value represented via a union which
  *		provides a standard way of accessing control types
  *		through a pointer (for compound controls only).
+ * @p_min:	The control's minimum value represented via a union which
+ *		provides a standard way of accessing control types
+ *		through a pointer (for compound controls only).
+ * @p_max:	The control's maximum value represented via a union which
+ *		provides a standard way of accessing control types
+ *		through a pointer (for compound controls only).
  * @p_cur:	The control's current value represented via a union which
  *		provides a standard way of accessing control types
  *		through a pointer.
@@ -292,6 +304,8 @@ struct v4l2_ctrl {
 	} cur;
 
 	union v4l2_ctrl_ptr p_def;
+	union v4l2_ctrl_ptr p_min;
+	union v4l2_ctrl_ptr p_max;
 	union v4l2_ctrl_ptr p_new;
 	union v4l2_ctrl_ptr p_cur;
 };
@@ -398,6 +412,8 @@ struct v4l2_ctrl_handler {
  * @step:	The control's step value for non-menu controls.
  * @def:	The control's default value.
  * @p_def:	The control's default value for compound controls.
+ * @p_min:	The control's minimum value for compound controls.
+ * @p_max:	The control's maximum value for compound controls.
  * @dims:	The size of each dimension.
  * @elem_size:	The size in bytes of the control.
  * @flags:	The control's flags.
@@ -427,6 +443,8 @@ struct v4l2_ctrl_config {
 	u64 step;
 	s64 def;
 	union v4l2_ctrl_ptr p_def;
+	union v4l2_ctrl_ptr p_min;
+	union v4l2_ctrl_ptr p_max;
 	u32 dims[V4L2_CTRL_MAX_DIMS];
 	u32 elem_size;
 	u32 flags;
@@ -696,17 +714,21 @@ struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items(struct v4l2_ctrl_handler *hdl,
  * @ops:       The control ops.
  * @id:        The control ID.
  * @p_def:     The control's default value.
+ * @p_min:     The control's default value.
+ * @p_ma:     The control's default value.
  *
  * Sames as v4l2_ctrl_new_std(), but with support to compound controls, thanks
- * to the @p_def field. Use v4l2_ctrl_ptr_create() to create @p_def from a
- * pointer. Use v4l2_ctrl_ptr_create(NULL) if the default value of the
- * compound control should be all zeroes.
+ * to the @p_def/min/max field. Use v4l2_ctrl_ptr_create() to create
+ * @p_def/min/max from a pointer. Use v4l2_ctrl_ptr_create(NULL) if the default
+ * value of the compound control should be all zeroes.
  *
  */
 struct v4l2_ctrl *v4l2_ctrl_new_std_compound(struct v4l2_ctrl_handler *hdl,
 					     const struct v4l2_ctrl_ops *ops,
 					     u32 id,
-					     const union v4l2_ctrl_ptr p_def);
+					     const union v4l2_ctrl_ptr p_def,
+					     const union v4l2_ctrl_ptr p_min,
+					     const union v4l2_ctrl_ptr p_max);
 
 /**
  * v4l2_ctrl_new_int_menu() - Create a new standard V4L2 integer menu control.
include/uapi/linux/videodev2.h +2 -0
index b712412cf763..d22ebb0102d4 100644
@@ -1793,6 +1793,8 @@ struct v4l2_ext_controls {
 #define V4L2_CTRL_WHICH_CUR_VAL   0
 #define V4L2_CTRL_WHICH_DEF_VAL   0x0f000000
 #define V4L2_CTRL_WHICH_REQUEST_VAL 0x0f010000
+#define V4L2_CTRL_WHICH_MIN_VAL   0x0f020000
+#define V4L2_CTRL_WHICH_MAX_VAL   0x0f030000
 
 enum v4l2_ctrl_type {
 	V4L2_CTRL_TYPE_INTEGER	     = 1,
Signature · 1 line
2.36.0.550.gb090851708-goog
author
#12 lore raw

PATCH v2 4/6 media: uvcvideo: implement UVC v1.5 ROI

In reply to Yunke Cao

Supports GET_CUR, GET_DEF, GET_MIN and GET_MAX requests for UVC v1.5 using V4L2 control API.

References a rejected attempt that uses v4l2 selection API:
https://lore.kernel.org/lkml/[email protected]

---
 .../userspace-api/media/drivers/uvcvideo.rst  |   1 +
 drivers/media/usb/uvc/uvc_ctrl.c              | 173 ++++++++++++++++--
 drivers/media/usb/uvc/uvc_v4l2.c              |  12 +-
 drivers/media/usb/uvc/uvcvideo.h              |  10 +-
 include/uapi/linux/usb/video.h                |   1 +
 include/uapi/linux/uvcvideo.h                 |   1 +
 6 files changed, 173 insertions(+), 25 deletions(-)
Documentation/userspace-api/media/drivers/uvcvideo.rst +1 -0
index e5fd8fad333c..43b8431b0d9f 100644
@@ -181,6 +181,7 @@ Argument: struct uvc_xu_control_mapping
 	UVC_CTRL_DATA_TYPE_BOOLEAN	Boolean
 	UVC_CTRL_DATA_TYPE_ENUM		Enumeration
 	UVC_CTRL_DATA_TYPE_BITMASK	Bitmask
+	UVC_CTRL_DATA_TYPE_RECT		Rectangular area
 
 
 UVCIOC_CTRL_QUERY - Query a UVC XU control
drivers/media/usb/uvc/uvc_ctrl.c +156 -17

272 lines not on this page · raw message

drivers/media/usb/uvc/uvc_v4l2.c +5 -7
index 711556d13d03..a88d3fe6de93 100644
@@ -1038,17 +1038,15 @@ 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) {
+	if (ctrls->which == V4L2_CTRL_WHICH_DEF_VAL ||
+	    ctrls->which == V4L2_CTRL_WHICH_MIN_VAL ||
+	    ctrls->which == V4L2_CTRL_WHICH_MAX_VAL) {
 		for (i = 0; i < ctrls->count; ++ctrl, ++i) {
-			struct v4l2_queryctrl qc = { .id = ctrl->id };
-
-			ret = uvc_query_v4l2_ctrl(chain, &qc);
+			ret = uvc_ctrl_get(chain, ctrl, ctrls->which);
 			if (ret < 0) {
 				ctrls->error_idx = i;
 				return ret;
 			}
-
-			ctrl->value = qc.default_value;
 		}
 
 		return 0;
@@ -1059,7 +1057,7 @@ static int uvc_ioctl_g_ext_ctrls(struct file *file, void *fh,
 		return ret;
 
 	for (i = 0; i < ctrls->count; ++ctrl, ++i) {
-		ret = uvc_ctrl_get(chain, ctrl);
+		ret = uvc_ctrl_get(chain, ctrl, ctrls->which);
 		if (ret < 0) {
 			uvc_ctrl_rollback(handle);
 			ctrls->error_idx = i;
drivers/media/usb/uvc/uvcvideo.h +9 -1
index 143230b3275b..f414ad7d57b2 100644
@@ -424,6 +424,13 @@ struct uvc_streaming_header {
 	u8 bTriggerUsage;
 };
 
+struct uvc_rect {
+	u16 top;
+	u16 left;
+	u16 bottom;
+	u16 right;
+} __packed;
+
 enum uvc_buffer_state {
 	UVC_BUF_STATE_IDLE	= 0,
 	UVC_BUF_STATE_QUEUED	= 1,
@@ -897,7 +904,8 @@ static inline int uvc_ctrl_rollback(struct uvc_fh *handle)
 	return __uvc_ctrl_commit(handle, 1, NULL);
 }
 
-int uvc_ctrl_get(struct uvc_video_chain *chain, struct v4l2_ext_control *xctrl);
+int uvc_ctrl_get(struct uvc_video_chain *chain, 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,
 			   bool read);
include/uapi/linux/usb/video.h +1 -0
index bfdae12cdacf..9076a444758a 100644
@@ -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
include/uapi/linux/uvcvideo.h +1 -0
index 8288137387c0..d7d77602a5e7 100644
@@ -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)
Signature · 1 line
2.36.0.550.gb090851708-goog
author
#13 lore raw

PATCH v2 5/6 media: uvcvideo: Initialize roi to default value

In reply to Yunke Cao

For the devices we tested with, firmwares have wrong initial ROI configuration. Initialize roi by setting to default value.

---
Changelog since v1:
- Fix a build error introduced in rebasing.

 drivers/media/usb/uvc/uvc_ctrl.c | 40 ++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
drivers/media/usb/uvc/uvc_ctrl.c +40 -0
index c3d816985f13..2e37bb8c784c 100644
@@ -2505,6 +2505,40 @@ static void uvc_ctrl_prune_entity(struct uvc_device *dev,
 	}
 }
 
+static int uvc_ctrl_init_roi(struct uvc_device *dev, struct uvc_control *ctrl)
+{
+	int ret;
+
+	ret = uvc_query_ctrl(dev, UVC_GET_DEF, ctrl->entity->id, dev->intfnum,
+			     UVC_CT_REGION_OF_INTEREST_CONTROL,
+			     uvc_ctrl_data(ctrl, UVC_CTRL_DATA_DEF),
+			     ctrl->info.size);
+	if (ret)
+		goto out;
+
+	/*
+	 * Some firmwares have wrong GET_CURRENT configuration. E.g. it's
+	 * below GET_MIN, or have rectangle coordinates mixed up. This
+	 * causes problems sometimes, because we are unable to set
+	 * auto-controls value without first setting ROI rectangle to
+	 * valid configuration.
+	 *
+	 * We expect that default configuration is always correct and
+	 * is within the GET_MIN / GET_MAX boundaries.
+	 *
+	 * Set current ROI configuration to GET_DEF, so that we will
+	 * always have properly configured ROI.
+	 */
+	ret = uvc_query_ctrl(dev, UVC_SET_CUR, 1, dev->intfnum,
+			     UVC_CT_REGION_OF_INTEREST_CONTROL,
+			     uvc_ctrl_data(ctrl, UVC_CTRL_DATA_DEF),
+			     ctrl->info.size);
+out:
+	if (ret)
+		dev_err(&dev->udev->dev, "Failed to fixup ROI (%d).\n", ret);
+	return ret;
+}
+
 /*
  * Add control information and hardcoded stock control mappings to the given
  * device.
@@ -2517,6 +2551,7 @@ static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain,
 	const struct uvc_control_mapping *mapping = uvc_ctrl_mappings;
 	const struct uvc_control_mapping *mend =
 		mapping + ARRAY_SIZE(uvc_ctrl_mappings);
+	const u8 camera_entity[16] = UVC_GUID_UVC_CAMERA;
 
 	/* XU controls initialization requires querying the device for control
 	 * information. As some buggy UVC devices will crash when queried
@@ -2537,6 +2572,11 @@ static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain,
 			 * GET_INFO on standard controls.
 			 */
 			uvc_ctrl_get_flags(chain->dev, ctrl, &ctrl->info);
+
+			if (ctrl->info.selector ==
+				UVC_CT_REGION_OF_INTEREST_CONTROL &&
+			    uvc_entity_match_guid(ctrl->entity, camera_entity))
+				uvc_ctrl_init_roi(chain->dev, ctrl);
 			break;
 		 }
 	}
Signature · 1 line
2.36.0.550.gb090851708-goog
author
#14 lore raw

PATCH v2 6/6 media: vivid: Add a roi rectangle control

In reply to Yunke Cao

The control supports current, default, minimum and maximum.

Tested by calling ioctls from the user space.

---
 .../media/test-drivers/vivid/vivid-ctrls.c    | 34 +++++++++++++++++++
 1 file changed, 34 insertions(+)
drivers/media/test-drivers/vivid/vivid-ctrls.c +34 -0
index e7516dc1227b..79093882d386 100644
@@ -34,6 +34,7 @@
 #define VIVID_CID_U8_4D_ARRAY		(VIVID_CID_CUSTOM_BASE + 10)
 #define VIVID_CID_AREA			(VIVID_CID_CUSTOM_BASE + 11)
 #define VIVID_CID_RO_INTEGER		(VIVID_CID_CUSTOM_BASE + 12)
+#define VIVID_CID_RECT			(VIVID_CID_CUSTOM_BASE + 13)
 
 #define VIVID_CID_VIVID_BASE		(0x00f00000 | 0xf000)
 #define VIVID_CID_VIVID_CLASS		(0x00f00000 | 1)
@@ -292,6 +293,38 @@ static const struct v4l2_ctrl_config vivid_ctrl_area = {
 	.p_def.p_const = &area,
 };
 
+static const struct v4l2_rect def_rect = {
+	.left = 0,
+	.top = 0,
+	.width = 1000,
+	.height = 2000,
+};
+
+static const struct v4l2_rect min_rect = {
+	.left = 0,
+	.top = 0,
+	.width = 1,
+	.height = 2,
+};
+
+static const struct v4l2_rect max_rect = {
+	.left = 0,
+	.top = 0,
+	.width = 2000,
+	.height = 4000,
+};
+
+static const struct v4l2_ctrl_config vivid_ctrl_rect = {
+	.ops = &vivid_user_gen_ctrl_ops,
+	.id = VIVID_CID_RECT,
+	.name = "Region of Interest Rectangle",
+	.type = V4L2_CTRL_TYPE_RECT,
+	.p_def.p_const = &def_rect,
+	.p_min.p_const = &min_rect,
+	.p_max.p_const = &max_rect,
+};
+
+
 static const struct v4l2_ctrl_config vivid_ctrl_ro_int32 = {
 	.ops = &vivid_user_gen_ctrl_ops,
 	.id = VIVID_CID_RO_INTEGER,
@@ -1611,6 +1644,7 @@ int vivid_create_controls(struct vivid_dev *dev, bool show_ccs_cap,
 	dev->int_menu = v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_int_menu, NULL);
 	dev->ro_int32 = v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_ro_int32, NULL);
 	v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_area, NULL);
+	v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_rect, NULL);
 	v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_u32_array, NULL);
 	v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_u16_matrix, NULL);
 	v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_u8_4d_array, NULL);
Signature · 1 line
2.36.0.550.gb090851708-goog