media: v4l2-ctrls: Add average QP control
authorMing Qian <ming.qian@nxp.com>
Mon, 6 May 2024 08:49:16 +0000 (17:49 +0900)
committerHans Verkuil <hverkuil-cisco@xs4all.nl>
Mon, 10 Jun 2024 08:24:30 +0000 (10:24 +0200)
Add a control V4L2_CID_MPEG_VIDEO_AVERAGE_QP to report the average QP
value of the current encoded frame. The value applies to the last
dequeued capture buffer.

Signed-off-by: Ming Qian <ming.qian@nxp.com>
Reviewed-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Sebastian Fricke <sebastian.fricke@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
drivers/media/v4l2-core/v4l2-ctrls-defs.c
include/uapi/linux/v4l2-controls.h

index 2a165ae063fb4f45696baf316f17356d3ccf9625..4a379bd9e3fbdb78dfda8e7bc4b25de079d61208 100644 (file)
@@ -1653,6 +1653,20 @@ enum v4l2_mpeg_video_h264_hierarchical_coding_type -
     Quantization parameter for a P frame for FWHT. Valid range: from 1
     to 31.
 
+``V4L2_CID_MPEG_VIDEO_AVERAGE_QP (integer)``
+    This read-only control returns the average QP value of the currently
+    encoded frame. The value applies to the last dequeued capture buffer
+    (VIDIOC_DQBUF). Its valid range depends on the encoding format and parameters.
+    For H264, its valid range is from 0 to 51.
+    For HEVC, its valid range is from 0 to 51 for 8 bit and
+    from 0 to 63 for 10 bit.
+    For H263 and MPEG4, its valid range is from 1 to 31.
+    For VP8, its valid range is from 0 to 127.
+    For VP9, its valid range is from 0 to 255.
+    If the codec's MIN_QP and MAX_QP are set, then the QP will meet both requirements.
+    Codecs need to always use the specified range, rather then a HW custom range.
+    Applicable to encoders
+
 .. raw:: latex
 
     \normalsize
index 8696eb1cdd6191fc34fecf02921a5a67052889e7..1ea52011247accc51d0261f56eab1cf13c0624a0 100644 (file)
@@ -970,6 +970,7 @@ const char *v4l2_ctrl_get_name(u32 id)
        case V4L2_CID_MPEG_VIDEO_LTR_COUNT:                     return "LTR Count";
        case V4L2_CID_MPEG_VIDEO_FRAME_LTR_INDEX:               return "Frame LTR Index";
        case V4L2_CID_MPEG_VIDEO_USE_LTR_FRAMES:                return "Use LTR Frames";
+       case V4L2_CID_MPEG_VIDEO_AVERAGE_QP:                    return "Average QP Value";
        case V4L2_CID_FWHT_I_FRAME_QP:                          return "FWHT I-Frame QP Value";
        case V4L2_CID_FWHT_P_FRAME_QP:                          return "FWHT P-Frame QP Value";
 
@@ -1507,6 +1508,10 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
                *max = 0xffffffffffffLL;
                *step = 1;
                break;
+       case V4L2_CID_MPEG_VIDEO_AVERAGE_QP:
+               *type = V4L2_CTRL_TYPE_INTEGER;
+               *flags |= V4L2_CTRL_FLAG_READ_ONLY;
+               break;
        case V4L2_CID_PIXEL_RATE:
                *type = V4L2_CTRL_TYPE_INTEGER64;
                *flags |= V4L2_CTRL_FLAG_READ_ONLY;
index 99c3f5e99da758a612de824f53c37c52d47a3928..974fd254e57309e6def95b4a4f8e4de13a3972a7 100644 (file)
@@ -898,6 +898,8 @@ enum v4l2_mpeg_video_av1_level {
        V4L2_MPEG_VIDEO_AV1_LEVEL_7_3 = 23
 };
 
+#define V4L2_CID_MPEG_VIDEO_AVERAGE_QP  (V4L2_CID_CODEC_BASE + 657)
+
 /*  MPEG-class control IDs specific to the CX2341x driver as defined by V4L2 */
 #define V4L2_CID_CODEC_CX2341X_BASE                            (V4L2_CTRL_CLASS_CODEC | 0x1000)
 #define V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE                (V4L2_CID_CODEC_CX2341X_BASE+0)