mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-23 16:50:47 +00:00
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:
parent
daff4e9fbd
commit
acf106e1a7
6 changed files with 133 additions and 125 deletions
|
@ -206,6 +206,48 @@ gst_vaapi_encoder_ensure_param_quality_level (GstVaapiEncoder * encoder,
|
|||
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:
|
||||
* @encoder: a #GstVaapiEncoder
|
||||
|
|
|
@ -2157,44 +2157,26 @@ static gboolean
|
|||
ensure_control_rate_params (GstVaapiEncoderH264 * encoder,
|
||||
GstVaapiEncPicture * picture)
|
||||
{
|
||||
GstVaapiEncMiscParam *misc;
|
||||
GstVaapiEncoder *const base_encoder = GST_VAAPI_ENCODER_CAST (encoder);
|
||||
|
||||
if (GST_VAAPI_ENCODER_RATE_CONTROL (encoder) == GST_VAAPI_RATECONTROL_CQP)
|
||||
return TRUE;
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
/* RateControl params */
|
||||
misc = GST_VAAPI_ENC_MISC_PARAM_NEW (RateControl, encoder);
|
||||
if (!misc)
|
||||
return FALSE;
|
||||
|
||||
{
|
||||
VAEncMiscParameterRateControl rate_control = {
|
||||
.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);
|
||||
GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder) = (VAEncMiscParameterRateControl) {
|
||||
.bits_per_second = encoder->bitrate_bits,
|
||||
.target_percentage = 70,
|
||||
.window_size = encoder->cpb_length,
|
||||
.initial_qp = encoder->init_qp,
|
||||
.min_qp = encoder->min_qp,
|
||||
};
|
||||
|
||||
/* HRD params */
|
||||
misc = GST_VAAPI_ENC_MISC_PARAM_NEW (HRD, encoder);
|
||||
if (!misc)
|
||||
return FALSE;
|
||||
fill_hrd_params (encoder, &GST_VAAPI_ENCODER_VA_HRD (encoder));
|
||||
/* *INDENT-ON* */
|
||||
|
||||
{
|
||||
fill_hrd_params (encoder, misc->data);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/* Generates additional control parameters */
|
||||
|
|
|
@ -1769,27 +1769,17 @@ static gboolean
|
|||
ensure_control_rate_params (GstVaapiEncoderH265 * encoder,
|
||||
GstVaapiEncPicture * picture)
|
||||
{
|
||||
GstVaapiEncMiscParam *misc;
|
||||
GstVaapiEncoder *const base_encoder = GST_VAAPI_ENCODER_CAST (encoder);
|
||||
|
||||
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, &GST_VAAPI_ENCODER_VA_HRD (encoder));
|
||||
|
||||
{
|
||||
fill_hrd_params (encoder, misc->data);
|
||||
}
|
||||
|
||||
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
|
||||
ensure_misc_params (GstVaapiEncoderH265 * encoder, GstVaapiEncPicture * picture)
|
||||
{
|
||||
|
|
|
@ -456,47 +456,27 @@ ensure_control_rate_params (GstVaapiEncoderMpeg2 * encoder,
|
|||
GstVaapiEncPicture * picture)
|
||||
{
|
||||
GstVaapiEncoder *const base_encoder = GST_VAAPI_ENCODER_CAST (encoder);
|
||||
GstVaapiEncMiscParam *misc;
|
||||
|
||||
if (GST_VAAPI_ENCODER_RATE_CONTROL (encoder) == GST_VAAPI_RATECONTROL_CQP)
|
||||
return TRUE;
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
/* RateControl params */
|
||||
misc = GST_VAAPI_ENC_MISC_PARAM_NEW (RateControl, encoder);
|
||||
if (!misc)
|
||||
return FALSE;
|
||||
|
||||
{
|
||||
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);
|
||||
GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder) = (VAEncMiscParameterRateControl) {
|
||||
.bits_per_second = base_encoder->bitrate * 1000,
|
||||
.target_percentage = 70,
|
||||
.window_size = 500,
|
||||
.initial_qp = encoder->cqp,
|
||||
};
|
||||
|
||||
/* 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,
|
||||
};
|
||||
GST_VAAPI_ENCODER_VA_HRD (encoder) = (VAEncMiscParameterHRD) {
|
||||
.buffer_size = base_encoder->bitrate * 1000 * 8,
|
||||
.initial_buffer_fullness = base_encoder->bitrate * 1000 * 4,
|
||||
};
|
||||
/* *INDENT-ON* */
|
||||
|
||||
memcpy (misc->data, &hrd, sizeof (hrd));
|
||||
}
|
||||
|
||||
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
|
||||
|
|
|
@ -175,6 +175,39 @@ G_BEGIN_DECLS
|
|||
#define GST_VAAPI_ENCODER_QUALITY_LEVEL(encoder) \
|
||||
(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) */
|
||||
#define GST_VAAPI_ENCODER_TUNE_MASK(TUNE) \
|
||||
(1U << G_PASTE (GST_VAAPI_ENCODER_TUNE_, TUNE))
|
||||
|
@ -244,6 +277,11 @@ struct _GstVaapiEncoder
|
|||
|
||||
/* Region of Interest */
|
||||
GList *roi_regions;
|
||||
|
||||
/* miscellaneous buffer parameters */
|
||||
VAEncMiscParameterRateControl va_ratecontrol;
|
||||
VAEncMiscParameterFrameRate va_framerate;
|
||||
VAEncMiscParameterHRD va_hrd;
|
||||
};
|
||||
|
||||
struct _GstVaapiEncoderClassData
|
||||
|
@ -362,6 +400,11 @@ gboolean
|
|||
gst_vaapi_encoder_ensure_param_quality_level (GstVaapiEncoder * encoder,
|
||||
GstVaapiEncPicture * picture);
|
||||
|
||||
G_GNUC_INTERNAL
|
||||
gboolean
|
||||
gst_vaapi_encoder_ensure_param_control_rate (GstVaapiEncoder * encoder,
|
||||
GstVaapiEncPicture * picture);
|
||||
|
||||
G_GNUC_INTERNAL
|
||||
gboolean
|
||||
gst_vaapi_encoder_ensure_num_slices (GstVaapiEncoder * encoder,
|
||||
|
|
|
@ -262,65 +262,36 @@ ensure_control_rate_params (GstVaapiEncoderVP8 * encoder,
|
|||
GstVaapiEncPicture * picture)
|
||||
{
|
||||
GstVaapiEncoder *const base_encoder = GST_VAAPI_ENCODER_CAST (encoder);
|
||||
GstVaapiEncMiscParam *misc;
|
||||
|
||||
if (GST_VAAPI_ENCODER_RATE_CONTROL (encoder) == GST_VAAPI_RATECONTROL_CQP)
|
||||
return TRUE;
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
/* RateControl params */
|
||||
misc = GST_VAAPI_ENC_MISC_PARAM_NEW (RateControl, encoder);
|
||||
if (!misc)
|
||||
return FALSE;
|
||||
|
||||
{
|
||||
VAEncMiscParameterRateControl rate_control = {
|
||||
.bits_per_second = base_encoder->bitrate * 1000,
|
||||
.target_percentage = 70,
|
||||
/* 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);
|
||||
GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder) = (VAEncMiscParameterRateControl) {
|
||||
.bits_per_second = base_encoder->bitrate * 1000,
|
||||
.target_percentage = 70,
|
||||
/* 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,
|
||||
};
|
||||
|
||||
/* 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);
|
||||
GST_VAAPI_ENCODER_VA_HRD (encoder) = (VAEncMiscParameterHRD) {
|
||||
.buffer_size = base_encoder->bitrate * 1000 * 2,
|
||||
.initial_buffer_fullness = base_encoder->bitrate * 1000,
|
||||
};
|
||||
|
||||
/* FrameRate params */
|
||||
misc = GST_VAAPI_ENC_MISC_PARAM_NEW (FrameRate, encoder);
|
||||
if (!misc)
|
||||
return FALSE;
|
||||
{
|
||||
VAEncMiscParameterFrameRate fr = {
|
||||
.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);
|
||||
GST_VAAPI_ENCODER_VA_FRAME_RATE (encoder) = (VAEncMiscParameterFrameRate) {
|
||||
.framerate = (guint) GST_VAAPI_ENCODER_FPS_D (encoder) << 16 |
|
||||
GST_VAAPI_ENCODER_FPS_N (encoder),
|
||||
};
|
||||
/* *INDENT-ON* */
|
||||
|
||||
return TRUE;
|
||||
return gst_vaapi_encoder_ensure_param_control_rate (base_encoder, picture);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
Loading…
Reference in a new issue