shithub: libvpx

Download patch

ref: f288c943c4d6c3fb03266dee821df797fb99bde0
parent: aff0a802e70ee87cd0a1673f3cffaa0b9d6112b4
author: Marco <marpan@google.com>
date: Mon Feb 8 05:41:13 EST 2016

vp9-dynamic resize: Fix bug on releasing scaled reference.

When the codec frame size is the same as the reference frame size,
release the scaled reference before assigning it a new buf_idx.
Only affects 1 pass non-svc mode, where the scaled references are
release only under certain conditions (to prevent un-needed scaling
of the references every frame).

Modified a unittest that can trigger this bug without this change.

https://code.google.com/p/chromium/issues/detail?id=582598

Change-Id: I9a884e36ebd7608b1641ec2a469e20a4f829cf43

--- a/test/resize_test.cc
+++ b/test/resize_test.cc
@@ -127,6 +127,20 @@
     return val / 2;
   if (frame < 180)
     return val * 3 / 4;
+  if (frame < 190)
+    return val;
+  if (frame < 200)
+    return val * 3 / 4;
+  if (frame < 210)
+    return val / 2;
+  if (frame < 220)
+    return val * 3 / 4;
+  if (frame < 230)
+    return val;
+  if (frame < 240)
+    return val / 2;
+  if (frame < 250)
+    return val * 3 / 4;
   return val;
 }
 
@@ -134,7 +148,7 @@
  public:
   ResizingVideoSource() {
     SetSize(kInitialWidth, kInitialHeight);
-    limit_ = 200;
+    limit_ = 300;
   }
 
   virtual ~ResizingVideoSource() {}
--- a/vp9/encoder/vp9_encoder.c
+++ b/vp9/encoder/vp9_encoder.c
@@ -2975,8 +2975,19 @@
         }
 #endif  // CONFIG_VP9_HIGHBITDEPTH
       } else {
-        const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame);
-        RefCntBuffer *const buf = &pool->frame_bufs[buf_idx];
+        int buf_idx;
+        RefCntBuffer *buf = NULL;
+        if (cpi->oxcf.pass == 0 && !cpi->use_svc) {
+          // Check for release of scaled reference.
+          buf_idx = cpi->scaled_ref_idx[ref_frame - 1];
+          buf = (buf_idx != INVALID_IDX) ? &pool->frame_bufs[buf_idx] : NULL;
+          if (buf != NULL) {
+            --buf->ref_count;
+            cpi->scaled_ref_idx[ref_frame - 1] = INVALID_IDX;
+          }
+        }
+        buf_idx = get_ref_frame_buf_idx(cpi, ref_frame);
+        buf = &pool->frame_bufs[buf_idx];
         buf->buf.y_crop_width = ref->y_crop_width;
         buf->buf.y_crop_height = ref->y_crop_height;
         cpi->scaled_ref_idx[ref_frame - 1] = buf_idx;