radeon/radeon_vce: fix out of target bitrate in CBR mode (H.264)
authorLouis Li <Ching-shih.Li@amd.com>
Tue, 31 Mar 2020 02:20:21 +0000 (10:20 +0800)
committerMarge Bot <eric+marge@anholt.net>
Mon, 10 Aug 2020 01:39:18 +0000 (01:39 +0000)
StoneyRidge may not comply to required target bitrate
when generating H.264 stream in CBR mode.

Signed-off-by: Louis Li <Ching-shih.Li@amd.com>
Reviewed-by: Leo Liu <leo.liu@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4384>

src/gallium/drivers/radeon/radeon_vce_52.c

index 141032d..dd2ffbb 100644 (file)
@@ -47,7 +47,17 @@ static void get_rate_control_param(struct rvce_encoder *enc, struct pipe_h264_en
    enc->enc_pic.rc.frame_rate_num = pic->rate_ctrl.frame_rate_num;
    enc->enc_pic.rc.frame_rate_den = pic->rate_ctrl.frame_rate_den;
    enc->enc_pic.rc.max_qp = 51;
-   enc->enc_pic.rc.vbv_buffer_size = pic->rate_ctrl.vbv_buffer_size;
+
+   /* For CBR mode, to guarantee bitrate of generated stream complies with
+    * target bitrate (e.g. no over +/-10%), vbv_buffer_size should be same
+    * as target bitrate.
+    */
+   if (enc->enc_pic.rc.rc_method == PIPE_H264_ENC_RATE_CONTROL_METHOD_CONSTANT) {
+           enc->enc_pic.rc.vbv_buffer_size = pic->rate_ctrl.target_bitrate;
+   } else {
+           enc->enc_pic.rc.vbv_buffer_size = pic->rate_ctrl.vbv_buffer_size;
+   }
+
    enc->enc_pic.rc.vbv_buf_lv = pic->rate_ctrl.vbv_buf_lv;
    enc->enc_pic.rc.fill_data_enable = pic->rate_ctrl.fill_data_enable;
    enc->enc_pic.rc.enforce_hrd = pic->rate_ctrl.enforce_hrd;