media: v4l2-ctrls: Add encoded frame quality controls
PATCH 1/1 media: v4l2-ctrls: Add encoded frame quality controls
When frame quality control is enabled encoder will choose the appropriate quantization parameter and bitrate to produce the client requested frame quality level. When frame quality control is disabled then frame quality is decided based on appropriate controls (i.e. V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE and/or V4L2_CID_MPEG_VIDEO_BITRATE_MODE)
--- .../userspace-api/media/v4l/ext-ctrls-codec.rst | 16 ++++++++++++++++ drivers/media/v4l2-core/v4l2-ctrls.c | 3 +++ include/uapi/linux/v4l2-controls.h | 2 ++ 3 files changed, 21 insertions(+)
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +16 -0
@@ -1081,6 +1081,22 @@ enum v4l2_mpeg_video_h264_entropy_mode - Macroblock level rate control enable. Applicable to the MPEG4 and H264 encoders. +``V4L2_CID_MPEG_VIDEO_FRAME_QUALITY_ENABLE (boolean)`` + Encoded frame quality control enable. If this control is enabled then + the quality level of the encoded frame is set with control + ``V4L2_CID_MPEG_VIDEO_CONSTANT_QUALITY``. If this control is disabled + then the quality level of encoded frame is adjusted with appropriate + controls (e.g. ``V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE`` or + ``V4L2_CID_MPEG_VIDEO_BITRATE_MODE``). Applicable to encoders. + +``V4L2_CID_MPEG_VIDEO_FRAME_QUALITY (integer)`` + Encoded frame quality control. If the control + ``V4L2_CID_MPEG_VIDEO_FRAME_QUALITY_ENABLE`` is enabled then the + quality of encoded frame is set with this control. Valid range is 1 to + 100 where 1 indicates lowest quality and 100 indicates highest quality. + Encoder will decide the appropriate quantization parameter and bitrate + to produce requested frame quality. Applicable to encoders. + ``V4L2_CID_MPEG_VIDEO_MPEG4_QPEL (boolean)`` Quarter pixel motion estimation for MPEG4. Applicable to the MPEG4 encoder.
drivers/media/v4l2-core/v4l2-ctrls.c +3 -0
@@ -982,6 +982,8 @@ const char *v4l2_ctrl_get_name(u32 id)case V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS :return "HEVC Slice Parameters" ;case V4L2_CID_MPEG_VIDEO_HEVC_DECODE_MODE :return "HEVC Decode Mode" ;case V4L2_CID_MPEG_VIDEO_HEVC_START_CODE :return "HEVC Start Code" ; +case V4L2_CID_MPEG_VIDEO_FRAME_QUALITY_ENABLE :return "Frame Quality Enable" ; +case V4L2_CID_MPEG_VIDEO_FRAME_QUALITY :return "Frame Quality" ;/* CAMERA controls */ /* Keep the order of the 'case's the same as in v4l2-controls.h! */
@@ -1178,6 +1180,7 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,case V4L2_CID_FLASH_READY :case V4L2_CID_MPEG_VIDEO_DECODER_MPEG4_DEBLOCK_FILTER :case V4L2_CID_MPEG_VIDEO_DECODER_SLICE_INTERFACE : +case V4L2_CID_MPEG_VIDEO_FRAME_QUALITY_ENABLE :case V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE :case V4L2_CID_MPEG_VIDEO_MB_RC_ENABLE :case V4L2_CID_MPEG_VIDEO_H264_8X8_TRANSFORM :
include/uapi/linux/v4l2-controls.h +2 -0
@@ -742,6 +742,8 @@ enum v4l2_cid_mpeg_video_hevc_size_of_length_field {#define V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L6_BR (V4L2_CID_MPEG_BASE + 642)#define V4L2_CID_MPEG_VIDEO_REF_NUMBER_FOR_PFRAMES (V4L2_CID_MPEG_BASE + 643)#define V4L2_CID_MPEG_VIDEO_PREPEND_SPSPPS_TO_IDR (V4L2_CID_MPEG_BASE + 644) +#define V4L2_CID_MPEG_VIDEO_FRAME_QUALITY_ENABLE (V4L2_CID_MPEG_BASE + 645) +#define V4L2_CID_MPEG_VIDEO_FRAME_QUALITY (V4L2_CID_MPEG_BASE + 646)/* MPEG-class control IDs specific to the CX2341x driver as defined by V4L2 */ #define V4L2_CID_MPEG_CX2341X_BASE (V4L2_CTRL_CLASS_MPEG | 0x1000)
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Hi,
Regarding below patch -
HEIF/HEIC image encoding uses HEVC/AVC encoders and client can set image quality level using V4L2_CID_MPEG_VIDEO_FRAME_QUALITY control.
Reference BITRATE_MODE_CQ at
https://developer.android.com/reference/android/media/MediaCodecInfo.EncoderCapabilities#BITRATE_MODE_CQ
Regards,
Maheshwar.
Quoted 96 lines · Maheshwar Ajja
When frame quality control is enabled encoder will choose the appropriate quantization parameter and bitrate to produce the client requested frame quality level. When frame quality control is disabled then frame quality is decided based on appropriate controls (i.e.
V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLEand/orV4L2_CID_MPEG_VIDEO_BITRATE_MODE)Signed-off-by Maheshwar Ajja <[email protected]>--- .../userspace-api/media/v4l/ext-ctrls-codec.rst | 16 ++++++++++++++++ drivers/media/v4l2-core/v4l2-ctrls.c | 3 +++ include/uapi/linux/v4l2-controls.h | 2 ++ 3 files changed, 21 insertions(+)Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +2
-0@@ -1081,6 +1081,22 @@ enum v4l2_mpeg_video_h264_entropy_mode - Macroblock level rate control enable. Applicable to the MPEG4 and H264 encoders. +``V4L2_CID_MPEG_VIDEO_FRAME_QUALITY_ENABLE (boolean)`` + Encoded frame quality control enable. If this control is enabledthen
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +2
-0+ the quality level of the encoded frame is set with control + ``V4L2_CID_MPEG_VIDEO_CONSTANT_QUALITY``. If this control isdisabled
+ then the quality level of encoded frame is adjusted with
appropriateDocumentation/userspace-api/media/v4l/ext-ctrls-codec.rst +7
-0+ controls (e.g. ``V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE`` or + ``V4L2_CID_MPEG_VIDEO_BITRATE_MODE``). Applicable to encoders. + +``V4L2_CID_MPEG_VIDEO_FRAME_QUALITY (integer)`` + Encoded frame quality control. If the control + ``V4L2_CID_MPEG_VIDEO_FRAME_QUALITY_ENABLE`` is enabled then the + quality of encoded frame is set with this control. Valid range is1 to
+ 100 where 1 indicates lowest quality and 100 indicates highest
quality.
+ Encoder will decide the appropriate quantization parameter and
bitrateDocumentation/userspace-api/media/v4l/ext-ctrls-codec.rst +2
-0+ to produce requested frame quality. Applicable to encoders. + ``V4L2_CID_MPEG_VIDEO_MPEG4_QPEL (boolean)`` Quarter pixel motion estimation for MPEG4. Applicable to the MPEG4 encoder.drivers/media/v4l2-core/v4l2-ctrls.c +2
-0@@ -982,6 +982,8 @@ const char *v4l2_ctrl_get_name(u32 id)case V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS :return "HEVC Slice Parameters";case V4L2_CID_MPEG_VIDEO_HEVC_DECODE_MODE :return "HEVC Decode Mode";case V4L2_CID_MPEG_VIDEO_HEVC_START_CODE :return "HEVC Start Code" ; +case V4L2_CID_MPEG_VIDEO_FRAME_QUALITY_ENABLE :return "Frame Quality Enable"; +case V4L2_CID_MPEG_VIDEO_FRAME_QUALITY :return "Frame Quality" ;drivers/media/v4l2-core/v4l2-ctrls.c +1
-0/* CAMERA controls */ /* Keep the order of the 'case's the same as in v4l2-controls.h! */ @@ -1178,6 +1180,7 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type, case V4L2_CID_FLASH_READY:case V4L2_CID_MPEG_VIDEO_DECODER_MPEG4_DEBLOCK_FILTER :case V4L2_CID_MPEG_VIDEO_DECODER_SLICE_INTERFACE : +case V4L2_CID_MPEG_VIDEO_FRAME_QUALITY_ENABLE :case V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE :case V4L2_CID_MPEG_VIDEO_MB_RC_ENABLE :drivers/media/v4l2-core/v4l2-ctrls.c +0
-0case V4L2_CID_MPEG_VIDEO_H264_8X8_TRANSFORM :include/uapi/linux/v4l2-controls.h +4
-0@@ -742,6 +742,8 @@ enum v4l2_cid_mpeg_video_hevc_size_of_length_field {#define V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L6_BR (V4L2_CID_MPEG_BASE + 642)#define V4L2_CID_MPEG_VIDEO_REF_NUMBER_FOR_PFRAMES (V4L2_CID_MPEG_BASE + 643)#define V4L2_CID_MPEG_VIDEO_PREPEND_SPSPPS_TO_IDR (V4L2_CID_MPEG_BASE + 644) +#define V4L2_CID_MPEG_VIDEO_FRAME_QUALITY_ENABLE (V4L2_CID_MPEG_BASE +645)
+#defineV4L2_CID_MPEG_VIDEO_FRAME_QUALITY(V4L2_CID_MPEG_BASE+ 646)/* MPEG-class control IDs specific to the CX2341x driver as defined
by V4L2 */
#defineV4L2_CID_MPEG_CX2341X_BASE(V4L2_CTRL_CLASS_MPEG|0x1000)
Hi Maheshwar,
Quoted 10 lines · On 18/05/2020 23:09, [email protected] wrote:
Hi,
Regarding below patch -
HEIF/HEIC image encoding uses HEVC/AVC encoders and client can set image quality level using
V4L2_CID_MPEG_VIDEO_FRAME_QUALITYcontrol.Reference
BITRATE_MODE_CQat
https://developer.android.com/reference/android/media/MediaCodecInfo.EncoderCapabilities#BITRATE_MODE_CQ
So what you are really introducing here is a new enum v4l2_mpeg_video_bitrate_mode
mode: V4L2_MPEG_VIDEO_BITRATE_MODE_CQ.
Why not just add that new mode, then add V4L2_CID_MPEG_VIDEO_CONSTANT_QUALITY which is only used if the bitrate mode is MODE_CQ.
That builds nicely on top of the already existing V4L2_CID_MPEG_VIDEO_BITRATE_MODE control.
Regards,
Hans
Quoted 102 lines
Regards,
Maheshwar.Quoted 96 lines · Maheshwar Ajja
When frame quality control is enabled encoder will choose the appropriate quantization parameter and bitrate to produce the client requested frame quality level. When frame quality control is disabled then frame quality is decided based on appropriate controls (i.e.
V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLEand/orV4L2_CID_MPEG_VIDEO_BITRATE_MODE)Signed-off-by Maheshwar Ajja <[email protected]>--- .../userspace-api/media/v4l/ext-ctrls-codec.rst | 16 ++++++++++++++++ drivers/media/v4l2-core/v4l2-ctrls.c | 3 +++ include/uapi/linux/v4l2-controls.h | 2 ++ 3 files changed, 21 insertions(+)Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +2
-0@@ -1081,6 +1081,22 @@ enum v4l2_mpeg_video_h264_entropy_mode - Macroblock level rate control enable. Applicable to the MPEG4 and H264 encoders. +``V4L2_CID_MPEG_VIDEO_FRAME_QUALITY_ENABLE (boolean)`` + Encoded frame quality control enable. If this control is enabledthen
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +2
-0+ the quality level of the encoded frame is set with control + ``V4L2_CID_MPEG_VIDEO_CONSTANT_QUALITY``. If this control isdisabled
+ then the quality level of encoded frame is adjusted with
appropriateDocumentation/userspace-api/media/v4l/ext-ctrls-codec.rst +7
-0+ controls (e.g. ``V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE`` or + ``V4L2_CID_MPEG_VIDEO_BITRATE_MODE``). Applicable to encoders. + +``V4L2_CID_MPEG_VIDEO_FRAME_QUALITY (integer)`` + Encoded frame quality control. If the control + ``V4L2_CID_MPEG_VIDEO_FRAME_QUALITY_ENABLE`` is enabled then the + quality of encoded frame is set with this control. Valid range is1 to
+ 100 where 1 indicates lowest quality and 100 indicates highest
quality.
+ Encoder will decide the appropriate quantization parameter and
bitrateDocumentation/userspace-api/media/v4l/ext-ctrls-codec.rst +2
-0+ to produce requested frame quality. Applicable to encoders. + ``V4L2_CID_MPEG_VIDEO_MPEG4_QPEL (boolean)`` Quarter pixel motion estimation for MPEG4. Applicable to the MPEG4 encoder.drivers/media/v4l2-core/v4l2-ctrls.c +2
-0@@ -982,6 +982,8 @@ const char *v4l2_ctrl_get_name(u32 id)case V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS :return "HEVC Slice Parameters";case V4L2_CID_MPEG_VIDEO_HEVC_DECODE_MODE :return "HEVC Decode Mode";case V4L2_CID_MPEG_VIDEO_HEVC_START_CODE :return "HEVC Start Code" ; +case V4L2_CID_MPEG_VIDEO_FRAME_QUALITY_ENABLE :return "Frame Quality Enable"; +case V4L2_CID_MPEG_VIDEO_FRAME_QUALITY :return "Frame Quality" ;drivers/media/v4l2-core/v4l2-ctrls.c +1
-0/* CAMERA controls */ /* Keep the order of the 'case's the same as in v4l2-controls.h! */ @@ -1178,6 +1180,7 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type, case V4L2_CID_FLASH_READY:case V4L2_CID_MPEG_VIDEO_DECODER_MPEG4_DEBLOCK_FILTER :case V4L2_CID_MPEG_VIDEO_DECODER_SLICE_INTERFACE : +case V4L2_CID_MPEG_VIDEO_FRAME_QUALITY_ENABLE :case V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE :case V4L2_CID_MPEG_VIDEO_MB_RC_ENABLE :drivers/media/v4l2-core/v4l2-ctrls.c +0
-0case V4L2_CID_MPEG_VIDEO_H264_8X8_TRANSFORM :include/uapi/linux/v4l2-controls.h +4
-0@@ -742,6 +742,8 @@ enum v4l2_cid_mpeg_video_hevc_size_of_length_field {#define V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L6_BR (V4L2_CID_MPEG_BASE + 642)#define V4L2_CID_MPEG_VIDEO_REF_NUMBER_FOR_PFRAMES (V4L2_CID_MPEG_BASE + 643)#define V4L2_CID_MPEG_VIDEO_PREPEND_SPSPPS_TO_IDR (V4L2_CID_MPEG_BASE + 644) +#define V4L2_CID_MPEG_VIDEO_FRAME_QUALITY_ENABLE (V4L2_CID_MPEG_BASE +645)
+#defineV4L2_CID_MPEG_VIDEO_FRAME_QUALITY(V4L2_CID_MPEG_BASE+ 646)/* MPEG-class control IDs specific to the CX2341x driver as defined
by V4L2 */
#defineV4L2_CID_MPEG_CX2341X_BASE(V4L2_CTRL_CLASS_MPEG|0x1000)
Hi Hans,
Thank you for the suggestion. I will update the patch accordingly.
Regards,
Maheshwar.
Quoted 143 lines · Hans Verkuil
Hi Maheshwar,
Quoted 10 lines · On 18/05/2020 23:09, [email protected] wrote:
Hi,
Regarding below patch -
HEIF/HEIC image encoding uses HEVC/AVC encoders and client can set image quality level using
V4L2_CID_MPEG_VIDEO_FRAME_QUALITYcontrol.Reference
BITRATE_MODE_CQat
https://developer.android.com/reference/android/media/MediaCodecInfo.EncoderCapabilities#BITRATE_MODE_CQSo what you are really introducing here is a new enum
v4l2_mpeg_video_bitrate_mode
mode:V4L2_MPEG_VIDEO_BITRATE_MODE_CQ.Why not just add that new mode, then add
V4L2_CID_MPEG_VIDEO_CONSTANT_QUALITYwhich is only used if the bitrate mode isMODE_CQ.That builds nicely on top of the already existing
V4L2_CID_MPEG_VIDEO_BITRATE_MODE
control.Regards,
Hans
Quoted 114 lines
Regards,
Maheshwar.Quoted 108 lines · Maheshwar Ajja
When frame quality control is enabled encoder will choose the appropriate quantization parameter and bitrate to produce the client requested frame quality level. When frame quality control is disabled then frame quality is decided based on appropriate controls (i.e.
V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLEand/orV4L2_CID_MPEG_VIDEO_BITRATE_MODE)Signed-off-by Maheshwar Ajja <[email protected]>--- .../userspace-api/media/v4l/ext-ctrls-codec.rst | 16 ++++++++++++++++ drivers/media/v4l2-core/v4l2-ctrls.c | 3 +++ include/uapi/linux/v4l2-controls.h | 2 ++ 3 files changed, 21 insertions(+)Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0
-0@@ -1081,6 +1081,22 @@ enum v4l2_mpeg_video_h264_entropy_mode - Macroblock level rate control enable. Applicable to the MPEG4and
H264 encoders.+``V4L2_CID_MPEG_VIDEO_FRAME_QUALITY_ENABLE (boolean)``
+ Encoded frame quality control enable. If this control is enabled
thenDocumentation/userspace-api/media/v4l/ext-ctrls-codec.rst +2
-0+ the quality level of the encoded frame is set with control + ``V4L2_CID_MPEG_VIDEO_CONSTANT_QUALITY``. If this control isdisabled
+ then the quality level of encoded frame is adjusted with
appropriateDocumentation/userspace-api/media/v4l/ext-ctrls-codec.rst +7
-0+ controls (e.g. ``V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE`` or + ``V4L2_CID_MPEG_VIDEO_BITRATE_MODE``). Applicable to encoders. + +``V4L2_CID_MPEG_VIDEO_FRAME_QUALITY (integer)`` + Encoded frame quality control. If the control + ``V4L2_CID_MPEG_VIDEO_FRAME_QUALITY_ENABLE`` is enabled then the + quality of encoded frame is set with this control. Valid rangeis
1 to
+ 100 where 1 indicates lowest quality and 100 indicates highest
quality.
+ Encoder will decide the appropriate quantization parameter and
bitrateDocumentation/userspace-api/media/v4l/ext-ctrls-codec.rst +2
-0+ to produce requested frame quality. Applicable to encoders. + ``V4L2_CID_MPEG_VIDEO_MPEG4_QPEL (boolean)`` Quarter pixel motion estimation for MPEG4. Applicable to theMPEG4
encoder.drivers/media/v4l2-core/v4l2-ctrls.c +1
-0@@ -982,6 +982,8 @@ const char *v4l2_ctrl_get_name(u32 id)case V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS :return "HEVC Slice Parameters";case V4L2_CID_MPEG_VIDEO_HEVC_DECODE_MODE :return "HEVC Decode Mode";case V4L2_CID_MPEG_VIDEO_HEVC_START_CODE :return "HEVC Start Code"; + case V4L2_CID_MPEG_VIDEO_FRAME_QUALITY_ENABLE: return "FrameQuality
Enable";drivers/media/v4l2-core/v4l2-ctrls.c +2
-0+case V4L2_CID_MPEG_VIDEO_FRAME_QUALITY :return "Frame Quality" ;/* CAMERA controls */ /* Keep the order of the 'case's the same as in v4l2-controls.h! */ @@ -1178,6 +1180,7 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type, case V4L2_CID_FLASH_READY:case V4L2_CID_MPEG_VIDEO_DECODER_MPEG4_DEBLOCK_FILTER :case V4L2_CID_MPEG_VIDEO_DECODER_SLICE_INTERFACE : +case V4L2_CID_MPEG_VIDEO_FRAME_QUALITY_ENABLE :case V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE :case V4L2_CID_MPEG_VIDEO_MB_RC_ENABLE :drivers/media/v4l2-core/v4l2-ctrls.c +0
-0case V4L2_CID_MPEG_VIDEO_H264_8X8_TRANSFORM :include/uapi/linux/v4l2-controls.h +0
-0@@ -742,6 +742,8 @@ enum
v4l2_cid_mpeg_video_hevc_size_of_length_field
{
#defineV4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L6_BR(V4L2_CID_MPEG_BASE
+ 642)
#defineV4L2_CID_MPEG_VIDEO_REF_NUMBER_FOR_PFRAMES(V4L2_CID_MPEG_BASE
+ 643)
#defineV4L2_CID_MPEG_VIDEO_PREPEND_SPSPPS_TO_IDR(V4L2_CID_MPEG_BASE
+ 644)include/uapi/linux/v4l2-controls.h +2
-0+#define V4L2_CID_MPEG_VIDEO_FRAME_QUALITY_ENABLE (V4L2_CID_MPEG_BASE +645)
+#defineV4L2_CID_MPEG_VIDEO_FRAME_QUALITY(V4L2_CID_MPEG_BASE+
646)/* MPEG-class control IDs specific to the CX2341x driver as defined
by V4L2 */
#defineV4L2_CID_MPEG_CX2341X_BASE(V4L2_CTRL_CLASS_MPEG|0x1000)
PATCH 1/1 media: v4l2-ctrls: Add encoder constant quality control
In reply to Maheshwar AjjaWhen V4L2_CID_MPEG_VIDEO_BITRATE_MODE value is V4L2_MPEG_VIDEO_BITRATE_MODE_CQ, encoder will produce constant quality output indicated by V4L2_CID_MPEG_VIDEO_CONSTANT_QUALITY control value. Encoder will choose appropriate quantization parameter and bitrate to produce requested frame quality level.
--- Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst | 10 ++++++++++ drivers/media/v4l2-core/v4l2-ctrls.c | 2 ++ include/uapi/linux/v4l2-controls.h | 2 ++ 3 files changed, 14 insertions(+)
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +10 -0
@@ -581,6 +581,8 @@ enum v4l2_mpeg_video_bitrate_mode - - Variable bitrate * - ``V4L2_MPEG_VIDEO_BITRATE_MODE_CBR`` - Constant bitrate + * - ``V4L2_MPEG_VIDEO_BITRATE_MODE_CQ`` + - Constant quality
@@ -592,6 +594,14 @@ enum v4l2_mpeg_video_bitrate_mode - the average video bitrate. It is ignored if the video bitrate mode is set to constant bitrate. +``V4L2_CID_MPEG_VIDEO_CONSTANT_QUALITY (integer)`` + Constant quality level control. This control is applicable when + ``V4L2_CID_MPEG_VIDEO_BITRATE_MODE`` value is + ``V4L2_MPEG_VIDEO_BITRATE_MODE_CQ``. Valid range is 1 to 100 + where 1 indicates lowest quality and 100 indicates highest quality. + Encoder will decide the appropriate quantization parameter and + bitrate to produce requested frame quality. + ``V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION (integer)`` For every captured frame, skip this many subsequent frames (default 0).
drivers/media/v4l2-core/v4l2-ctrls.c +2 -0
@@ -199,6 +199,7 @@ const char * const *v4l2_ctrl_get_menu(u32 id)static const char *const mpeg_video_bitrate_mode[] = {"Variable Bitrate" ,"Constant Bitrate" , +"Constant Quality" ,NULL };static const char *const mpeg_stream_type[] = {
@@ -982,6 +983,7 @@ const char *v4l2_ctrl_get_name(u32 id)case V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS :return "HEVC Slice Parameters" ;case V4L2_CID_MPEG_VIDEO_HEVC_DECODE_MODE :return "HEVC Decode Mode" ;case V4L2_CID_MPEG_VIDEO_HEVC_START_CODE :return "HEVC Start Code" ; +case V4L2_CID_MPEG_VIDEO_CONSTANT_QUALITY :return "Constant Quality" ;/* CAMERA controls */ /* Keep the order of the 'case's the same as in v4l2-controls.h! */
include/uapi/linux/v4l2-controls.h +2 -0
@@ -375,6 +375,7 @@ enum v4l2_mpeg_video_aspect {enum v4l2_mpeg_video_bitrate_mode {V4L2_MPEG_VIDEO_BITRATE_MODE_VBR =0 ,V4L2_MPEG_VIDEO_BITRATE_MODE_CBR =1 , +V4L2_MPEG_VIDEO_BITRATE_MODE_CQ =2 , };#define V4L2_CID_MPEG_VIDEO_BITRATE (V4L2_CID_MPEG_BASE+207)#define V4L2_CID_MPEG_VIDEO_BITRATE_PEAK (V4L2_CID_MPEG_BASE+208)
@@ -742,6 +743,7 @@ enum v4l2_cid_mpeg_video_hevc_size_of_length_field {#define V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L6_BR (V4L2_CID_MPEG_BASE + 642)#define V4L2_CID_MPEG_VIDEO_REF_NUMBER_FOR_PFRAMES (V4L2_CID_MPEG_BASE + 643)#define V4L2_CID_MPEG_VIDEO_PREPEND_SPSPPS_TO_IDR (V4L2_CID_MPEG_BASE + 644) +#define V4L2_CID_MPEG_VIDEO_CONSTANT_QUALITY (V4L2_CID_MPEG_BASE + 645)/* MPEG-class control IDs specific to the CX2341x driver as defined by V4L2 */ #define V4L2_CID_MPEG_CX2341X_BASE (V4L2_CTRL_CLASS_MPEG | 0x1000)
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [PATCH] media: v4l2-ctrls: Add encoder constant quality control
Quoted 55 lines · Maheshwar Ajja
When
V4L2_CID_MPEG_VIDEO_BITRATE_MODEvalue isV4L2_MPEG_VIDEO_BITRATE_MODE_CQ, encoder will produce constant quality output indicated byV4L2_CID_MPEG_VIDEO_CONSTANT_QUALITYcontrol value. Encoder will choose appropriate quantization parameter and bitrate to produce requested frame quality level.Signed-off-by Maheshwar Ajja <[email protected]>--- Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst | 10 ++++++++++ drivers/media/v4l2-core/v4l2-ctrls.c | 2 ++ include/uapi/linux/v4l2-controls.h | 2 ++ 3 files changed, 14 insertions(+)Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +10
-0@@ -581,6 +581,8 @@ enum v4l2_mpeg_video_bitrate_mode - - Variable bitrate * - ``V4L2_MPEG_VIDEO_BITRATE_MODE_CBR`` - Constant bitrate + * - ``V4L2_MPEG_VIDEO_BITRATE_MODE_CQ`` + - Constant quality@@ -592,6 +594,14 @@ enum v4l2_mpeg_video_bitrate_mode - the average video bitrate. It is ignored if the video bitrate mode is set to constant bitrate. +``V4L2_CID_MPEG_VIDEO_CONSTANT_QUALITY (integer)`` + Constant quality level control. This control is applicable when + ``V4L2_CID_MPEG_VIDEO_BITRATE_MODE`` value is + ``V4L2_MPEG_VIDEO_BITRATE_MODE_CQ``. Valid range is 1 to 100 + where 1 indicates lowest quality and 100 indicates highest quality. + Encoder will decide the appropriate quantization parameter and + bitrate to produce requested frame quality. + ``V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION (integer)`` For every captured frame, skip this many subsequent frames (default 0).drivers/media/v4l2-core/v4l2-ctrls.c +1
-0@@ -199,6 +199,7 @@ const char * const *v4l2_ctrl_get_menu(u32 id)static const char *const mpeg_video_bitrate_mode[] = {"Variable Bitrate" ,"Constant Bitrate" , +"Constant Quality" ,NULL };static const char *const mpeg_stream_type[] = {
drivers/media/v4l2-core/v4l2-ctrls.c const char *v4l2_ctrl_get_name(u32 id) · line 986
Quoted 4 lines
drivers/media/v4l2-core/v4l2-ctrls.c +1
-0@@ -982,6 +983,7 @@ const char *v4l2_ctrl_get_name(u32 id)case V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS :return "HEVC Slice Parameters" ;case V4L2_CID_MPEG_VIDEO_HEVC_DECODE_MODE :return "HEVC Decode Mode" ;case V4L2_CID_MPEG_VIDEO_HEVC_START_CODE :return "HEVC Start Code" ; +case V4L2_CID_MPEG_VIDEO_CONSTANT_QUALITY :return "Constant Quality" ;
Add this to the codec controls that are earlier in this function (around line 925).
It's not HEVC specific, it can be used by any codec with constant quality support, so it looks odd making this part of the HEVC controls.
Other than that, this looks good. Before it can be accepted we do need a driver that supports this feature, so a second patch is needed that adds this to a driver (I'm guessing that that will be the venus driver).
Regards,
Hans
Quoted 24 lines
drivers/media/v4l2-core/v4l2-ctrls.c +0
-0/* CAMERA controls */ /* Keep the order of the 'case's the same as in v4l2-controls.h! */ include/uapi/linux/v4l2-controls.h +2
-0@@ -375,6 +375,7 @@ enum v4l2_mpeg_video_aspect {enum v4l2_mpeg_video_bitrate_mode {V4L2_MPEG_VIDEO_BITRATE_MODE_VBR =0 ,V4L2_MPEG_VIDEO_BITRATE_MODE_CBR =1 , +V4L2_MPEG_VIDEO_BITRATE_MODE_CQ =2 , };#define V4L2_CID_MPEG_VIDEO_BITRATE (V4L2_CID_MPEG_BASE+207)#define V4L2_CID_MPEG_VIDEO_BITRATE_PEAK (V4L2_CID_MPEG_BASE+208)@@ -742,6 +743,7 @@ enum v4l2_cid_mpeg_video_hevc_size_of_length_field {#define V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L6_BR (V4L2_CID_MPEG_BASE + 642)#define V4L2_CID_MPEG_VIDEO_REF_NUMBER_FOR_PFRAMES (V4L2_CID_MPEG_BASE + 643)#define V4L2_CID_MPEG_VIDEO_PREPEND_SPSPPS_TO_IDR (V4L2_CID_MPEG_BASE + 644) +#define V4L2_CID_MPEG_VIDEO_CONSTANT_QUALITY (V4L2_CID_MPEG_BASE + 645)/* MPEG-class control IDs specific to the CX2341x driver as defined by V4L2 */ #define V4L2_CID_MPEG_CX2341X_BASE (V4L2_CTRL_CLASS_MPEG | 0x1000)