rtc: Fixes/adjustments to dynamic resize For resize_mode = 3 (dynamic): add flag to disallow 3/4 down/up switch, and increase the time window for switching down/up. Keep this flag (one_half_only) on as default for now. This reduces resolution toggling observed in some tests. Also relax the conditions for entering the resize logic: allow it for screen content mode and for aq_mode enabled. Change-Id: If0851953e0f432b206a917557cfb0176cee4e095
diff --git a/av1/encoder/ratectrl.c b/av1/encoder/ratectrl.c index b1c68d8..424de3e 100644 --- a/av1/encoder/ratectrl.c +++ b/av1/encoder/ratectrl.c
@@ -3595,6 +3595,7 @@ const int min_width = (160 * 4) / 3; const int min_height = (90 * 4) / 3; int down_size_on = 1; + int one_half_only = 1; // Don't resize on key frame; reset the counters on key frame. if (cm->current_frame.frame_type == KEY_FRAME) { rc->resize_avg_qp = 0; @@ -3606,14 +3607,11 @@ if ((cm->width * cm->height) < min_width * min_height) down_size_on = 0; // Resize based on average buffer underflow and QP over some window. - // Ignore samples close to key frame or scene change, since QP is usually high + // Ignore samples close to key frame and scene change since QP is usually high // after key and scene change. // Need to incorpoate content/motion from scene detection analysis. - if (cpi->rc.frames_since_key > cpi->framerate && - (cpi->oxcf.tune_cfg.content != AOM_CONTENT_SCREEN || - cpi->oxcf.q_cfg.aq_mode != CYCLIC_REFRESH_AQ || - cpi->cyclic_refresh->counter_encode_maxq_scene_change > 4)) { - const int window = AOMMIN(30, (int)(2 * cpi->framerate)); + if (rc->frames_since_key > cpi->framerate && !rc->high_source_sad) { + const int window = AOMMAX(60, (int)(3 * cpi->framerate)); rc->resize_avg_qp += p_rc->last_q[INTER_FRAME]; if (cpi->ppi->p_rc.buffer_level < (int)(30 * p_rc->optimal_buffer_level / 100)) @@ -3633,13 +3631,14 @@ resize_action = DOWN_ONEHALF; rc->resize_state = ONE_HALF; } else if (rc->resize_state == ORIG) { - resize_action = DOWN_THREEFOUR; - rc->resize_state = THREE_QUARTER; + resize_action = one_half_only ? DOWN_ONEHALF : DOWN_THREEFOUR; + rc->resize_state = one_half_only ? ONE_HALF : THREE_QUARTER; } } else if (rc->resize_state != ORIG && avg_qp < avg_qp_thr1 * cpi->rc.worst_quality / 100) { if (rc->resize_state == THREE_QUARTER || - avg_qp < avg_qp_thr2 * cpi->rc.worst_quality / 100) { + avg_qp < avg_qp_thr2 * cpi->rc.worst_quality / 100 || + one_half_only) { resize_action = UP_ORIG; rc->resize_state = ORIG; } else if (rc->resize_state == ONE_HALF) {
diff --git a/test/resize_test.cc b/test/resize_test.cc index ba90fbb..901bc12 100644 --- a/test/resize_test.cc +++ b/test/resize_test.cc
@@ -983,7 +983,7 @@ cfg_.g_w = 352; cfg_.g_h = 288; change_bitrate_ = true; - frame_change_bitrate_ = 120; + frame_change_bitrate_ = 200; set_scale_mode_ = false; set_scale_mode2_ = false; set_scale_mode3_ = false; @@ -994,7 +994,7 @@ // Disable dropped frames. cfg_.rc_dropframe_thresh = 0; // Starting bitrate low. - cfg_.rc_target_bitrate = 100; + cfg_.rc_target_bitrate = 30; cfg_.rc_resize_mode = RESIZE_DYNAMIC; cfg_.g_forced_max_frame_width = 1280; cfg_.g_forced_max_frame_height = 1280;