Move the assertion in get_free_fb() to its callers

One of the get_free_fb() callers in av1/encoder/encoder.c (in the
scale_references() function) ignores get_free_fb() failure. This CL
allows that caller to avoid an assertion failure when get_free_fb()
fails.

BUG=aomedia:2179
BUG=aomedia:2193

Change-Id: I071e4809878e82ae3fb0ebdb070bcac3de022de8
diff --git a/av1/common/onyxc_int.h b/av1/common/onyxc_int.h
index cf600d1..15b3463 100644
--- a/av1/common/onyxc_int.h
+++ b/av1/common/onyxc_int.h
@@ -597,9 +597,6 @@
 
     frame_bufs[i].ref_count = 1;
   } else {
-    // We should never run out of free buffers. If this assertion fails, there
-    // is a reference leak.
-    assert(0 && "Ran out of free frame buffers. Likely a reference leak.");
     // Reset i to be INVALID_IDX to indicate no free buffer found.
     i = INVALID_IDX;
   }
diff --git a/av1/decoder/decodeframe.c b/av1/decoder/decodeframe.c
index 285e365..ae32a0b 100644
--- a/av1/decoder/decodeframe.c
+++ b/av1/decoder/decodeframe.c
@@ -5056,6 +5056,8 @@
           // pixels set to neutral grey.
           buf_idx = get_free_fb(cm);
           if (buf_idx == INVALID_IDX) {
+            assert(0 &&
+                   "Ran out of free frame buffers. Likely a reference leak.");
             aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR,
                                "Unable to find free frame buffer");
           }
diff --git a/av1/decoder/decoder.c b/av1/decoder/decoder.c
index ba13741..5c9bfd3 100644
--- a/av1/decoder/decoder.c
+++ b/av1/decoder/decoder.c
@@ -483,6 +483,7 @@
   // Find a free frame buffer. Return error if can not find any.
   cm->new_fb_idx = get_free_fb(cm);
   if (cm->new_fb_idx == INVALID_IDX) {
+    assert(0 && "Ran out of free frame buffers. Likely a reference leak.");
     cm->error.error_code = AOM_CODEC_MEM_ERROR;
     return 1;
   }
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index fdc409f..4470f92 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -3746,6 +3746,7 @@
           new_fb = get_free_fb(cm);
           force_scaling = 1;
         }
+        // TODO(wtc): Is it OK to ignore the get_free_fb() failure?
         if (new_fb == INVALID_IDX) return;
         new_fb_ptr = &pool->frame_bufs[new_fb];
         if (force_scaling || new_fb_ptr->buf.y_crop_width != cm->width ||
@@ -6510,7 +6511,10 @@
     }
     cm->new_fb_idx = get_free_fb(cm);
 
-    if (cm->new_fb_idx == INVALID_IDX) return -1;
+    if (cm->new_fb_idx == INVALID_IDX) {
+      assert(0 && "Ran out of free frame buffers. Likely a reference leak.");
+      return -1;
+    }
 
     // Clear down mmx registers
     aom_clear_system_state();
@@ -6700,7 +6704,10 @@
   }
   cm->new_fb_idx = get_free_fb(cm);
 
-  if (cm->new_fb_idx == INVALID_IDX) return -1;
+  if (cm->new_fb_idx == INVALID_IDX) {
+    assert(0 && "Ran out of free frame buffers. Likely a reference leak.");
+    return -1;
+  }
 
   // Retain the RF_LEVEL for the current newly coded frame.
   cpi->frame_rf_level[cm->new_fb_idx] =