libs: encoder: add target-percentage property

Allow users to set the target-percentage for
variable rate controls.  The default value is
70 (as hard-coded prior).

v2: minimum allowed value changed from 0 to 1
v3: target-percentage unchanged if CBR used

Resolves #129
This commit is contained in:
U. Artie Eoff 2019-05-01 12:56:55 -07:00 committed by Víctor Manuel Jáquez Leal
parent b6457e4ce5
commit be496a66c5
3 changed files with 47 additions and 3 deletions

View file

@ -145,8 +145,6 @@ gst_vaapi_encoder_properties_get_default (const GstVaapiEncoderClass * klass)
* else minimum bitrate = maximum bitrate * (2 * target percentage -100) / 100
* Target bitrate will be calculated like the following in the driver.
* target bitrate = maximum bitrate * target percentage / 100
*
* Note that target percentage is set as 70 currently in GStreamer VA-API.
*/
GST_VAAPI_ENCODER_PROPERTIES_APPEND (props,
GST_VAAPI_ENCODER_PROP_BITRATE,
@ -155,6 +153,18 @@ gst_vaapi_encoder_properties_get_default (const GstVaapiEncoderClass * klass)
"The desired bitrate expressed in kbps (0: auto-calculate)",
0, 100 * 1024, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GstVaapiEncoder:target-percentage:
*
* The desired target percentage of bitrate for variable rate controls.
*/
GST_VAAPI_ENCODER_PROPERTIES_APPEND (props,
GST_VAAPI_ENCODER_PROP_TARGET_PERCENTAGE,
g_param_spec_uint ("target-percentage",
"Target Percentage",
"The desired target percentage of bitrate for variable rate "
"controls.", 1, 100, 70, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GstVaapiEncoder:keyframe-period:
*
@ -1035,7 +1045,7 @@ gst_vaapi_encoder_reconfigure_internal (GstVaapiEncoder * encoder)
target_percentage =
(GST_VAAPI_ENCODER_RATE_CONTROL (encoder) == GST_VAAPI_RATECONTROL_CBR) ?
100 : 70;
100 : encoder->target_percentage;
/* *INDENT-OFF* */
/* Default values for rate control parameter */
@ -1199,6 +1209,10 @@ set_property (GstVaapiEncoder * encoder, gint prop_id, const GValue * value)
status = gst_vaapi_encoder_set_bitrate (encoder,
g_value_get_uint (value));
break;
case GST_VAAPI_ENCODER_PROP_TARGET_PERCENTAGE:
status = gst_vaapi_encoder_set_target_percentage (encoder,
g_value_get_uint (value));
break;
case GST_VAAPI_ENCODER_PROP_KEYFRAME_PERIOD:
status = gst_vaapi_encoder_set_keyframe_period (encoder,
g_value_get_uint (value));
@ -1368,6 +1382,28 @@ gst_vaapi_encoder_set_bitrate (GstVaapiEncoder * encoder, guint bitrate)
return GST_VAAPI_ENCODER_STATUS_SUCCESS;
}
GstVaapiEncoderStatus
gst_vaapi_encoder_set_target_percentage (GstVaapiEncoder * encoder,
guint target_percentage)
{
g_return_val_if_fail (encoder != NULL, 0);
if (encoder->target_percentage != target_percentage
&& encoder->num_codedbuf_queued > 0) {
if (GST_VAAPI_ENCODER_RATE_CONTROL (encoder) != GST_VAAPI_RATECONTROL_CBR) {
GST_INFO ("Target percentage is changed to %d on runtime",
target_percentage);
encoder->target_percentage = target_percentage;
return gst_vaapi_encoder_reconfigure_internal (encoder);
}
GST_WARNING ("Target percentage is ignored for CBR rate-control");
return GST_VAAPI_ENCODER_STATUS_SUCCESS;
}
encoder->target_percentage = target_percentage;
return GST_VAAPI_ENCODER_STATUS_SUCCESS;
}
/**
* gst_vaapi_encoder_set_keyframe_period:
* @encoder: a #GstVaapiEncoder

View file

@ -114,6 +114,8 @@ typedef enum {
* GstVaapiEncoderProp:
* @GST_VAAPI_ENCODER_PROP_RATECONTROL: Rate control (#GstVaapiRateControl).
* @GST_VAAPI_ENCODER_PROP_BITRATE: Bitrate expressed in kbps (uint).
* @GST_VAAPI_ENCODER_PROP_TARGET_PERCENTAGE: Desired target percentage of
* bitrate for variable rate controls.
* @GST_VAAPI_ENCODER_PROP_KEYFRAME_PERIOD: The maximal distance
* between two keyframes (uint).
* @GST_VAAPI_ENCODER_PROP_TUNE: The tuning options (#GstVaapiEncoderTune).
@ -126,6 +128,7 @@ typedef enum {
typedef enum {
GST_VAAPI_ENCODER_PROP_RATECONTROL = 1,
GST_VAAPI_ENCODER_PROP_BITRATE,
GST_VAAPI_ENCODER_PROP_TARGET_PERCENTAGE,
GST_VAAPI_ENCODER_PROP_KEYFRAME_PERIOD,
GST_VAAPI_ENCODER_PROP_TUNE,
GST_VAAPI_ENCODER_PROP_QUALITY_LEVEL,
@ -180,6 +183,10 @@ gst_vaapi_encoder_set_rate_control (GstVaapiEncoder * encoder,
GstVaapiEncoderStatus
gst_vaapi_encoder_set_bitrate (GstVaapiEncoder * encoder, guint bitrate);
GstVaapiEncoderStatus
gst_vaapi_encoder_set_target_percentage (GstVaapiEncoder * encoder,
guint target_percentage);
GstVaapiEncoderStatus
gst_vaapi_encoder_put_frame (GstVaapiEncoder * encoder,
GstVideoCodecFrame * frame);

View file

@ -262,6 +262,7 @@ struct _GstVaapiEncoder
GstVaapiRateControl rate_control;
guint32 rate_control_mask;
guint bitrate; /* kbps */
guint target_percentage;
guint keyframe_period;
/* Maximum number of reference frames supported