From de53e6de4958aea839a9b64c78c631775a1784ab Mon Sep 17 00:00:00 2001
From: jackychen <jackychen@google.com>
Date: Mon, 5 Oct 2015 15:35:22 -0700
Subject: [PATCH] Add the check of resolution in VP9 dynamic resizing.

The resolution check fixs the issue which resets resize_pending
unnecessarily and causes not-bitexact with previous one-step version.

Change-Id: I4e7660b3c8f34f59781e2e61ca30d61080c322de
---
 vp9/encoder/vp9_ratectrl.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/vp9/encoder/vp9_ratectrl.c b/vp9/encoder/vp9_ratectrl.c
index 2146b4fda0..20e72758e4 100644
--- a/vp9/encoder/vp9_ratectrl.c
+++ b/vp9/encoder/vp9_ratectrl.c
@@ -1852,18 +1852,20 @@ int vp9_resize_one_pass_cbr(VP9_COMP *cpi) {
       // Resize back up if average QP is low, and we are currently in a resized
       // down state, i.e. 1/2 or 3/4 of original resolution.
       // Currently, use a flag to turn 3/4 resizing feature on/off.
-      if (cpi->resize_buffer_underflow > (cpi->resize_count >> 1)) {
+      if (cpi->resize_state == ORIG &&
+          cpi->resize_buffer_underflow > (cpi->resize_count >> 1)) {
         resize_action = DOWN_ONEHALF;
         cpi->resize_state = ONE_HALF;
       } else if (cpi->resize_buffer_underflow > (cpi->resize_count >> 2)) {
-        if (cpi->resize_state == THREE_QUARTER || ONEHALFONLY_RESIZE) {
+        if (cpi->resize_state == THREE_QUARTER) {
           resize_action = DOWN_ONEHALF;
           cpi->resize_state = ONE_HALF;
         } else if (cpi->resize_state == ORIG) {
-          resize_action = DOWN_THREEFOUR;
-          cpi->resize_state = THREE_QUARTER;
+          resize_action = ONEHALFONLY_RESIZE ? DOWN_ONEHALF : DOWN_THREEFOUR;
+          cpi->resize_state = ONEHALFONLY_RESIZE ? ONE_HALF : THREE_QUARTER;
         }
-      } else if (avg_qp < 60 * cpi->rc.worst_quality / 100) {
+      } else if (cpi->resize_state != ORIG &&
+                 avg_qp < 60 * cpi->rc.worst_quality / 100) {
         if (cpi->resize_state == THREE_QUARTER ||
             avg_qp < 40 * cpi->rc.worst_quality / 100 ||
             ONEHALFONLY_RESIZE) {
-- 
GitLab