[RFC v2 4/6] media: v4l2-ctrls: Add V4L2_CTRL_TYPE_REGION
Ming Qian
ming.qian at nxp.com
Thu Oct 17 22:44:46 PDT 2024
Add p_region to struct v4l2_ext_control with basic support in
v4l2-ctrls.
Signed-off-by: Ming Qian <ming.qian at nxp.com>
Signed-off-by: TaoJiang <tao.jiang_2 at nxp.com>
---
.../userspace-api/media/v4l/vidioc-g-ext-ctrls.rst | 4 ++++
.../userspace-api/media/v4l/vidioc-queryctrl.rst | 12 ++++++++++++
.../userspace-api/media/videodev2.h.rst.exceptions | 1 +
drivers/media/v4l2-core/v4l2-ctrls-core.c | 14 +++++++++++++-
include/media/v4l2-ctrls.h | 2 ++
include/uapi/linux/videodev2.h | 8 ++++++++
6 files changed, 40 insertions(+), 1 deletion(-)
diff --git a/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst b/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst
index b8698b85bd80..f00c6d1f7784 100644
--- a/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst
+++ b/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst
@@ -203,6 +203,10 @@ still cause this situation.
- ``p_rect``
- 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_video_region_param` *
+ - ``p_region``
+ - A pointer to a struct :c:type:`v4l2_ctrl_video_region_param`. Valid if
+ this control is of type ``V4L2_CTRL_TYPE_REGION``.
* - 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
diff --git a/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst b/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst
index 3815732f6a9b..df3cd36b67ab 100644
--- a/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst
+++ b/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst
@@ -451,6 +451,18 @@ See also the examples in :ref:`control`.
``V4L2_CTRL_WHICH_MAX_VAL`` is optional and depends on the
``V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX`` flag. See the documentation of
the specific control on how to interpret the minimum and maximum values.
+ * - ``V4L2_CTRL_TYPE_REGION``
+ - n/a
+ - n/a
+ - n/a
+ - A struct :c:type:`v4l2_ctrl_video_region_param`, containing a rectangle
+ described by the position of its top-left corner, the width and the height.
+ And a parameter for detailed purpose, for example, it's QP offset for video
+ encoder ROI. Units depend on the use case. Support for
+ ``V4L2_CTRL_WHICH_MIN_VAL`` and ``V4L2_CTRL_WHICH_MAX_VAL`` is optional and
+ depends on the ``V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX`` flag. See the
+ documentation of the specific control on how to interpret the minimum and
+ maximum values.
* - ``V4L2_CTRL_TYPE_H264_SPS``
- n/a
- n/a
diff --git a/Documentation/userspace-api/media/videodev2.h.rst.exceptions b/Documentation/userspace-api/media/videodev2.h.rst.exceptions
index 35d3456cc812..22307e029883 100644
--- a/Documentation/userspace-api/media/videodev2.h.rst.exceptions
+++ b/Documentation/userspace-api/media/videodev2.h.rst.exceptions
@@ -151,6 +151,7 @@ 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_REGION :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`
diff --git a/drivers/media/v4l2-core/v4l2-ctrls-core.c b/drivers/media/v4l2-core/v4l2-ctrls-core.c
index a3abbde5379b..8dabc6a87126 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls-core.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls-core.c
@@ -441,6 +441,11 @@ void v4l2_ctrl_type_op_log(const struct v4l2_ctrl *ctrl)
ptr.p_rect->width, ptr.p_rect->height,
ptr.p_rect->left, ptr.p_rect->top);
break;
+ case V4L2_CTRL_TYPE_REGION:
+ pr_cont("%ux%u@%dx%d, %d",
+ ptr.p_rect->width, ptr.p_rect->height,
+ ptr.p_rect->left, ptr.p_rect->top, ptr.p_region->parameter);
+ break;
default:
pr_cont("unknown type %d", ctrl->type);
break;
@@ -886,6 +891,7 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx,
struct v4l2_ctrl_hevc_decode_params *p_hevc_decode_params;
struct v4l2_area *area;
struct v4l2_rect *rect;
+ struct v4l2_ctrl_video_region_param *p_region;
void *p = ptr.p + idx * ctrl->elem_size;
unsigned int i;
@@ -1248,7 +1254,10 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx,
if (!rect->width || !rect->height)
return -EINVAL;
break;
-
+ case V4L2_CTRL_TYPE_REGION:
+ p_region = p;
+ zero_reserved(*p_region);
+ break;
default:
return -EINVAL;
}
@@ -1957,6 +1966,9 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
case V4L2_CTRL_TYPE_RECT:
elem_size = sizeof(struct v4l2_rect);
break;
+ case V4L2_CTRL_TYPE_REGION:
+ elem_size = sizeof(struct v4l2_ctrl_video_region_param);
+ break;
default:
if (type < V4L2_CTRL_COMPOUND_TYPES)
elem_size = sizeof(s32);
diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h
index 5c38d6d5ae5b..8b271a7485f4 100644
--- a/include/media/v4l2-ctrls.h
+++ b/include/media/v4l2-ctrls.h
@@ -57,6 +57,7 @@ struct video_device;
* @p_av1_frame: Pointer to an AV1 frame structure.
* @p_av1_film_grain: Pointer to an AV1 film grain structure.
* @p_rect: Pointer to a rectangle.
+ * @p_region: Pointer to a video region
* @p: Pointer to a compound value.
* @p_const: Pointer to a constant compound value.
*/
@@ -91,6 +92,7 @@ union v4l2_ctrl_ptr {
struct v4l2_ctrl_av1_frame *p_av1_frame;
struct v4l2_ctrl_av1_film_grain *p_av1_film_grain;
struct v4l2_rect *p_rect;
+ struct v4l2_ctrl_video_region_param *p_region;
void *p;
const void *p_const;
};
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index 4007041302d3..503cbb884734 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -448,6 +448,12 @@ struct v4l2_area {
__u32 height;
};
+struct v4l2_ctrl_video_region_param {
+ struct v4l2_rect rect;
+ __s32 parameter;
+ __u32 reserved[2];
+};
+
/**
* struct v4l2_capability - Describes V4L2 device caps returned by VIDIOC_QUERYCAP
*
@@ -1858,6 +1864,7 @@ struct v4l2_ext_control {
__s64 __user *p_s64;
struct v4l2_area __user *p_area;
struct v4l2_rect __user *p_rect;
+ struct v4l2_ctrl_video_region_param __user *p_region;
struct v4l2_ctrl_h264_sps __user *p_h264_sps;
struct v4l2_ctrl_h264_pps __user *p_h264_pps;
struct v4l2_ctrl_h264_scaling_matrix __user *p_h264_scaling_matrix;
@@ -1931,6 +1938,7 @@ enum v4l2_ctrl_type {
V4L2_CTRL_TYPE_U32 = 0x0102,
V4L2_CTRL_TYPE_AREA = 0x0106,
V4L2_CTRL_TYPE_RECT = 0x0107,
+ V4L2_CTRL_TYPE_REGION = 0x0108,
V4L2_CTRL_TYPE_HDR10_CLL_INFO = 0x0110,
V4L2_CTRL_TYPE_HDR10_MASTERING_DISPLAY = 0x0111,
--
2.43.0-rc1
More information about the linux-arm-kernel
mailing list