Skip to content

Commit

Permalink
vp9_calc_iframe_target_size_one_pass_cbr: clamp final target
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jzern committed Aug 8, 2024
1 parent bb95d36 commit 634e1f8
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions vp9/encoder/vp9_ratectrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down

0 comments on commit 634e1f8

Please sign in to comment.