libs: encoder: vp8,h264,h265,mpeg2: refactor misc parameters

This is patch pretends to decouple the assignation of the values
in the parameter structures and the VA buffer's parameters setting.

It may lead to some issues since HRD, framerate or controlrate may
not be handled by the specific encoder, but they are set in
the VA buffer's parameters.

I leave as it because this patch is just a transitional patch.

https://bugzilla.gnome.org/show_bug.cgi?id=783449
This commit is contained in:
Víctor Manuel Jáquez Leal 2017-06-05 17:31:10 +02:00
parent daff4e9fbd
commit acf106e1a7
6 changed files with 133 additions and 125 deletions

View file

@ -206,6 +206,48 @@ gst_vaapi_encoder_ensure_param_quality_level (GstVaapiEncoder * encoder,
return TRUE; return TRUE;
} }
gboolean
gst_vaapi_encoder_ensure_param_control_rate (GstVaapiEncoder * encoder,
GstVaapiEncPicture * picture)
{
GstVaapiEncMiscParam *misc;
if (GST_VAAPI_ENCODER_RATE_CONTROL (encoder) == GST_VAAPI_RATECONTROL_CQP)
return TRUE;
/* RateControl params */
misc = GST_VAAPI_ENC_MISC_PARAM_NEW (RateControl, encoder);
if (!misc)
return FALSE;
memcpy (misc->data, &GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder),
sizeof (VAEncMiscParameterRateControl));
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;
memcpy (misc->data, &GST_VAAPI_ENCODER_VA_HRD (encoder),
sizeof (VAEncMiscParameterHRD));
gst_vaapi_enc_picture_add_misc_param (picture, misc);
gst_vaapi_codec_object_replace (&misc, NULL);
/* FrameRate params */
if (GST_VAAPI_ENCODER_VA_FRAME_RATE (encoder).framerate == 0)
return TRUE;
misc = GST_VAAPI_ENC_MISC_PARAM_NEW (FrameRate, encoder);
if (!misc)
return FALSE;
memcpy (misc->data, &GST_VAAPI_ENCODER_VA_FRAME_RATE (encoder),
sizeof (VAEncMiscParameterFrameRate));
gst_vaapi_enc_picture_add_misc_param (picture, misc);
gst_vaapi_codec_object_replace (&misc, NULL);
return TRUE;
}
/** /**
* gst_vaapi_encoder_ref: * gst_vaapi_encoder_ref:
* @encoder: a #GstVaapiEncoder * @encoder: a #GstVaapiEncoder

View file

@ -2157,44 +2157,26 @@ static gboolean
ensure_control_rate_params (GstVaapiEncoderH264 * encoder, ensure_control_rate_params (GstVaapiEncoderH264 * encoder,
GstVaapiEncPicture * picture) GstVaapiEncPicture * picture)
{ {
GstVaapiEncMiscParam *misc; GstVaapiEncoder *const base_encoder = GST_VAAPI_ENCODER_CAST (encoder);
if (GST_VAAPI_ENCODER_RATE_CONTROL (encoder) == GST_VAAPI_RATECONTROL_CQP) if (GST_VAAPI_ENCODER_RATE_CONTROL (encoder) == GST_VAAPI_RATECONTROL_CQP)
return TRUE; return TRUE;
/* *INDENT-OFF* */
/* RateControl params */ /* RateControl params */
misc = GST_VAAPI_ENC_MISC_PARAM_NEW (RateControl, encoder); GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder) = (VAEncMiscParameterRateControl) {
if (!misc) .bits_per_second = encoder->bitrate_bits,
return FALSE; .target_percentage = 70,
.window_size = encoder->cpb_length,
{ .initial_qp = encoder->init_qp,
VAEncMiscParameterRateControl rate_control = { .min_qp = encoder->min_qp,
.bits_per_second = encoder->bitrate_bits, };
.target_percentage = 70,
.window_size = encoder->cpb_length,
.initial_qp = encoder->init_qp,
.min_qp = encoder->min_qp,
};
memcpy (misc->data, &rate_control, sizeof (rate_control));
}
gst_vaapi_enc_picture_add_misc_param (picture, misc);
gst_vaapi_codec_object_replace (&misc, NULL);
/* HRD params */ /* HRD params */
misc = GST_VAAPI_ENC_MISC_PARAM_NEW (HRD, encoder); fill_hrd_params (encoder, &GST_VAAPI_ENCODER_VA_HRD (encoder));
if (!misc) /* *INDENT-ON* */
return FALSE;
{ return gst_vaapi_encoder_ensure_param_control_rate (base_encoder, picture);
fill_hrd_params (encoder, misc->data);
}
gst_vaapi_enc_picture_add_misc_param (picture, misc);
gst_vaapi_codec_object_replace (&misc, NULL);
return TRUE;
} }
/* Generates additional control parameters */ /* Generates additional control parameters */

