ref: e9c6cb64744f6df31ba52501d4759b50ba832df2
parent: 3101666d2a8b5b2e6bff14ffb39db685f1cc98a0
author: Marco Paniconi <marpan@google.com>
date: Wed Jun 17 06:27:39 EDT 2020
vp9-rtc: Fixes to resizer for real-time Reduce the time before sampling begins (after key) and reduce averaging window, to make resize act faster. Reset RC paramaters for temporal layers on resize. Add per-frame-bandwidth thresholds to force downsize for extreme case, for HD input. Change-Id: I8e08580b2216a2e6981502552025370703cd206c
--- a/test/resize_test.cc
+++ b/test/resize_test.cc
@@ -672,11 +672,11 @@
ASSERT_EQ(info->h, GetFrameHeight(idx));
if (info->w != last_w || info->h != last_h) {
resize_count++;
- if (resize_count == 1) {
+ if (resize_count <= 2) {
// Verify that resize down occurs.
ASSERT_LT(info->w, last_w);
ASSERT_LT(info->h, last_h);
- } else if (resize_count == 2) {
+ } else if (resize_count > 2) {
// Verify that resize up occurs.
ASSERT_GT(info->w, last_w);
ASSERT_GT(info->h, last_h);
@@ -687,8 +687,8 @@
}
#if CONFIG_VP9_DECODER
- // Verify that we get 2 resize events in this test.
- ASSERT_EQ(resize_count, 2) << "Resizing should occur twice.";
+ // Verify that we get 4 resize events in this test.
+ ASSERT_EQ(resize_count, 4) << "Resizing should occur twice.";
EXPECT_EQ(static_cast<unsigned int>(0), GetMismatchFrames());
#else
printf("Warning: VP9 decoder unavailable, unable to check resize count!\n");
--- a/vp9/encoder/vp9_ratectrl.c
+++ b/vp9/encoder/vp9_ratectrl.c
@@ -2391,6 +2391,11 @@
cpi->resize_scale_num * lc->scaling_factor_num;
lc->scaling_factor_den_resize =
cpi->resize_scale_den * lc->scaling_factor_den;
+ // Reset rate control for all temporal layers.
+ lc->rc.buffer_level = lc->rc.optimal_buffer_level;
+ lc->rc.bits_off_target = lc->rc.optimal_buffer_level;
+ lc->rc.rate_correction_factors[INTER_FRAME] =
+ rc->rate_correction_factors[INTER_FRAME];
}
// Set the size for this current temporal layer.
lc = &svc->layer_context[svc->spatial_layer_id *
@@ -2663,6 +2668,7 @@
int min_width = (320 * 4) / 3;
int min_height = (180 * 4) / 3;
int down_size_on = 1;
+ int force_downsize_rate = 0;
cpi->resize_scale_num = 1;
cpi->resize_scale_den = 1;
// Don't resize on key frame; reset the counters on key frame.
@@ -2683,10 +2689,31 @@
}
#endif
+ // Force downsize based on per-frame-bandwidth, for extreme case,
+ // for HD input.
+ if (cpi->resize_state == ORIG && cm->width * cm->height >= 1280 * 720) {
+ if (rc->avg_frame_bandwidth < (int)(300000 / 30)) {
+ resize_action = DOWN_ONEHALF;
+ cpi->resize_state = ONE_HALF;
+ force_downsize_rate = 1;
+ } else if (rc->avg_frame_bandwidth < (int)(400000 / 30)) {
+ resize_action = ONEHALFONLY_RESIZE ? DOWN_ONEHALF : DOWN_THREEFOUR;
+ cpi->resize_state = ONEHALFONLY_RESIZE ? ONE_HALF : THREE_QUARTER;
+ force_downsize_rate = 1;
+ }
+ } else if (cpi->resize_state == THREE_QUARTER &&
+ cm->width * cm->height >= 960 * 540) {
+ if (rc->avg_frame_bandwidth < (int)(300000 / 30)) {
+ resize_action = DOWN_ONEHALF;
+ cpi->resize_state = ONE_HALF;
+ force_downsize_rate = 1;
+ }
+ }
+
// Resize based on average buffer underflow and QP over some window.
// Ignore samples close to key frame, since QP is usually high after key.
- if (cpi->rc.frames_since_key > 2 * cpi->framerate) {
- const int window = (int)(4 * cpi->framerate);
+ if (!force_downsize_rate && cpi->rc.frames_since_key > cpi->framerate) {
+ const int window = VPXMIN(30, (int)(2 * cpi->framerate));
cpi->resize_avg_qp += cm->base_qindex;
if (cpi->rc.buffer_level < (int)(30 * rc->optimal_buffer_level / 100))
++cpi->resize_buffer_underflow;