From 4b5ecca29c81d0219d83d3271c1aa5e25c3673d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Manuel=20J=C3=A1quez=20Leal?= Date: Wed, 7 Jun 2017 12:25:24 +0200 Subject: [PATCH] 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. --- gst-libs/gst/vaapi/gstvaapiencoder.c | 9 +++++++++ gst-libs/gst/vaapi/gstvaapiencoder_h264.c | 14 +++++--------- gst-libs/gst/vaapi/gstvaapiencoder_h265.c | 18 +++++++----------- gst-libs/gst/vaapi/gstvaapiencoder_mpeg2.c | 9 ++------- gst-libs/gst/vaapi/gstvaapiencoder_vp8.c | 13 +++---------- gst-libs/gst/vaapi/gstvaapiencoder_vp9.c | 10 ++++------ 6 files changed, 30 insertions(+), 43 deletions(-) diff --git a/gst-libs/gst/vaapi/gstvaapiencoder.c b/gst-libs/gst/vaapi/gstvaapiencoder.c index ea20df089e..d266f60b1c 100644 --- a/gst-libs/gst/vaapi/gstvaapiencoder.c +++ b/gst-libs/gst/vaapi/gstvaapiencoder.c @@ -812,6 +812,15 @@ gst_vaapi_encoder_reconfigure_internal (GstVaapiEncoder * encoder) GST_VAAPI_ENCODER_VA_FRAME_RATE (encoder).framerate = (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); if (status != GST_VAAPI_ENCODER_STATUS_SUCCESS) return status; diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_h264.c b/gst-libs/gst/vaapi/gstvaapiencoder_h264.c index 6ffbd96623..fb3dab920a 100644 --- a/gst-libs/gst/vaapi/gstvaapiencoder_h264.c +++ b/gst-libs/gst/vaapi/gstvaapiencoder_h264.c @@ -2159,19 +2159,15 @@ ensure_control_rate_params (GstVaapiEncoderH264 * encoder) if (GST_VAAPI_ENCODER_RATE_CONTROL (encoder) == GST_VAAPI_RATECONTROL_CQP) return TRUE; - /* *INDENT-OFF* */ /* RateControl params */ - 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, - }; + GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).bits_per_second = + encoder->bitrate_bits; + GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).window_size = encoder->cpb_length; + GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).initial_qp = encoder->init_qp; + GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).min_qp = encoder->min_qp; /* HRD params */ fill_hrd_params (encoder, &GST_VAAPI_ENCODER_VA_HRD (encoder)); - /* *INDENT-ON* */ return TRUE; } diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_h265.c b/gst-libs/gst/vaapi/gstvaapiencoder_h265.c index 69393c04e4..b8cd97cbfa 100644 --- a/gst-libs/gst/vaapi/gstvaapiencoder_h265.c +++ b/gst-libs/gst/vaapi/gstvaapiencoder_h265.c @@ -1773,21 +1773,17 @@ ensure_control_rate_params (GstVaapiEncoderH265 * encoder) if (GST_VAAPI_ENCODER_RATE_CONTROL (encoder) == GST_VAAPI_RATECONTROL_CQP) return TRUE; - /* *INDENT-OFF* */ /* RateControl params */ - GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder) = (VAEncMiscParameterRateControl) { - .bits_per_second = encoder->bitrate_bits, - .target_percentage = 70, - /* CPB (Coded picture buffer) length in milliseconds, which could - * be provided as a property */ - .window_size = encoder->cpb_length, - .initial_qp = encoder->init_qp, - .min_qp = encoder->min_qp, - }; + GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).bits_per_second = + encoder->bitrate_bits; + /* CPB (Coded picture buffer) length in milliseconds, which could be + * provided as a property */ + GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).window_size = encoder->cpb_length; + GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).initial_qp = encoder->init_qp; + GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).min_qp = encoder->min_qp; /* HRD params */ fill_hrd_params (encoder, &GST_VAAPI_ENCODER_VA_HRD (encoder)); - /* *INDENT-ON* */ return TRUE; } diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_mpeg2.c b/gst-libs/gst/vaapi/gstvaapiencoder_mpeg2.c index 2c284ee4b5..ab074071d2 100644 --- a/gst-libs/gst/vaapi/gstvaapiencoder_mpeg2.c +++ b/gst-libs/gst/vaapi/gstvaapiencoder_mpeg2.c @@ -459,15 +459,10 @@ ensure_control_rate_params (GstVaapiEncoderMpeg2 * encoder) if (GST_VAAPI_ENCODER_RATE_CONTROL (encoder) == GST_VAAPI_RATECONTROL_CQP) return TRUE; - /* *INDENT-OFF* */ /* RateControl params */ - 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, - }; + GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).initial_qp = encoder->cqp; + /* *INDENT-OFF* */ /* HRD params */ GST_VAAPI_ENCODER_VA_HRD (encoder) = (VAEncMiscParameterHRD) { .buffer_size = base_encoder->bitrate * 1000 * 8, diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_vp8.c b/gst-libs/gst/vaapi/gstvaapiencoder_vp8.c index f823974db9..9357527766 100644 --- a/gst-libs/gst/vaapi/gstvaapiencoder_vp8.c +++ b/gst-libs/gst/vaapi/gstvaapiencoder_vp8.c @@ -268,18 +268,11 @@ ensure_control_rate_params (GstVaapiEncoderVP8 * encoder) if (GST_VAAPI_ENCODER_RATE_CONTROL (encoder) == GST_VAAPI_RATECONTROL_CQP) return TRUE; - /* *INDENT-OFF* */ /* RateControl params */ - 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, - }; + GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).initial_qp = encoder->yac_qi; + GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).min_qp = 1; + /* *INDENT-OFF* */ /* HRD params */ GST_VAAPI_ENCODER_VA_HRD (encoder) = (VAEncMiscParameterHRD) { .buffer_size = base_encoder->bitrate * 1000 * 2, diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_vp9.c b/gst-libs/gst/vaapi/gstvaapiencoder_vp9.c index fbc8d665db..35b4f7e6cf 100644 --- a/gst-libs/gst/vaapi/gstvaapiencoder_vp9.c +++ b/gst-libs/gst/vaapi/gstvaapiencoder_vp9.c @@ -269,14 +269,12 @@ ensure_control_rate_params (GstVaapiEncoderVP9 * encoder) if (GST_VAAPI_ENCODER_RATE_CONTROL (encoder) == GST_VAAPI_RATECONTROL_CQP) return TRUE; - /* *INDENT-OFF* */ /* RateControl params */ - GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder) = (VAEncMiscParameterRateControl) { - .bits_per_second = encoder->bitrate_bits, - .target_percentage = 70, - .window_size = encoder->cpb_length, - }; + GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).bits_per_second = + encoder->bitrate_bits; + GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).window_size = encoder->cpb_length; + /* *INDENT-OFF* */ /* HRD params */ GST_VAAPI_ENCODER_VA_HRD (encoder) = (VAEncMiscParameterHRD) { .buffer_size = encoder->bitrate_bits * 2,