View file

@ -1769,27 +1769,17 @@ static gboolean
ensure_control_rate_params (GstVaapiEncoderH265 * encoder, ensure_control_rate_params (GstVaapiEncoderH265 * encoder,
GstVaapiEncPicture * picture) GstVaapiEncPicture * picture)
{ {
GstVaapiEncMiscParam *misc; GstVaapiEncoder *const base_encoder = GST_VAAPI_ENCODER_CAST (encoder);
if (GST_VAAPI_ENCODER_RATE_CONTROL (encoder) == GST_VAAPI_RATECONTROL_CQP) if (GST_VAAPI_ENCODER_RATE_CONTROL (encoder) == GST_VAAPI_RATECONTROL_CQP)
return TRUE; return TRUE;
/* HRD params */ /* HRD params */
misc = GST_VAAPI_ENC_MISC_PARAM_NEW (HRD, encoder); fill_hrd_params (encoder, &GST_VAAPI_ENCODER_VA_HRD (encoder));
if (!misc)
return FALSE;
{ return gst_vaapi_encoder_ensure_param_control_rate (base_encoder, picture);
fill_hrd_params (encoder, misc->data);
}
gst_vaapi_enc_picture_add_misc_param (picture, misc);
gst_vaapi_codec_object_replace (&misc, NULL);
return TRUE;
} }
static gboolean static gboolean
ensure_misc_params (GstVaapiEncoderH265 * encoder, GstVaapiEncPicture * picture) ensure_misc_params (GstVaapiEncoderH265 * encoder, GstVaapiEncPicture * picture)
{ {

View file

@ -456,47 +456,27 @@ ensure_control_rate_params (GstVaapiEncoderMpeg2 * encoder,
GstVaapiEncPicture * picture) GstVaapiEncPicture * picture)
{ {
GstVaapiEncoder *const base_encoder = GST_VAAPI_ENCODER_CAST (encoder); GstVaapiEncoder *const base_encoder = GST_VAAPI_ENCODER_CAST (encoder);
GstVaapiEncMiscParam *misc;
if (GST_VAAPI_ENCODER_RATE_CONTROL (encoder) == GST_VAAPI_RATECONTROL_CQP) if (GST_VAAPI_ENCODER_RATE_CONTROL (encoder) == GST_VAAPI_RATECONTROL_CQP)
return TRUE; return TRUE;
/* *INDENT-OFF* */
/* RateControl params */ /* RateControl params */
misc = GST_VAAPI_ENC_MISC_PARAM_NEW (RateControl, encoder); GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder) = (VAEncMiscParameterRateControl) {
if (!misc) .bits_per_second = base_encoder->bitrate * 1000,
return FALSE; .target_percentage = 70,
.window_size = 500,
{ .initial_qp = encoder->cqp,
VAEncMiscParameterRateControl rate_control = { };
.bits_per_second = base_encoder->bitrate * 1000,
.target_percentage = 70,
.window_size = 500,
.initial_qp = encoder->cqp,
};
memcpy (misc->data, &rate_control, sizeof (rate_control));
}
gst_vaapi_enc_picture_add_misc_param (picture, misc);
gst_vaapi_codec_object_replace (&misc, NULL);
/* HRD params */ /* HRD params */
misc = GST_VAAPI_ENC_MISC_PARAM_NEW (HRD, encoder); GST_VAAPI_ENCODER_VA_HRD (encoder) = (VAEncMiscParameterHRD) {
if (!misc) .buffer_size = base_encoder->bitrate * 1000 * 8,
return FALSE; .initial_buffer_fullness = base_encoder->bitrate * 1000 * 4,
{ };
VAEncMiscParameterHRD hrd = { /* *INDENT-ON* */
.buffer_size = base_encoder->bitrate * 1000 * 8,
.initial_buffer_fullness = base_encoder->bitrate * 1000 * 4,
};
memcpy (misc->data, &hrd, sizeof (hrd)); return gst_vaapi_encoder_ensure_param_control_rate (base_encoder, picture);
}
gst_vaapi_enc_picture_add_misc_param (picture, misc);
gst_vaapi_codec_object_replace (&misc, NULL);
return TRUE;
} }
static gboolean static gboolean

