From 634e1f8fb196f0e04c0dceae7043e8a12a0d31f9 Mon Sep 17 00:00:00 2001 From: James Zern Date: Mon, 5 Aug 2024 13:00:13 -0700 Subject: [PATCH] vp9_calc_iframe_target_size_one_pass_cbr: clamp final target to INT_MAX. This matches calc_iframe_target_size() in VP8 (http://crbug.com/1473473). If rc->avg_frame_bandwidth is large even small kf_boost values will overflow an int. Change-Id: Iaca5b47fe97793ae70930b3b2c2f42725d2c96fb --- vp9/encoder/vp9_ratectrl.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/vp9/encoder/vp9_ratectrl.c b/vp9/encoder/vp9_ratectrl.c index 7ae73adcaae..7e49e912d0f 100644 --- a/vp9/encoder/vp9_ratectrl.c +++ b/vp9/encoder/vp9_ratectrl.c @@ -2182,11 +2182,9 @@ int vp9_calc_iframe_target_size_one_pass_cbr(const VP9_COMP *cpi) { const RATE_CONTROL *rc = &cpi->rc; const VP9EncoderConfig *oxcf = &cpi->oxcf; const SVC *const svc = &cpi->svc; - int target; + int64_t target; if (cpi->common.current_video_frame == 0) { - target = ((rc->starting_buffer_level / 2) > INT_MAX) - ? INT_MAX - : (int)(rc->starting_buffer_level / 2); + target = rc->starting_buffer_level / 2; } else { int kf_boost = 32; double framerate = cpi->framerate; @@ -2202,9 +2200,11 @@ int vp9_calc_iframe_target_size_one_pass_cbr(const VP9_COMP *cpi) { if (rc->frames_since_key < framerate / 2) { kf_boost = (int)round(kf_boost * rc->frames_since_key / (framerate / 2)); } - target = (int)(((int64_t)(16 + kf_boost) * rc->avg_frame_bandwidth) >> 4); + + target = ((int64_t)(16 + kf_boost) * rc->avg_frame_bandwidth) >> 4; } - return vp9_rc_clamp_iframe_target_size(cpi, target); + target = VPXMIN(INT_MAX, target); + return vp9_rc_clamp_iframe_target_size(cpi, (int)target); } static void set_intra_only_frame(VP9_COMP *cpi) {