msdkenc{h264,h265}: add min-qp and max-qp properties

The SDK allows user to set a QP range [1], so add min-qp and max-qp to
sepecify QP range. By default, there is no limitations on QP.

[1] https://github.com/Intel-Media-SDK/MediaSDK/blob/master/doc/mediasdk-man.md#mfxextcodingoption2

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1908>
This commit is contained in:
Haihao Xiang 2020-12-23 16:11:42 +08:00
parent 7bc3d51b42
commit 1f1a5b4ad1
4 changed files with 77 additions and 0 deletions

View file

@ -55,6 +55,8 @@ enum
PROP_B_PYRAMID, PROP_B_PYRAMID,
PROP_TUNE_MODE, PROP_TUNE_MODE,
PROP_P_PYRAMID, PROP_P_PYRAMID,
PROP_MIN_QP,
PROP_MAX_QP,
}; };
enum enum
@ -72,6 +74,8 @@ enum
#define PROP_B_PYRAMID_DEFAULT FALSE #define PROP_B_PYRAMID_DEFAULT FALSE
#define PROP_TUNE_MODE_DEFAULT MFX_CODINGOPTION_UNKNOWN #define PROP_TUNE_MODE_DEFAULT MFX_CODINGOPTION_UNKNOWN
#define PROP_P_PYRAMID_DEFAULT FALSE #define PROP_P_PYRAMID_DEFAULT FALSE
#define PROP_MIN_QP_DEFAULT 0
#define PROP_MAX_QP_DEFAULT 0
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC, GST_PAD_SRC,
@ -378,6 +382,11 @@ gst_msdkh264enc_configure (GstMsdkEnc * encoder)
encoder->option2.Trellis = thiz->trellis ? thiz->trellis : MFX_TRELLIS_OFF; encoder->option2.Trellis = thiz->trellis ? thiz->trellis : MFX_TRELLIS_OFF;
encoder->option2.MaxSliceSize = thiz->max_slice_size; encoder->option2.MaxSliceSize = thiz->max_slice_size;
encoder->option2.MinQPI = encoder->option2.MinQPP = encoder->option2.MinQPB =
thiz->min_qp;
encoder->option2.MaxQPI = encoder->option2.MaxQPP = encoder->option2.MaxQPB =
thiz->max_qp;
if (encoder->rate_control == MFX_RATECONTROL_LA || if (encoder->rate_control == MFX_RATECONTROL_LA ||
encoder->rate_control == MFX_RATECONTROL_LA_HRD || encoder->rate_control == MFX_RATECONTROL_LA_HRD ||
encoder->rate_control == MFX_RATECONTROL_LA_ICQ) encoder->rate_control == MFX_RATECONTROL_LA_ICQ)
@ -571,6 +580,12 @@ gst_msdkh264enc_set_property (GObject * object, guint prop_id,
case PROP_P_PYRAMID: case PROP_P_PYRAMID:
thiz->p_pyramid = g_value_get_boolean (value); thiz->p_pyramid = g_value_get_boolean (value);
break; break;
case PROP_MIN_QP:
thiz->min_qp = g_value_get_uint (value);
break;
case PROP_MAX_QP:
thiz->max_qp = g_value_get_uint (value);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@ -619,6 +634,12 @@ gst_msdkh264enc_get_property (GObject * object, guint prop_id, GValue * value,
case PROP_P_PYRAMID: case PROP_P_PYRAMID:
g_value_set_boolean (value, thiz->p_pyramid); g_value_set_boolean (value, thiz->p_pyramid);
break; break;
case PROP_MIN_QP:
g_value_set_uint (value, thiz->min_qp);
break;
case PROP_MAX_QP:
g_value_set_uint (value, thiz->max_qp);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@ -725,6 +746,18 @@ gst_msdkh264enc_class_init (GstMsdkH264EncClass * klass)
"Enable P-Pyramid Reference structure", FALSE, "Enable P-Pyramid Reference structure", FALSE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_MIN_QP,
g_param_spec_uint ("min-qp", "Min QP",
"Minimal quantizer for I/P/B frames",
0, 51, PROP_MIN_QP_DEFAULT,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_MAX_QP,
g_param_spec_uint ("max-qp", "Max QP",
"Maximum quantizer for I/P/B frames",
0, 51, PROP_MAX_QP_DEFAULT,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
gst_element_class_set_static_metadata (element_class, gst_element_class_set_static_metadata (element_class,
"Intel MSDK H264 encoder", "Codec/Encoder/Video/Hardware", "Intel MSDK H264 encoder", "Codec/Encoder/Video/Hardware",
"H264 video encoder based on Intel Media SDK", "H264 video encoder based on Intel Media SDK",
@ -744,4 +777,6 @@ gst_msdkh264enc_init (GstMsdkH264Enc * thiz)
thiz->b_pyramid = PROP_B_PYRAMID_DEFAULT; thiz->b_pyramid = PROP_B_PYRAMID_DEFAULT;
thiz->tune_mode = PROP_TUNE_MODE_DEFAULT; thiz->tune_mode = PROP_TUNE_MODE_DEFAULT;
thiz->p_pyramid = PROP_P_PYRAMID_DEFAULT; thiz->p_pyramid = PROP_P_PYRAMID_DEFAULT;
thiz->min_qp = PROP_MIN_QP_DEFAULT;
thiz->max_qp = PROP_MAX_QP_DEFAULT;
} }

View file

@ -72,6 +72,8 @@ struct _GstMsdkH264Enc
gint tune_mode; gint tune_mode;
guint prop_flag; guint prop_flag;
guint p_pyramid; guint p_pyramid;
guint min_qp;
guint max_qp;
GstH264NalParser *parser; GstH264NalParser *parser;
GArray *cc_sei_array; GArray *cc_sei_array;

View file

@ -54,6 +54,8 @@ enum
PROP_TRANSFORM_SKIP, PROP_TRANSFORM_SKIP,
PROP_B_PYRAMID, PROP_B_PYRAMID,
PROP_P_PYRAMID, PROP_P_PYRAMID,
PROP_MIN_QP,
PROP_MAX_QP,
}; };
enum enum
@ -70,6 +72,8 @@ enum
#define PROP_TRANSFORM_SKIP_DEFAULT MFX_CODINGOPTION_UNKNOWN #define PROP_TRANSFORM_SKIP_DEFAULT MFX_CODINGOPTION_UNKNOWN
#define PROP_B_PYRAMID_DEFAULT FALSE #define PROP_B_PYRAMID_DEFAULT FALSE
#define PROP_P_PYRAMID_DEFAULT FALSE #define PROP_P_PYRAMID_DEFAULT FALSE
#define PROP_MIN_QP_DEFAULT 0
#define PROP_MAX_QP_DEFAULT 0
#define RAW_FORMATS "NV12, I420, YV12, YUY2, UYVY, BGRA, P010_10LE, VUYA" #define RAW_FORMATS "NV12, I420, YV12, YUY2, UYVY, BGRA, P010_10LE, VUYA"
#define PROFILES "main, main-10, main-444" #define PROFILES "main, main-10, main-444"
@ -343,6 +347,10 @@ gst_msdkh265enc_configure (GstMsdkEnc * encoder)
/* Enable Extended coding options */ /* Enable Extended coding options */
encoder->option2.MaxSliceSize = h265enc->max_slice_size; encoder->option2.MaxSliceSize = h265enc->max_slice_size;
encoder->option2.MinQPI = encoder->option2.MinQPP = encoder->option2.MinQPB =
h265enc->min_qp;
encoder->option2.MaxQPI = encoder->option2.MaxQPP = encoder->option2.MaxQPB =
h265enc->max_qp;
#if (MFX_VERSION >= 1026) #if (MFX_VERSION >= 1026)
if (h265enc->transform_skip != MFX_CODINGOPTION_UNKNOWN) { if (h265enc->transform_skip != MFX_CODINGOPTION_UNKNOWN) {
@ -558,6 +566,14 @@ gst_msdkh265enc_set_property (GObject * object, guint prop_id,
thiz->p_pyramid = g_value_get_boolean (value); thiz->p_pyramid = g_value_get_boolean (value);
break; break;
case PROP_MIN_QP:
thiz->min_qp = g_value_get_uint (value);
break;
case PROP_MAX_QP:
thiz->max_qp = g_value_get_uint (value);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@ -610,6 +626,14 @@ gst_msdkh265enc_get_property (GObject * object, guint prop_id, GValue * value,
g_value_set_boolean (value, thiz->p_pyramid); g_value_set_boolean (value, thiz->p_pyramid);
break; break;
case PROP_MIN_QP:
g_value_set_uint (value, thiz->min_qp);
break;
case PROP_MAX_QP:
g_value_set_uint (value, thiz->max_qp);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@ -745,6 +769,18 @@ gst_msdkh265enc_class_init (GstMsdkH265EncClass * klass)
"Enable P-Pyramid Reference structure", FALSE, "Enable P-Pyramid Reference structure", FALSE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_MIN_QP,
g_param_spec_uint ("min-qp", "Min QP",
"Minimal quantizer for I/P/B frames",
0, 51, PROP_MIN_QP_DEFAULT,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_MAX_QP,
g_param_spec_uint ("max-qp", "Max QP",
"Maximum quantizer for I/P/B frames",
0, 51, PROP_MAX_QP_DEFAULT,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
gst_element_class_set_static_metadata (element_class, gst_element_class_set_static_metadata (element_class,
"Intel MSDK H265 encoder", "Intel MSDK H265 encoder",
"Codec/Encoder/Video/Hardware", "Codec/Encoder/Video/Hardware",
@ -767,5 +803,7 @@ gst_msdkh265enc_init (GstMsdkH265Enc * thiz)
thiz->transform_skip = PROP_TRANSFORM_SKIP_DEFAULT; thiz->transform_skip = PROP_TRANSFORM_SKIP_DEFAULT;
thiz->b_pyramid = PROP_B_PYRAMID_DEFAULT; thiz->b_pyramid = PROP_B_PYRAMID_DEFAULT;
thiz->p_pyramid = PROP_P_PYRAMID_DEFAULT; thiz->p_pyramid = PROP_P_PYRAMID_DEFAULT;
thiz->min_qp = PROP_MIN_QP_DEFAULT;
thiz->max_qp = PROP_MAX_QP_DEFAULT;
msdk_enc->num_extra_frames = 1; msdk_enc->num_extra_frames = 1;
} }

View file

@ -65,6 +65,8 @@ struct _GstMsdkH265Enc
gushort transform_skip; gushort transform_skip;
guint b_pyramid; guint b_pyramid;
guint p_pyramid; guint p_pyramid;
guint min_qp;
guint max_qp;
mfxExtHEVCTiles ext_tiles; mfxExtHEVCTiles ext_tiles;
/* roi[0] for current ROI and roi[1] for previous ROI */ /* roi[0] for current ROI and roi[1] for previous ROI */