Skip to content

Commit

Permalink
vp9: round avg_frame_bandwidth result
Browse files Browse the repository at this point in the history
in vp9_rc_update_framerate() and in functions in vp9_svc_layercontext.c.

This matches the code in VP8 and AV1 as discussed in
https://chromium-review.googlesource.com/c/webm/libvpx/+/5566050/2/vp8/encoder/onyx_if.c

Change-Id: I084f8002f8f6c8efffc511566910b3f3df47ba4e
  • Loading branch information
jzern committed Jun 5, 2024
1 parent 60807f0 commit 713e0fa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
5 changes: 3 additions & 2 deletions vp9/encoder/vp9_ratectrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2631,9 +2631,10 @@ void vp9_rc_update_framerate(VP9_COMP *cpi) {
const VP9_COMMON *const cm = &cpi->common;
const VP9EncoderConfig *const oxcf = &cpi->oxcf;
RATE_CONTROL *const rc = &cpi->rc;
const double avg_frame_bandwidth =
round(oxcf->target_bandwidth / cpi->framerate);

rc->avg_frame_bandwidth =
(int)VPXMIN(oxcf->target_bandwidth / cpi->framerate, INT_MAX);
rc->avg_frame_bandwidth = (int)VPXMIN(avg_frame_bandwidth, INT_MAX);

int64_t vbr_min_bits =
(int64_t)rc->avg_frame_bandwidth * oxcf->two_pass_vbrmin_section / 100;
Expand Down
18 changes: 11 additions & 7 deletions vp9/encoder/vp9_svc_layercontext.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,9 @@ void vp9_update_layer_context_change_config(VP9_COMP *const cpi,
VPXMIN(lrc->bits_off_target, lrc->maximum_buffer_size);
lrc->buffer_level = VPXMIN(lrc->buffer_level, lrc->maximum_buffer_size);
lc->framerate = cpi->framerate / oxcf->ts_rate_decimator[tl];
lrc->avg_frame_bandwidth =
(int)VPXMIN(lc->target_bandwidth / lc->framerate, INT_MAX);
const double avg_frame_bandwidth =
round(lc->target_bandwidth / lc->framerate);
lrc->avg_frame_bandwidth = (int)VPXMIN(avg_frame_bandwidth, INT_MAX);
lrc->max_frame_bandwidth = rc->max_frame_bandwidth;
lrc->worst_quality = rc->worst_quality;
lrc->best_quality = rc->best_quality;
Expand Down Expand Up @@ -273,8 +274,9 @@ void vp9_update_layer_context_change_config(VP9_COMP *const cpi,
} else {
lc->framerate = cpi->framerate;
}
lrc->avg_frame_bandwidth =
(int)VPXMIN(lc->target_bandwidth / lc->framerate, INT_MAX);
const double avg_frame_bandwidth =
round(lc->target_bandwidth / lc->framerate);
lrc->avg_frame_bandwidth = (int)VPXMIN(avg_frame_bandwidth, INT_MAX);
lrc->max_frame_bandwidth = rc->max_frame_bandwidth;
// Update qp-related quantities.
lrc->worst_quality = rc->worst_quality;
Expand Down Expand Up @@ -316,8 +318,9 @@ void vp9_update_temporal_layer_framerate(VP9_COMP *const cpi) {
const int tl = svc->temporal_layer_id;

lc->framerate = cpi->framerate / oxcf->ts_rate_decimator[tl];
lrc->avg_frame_bandwidth =
(int)VPXMIN(lc->target_bandwidth / lc->framerate, INT_MAX);
const double avg_frame_bandwidth =
round(lc->target_bandwidth / lc->framerate);
lrc->avg_frame_bandwidth = (int)VPXMIN(avg_frame_bandwidth, INT_MAX);
lrc->max_frame_bandwidth = cpi->rc.max_frame_bandwidth;
// Update the average layer frame size (non-cumulative per-frame-bw).
if (tl == 0) {
Expand All @@ -339,7 +342,8 @@ void vp9_update_spatial_layer_framerate(VP9_COMP *const cpi, double framerate) {
RATE_CONTROL *const lrc = &lc->rc;

lc->framerate = framerate;
const double avg_frame_bandwidth = lc->target_bandwidth / lc->framerate;
const double avg_frame_bandwidth =
round(lc->target_bandwidth / lc->framerate);
lrc->avg_frame_bandwidth = (int)VPXMIN(avg_frame_bandwidth, INT_MAX);
const int64_t vbr_min_bits =
(int64_t)lrc->avg_frame_bandwidth * oxcf->two_pass_vbrmin_section / 100;
Expand Down

0 comments on commit 713e0fa

Please sign in to comment.