msdk: Add more tuning options

Added tuning options for mb level bitrate control,
adaptive I-frame insertion, and adaptive B-frame insertion.

https://bugzilla.gnome.org/show_bug.cgi?id=791637
This commit is contained in:
Sreerenj Balachandran 2018-02-15 17:29:13 +00:00
parent f25bcf7cb8
commit 07c05a75a5
5 changed files with 99 additions and 17 deletions

View file

@ -100,6 +100,9 @@ static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
#define PROP_RC_LOOKAHEAD_DEPTH_DEFAULT 10
#define PROP_MAX_VBV_BITRATE_DEFAULT 0
#define PROP_MAX_FRAME_SIZE_DEFAULT 0
#define PROP_MBBRC_DEFAULT MFX_CODINGOPTION_OFF
#define PROP_ADAPTIVE_I_DEFAULT MFX_CODINGOPTION_OFF
#define PROP_ADAPTIVE_B_DEFAULT MFX_CODINGOPTION_OFF
#define gst_msdkenc_parent_class parent_class
G_DEFINE_TYPE (GstMsdkEnc, gst_msdkenc, GST_TYPE_VIDEO_ENCODER);
@ -155,7 +158,6 @@ ensure_bitrate_control (GstMsdkEnc * thiz)
case MFX_RATECONTROL_LA_ICQ:
option2->LookAheadDepth = thiz->lookahead_depth;
thiz->enable_extopt2 = TRUE;
case MFX_RATECONTROL_ICQ:
mfx->ICQQuality = CLAMP (thiz->qpi, 1, 51);
break;
@ -163,7 +165,6 @@ ensure_bitrate_control (GstMsdkEnc * thiz)
case MFX_RATECONTROL_LA: /* VBR with LA. Only supported in H264?? */
case MFX_RATECONTROL_LA_HRD: /* VBR with LA, HRD compliant */
option2->LookAheadDepth = thiz->lookahead_depth;
thiz->enable_extopt2 = TRUE;
break;
case MFX_RATECONTROL_QVBR:
@ -177,7 +178,6 @@ ensure_bitrate_control (GstMsdkEnc * thiz)
case MFX_RATECONTROL_VBR:
option2->MaxFrameSize = thiz->max_frame_size * 1000;
thiz->enable_extopt2 = TRUE;
break;
case MFX_RATECONTROL_VCM:
@ -194,6 +194,30 @@ ensure_bitrate_control (GstMsdkEnc * thiz)
}
}
static void
ensure_extended_coding_options (GstMsdkEnc * thiz)
{
mfxExtCodingOption2 *option2 = &thiz->option2;
mfxExtCodingOption3 *option3 = &thiz->option3;
/* Fill ExtendedCodingOption2, set non-zero defaults too */
option2->Header.BufferId = MFX_EXTBUFF_CODING_OPTION2;
option2->Header.BufferSz = sizeof (thiz->option2);
option2->MBBRC = thiz->mbbrc;
option2->AdaptiveI = thiz->adaptive_i;
option2->AdaptiveB = thiz->adaptive_b;
option2->BitrateLimit = MFX_CODINGOPTION_OFF;
option2->EnableMAD = MFX_CODINGOPTION_OFF;
option2->UseRawRef = MFX_CODINGOPTION_OFF;
gst_msdkenc_add_extra_param (thiz, (mfxExtBuffer *) option2);
if (thiz->enable_extopt3) {
option3->Header.BufferId = MFX_EXTBUFF_CODING_OPTION3;
option3->Header.BufferSz = sizeof (thiz->option3);
gst_msdkenc_add_extra_param (thiz, (mfxExtBuffer *) option3);
}
}
static gboolean
gst_msdkenc_init_encoder (GstMsdkEnc * thiz)
{
@ -356,23 +380,15 @@ gst_msdkenc_init_encoder (GstMsdkEnc * thiz)
/* ensure bitrate control parameters */
ensure_bitrate_control (thiz);
/* Enable ExtCodingOption2 */
ensure_extended_coding_options (thiz);
/* allow subclass configure further */
if (klass->configure) {
if (!klass->configure (thiz))
goto failed;
}
if (thiz->enable_extopt2) {
thiz->option2.Header.BufferId = MFX_EXTBUFF_CODING_OPTION2;
thiz->option2.Header.BufferSz = sizeof (thiz->option2);
gst_msdkenc_add_extra_param (thiz, (mfxExtBuffer *) & thiz->option2);
}
if (thiz->enable_extopt3) {
thiz->option3.Header.BufferId = MFX_EXTBUFF_CODING_OPTION3;
thiz->option3.Header.BufferSz = sizeof (thiz->option3);
gst_msdkenc_add_extra_param (thiz, (mfxExtBuffer *) & thiz->option3);
}
if (thiz->num_extra_params) {
thiz->param.NumExtParam = thiz->num_extra_params;
thiz->param.ExtParam = thiz->extra_params;
@ -1361,8 +1377,10 @@ gst_msdkenc_init (GstMsdkEnc * thiz)
thiz->i_frames = PROP_I_FRAMES_DEFAULT;
thiz->b_frames = PROP_B_FRAMES_DEFAULT;
thiz->num_slices = PROP_NUM_SLICES_DEFAULT;
thiz->mbbrc = PROP_MBBRC_DEFAULT;
thiz->adaptive_i = PROP_ADAPTIVE_I_DEFAULT;
thiz->adaptive_b = PROP_ADAPTIVE_B_DEFAULT;
thiz->enable_extopt2 = FALSE;
thiz->enable_extopt3 = FALSE;
memset (&thiz->option2, 0, sizeof (thiz->option2));
memset (&thiz->option2, 0, sizeof (thiz->option3));

View file

@ -117,7 +117,6 @@ struct _GstMsdkEnc
/* Additional encoder coding options */
mfxExtCodingOption2 option2;
gboolean enable_extopt2;
mfxExtCodingOption3 option3;
gboolean enable_extopt3;
@ -147,6 +146,9 @@ struct _GstMsdkEnc
guint i_frames;
guint b_frames;
guint num_slices;
gint16 mbbrc;
gint16 adaptive_i;
gint16 adaptive_b;
gboolean reconfig;
};

View file

@ -287,7 +287,6 @@ gst_msdkh264enc_configure (GstMsdkEnc * encoder)
gst_msdkenc_add_extra_param (encoder, (mfxExtBuffer *) & thiz->option);
encoder->enable_extopt2 = TRUE;
encoder->option2.Trellis = thiz->trellis ? thiz->trellis : MFX_TRELLIS_OFF;
encoder->option2.MaxSliceSize = thiz->max_slice_size;
if (encoder->rate_control == MFX_RATECONTROL_LA ||

View file

@ -100,3 +100,57 @@ gst_msdkenc_rc_lookahead_ds_get_type (void)
}
return type;
}
GType
gst_msdkenc_mbbrc_get_type (void)
{
static GType type = 0;
static const GEnumValue values[] = {
{MFX_CODINGOPTION_UNKNOWN, "SDK desides what to do", "auto"},
{MFX_CODINGOPTION_OFF, "Disable Macroblock level bit rate control", "off"},
{MFX_CODINGOPTION_ON, "Enable Macroblock level bit rate control ", "on"},
{0, NULL, NULL}
};
if (!type) {
type = g_enum_register_static ("GstMsdkEncMbBitrateControl", values);
}
return type;
}
GType
gst_msdkenc_adaptive_i_get_type (void)
{
static GType type = 0;
static const GEnumValue values[] = {
{MFX_CODINGOPTION_UNKNOWN, "SDK desides what to do", "auto"},
{MFX_CODINGOPTION_OFF, "Disable Adaptive I frame insertion ", "off"},
{MFX_CODINGOPTION_ON, "Enable Aaptive I frame insertion ", "on"},
{0, NULL, NULL}
};
if (!type) {
type = g_enum_register_static ("GstMsdkEncAdaptiveI", values);
}
return type;
}
GType
gst_msdkenc_adaptive_b_get_type (void)
{
static GType type = 0;
static const GEnumValue values[] = {
{MFX_CODINGOPTION_UNKNOWN, "SDK desides what to do", "auto"},
{MFX_CODINGOPTION_OFF, "Disable Adaptive B-Frame insertion ", "off"},
{MFX_CODINGOPTION_ON, "Enable Aaptive B-Frame insertion ", "on"},
{0, NULL, NULL}
};
if (!type) {
type = g_enum_register_static ("GstMsdkEncAdaptiveB", values);
}
return type;
}

View file

@ -49,5 +49,14 @@ gst_msdkenc_trellis_quantization_get_type (void);
GType
gst_msdkenc_rc_lookahead_ds_get_type (void);
GType
gst_msdkenc_mbbrc_get_type (void);
GType
gst_msdkenc_adaptive_i_get_type (void);
GType
gst_msdkenc_adaptive_b_get_type (void);
G_END_DECLS
#endif