From: Louis Li Date: Tue, 31 Mar 2020 02:20:21 +0000 (+0800) Subject: radeon/radeon_vce: fix out of target bitrate in CBR mode (H.264) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f7e7cf637e1b457d56b3aaf4d05c928ef9acff17;p=mesa.git radeon/radeon_vce: fix out of target bitrate in CBR mode (H.264) StoneyRidge may not comply to required target bitrate when generating H.264 stream in CBR mode. Signed-off-by: Louis Li Reviewed-by: Leo Liu Part-of: --- diff --git a/src/gallium/drivers/radeon/radeon_vce_52.c b/src/gallium/drivers/radeon/radeon_vce_52.c index 141032d6617..dd2ffbb10d3 100644 --- a/src/gallium/drivers/radeon/radeon_vce_52.c +++ b/src/gallium/drivers/radeon/radeon_vce_52.c @@ -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;