libs: encoder: h264,h265,mpeg2,vp8: refactor HDR

Move the Hypothetical Reference Decoder (HRD) parameter, from
ensure_misc_params() to ensure_control_rate_params(), since it
only shall be defined when the control rate is either VBR or CBR.

https://bugzilla.gnome.org/show_bug.cgi?id=783449
This commit is contained in:
Víctor Manuel Jáquez Leal 2017-06-02 19:33:36 +02:00
parent b538a86d4e
commit fc5106bd31
4 changed files with 72 additions and 53 deletions

View file

@ -2182,6 +2182,18 @@ ensure_control_rate_params (GstVaapiEncoderH264 * encoder,
gst_vaapi_enc_picture_add_misc_param (picture, misc);
gst_vaapi_codec_object_replace (&misc, NULL);
/* HRD params */
misc = GST_VAAPI_ENC_MISC_PARAM_NEW (HRD, encoder);
if (!misc)
return FALSE;
{
fill_hrd_params (encoder, misc->data);
}
gst_vaapi_enc_picture_add_misc_param (picture, misc);
gst_vaapi_codec_object_replace (&misc, NULL);
return TRUE;
}
@ -2193,14 +2205,6 @@ ensure_misc_params (GstVaapiEncoderH264 * encoder, GstVaapiEncPicture * picture)
GstVaapiEncMiscParam *misc;
guint num_roi;
/* HRD params */
misc = GST_VAAPI_ENC_MISC_PARAM_NEW (HRD, encoder);
if (!misc)
return FALSE;
fill_hrd_params (encoder, misc->data);
gst_vaapi_enc_picture_add_misc_param (picture, misc);
gst_vaapi_codec_object_replace (&misc, NULL);
if (!ensure_control_rate_params (encoder, picture))
return FALSE;

View file

@ -1766,21 +1766,37 @@ error_create_packed_seq_hdr:
}
static gboolean
ensure_misc_params (GstVaapiEncoderH265 * encoder, GstVaapiEncPicture * picture)
ensure_control_rate_params (GstVaapiEncoderH265 * encoder,
GstVaapiEncPicture * picture)
{
GstVaapiEncoder *const base_encoder = GST_VAAPI_ENCODER_CAST (encoder);
GstVaapiEncMiscParam *misc = NULL;
GstVaapiEncMiscParam *misc;
/* HRD params for rate control */
if (GST_VAAPI_ENCODER_RATE_CONTROL (encoder) == GST_VAAPI_RATECONTROL_CBR) {
if (GST_VAAPI_ENCODER_RATE_CONTROL (encoder) == GST_VAAPI_RATECONTROL_CQP)
return TRUE;
/* HRD params */
misc = GST_VAAPI_ENC_MISC_PARAM_NEW (HRD, encoder);
if (!misc)
return FALSE;
{
fill_hrd_params (encoder, misc->data);
gst_vaapi_enc_picture_add_misc_param (picture, misc);
gst_vaapi_codec_object_replace (&misc, NULL);
}
gst_vaapi_enc_picture_add_misc_param (picture, misc);
gst_vaapi_codec_object_replace (&misc, NULL);
return TRUE;
}
static gboolean
ensure_misc_params (GstVaapiEncoderH265 * encoder, GstVaapiEncPicture * picture)
{
GstVaapiEncoder *const base_encoder = GST_VAAPI_ENCODER_CAST (encoder);
if (!ensure_control_rate_params (encoder, picture))
return FALSE;
if (!gst_vaapi_encoder_ensure_param_quality_level (base_encoder, picture))
return FALSE;
return TRUE;

View file

@ -480,6 +480,22 @@ ensure_control_rate_params (GstVaapiEncoderMpeg2 * encoder,
gst_vaapi_enc_picture_add_misc_param (picture, misc);
gst_vaapi_codec_object_replace (&misc, NULL);
/* HRD params */
misc = GST_VAAPI_ENC_MISC_PARAM_NEW (HRD, encoder);
if (!misc)
return FALSE;
{
VAEncMiscParameterHRD hrd = {
.buffer_size = base_encoder->bitrate * 1000 * 8,
.initial_buffer_fullness = base_encoder->bitrate * 1000 * 4,
};
memcpy (misc->data, &hrd, sizeof (hrd));
}
gst_vaapi_enc_picture_add_misc_param (picture, misc);
gst_vaapi_codec_object_replace (&misc, NULL);
return TRUE;
}
@ -488,23 +504,6 @@ set_misc_parameters (GstVaapiEncoderMpeg2 * encoder,
GstVaapiEncPicture * picture)
{
GstVaapiEncoder *const base_encoder = GST_VAAPI_ENCODER_CAST (encoder);
GstVaapiEncMiscParam *misc = NULL;
VAEncMiscParameterHRD *hrd;
/* add hrd */
misc = GST_VAAPI_ENC_MISC_PARAM_NEW (HRD, encoder);
if (!misc)
return FALSE;
gst_vaapi_enc_picture_add_misc_param (picture, misc);
hrd = misc->data;
if (base_encoder->bitrate > 0) {
hrd->initial_buffer_fullness = base_encoder->bitrate * 1000 * 4;
hrd->buffer_size = base_encoder->bitrate * 1000 * 8;
} else {
hrd->initial_buffer_fullness = 0;
hrd->buffer_size = 0;
}
gst_vaapi_codec_object_replace (&misc, NULL);
if (!ensure_control_rate_params (encoder, picture))
return FALSE;

View file

@ -289,6 +289,23 @@ ensure_control_rate_params (GstVaapiEncoderVP8 * encoder,
gst_vaapi_enc_picture_add_misc_param (picture, misc);
gst_vaapi_codec_object_replace (&misc, NULL);
/* HRD params */
misc = GST_VAAPI_ENC_MISC_PARAM_NEW (HRD, encoder);
if (!misc)
return FALSE;
{
VAEncMiscParameterHRD hrd = {
.buffer_size = base_encoder->bitrate * 1000 * 2,
.initial_buffer_fullness = base_encoder->bitrate * 1000,
};
memcpy (misc->data, &hrd, sizeof (hrd));
}
gst_vaapi_enc_picture_add_misc_param (picture, misc);
gst_vaapi_codec_object_replace (&misc, NULL);
return TRUE;
}
@ -318,23 +335,6 @@ ensure_misc_params (GstVaapiEncoderVP8 * encoder, GstVaapiEncPicture * picture)
gst_vaapi_enc_picture_add_misc_param (picture, misc);
gst_vaapi_codec_object_replace (&misc, NULL);
misc = GST_VAAPI_ENC_MISC_PARAM_NEW (HRD, encoder);
if (!misc)
return FALSE;
{
VAEncMiscParameterHRD *hrd = misc->data;
if (base_encoder->bitrate > 0) {
hrd->buffer_size = base_encoder->bitrate * 1000 * 2;
hrd->initial_buffer_fullness = base_encoder->bitrate * 1000;
} else {
hrd->buffer_size = 0;
hrd->initial_buffer_fullness = 0;
}
}
gst_vaapi_enc_picture_add_misc_param (picture, misc);
gst_vaapi_codec_object_replace (&misc, NULL);
return TRUE;
}