View file

@ -175,6 +175,39 @@ G_BEGIN_DECLS
#define GST_VAAPI_ENCODER_QUALITY_LEVEL(encoder) \ #define GST_VAAPI_ENCODER_QUALITY_LEVEL(encoder) \
(GST_VAAPI_ENCODER_CAST (encoder)->va_quality_level.quality_level) (GST_VAAPI_ENCODER_CAST (encoder)->va_quality_level.quality_level)
/**
* GST_VAAPI_ENCODER_VA_RATE_CONTROL:
* @encoder: a #GstVaapiEncoder
*
* Macro that evaluates to #VAEncMiscParameterRateControl
* This is an internal macro that does not do any run-time type check.
*/
#undef GST_VAAPI_ENCODER_VA_RATE_CONTROL
#define GST_VAAPI_ENCODER_VA_RATE_CONTROL(encoder) \
(GST_VAAPI_ENCODER_CAST (encoder)->va_ratecontrol)
/**
* GST_VAAPI_ENCODER_VA_FRAME_RATE:
* @encoder: a #GstVaapiEncoder
*
* Macro that evaluates to #VAEncMiscParameterFrameRate
* This is an internal macro that does not do any run-time type check.
*/
#undef GST_VAAPI_ENCODER_VA_FRAME_RATE
#define GST_VAAPI_ENCODER_VA_FRAME_RATE(encoder) \
(GST_VAAPI_ENCODER_CAST (encoder)->va_framerate)
/**
* GST_VAAPI_ENCODER_VA_HRD:
* @encoder: a #GstVaapiEncoder
*
* Macro that evaluates to #VAEncMiscParameterHRD
* This is an internal macro that does not do any run-time type check.
*/
#undef GST_VAAPI_ENCODER_VA_HRD
#define GST_VAAPI_ENCODER_VA_HRD(encoder) \
(GST_VAAPI_ENCODER_CAST (encoder)->va_hrd)
/* Generate a mask for the supplied tuning option (internal) */ /* Generate a mask for the supplied tuning option (internal) */
#define GST_VAAPI_ENCODER_TUNE_MASK(TUNE) \ #define GST_VAAPI_ENCODER_TUNE_MASK(TUNE) \
(1U << G_PASTE (GST_VAAPI_ENCODER_TUNE_, TUNE)) (1U << G_PASTE (GST_VAAPI_ENCODER_TUNE_, TUNE))
@ -244,6 +277,11 @@ struct _GstVaapiEncoder
/* Region of Interest */ /* Region of Interest */
GList *roi_regions; GList *roi_regions;
/* miscellaneous buffer parameters */
VAEncMiscParameterRateControl va_ratecontrol;
VAEncMiscParameterFrameRate va_framerate;
VAEncMiscParameterHRD va_hrd;
}; };
struct _GstVaapiEncoderClassData struct _GstVaapiEncoderClassData
@ -362,6 +400,11 @@ gboolean
gst_vaapi_encoder_ensure_param_quality_level (GstVaapiEncoder * encoder, gst_vaapi_encoder_ensure_param_quality_level (GstVaapiEncoder * encoder,
GstVaapiEncPicture * picture); GstVaapiEncPicture * picture);
G_GNUC_INTERNAL
gboolean
gst_vaapi_encoder_ensure_param_control_rate (GstVaapiEncoder * encoder,
GstVaapiEncPicture * picture);
G_GNUC_INTERNAL G_GNUC_INTERNAL
gboolean gboolean
gst_vaapi_encoder_ensure_num_slices (GstVaapiEncoder * encoder, gst_vaapi_encoder_ensure_num_slices (GstVaapiEncoder * encoder,

View file

@ -262,65 +262,36 @@ ensure_control_rate_params (GstVaapiEncoderVP8 * encoder,
GstVaapiEncPicture * picture) GstVaapiEncPicture * picture)
{ {
GstVaapiEncoder *const base_encoder = GST_VAAPI_ENCODER_CAST (encoder); GstVaapiEncoder *const base_encoder = GST_VAAPI_ENCODER_CAST (encoder);
GstVaapiEncMiscParam *misc;
if (GST_VAAPI_ENCODER_RATE_CONTROL (encoder) == GST_VAAPI_RATECONTROL_CQP) if (GST_VAAPI_ENCODER_RATE_CONTROL (encoder) == GST_VAAPI_RATECONTROL_CQP)
return TRUE; return TRUE;
/* *INDENT-OFF* */
/* RateControl params */ /* RateControl params */
misc = GST_VAAPI_ENC_MISC_PARAM_NEW (RateControl, encoder); GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder) = (VAEncMiscParameterRateControl) {
if (!misc) .bits_per_second = base_encoder->bitrate * 1000,
return FALSE; .target_percentage = 70,
/* CPB (Coded picture buffer) length in milliseconds, which
{ * could be provided as a property */
VAEncMiscParameterRateControl rate_control = { .window_size = 500,
.bits_per_second = base_encoder->bitrate * 1000, .initial_qp = encoder->yac_qi,
.target_percentage = 70, .min_qp = 1,
/* CPB (Coded picture buffer) length in milliseconds, which };
* could be provided as a property */
.window_size = 500,
.initial_qp = encoder->yac_qi,
.min_qp = 1,
};
memcpy (misc->data, &rate_control, sizeof (rate_control));
}
gst_vaapi_enc_picture_add_misc_param (picture, misc);
gst_vaapi_codec_object_replace (&misc, NULL);
/* HRD params */ /* HRD params */
misc = GST_VAAPI_ENC_MISC_PARAM_NEW (HRD, encoder); GST_VAAPI_ENCODER_VA_HRD (encoder) = (VAEncMiscParameterHRD) {
if (!misc) .buffer_size = base_encoder->bitrate * 1000 * 2,
return FALSE; .initial_buffer_fullness = base_encoder->bitrate * 1000,
};
{
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);
/* FrameRate params */ /* FrameRate params */
misc = GST_VAAPI_ENC_MISC_PARAM_NEW (FrameRate, encoder); GST_VAAPI_ENCODER_VA_FRAME_RATE (encoder) = (VAEncMiscParameterFrameRate) {
if (!misc) .framerate = (guint) GST_VAAPI_ENCODER_FPS_D (encoder) << 16 |
return FALSE; GST_VAAPI_ENCODER_FPS_N (encoder),
{ };
VAEncMiscParameterFrameRate fr = { /* *INDENT-ON* */
.framerate = (guint) GST_VAAPI_ENCODER_FPS_D (encoder) << 16 |
GST_VAAPI_ENCODER_FPS_N (encoder),
};
memcpy (misc->data, &fr, sizeof (fr));
}
gst_vaapi_enc_picture_add_misc_param (picture, misc);
gst_vaapi_codec_object_replace (&misc, NULL);
return TRUE; return gst_vaapi_encoder_ensure_param_control_rate (base_encoder, picture);
} }
static gboolean static gboolean