libs: encoder: h264,h265,mpeg2,vp8,vp9: refactor ratecontrol param

Centralize the common configuration for the Rate Control parameter,
thus can be overloaded per each specific encoder.
This commit is contained in:
Víctor Manuel Jáquez Leal 2017-06-07 12:25:24 +02:00
parent 035efded75
commit 4b5ecca29c
6 changed files with 30 additions and 43 deletions

View file

@ -812,6 +812,15 @@ gst_vaapi_encoder_reconfigure_internal (GstVaapiEncoder * encoder)
GST_VAAPI_ENCODER_VA_FRAME_RATE (encoder).framerate = GST_VAAPI_ENCODER_VA_FRAME_RATE (encoder).framerate =
(guint) GST_VIDEO_INFO_FPS_D (vip) << 16 | GST_VIDEO_INFO_FPS_N (vip); (guint) GST_VIDEO_INFO_FPS_D (vip) << 16 | GST_VIDEO_INFO_FPS_N (vip);
/* *INDENT-OFF* */
/* Default values for rate control parameter */
GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder) = (VAEncMiscParameterRateControl) {
.bits_per_second = encoder->bitrate * 1000,
.target_percentage = 70,
.window_size = 500,
};
/* *INDENT-ON* */
status = klass->reconfigure (encoder); status = klass->reconfigure (encoder);
if (status != GST_VAAPI_ENCODER_STATUS_SUCCESS) if (status != GST_VAAPI_ENCODER_STATUS_SUCCESS)
return status; return status;

View file

@ -2159,19 +2159,15 @@ ensure_control_rate_params (GstVaapiEncoderH264 * 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 */
GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder) = (VAEncMiscParameterRateControl) { GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).bits_per_second =
.bits_per_second = encoder->bitrate_bits, encoder->bitrate_bits;
.target_percentage = 70, GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).window_size = encoder->cpb_length;
.window_size = encoder->cpb_length, GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).initial_qp = encoder->init_qp;
.initial_qp = encoder->init_qp, GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).min_qp = encoder->min_qp;
.min_qp = encoder->min_qp,
};
/* HRD params */ /* HRD params */
fill_hrd_params (encoder, &GST_VAAPI_ENCODER_VA_HRD (encoder)); fill_hrd_params (encoder, &GST_VAAPI_ENCODER_VA_HRD (encoder));
/* *INDENT-ON* */
return TRUE; return TRUE;
} }

View file

@ -1773,21 +1773,17 @@ ensure_control_rate_params (GstVaapiEncoderH265 * 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 */
GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder) = (VAEncMiscParameterRateControl) { GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).bits_per_second =
.bits_per_second = encoder->bitrate_bits, encoder->bitrate_bits;
.target_percentage = 70, /* CPB (Coded picture buffer) length in milliseconds, which could be
/* CPB (Coded picture buffer) length in milliseconds, which could * provided as a property */
* be provided as a property */ GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).window_size = encoder->cpb_length;
.window_size = encoder->cpb_length, GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).initial_qp = encoder->init_qp;
.initial_qp = encoder->init_qp, GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).min_qp = encoder->min_qp;
.min_qp = encoder->min_qp,
};
/* HRD params */ /* HRD params */
fill_hrd_params (encoder, &GST_VAAPI_ENCODER_VA_HRD (encoder)); fill_hrd_params (encoder, &GST_VAAPI_ENCODER_VA_HRD (encoder));
/* *INDENT-ON* */
return TRUE; return TRUE;
} }

View file

@ -459,15 +459,10 @@ ensure_control_rate_params (GstVaapiEncoderMpeg2 * 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 */
GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder) = (VAEncMiscParameterRateControl) { GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).initial_qp = encoder->cqp;
.bits_per_second = base_encoder->bitrate * 1000,
.target_percentage = 70,
.window_size = 500,
.initial_qp = encoder->cqp,
};
/* *INDENT-OFF* */
/* HRD params */ /* HRD params */
GST_VAAPI_ENCODER_VA_HRD (encoder) = (VAEncMiscParameterHRD) { GST_VAAPI_ENCODER_VA_HRD (encoder) = (VAEncMiscParameterHRD) {
.buffer_size = base_encoder->bitrate * 1000 * 8, .buffer_size = base_encoder->bitrate * 1000 * 8,

View file

@ -268,18 +268,11 @@ ensure_control_rate_params (GstVaapiEncoderVP8 * 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 */
GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder) = (VAEncMiscParameterRateControl) { GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).initial_qp = encoder->yac_qi;
.bits_per_second = base_encoder->bitrate * 1000, GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).min_qp = 1;
.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,
};
/* *INDENT-OFF* */
/* HRD params */ /* HRD params */
GST_VAAPI_ENCODER_VA_HRD (encoder) = (VAEncMiscParameterHRD) { GST_VAAPI_ENCODER_VA_HRD (encoder) = (VAEncMiscParameterHRD) {
.buffer_size = base_encoder->bitrate * 1000 * 2, .buffer_size = base_encoder->bitrate * 1000 * 2,

View file

@ -269,14 +269,12 @@ ensure_control_rate_params (GstVaapiEncoderVP9 * 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 */
GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder) = (VAEncMiscParameterRateControl) { GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).bits_per_second =
.bits_per_second = encoder->bitrate_bits, encoder->bitrate_bits;
.target_percentage = 70, GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).window_size = encoder->cpb_length;
.window_size = encoder->cpb_length,
};
/* *INDENT-OFF* */
/* HRD params */ /* HRD params */
GST_VAAPI_ENCODER_VA_HRD (encoder) = (VAEncMiscParameterHRD) { GST_VAAPI_ENCODER_VA_HRD (encoder) = (VAEncMiscParameterHRD) {
.buffer_size = encoder->bitrate_bits * 2, .buffer_size = encoder->bitrate_bits * 2,