Allocate grain image using frame buffer callback.

Add the aom_img_alloc_with_cb function. It is currently for internal
use only. Use it to allocate the grain image with the frame buffer
callback.

Also add two test vectors for film grain synthesis.

BUG=aomedia:2222

Change-Id: I2bb264431aaa27fa2dd83acbb1d5e23aac6d8e25
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c767ae3..4ee2fe3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -115,6 +115,7 @@
             "${AOM_ROOT}/aom/aomcx.h"
             "${AOM_ROOT}/aom/aomdx.h"
             "${AOM_ROOT}/aom/internal/aom_codec_internal.h"
+            "${AOM_ROOT}/aom/internal/aom_image_internal.h"
             "${AOM_ROOT}/aom/src/aom_codec.c"
             "${AOM_ROOT}/aom/src/aom_decoder.c"
             "${AOM_ROOT}/aom/src/aom_encoder.c"
diff --git a/aom/internal/aom_image_internal.h b/aom/internal/aom_image_internal.h
new file mode 100644
index 0000000..ba9cb64
--- /dev/null
+++ b/aom/internal/aom_image_internal.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ *
+ * This source code is subject to the terms of the BSD 2 Clause License and
+ * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
+ * was not distributed with this source code in the LICENSE file, you can
+ * obtain it at www.aomedia.org/license/software. If the Alliance for Open
+ * Media Patent License 1.0 was not distributed with this source code in the
+ * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ */
+
+/*!\file
+ * \brief Describes the internal functions associated with the aom image
+ * descriptor.
+ *
+ */
+#ifndef AOM_AOM_INTERNAL_AOM_IMAGE_INTERNAL_H_
+#define AOM_AOM_INTERNAL_AOM_IMAGE_INTERNAL_H_
+
+#include "aom/aom_image.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void *(*aom_alloc_img_data_cb_fn_t)(void *priv, size_t size);
+
+/*!\brief Open a descriptor, allocating storage for the underlying image by
+ * using the provided callback function.
+ *
+ * Returns a descriptor for storing an image of the given format. The storage
+ * for the image is allocated by using the provided callback function. Unlike
+ * aom_img_alloc(), the returned descriptor does not own the storage for the
+ * image. The caller is responsible for freeing the storage for the image.
+ *
+ * Note: If the callback function is invoked and succeeds,
+ * aom_img_alloc_with_cb() is guaranteed to succeed. Therefore, if
+ * aom_img_alloc_with_cb() fails, the caller is assured that no storage was
+ * allocated.
+ *
+ * \param[in]    img       Pointer to storage for descriptor. If this parameter
+ *                         is NULL, the storage for the descriptor will be
+ *                         allocated on the heap.
+ * \param[in]    fmt       Format for the image
+ * \param[in]    d_w       Width of the image
+ * \param[in]    d_h       Height of the image
+ * \param[in]    align     Alignment, in bytes, of the image buffer and
+ *                         each row in the image (stride).
+ * \param[in]    alloc_cb  Callback function used to allocate storage for the
+ *                         image.
+ * \param[in]    cb_priv   The first argument ('priv') for the callback
+ *                         function.
+ *
+ * \return Returns a pointer to the initialized image descriptor. If the img
+ *         parameter is non-null, the value of the img parameter will be
+ *         returned.
+ */
+aom_image_t *aom_img_alloc_with_cb(aom_image_t *img, aom_img_fmt_t fmt,
+                                   unsigned int d_w, unsigned int d_h,
+                                   unsigned int align,
+                                   aom_alloc_img_data_cb_fn_t alloc_cb,
+                                   void *cb_priv);
+
+#ifdef __cplusplus
+}  // extern "C"
+#endif
+
+#endif  // AOM_AOM_INTERNAL_AOM_IMAGE_INTERNAL_H_
diff --git a/aom/src/aom_image.c b/aom/src/aom_image.c
index d6696c9..723ff83 100644
--- a/aom/src/aom_image.c
+++ b/aom/src/aom_image.c
@@ -14,7 +14,9 @@
 
 #include "aom/aom_image.h"
 #include "aom/aom_integer.h"
+#include "aom/internal/aom_image_internal.h"
 #include "aom_mem/aom_mem.h"
+#include "aom_mem/include/aom_mem_intrnl.h"
 
 static INLINE unsigned int align_image_dimension(unsigned int d,
                                                  unsigned int subsampling,
@@ -29,7 +31,8 @@
 static aom_image_t *img_alloc_helper(
     aom_image_t *img, aom_img_fmt_t fmt, unsigned int d_w, unsigned int d_h,
     unsigned int buf_align, unsigned int stride_align, unsigned int size_align,
-    unsigned char *img_data, unsigned int border) {
+    unsigned int border, unsigned char *img_data,
+    aom_alloc_img_data_cb_fn_t alloc_cb, void *cb_priv) {
   unsigned int h, w, s, xcs, ycs, bps;
   unsigned int stride_in_bytes;
 
@@ -118,8 +121,17 @@
 
     if (alloc_size != (size_t)alloc_size) goto fail;
 
-    img->img_data = (uint8_t *)aom_memalign(buf_align, (size_t)alloc_size);
-    img->img_data_owner = 1;
+    if (alloc_cb) {
+      const size_t padded_alloc_size = (size_t)alloc_size + buf_align - 1;
+      img->img_data = (uint8_t *)alloc_cb(cb_priv, padded_alloc_size);
+      if (img->img_data) {
+        img->img_data = align_addr(img->img_data, buf_align);
+      }
+      img->img_data_owner = 0;
+    } else {
+      img->img_data = (uint8_t *)aom_memalign(buf_align, (size_t)alloc_size);
+      img->img_data_owner = 1;
+    }
     img->sz = (size_t)alloc_size;
   }
 
@@ -138,8 +150,10 @@
   img->stride[AOM_PLANE_Y] = stride_in_bytes;
   img->stride[AOM_PLANE_U] = img->stride[AOM_PLANE_V] = stride_in_bytes >> xcs;
 
-  /* Default viewport to entire image */
-  if (!aom_img_set_rect(img, 0, 0, d_w, d_h, border)) return img;
+  /* Default viewport to entire image. (This aom_img_set_rect call always
+   * succeeds.) */
+  aom_img_set_rect(img, 0, 0, d_w, d_h, border);
+  return img;
 
 fail:
   aom_img_free(img);
@@ -149,7 +163,17 @@
 aom_image_t *aom_img_alloc(aom_image_t *img, aom_img_fmt_t fmt,
                            unsigned int d_w, unsigned int d_h,
                            unsigned int align) {
-  return img_alloc_helper(img, fmt, d_w, d_h, align, align, 1, NULL, 0);
+  return img_alloc_helper(img, fmt, d_w, d_h, align, align, 1, 0, NULL, NULL,
+                          NULL);
+}
+
+aom_image_t *aom_img_alloc_with_cb(aom_image_t *img, aom_img_fmt_t fmt,
+                                   unsigned int d_w, unsigned int d_h,
+                                   unsigned int align,
+                                   aom_alloc_img_data_cb_fn_t alloc_cb,
+                                   void *cb_priv) {
+  return img_alloc_helper(img, fmt, d_w, d_h, align, align, 1, 0, NULL,
+                          alloc_cb, cb_priv);
 }
 
 aom_image_t *aom_img_wrap(aom_image_t *img, aom_img_fmt_t fmt, unsigned int d_w,
@@ -157,7 +181,8 @@
                           unsigned char *img_data) {
   /* Set buf_align = 1. It is ignored by img_alloc_helper because img_data is
    * not NULL. */
-  return img_alloc_helper(img, fmt, d_w, d_h, 1, stride_align, 1, img_data, 0);
+  return img_alloc_helper(img, fmt, d_w, d_h, 1, stride_align, 1, 0, img_data,
+                          NULL, NULL);
 }
 
 aom_image_t *aom_img_alloc_with_border(aom_image_t *img, aom_img_fmt_t fmt,
@@ -165,8 +190,8 @@
                                        unsigned int align,
                                        unsigned int size_align,
                                        unsigned int border) {
-  return img_alloc_helper(img, fmt, d_w, d_h, align, align, size_align, NULL,
-                          border);
+  return img_alloc_helper(img, fmt, d_w, d_h, align, align, size_align, border,
+                          NULL, NULL, NULL);
 }
 
 int aom_img_set_rect(aom_image_t *img, unsigned int x, unsigned int y,
diff --git a/av1/av1_dx_iface.c b/av1/av1_dx_iface.c
index b269cba..0de272a 100644
--- a/av1/av1_dx_iface.c
+++ b/av1/av1_dx_iface.c
@@ -16,6 +16,7 @@
 #include "config/aom_version.h"
 
 #include "aom/internal/aom_codec_internal.h"
+#include "aom/internal/aom_image_internal.h"
 #include "aom/aomdx.h"
 #include "aom/aom_decoder.h"
 #include "aom_dsp/bitreader_buffer.h"
@@ -65,7 +66,9 @@
   int num_frame_workers;
   int next_output_worker_id;
 
-  aom_image_t *image_with_grain[MAX_NUM_SPATIAL_LAYERS];
+  aom_image_t image_with_grain;
+  aom_codec_frame_buffer_t grain_image_frame_buffers[MAX_NUM_SPATIAL_LAYERS];
+  size_t num_grain_image_frame_buffers;
   int need_resync;  // wait for key/intra-only frame
   // BufferPool that holds all reference frames. Shared by all the FrameWorkers.
   BufferPool *buffer_pool;
@@ -105,7 +108,7 @@
       // default values
       priv->cfg.cfg.ext_partition = 1;
     }
-    av1_zero(priv->image_with_grain);
+    priv->num_grain_image_frame_buffers = 0;
     // Turn row_mt on by default.
     priv->row_mt = 1;
 
@@ -141,15 +144,16 @@
   }
 
   if (ctx->buffer_pool) {
+    for (size_t i = 0; i < ctx->num_grain_image_frame_buffers; i++) {
+      ctx->buffer_pool->release_fb_cb(ctx->buffer_pool->cb_priv,
+                                      &ctx->grain_image_frame_buffers[i]);
+    }
     av1_free_ref_frame_buffers(ctx->buffer_pool);
     av1_free_internal_frame_buffers(&ctx->buffer_pool->int_frame_buffers);
   }
 
   aom_free(ctx->frame_workers);
   aom_free(ctx->buffer_pool);
-  for (int i = 0; i < MAX_NUM_SPATIAL_LAYERS; i++) {
-    if (ctx->image_with_grain[i]) aom_img_free(ctx->image_with_grain[i]);
-  }
   aom_free(ctx);
   return AOM_CODEC_OK;
 }
@@ -632,6 +636,13 @@
       pbi->num_output_frames = 0;
     }
     unlock_buffer_pool(pool);
+    for (size_t j = 0; j < ctx->num_grain_image_frame_buffers; j++) {
+      pool->release_fb_cb(pool->cb_priv, &ctx->grain_image_frame_buffers[j]);
+      ctx->grain_image_frame_buffers[j].data = NULL;
+      ctx->grain_image_frame_buffers[j].size = 0;
+      ctx->grain_image_frame_buffers[j].priv = NULL;
+    }
+    ctx->num_grain_image_frame_buffers = 0;
   }
 
   /* Sanity checks */
@@ -699,45 +710,50 @@
   return res;
 }
 
+typedef struct {
+  BufferPool *pool;
+  aom_codec_frame_buffer_t *fb;
+} AllocCbParam;
+
+static void *AllocWithGetFrameBufferCb(void *priv, size_t size) {
+  AllocCbParam *param = (AllocCbParam *)priv;
+  if (param->pool->get_fb_cb(param->pool->cb_priv, size, param->fb) < 0)
+    return NULL;
+  if (param->fb->data == NULL || param->fb->size < size) return NULL;
+  return param->fb->data;
+}
+
 // If grain_params->apply_grain is false, returns img. Otherwise, adds film
-// grain to img, saves the result in *grain_img_ptr (allocating *grain_img_ptr
-// if necessary), and returns *grain_img_ptr.
-static aom_image_t *add_grain_if_needed(aom_image_t *img,
-                                        aom_image_t **grain_img_ptr,
+// grain to img, saves the result in grain_img, and returns grain_img.
+static aom_image_t *add_grain_if_needed(aom_codec_alg_priv_t *ctx,
+                                        aom_image_t *img,
+                                        aom_image_t *grain_img,
                                         aom_film_grain_t *grain_params) {
   if (!grain_params->apply_grain) return img;
 
-  aom_image_t *grain_img_buf = *grain_img_ptr;
-
   const int w_even = ALIGN_POWER_OF_TWO(img->d_w, 1);
   const int h_even = ALIGN_POWER_OF_TWO(img->d_h, 1);
 
-  if (grain_img_buf) {
-    const int alloc_w = ALIGN_POWER_OF_TWO(grain_img_buf->d_w, 1);
-    const int alloc_h = ALIGN_POWER_OF_TWO(grain_img_buf->d_h, 1);
-    if (w_even != alloc_w || h_even != alloc_h ||
-        img->fmt != grain_img_buf->fmt) {
-      aom_img_free(grain_img_buf);
-      grain_img_buf = NULL;
-      *grain_img_ptr = NULL;
-    }
-  }
-  if (!grain_img_buf) {
-    grain_img_buf = aom_img_alloc(NULL, img->fmt, w_even, h_even, 16);
-    *grain_img_ptr = grain_img_buf;
+  BufferPool *const pool = ctx->buffer_pool;
+  aom_codec_frame_buffer_t *fb =
+      &ctx->grain_image_frame_buffers[ctx->num_grain_image_frame_buffers];
+  AllocCbParam param;
+  param.pool = pool;
+  param.fb = fb;
+  if (!aom_img_alloc_with_cb(grain_img, img->fmt, w_even, h_even, 16,
+                             AllocWithGetFrameBufferCb, &param)) {
+    return NULL;
   }
 
-  if (grain_img_buf) {
-    grain_img_buf->user_priv = img->user_priv;
-    grain_img_buf->fb_priv = img->fb_priv;
-    if (av1_add_film_grain(grain_params, img, grain_img_buf)) {
-      aom_img_free(grain_img_buf);
-      grain_img_buf = NULL;
-      *grain_img_ptr = NULL;
-    }
+  grain_img->user_priv = img->user_priv;
+  grain_img->fb_priv = fb->priv;
+  if (av1_add_film_grain(grain_params, img, grain_img)) {
+    pool->release_fb_cb(pool->cb_priv, fb);
+    return NULL;
   }
 
-  return grain_img_buf;
+  ctx->num_grain_image_frame_buffers++;
+  return grain_img;
 }
 
 static aom_image_t *decoder_get_frame(aom_codec_alg_priv_t *ctx,
@@ -834,7 +850,7 @@
           img->spatial_id = cm->spatial_layer_id;
           if (cm->skip_film_grain) grain_params->apply_grain = 0;
           aom_image_t *res = add_grain_if_needed(
-              img, &ctx->image_with_grain[*index], grain_params);
+              ctx, img, &ctx->image_with_grain, grain_params);
           if (!res) {
             aom_internal_error(&pbi->common.error, AOM_CODEC_CORRUPT_FRAME,
                                "Grain systhesis failed\n");
diff --git a/test/external_frame_buffer_test.cc b/test/external_frame_buffer_test.cc
index 4938a64..f6e4e0e 100644
--- a/test/external_frame_buffer_test.cc
+++ b/test/external_frame_buffer_test.cc
@@ -117,13 +117,11 @@
   // Checks that the aom_image_t data is contained within the external frame
   // buffer private data passed back in the aom_image_t.
   void CheckImageFrameBuffer(const aom_image_t *img) {
-    if (img->fb_priv != NULL) {
-      const struct ExternalFrameBuffer *const ext_fb =
-          reinterpret_cast<ExternalFrameBuffer *>(img->fb_priv);
+    const struct ExternalFrameBuffer *const ext_fb =
+        reinterpret_cast<ExternalFrameBuffer *>(img->fb_priv);
 
-      ASSERT_TRUE(img->planes[0] >= ext_fb->data &&
-                  img->planes[0] < (ext_fb->data + ext_fb->size));
-    }
+    ASSERT_TRUE(img->planes[0] >= ext_fb->data &&
+                img->planes[0] < (ext_fb->data + ext_fb->size));
   }
 
   int num_used_buffers() const { return num_used_buffers_; }
@@ -266,6 +264,12 @@
     // Check md5 match.
     ASSERT_STREQ(expected_md5, actual_md5)
         << "Md5 checksums don't match: frame number = " << frame_number;
+
+    const struct ExternalFrameBuffer *const ext_fb =
+        reinterpret_cast<ExternalFrameBuffer *>(img.fb_priv);
+
+    ASSERT_TRUE(img.planes[0] >= ext_fb->data &&
+                img.planes[0] < (ext_fb->data + ext_fb->size));
   }
 
   // Callback to get a free external frame buffer. Return value < 0 is an
diff --git a/test/test-data.sha1 b/test/test-data.sha1
index 22bb4cd..b2c8d6e 100644
--- a/test/test-data.sha1
+++ b/test/test-data.sha1
@@ -543,3 +543,7 @@
 b48a717c7c003b8dd23c3c2caed1ac673380fdb3 *av1-1-b8-06-mfmv.ivf
 1424e3cb53e00eb56b94f4c725826274212c42b6 *av1-1-b8-06-mfmv.ivf.md5
 f8724ed96272ddbc35776908f2df7cb9955766a9 *paris_352_288_30.y4m
+11bb40026103182c23a88133edafca369e5575e2 *av1-1-b8-23-film_grain-50.ivf
+c58ccf7ff04711acc559c06f0bfce3c5b14800c3 *av1-1-b8-23-film_grain-50.ivf.md5
+2f883c7e11c21a31f79bd9c809541be90b0c7c4a *av1-1-b10-23-film_grain-50.ivf
+83f2094fca597ad38b4fd623b807de1774c53ffb *av1-1-b10-23-film_grain-50.ivf.md5
diff --git a/test/test_data_util.cmake b/test/test_data_util.cmake
index d646de6..79aa88f 100644
--- a/test/test_data_util.cmake
+++ b/test/test_data_util.cmake
@@ -295,6 +295,8 @@
               "av1-1-b10-00-quantizer-62.ivf.md5"
               "av1-1-b10-00-quantizer-63.ivf"
               "av1-1-b10-00-quantizer-63.ivf.md5"
+              "av1-1-b10-23-film_grain-50.ivf"
+              "av1-1-b10-23-film_grain-50.ivf.md5"
               "av1-1-b8-01-size-16x16.ivf"
               "av1-1-b8-01-size-16x16.ivf.md5"
               "av1-1-b8-01-size-16x18.ivf"
@@ -513,6 +515,8 @@
               "av1-1-b8-22-svc-L1T2.ivf.md5"
               "av1-1-b8-22-svc-L2T2.ivf"
               "av1-1-b8-22-svc-L2T2.ivf.md5"
+              "av1-1-b8-23-film_grain-50.ivf"
+              "av1-1-b8-23-film_grain-50.ivf.md5"
               "invalid-bug-1814.ivf"
               "invalid-bug-1814.ivf.res"
               "invalid-chromium-906381.ivf"
diff --git a/test/test_vectors.cc b/test/test_vectors.cc
index d2cd901..09bbdfd 100644
--- a/test/test_vectors.cc
+++ b/test/test_vectors.cc
@@ -16,243 +16,128 @@
 #define NELEMENTS(x) static_cast<int>(sizeof(x) / sizeof(x[0]))
 
 #if CONFIG_AV1_DECODER
-const char *const kAV1TestVectors[] = { "av1-1-b8-00-quantizer-00.ivf",
-                                        "av1-1-b8-00-quantizer-01.ivf",
-                                        "av1-1-b8-00-quantizer-02.ivf",
-                                        "av1-1-b8-00-quantizer-03.ivf",
-                                        "av1-1-b8-00-quantizer-04.ivf",
-                                        "av1-1-b8-00-quantizer-05.ivf",
-                                        "av1-1-b8-00-quantizer-06.ivf",
-                                        "av1-1-b8-00-quantizer-07.ivf",
-                                        "av1-1-b8-00-quantizer-08.ivf",
-                                        "av1-1-b8-00-quantizer-09.ivf",
-                                        "av1-1-b8-00-quantizer-10.ivf",
-                                        "av1-1-b8-00-quantizer-11.ivf",
-                                        "av1-1-b8-00-quantizer-12.ivf",
-                                        "av1-1-b8-00-quantizer-13.ivf",
-                                        "av1-1-b8-00-quantizer-14.ivf",
-                                        "av1-1-b8-00-quantizer-15.ivf",
-                                        "av1-1-b8-00-quantizer-16.ivf",
-                                        "av1-1-b8-00-quantizer-17.ivf",
-                                        "av1-1-b8-00-quantizer-18.ivf",
-                                        "av1-1-b8-00-quantizer-19.ivf",
-                                        "av1-1-b8-00-quantizer-20.ivf",
-                                        "av1-1-b8-00-quantizer-21.ivf",
-                                        "av1-1-b8-00-quantizer-22.ivf",
-                                        "av1-1-b8-00-quantizer-23.ivf",
-                                        "av1-1-b8-00-quantizer-24.ivf",
-                                        "av1-1-b8-00-quantizer-25.ivf",
-                                        "av1-1-b8-00-quantizer-26.ivf",
-                                        "av1-1-b8-00-quantizer-27.ivf",
-                                        "av1-1-b8-00-quantizer-28.ivf",
-                                        "av1-1-b8-00-quantizer-29.ivf",
-                                        "av1-1-b8-00-quantizer-30.ivf",
-                                        "av1-1-b8-00-quantizer-31.ivf",
-                                        "av1-1-b8-00-quantizer-32.ivf",
-                                        "av1-1-b8-00-quantizer-33.ivf",
-                                        "av1-1-b8-00-quantizer-34.ivf",
-                                        "av1-1-b8-00-quantizer-35.ivf",
-                                        "av1-1-b8-00-quantizer-36.ivf",
-                                        "av1-1-b8-00-quantizer-37.ivf",
-                                        "av1-1-b8-00-quantizer-38.ivf",
-                                        "av1-1-b8-00-quantizer-39.ivf",
-                                        "av1-1-b8-00-quantizer-40.ivf",
-                                        "av1-1-b8-00-quantizer-41.ivf",
-                                        "av1-1-b8-00-quantizer-42.ivf",
-                                        "av1-1-b8-00-quantizer-43.ivf",
-                                        "av1-1-b8-00-quantizer-44.ivf",
-                                        "av1-1-b8-00-quantizer-45.ivf",
-                                        "av1-1-b8-00-quantizer-46.ivf",
-                                        "av1-1-b8-00-quantizer-47.ivf",
-                                        "av1-1-b8-00-quantizer-48.ivf",
-                                        "av1-1-b8-00-quantizer-49.ivf",
-                                        "av1-1-b8-00-quantizer-50.ivf",
-                                        "av1-1-b8-00-quantizer-51.ivf",
-                                        "av1-1-b8-00-quantizer-52.ivf",
-                                        "av1-1-b8-00-quantizer-53.ivf",
-                                        "av1-1-b8-00-quantizer-54.ivf",
-                                        "av1-1-b8-00-quantizer-55.ivf",
-                                        "av1-1-b8-00-quantizer-56.ivf",
-                                        "av1-1-b8-00-quantizer-57.ivf",
-                                        "av1-1-b8-00-quantizer-58.ivf",
-                                        "av1-1-b8-00-quantizer-59.ivf",
-                                        "av1-1-b8-00-quantizer-60.ivf",
-                                        "av1-1-b8-00-quantizer-61.ivf",
-                                        "av1-1-b8-00-quantizer-62.ivf",
-                                        "av1-1-b8-00-quantizer-63.ivf",
-                                        "av1-1-b10-00-quantizer-00.ivf",
-                                        "av1-1-b10-00-quantizer-01.ivf",
-                                        "av1-1-b10-00-quantizer-02.ivf",
-                                        "av1-1-b10-00-quantizer-03.ivf",
-                                        "av1-1-b10-00-quantizer-04.ivf",
-                                        "av1-1-b10-00-quantizer-05.ivf",
-                                        "av1-1-b10-00-quantizer-06.ivf",
-                                        "av1-1-b10-00-quantizer-07.ivf",
-                                        "av1-1-b10-00-quantizer-08.ivf",
-                                        "av1-1-b10-00-quantizer-09.ivf",
-                                        "av1-1-b10-00-quantizer-10.ivf",
-                                        "av1-1-b10-00-quantizer-11.ivf",
-                                        "av1-1-b10-00-quantizer-12.ivf",
-                                        "av1-1-b10-00-quantizer-13.ivf",
-                                        "av1-1-b10-00-quantizer-14.ivf",
-                                        "av1-1-b10-00-quantizer-15.ivf",
-                                        "av1-1-b10-00-quantizer-16.ivf",
-                                        "av1-1-b10-00-quantizer-17.ivf",
-                                        "av1-1-b10-00-quantizer-18.ivf",
-                                        "av1-1-b10-00-quantizer-19.ivf",
-                                        "av1-1-b10-00-quantizer-20.ivf",
-                                        "av1-1-b10-00-quantizer-21.ivf",
-                                        "av1-1-b10-00-quantizer-22.ivf",
-                                        "av1-1-b10-00-quantizer-23.ivf",
-                                        "av1-1-b10-00-quantizer-24.ivf",
-                                        "av1-1-b10-00-quantizer-25.ivf",
-                                        "av1-1-b10-00-quantizer-26.ivf",
-                                        "av1-1-b10-00-quantizer-27.ivf",
-                                        "av1-1-b10-00-quantizer-28.ivf",
-                                        "av1-1-b10-00-quantizer-29.ivf",
-                                        "av1-1-b10-00-quantizer-30.ivf",
-                                        "av1-1-b10-00-quantizer-31.ivf",
-                                        "av1-1-b10-00-quantizer-32.ivf",
-                                        "av1-1-b10-00-quantizer-33.ivf",
-                                        "av1-1-b10-00-quantizer-34.ivf",
-                                        "av1-1-b10-00-quantizer-35.ivf",
-                                        "av1-1-b10-00-quantizer-36.ivf",
-                                        "av1-1-b10-00-quantizer-37.ivf",
-                                        "av1-1-b10-00-quantizer-38.ivf",
-                                        "av1-1-b10-00-quantizer-39.ivf",
-                                        "av1-1-b10-00-quantizer-40.ivf",
-                                        "av1-1-b10-00-quantizer-41.ivf",
-                                        "av1-1-b10-00-quantizer-42.ivf",
-                                        "av1-1-b10-00-quantizer-43.ivf",
-                                        "av1-1-b10-00-quantizer-44.ivf",
-                                        "av1-1-b10-00-quantizer-45.ivf",
-                                        "av1-1-b10-00-quantizer-46.ivf",
-                                        "av1-1-b10-00-quantizer-47.ivf",
-                                        "av1-1-b10-00-quantizer-48.ivf",
-                                        "av1-1-b10-00-quantizer-49.ivf",
-                                        "av1-1-b10-00-quantizer-50.ivf",
-                                        "av1-1-b10-00-quantizer-51.ivf",
-                                        "av1-1-b10-00-quantizer-52.ivf",
-                                        "av1-1-b10-00-quantizer-53.ivf",
-                                        "av1-1-b10-00-quantizer-54.ivf",
-                                        "av1-1-b10-00-quantizer-55.ivf",
-                                        "av1-1-b10-00-quantizer-56.ivf",
-                                        "av1-1-b10-00-quantizer-57.ivf",
-                                        "av1-1-b10-00-quantizer-58.ivf",
-                                        "av1-1-b10-00-quantizer-59.ivf",
-                                        "av1-1-b10-00-quantizer-60.ivf",
-                                        "av1-1-b10-00-quantizer-61.ivf",
-                                        "av1-1-b10-00-quantizer-62.ivf",
-                                        "av1-1-b10-00-quantizer-63.ivf",
-                                        "av1-1-b8-01-size-16x16.ivf",
-                                        "av1-1-b8-01-size-16x18.ivf",
-                                        "av1-1-b8-01-size-16x32.ivf",
-                                        "av1-1-b8-01-size-16x34.ivf",
-                                        "av1-1-b8-01-size-16x64.ivf",
-                                        "av1-1-b8-01-size-16x66.ivf",
-                                        "av1-1-b8-01-size-18x16.ivf",
-                                        "av1-1-b8-01-size-18x18.ivf",
-                                        "av1-1-b8-01-size-18x32.ivf",
-                                        "av1-1-b8-01-size-18x34.ivf",
-                                        "av1-1-b8-01-size-18x64.ivf",
-                                        "av1-1-b8-01-size-18x66.ivf",
-                                        "av1-1-b8-01-size-196x196.ivf",
-                                        "av1-1-b8-01-size-196x198.ivf",
-                                        "av1-1-b8-01-size-196x200.ivf",
-                                        "av1-1-b8-01-size-196x202.ivf",
-                                        "av1-1-b8-01-size-196x208.ivf",
-                                        "av1-1-b8-01-size-196x210.ivf",
-                                        "av1-1-b8-01-size-196x224.ivf",
-                                        "av1-1-b8-01-size-196x226.ivf",
-                                        "av1-1-b8-01-size-198x196.ivf",
-                                        "av1-1-b8-01-size-198x198.ivf",
-                                        "av1-1-b8-01-size-198x200.ivf",
-                                        "av1-1-b8-01-size-198x202.ivf",
-                                        "av1-1-b8-01-size-198x208.ivf",
-                                        "av1-1-b8-01-size-198x210.ivf",
-                                        "av1-1-b8-01-size-198x224.ivf",
-                                        "av1-1-b8-01-size-198x226.ivf",
-                                        "av1-1-b8-01-size-200x196.ivf",
-                                        "av1-1-b8-01-size-200x198.ivf",
-                                        "av1-1-b8-01-size-200x200.ivf",
-                                        "av1-1-b8-01-size-200x202.ivf",
-                                        "av1-1-b8-01-size-200x208.ivf",
-                                        "av1-1-b8-01-size-200x210.ivf",
-                                        "av1-1-b8-01-size-200x224.ivf",
-                                        "av1-1-b8-01-size-200x226.ivf",
-                                        "av1-1-b8-01-size-202x196.ivf",
-                                        "av1-1-b8-01-size-202x198.ivf",
-                                        "av1-1-b8-01-size-202x200.ivf",
-                                        "av1-1-b8-01-size-202x202.ivf",
-                                        "av1-1-b8-01-size-202x208.ivf",
-                                        "av1-1-b8-01-size-202x210.ivf",
-                                        "av1-1-b8-01-size-202x224.ivf",
-                                        "av1-1-b8-01-size-202x226.ivf",
-                                        "av1-1-b8-01-size-208x196.ivf",
-                                        "av1-1-b8-01-size-208x198.ivf",
-                                        "av1-1-b8-01-size-208x200.ivf",
-                                        "av1-1-b8-01-size-208x202.ivf",
-                                        "av1-1-b8-01-size-208x208.ivf",
-                                        "av1-1-b8-01-size-208x210.ivf",
-                                        "av1-1-b8-01-size-208x224.ivf",
-                                        "av1-1-b8-01-size-208x226.ivf",
-                                        "av1-1-b8-01-size-210x196.ivf",
-                                        "av1-1-b8-01-size-210x198.ivf",
-                                        "av1-1-b8-01-size-210x200.ivf",
-                                        "av1-1-b8-01-size-210x202.ivf",
-                                        "av1-1-b8-01-size-210x208.ivf",
-                                        "av1-1-b8-01-size-210x210.ivf",
-                                        "av1-1-b8-01-size-210x224.ivf",
-                                        "av1-1-b8-01-size-210x226.ivf",
-                                        "av1-1-b8-01-size-224x196.ivf",
-                                        "av1-1-b8-01-size-224x198.ivf",
-                                        "av1-1-b8-01-size-224x200.ivf",
-                                        "av1-1-b8-01-size-224x202.ivf",
-                                        "av1-1-b8-01-size-224x208.ivf",
-                                        "av1-1-b8-01-size-224x210.ivf",
-                                        "av1-1-b8-01-size-224x224.ivf",
-                                        "av1-1-b8-01-size-224x226.ivf",
-                                        "av1-1-b8-01-size-226x196.ivf",
-                                        "av1-1-b8-01-size-226x198.ivf",
-                                        "av1-1-b8-01-size-226x200.ivf",
-                                        "av1-1-b8-01-size-226x202.ivf",
-                                        "av1-1-b8-01-size-226x208.ivf",
-                                        "av1-1-b8-01-size-226x210.ivf",
-                                        "av1-1-b8-01-size-226x224.ivf",
-                                        "av1-1-b8-01-size-226x226.ivf",
-                                        "av1-1-b8-01-size-32x16.ivf",
-                                        "av1-1-b8-01-size-32x18.ivf",
-                                        "av1-1-b8-01-size-32x32.ivf",
-                                        "av1-1-b8-01-size-32x34.ivf",
-                                        "av1-1-b8-01-size-32x64.ivf",
-                                        "av1-1-b8-01-size-32x66.ivf",
-                                        "av1-1-b8-01-size-34x16.ivf",
-                                        "av1-1-b8-01-size-34x18.ivf",
-                                        "av1-1-b8-01-size-34x32.ivf",
-                                        "av1-1-b8-01-size-34x34.ivf",
-                                        "av1-1-b8-01-size-34x64.ivf",
-                                        "av1-1-b8-01-size-34x66.ivf",
-                                        "av1-1-b8-01-size-64x16.ivf",
-                                        "av1-1-b8-01-size-64x18.ivf",
-                                        "av1-1-b8-01-size-64x32.ivf",
-                                        "av1-1-b8-01-size-64x34.ivf",
-                                        "av1-1-b8-01-size-64x64.ivf",
-                                        "av1-1-b8-01-size-64x66.ivf",
-                                        "av1-1-b8-01-size-66x16.ivf",
-                                        "av1-1-b8-01-size-66x18.ivf",
-                                        "av1-1-b8-01-size-66x32.ivf",
-                                        "av1-1-b8-01-size-66x34.ivf",
-                                        "av1-1-b8-01-size-66x64.ivf",
-                                        "av1-1-b8-01-size-66x66.ivf",
-                                        "av1-1-b8-02-allintra.ivf",
-                                        "av1-1-b8-03-sizedown.mkv",
-                                        "av1-1-b8-03-sizeup.mkv",
-                                        "av1-1-b8-04-cdfupdate.ivf",
-                                        "av1-1-b8-05-mv.ivf",
-                                        "av1-1-b8-06-mfmv.ivf",
-                                        "av1-1-b8-22-svc-L1T2.ivf",
-                                        "av1-1-b8-22-svc-L2T1.ivf",
-                                        "av1-1-b8-22-svc-L2T2.ivf" };
+const char *const kAV1TestVectors[] = {
+  "av1-1-b8-00-quantizer-00.ivf",   "av1-1-b8-00-quantizer-01.ivf",
+  "av1-1-b8-00-quantizer-02.ivf",   "av1-1-b8-00-quantizer-03.ivf",
+  "av1-1-b8-00-quantizer-04.ivf",   "av1-1-b8-00-quantizer-05.ivf",
+  "av1-1-b8-00-quantizer-06.ivf",   "av1-1-b8-00-quantizer-07.ivf",
+  "av1-1-b8-00-quantizer-08.ivf",   "av1-1-b8-00-quantizer-09.ivf",
+  "av1-1-b8-00-quantizer-10.ivf",   "av1-1-b8-00-quantizer-11.ivf",
+  "av1-1-b8-00-quantizer-12.ivf",   "av1-1-b8-00-quantizer-13.ivf",
+  "av1-1-b8-00-quantizer-14.ivf",   "av1-1-b8-00-quantizer-15.ivf",
+  "av1-1-b8-00-quantizer-16.ivf",   "av1-1-b8-00-quantizer-17.ivf",
+  "av1-1-b8-00-quantizer-18.ivf",   "av1-1-b8-00-quantizer-19.ivf",
+  "av1-1-b8-00-quantizer-20.ivf",   "av1-1-b8-00-quantizer-21.ivf",
+  "av1-1-b8-00-quantizer-22.ivf",   "av1-1-b8-00-quantizer-23.ivf",
+  "av1-1-b8-00-quantizer-24.ivf",   "av1-1-b8-00-quantizer-25.ivf",
+  "av1-1-b8-00-quantizer-26.ivf",   "av1-1-b8-00-quantizer-27.ivf",
+  "av1-1-b8-00-quantizer-28.ivf",   "av1-1-b8-00-quantizer-29.ivf",
+  "av1-1-b8-00-quantizer-30.ivf",   "av1-1-b8-00-quantizer-31.ivf",
+  "av1-1-b8-00-quantizer-32.ivf",   "av1-1-b8-00-quantizer-33.ivf",
+  "av1-1-b8-00-quantizer-34.ivf",   "av1-1-b8-00-quantizer-35.ivf",
+  "av1-1-b8-00-quantizer-36.ivf",   "av1-1-b8-00-quantizer-37.ivf",
+  "av1-1-b8-00-quantizer-38.ivf",   "av1-1-b8-00-quantizer-39.ivf",
+  "av1-1-b8-00-quantizer-40.ivf",   "av1-1-b8-00-quantizer-41.ivf",
+  "av1-1-b8-00-quantizer-42.ivf",   "av1-1-b8-00-quantizer-43.ivf",
+  "av1-1-b8-00-quantizer-44.ivf",   "av1-1-b8-00-quantizer-45.ivf",
+  "av1-1-b8-00-quantizer-46.ivf",   "av1-1-b8-00-quantizer-47.ivf",
+  "av1-1-b8-00-quantizer-48.ivf",   "av1-1-b8-00-quantizer-49.ivf",
+  "av1-1-b8-00-quantizer-50.ivf",   "av1-1-b8-00-quantizer-51.ivf",
+  "av1-1-b8-00-quantizer-52.ivf",   "av1-1-b8-00-quantizer-53.ivf",
+  "av1-1-b8-00-quantizer-54.ivf",   "av1-1-b8-00-quantizer-55.ivf",
+  "av1-1-b8-00-quantizer-56.ivf",   "av1-1-b8-00-quantizer-57.ivf",
+  "av1-1-b8-00-quantizer-58.ivf",   "av1-1-b8-00-quantizer-59.ivf",
+  "av1-1-b8-00-quantizer-60.ivf",   "av1-1-b8-00-quantizer-61.ivf",
+  "av1-1-b8-00-quantizer-62.ivf",   "av1-1-b8-00-quantizer-63.ivf",
+  "av1-1-b10-00-quantizer-00.ivf",  "av1-1-b10-00-quantizer-01.ivf",
+  "av1-1-b10-00-quantizer-02.ivf",  "av1-1-b10-00-quantizer-03.ivf",
+  "av1-1-b10-00-quantizer-04.ivf",  "av1-1-b10-00-quantizer-05.ivf",
+  "av1-1-b10-00-quantizer-06.ivf",  "av1-1-b10-00-quantizer-07.ivf",
+  "av1-1-b10-00-quantizer-08.ivf",  "av1-1-b10-00-quantizer-09.ivf",
+  "av1-1-b10-00-quantizer-10.ivf",  "av1-1-b10-00-quantizer-11.ivf",
+  "av1-1-b10-00-quantizer-12.ivf",  "av1-1-b10-00-quantizer-13.ivf",
+  "av1-1-b10-00-quantizer-14.ivf",  "av1-1-b10-00-quantizer-15.ivf",
+  "av1-1-b10-00-quantizer-16.ivf",  "av1-1-b10-00-quantizer-17.ivf",
+  "av1-1-b10-00-quantizer-18.ivf",  "av1-1-b10-00-quantizer-19.ivf",
+  "av1-1-b10-00-quantizer-20.ivf",  "av1-1-b10-00-quantizer-21.ivf",
+  "av1-1-b10-00-quantizer-22.ivf",  "av1-1-b10-00-quantizer-23.ivf",
+  "av1-1-b10-00-quantizer-24.ivf",  "av1-1-b10-00-quantizer-25.ivf",
+  "av1-1-b10-00-quantizer-26.ivf",  "av1-1-b10-00-quantizer-27.ivf",
+  "av1-1-b10-00-quantizer-28.ivf",  "av1-1-b10-00-quantizer-29.ivf",
+  "av1-1-b10-00-quantizer-30.ivf",  "av1-1-b10-00-quantizer-31.ivf",
+  "av1-1-b10-00-quantizer-32.ivf",  "av1-1-b10-00-quantizer-33.ivf",
+  "av1-1-b10-00-quantizer-34.ivf",  "av1-1-b10-00-quantizer-35.ivf",
+  "av1-1-b10-00-quantizer-36.ivf",  "av1-1-b10-00-quantizer-37.ivf",
+  "av1-1-b10-00-quantizer-38.ivf",  "av1-1-b10-00-quantizer-39.ivf",
+  "av1-1-b10-00-quantizer-40.ivf",  "av1-1-b10-00-quantizer-41.ivf",
+  "av1-1-b10-00-quantizer-42.ivf",  "av1-1-b10-00-quantizer-43.ivf",
+  "av1-1-b10-00-quantizer-44.ivf",  "av1-1-b10-00-quantizer-45.ivf",
+  "av1-1-b10-00-quantizer-46.ivf",  "av1-1-b10-00-quantizer-47.ivf",
+  "av1-1-b10-00-quantizer-48.ivf",  "av1-1-b10-00-quantizer-49.ivf",
+  "av1-1-b10-00-quantizer-50.ivf",  "av1-1-b10-00-quantizer-51.ivf",
+  "av1-1-b10-00-quantizer-52.ivf",  "av1-1-b10-00-quantizer-53.ivf",
+  "av1-1-b10-00-quantizer-54.ivf",  "av1-1-b10-00-quantizer-55.ivf",
+  "av1-1-b10-00-quantizer-56.ivf",  "av1-1-b10-00-quantizer-57.ivf",
+  "av1-1-b10-00-quantizer-58.ivf",  "av1-1-b10-00-quantizer-59.ivf",
+  "av1-1-b10-00-quantizer-60.ivf",  "av1-1-b10-00-quantizer-61.ivf",
+  "av1-1-b10-00-quantizer-62.ivf",  "av1-1-b10-00-quantizer-63.ivf",
+  "av1-1-b10-23-film_grain-50.ivf", "av1-1-b8-01-size-16x16.ivf",
+  "av1-1-b8-01-size-16x18.ivf",     "av1-1-b8-01-size-16x32.ivf",
+  "av1-1-b8-01-size-16x34.ivf",     "av1-1-b8-01-size-16x64.ivf",
+  "av1-1-b8-01-size-16x66.ivf",     "av1-1-b8-01-size-18x16.ivf",
+  "av1-1-b8-01-size-18x18.ivf",     "av1-1-b8-01-size-18x32.ivf",
+  "av1-1-b8-01-size-18x34.ivf",     "av1-1-b8-01-size-18x64.ivf",
+  "av1-1-b8-01-size-18x66.ivf",     "av1-1-b8-01-size-196x196.ivf",
+  "av1-1-b8-01-size-196x198.ivf",   "av1-1-b8-01-size-196x200.ivf",
+  "av1-1-b8-01-size-196x202.ivf",   "av1-1-b8-01-size-196x208.ivf",
+  "av1-1-b8-01-size-196x210.ivf",   "av1-1-b8-01-size-196x224.ivf",
+  "av1-1-b8-01-size-196x226.ivf",   "av1-1-b8-01-size-198x196.ivf",
+  "av1-1-b8-01-size-198x198.ivf",   "av1-1-b8-01-size-198x200.ivf",
+  "av1-1-b8-01-size-198x202.ivf",   "av1-1-b8-01-size-198x208.ivf",
+  "av1-1-b8-01-size-198x210.ivf",   "av1-1-b8-01-size-198x224.ivf",
+  "av1-1-b8-01-size-198x226.ivf",   "av1-1-b8-01-size-200x196.ivf",
+  "av1-1-b8-01-size-200x198.ivf",   "av1-1-b8-01-size-200x200.ivf",
+  "av1-1-b8-01-size-200x202.ivf",   "av1-1-b8-01-size-200x208.ivf",
+  "av1-1-b8-01-size-200x210.ivf",   "av1-1-b8-01-size-200x224.ivf",
+  "av1-1-b8-01-size-200x226.ivf",   "av1-1-b8-01-size-202x196.ivf",
+  "av1-1-b8-01-size-202x198.ivf",   "av1-1-b8-01-size-202x200.ivf",
+  "av1-1-b8-01-size-202x202.ivf",   "av1-1-b8-01-size-202x208.ivf",
+  "av1-1-b8-01-size-202x210.ivf",   "av1-1-b8-01-size-202x224.ivf",
+  "av1-1-b8-01-size-202x226.ivf",   "av1-1-b8-01-size-208x196.ivf",
+  "av1-1-b8-01-size-208x198.ivf",   "av1-1-b8-01-size-208x200.ivf",
+  "av1-1-b8-01-size-208x202.ivf",   "av1-1-b8-01-size-208x208.ivf",
+  "av1-1-b8-01-size-208x210.ivf",   "av1-1-b8-01-size-208x224.ivf",
+  "av1-1-b8-01-size-208x226.ivf",   "av1-1-b8-01-size-210x196.ivf",
+  "av1-1-b8-01-size-210x198.ivf",   "av1-1-b8-01-size-210x200.ivf",
+  "av1-1-b8-01-size-210x202.ivf",   "av1-1-b8-01-size-210x208.ivf",
+  "av1-1-b8-01-size-210x210.ivf",   "av1-1-b8-01-size-210x224.ivf",
+  "av1-1-b8-01-size-210x226.ivf",   "av1-1-b8-01-size-224x196.ivf",
+  "av1-1-b8-01-size-224x198.ivf",   "av1-1-b8-01-size-224x200.ivf",
+  "av1-1-b8-01-size-224x202.ivf",   "av1-1-b8-01-size-224x208.ivf",
+  "av1-1-b8-01-size-224x210.ivf",   "av1-1-b8-01-size-224x224.ivf",
+  "av1-1-b8-01-size-224x226.ivf",   "av1-1-b8-01-size-226x196.ivf",
+  "av1-1-b8-01-size-226x198.ivf",   "av1-1-b8-01-size-226x200.ivf",
+  "av1-1-b8-01-size-226x202.ivf",   "av1-1-b8-01-size-226x208.ivf",
+  "av1-1-b8-01-size-226x210.ivf",   "av1-1-b8-01-size-226x224.ivf",
+  "av1-1-b8-01-size-226x226.ivf",   "av1-1-b8-01-size-32x16.ivf",
+  "av1-1-b8-01-size-32x18.ivf",     "av1-1-b8-01-size-32x32.ivf",
+  "av1-1-b8-01-size-32x34.ivf",     "av1-1-b8-01-size-32x64.ivf",
+  "av1-1-b8-01-size-32x66.ivf",     "av1-1-b8-01-size-34x16.ivf",
+  "av1-1-b8-01-size-34x18.ivf",     "av1-1-b8-01-size-34x32.ivf",
+  "av1-1-b8-01-size-34x34.ivf",     "av1-1-b8-01-size-34x64.ivf",
+  "av1-1-b8-01-size-34x66.ivf",     "av1-1-b8-01-size-64x16.ivf",
+  "av1-1-b8-01-size-64x18.ivf",     "av1-1-b8-01-size-64x32.ivf",
+  "av1-1-b8-01-size-64x34.ivf",     "av1-1-b8-01-size-64x64.ivf",
+  "av1-1-b8-01-size-64x66.ivf",     "av1-1-b8-01-size-66x16.ivf",
+  "av1-1-b8-01-size-66x18.ivf",     "av1-1-b8-01-size-66x32.ivf",
+  "av1-1-b8-01-size-66x34.ivf",     "av1-1-b8-01-size-66x64.ivf",
+  "av1-1-b8-01-size-66x66.ivf",     "av1-1-b8-02-allintra.ivf",
+  "av1-1-b8-03-sizedown.mkv",       "av1-1-b8-03-sizeup.mkv",
+  "av1-1-b8-04-cdfupdate.ivf",      "av1-1-b8-05-mv.ivf",
+  "av1-1-b8-06-mfmv.ivf",           "av1-1-b8-22-svc-L1T2.ivf",
+  "av1-1-b8-22-svc-L2T1.ivf",       "av1-1-b8-22-svc-L2T2.ivf",
+  "av1-1-b8-23-film_grain-50.ivf"
+};
 const int kNumAV1TestVectors = NELEMENTS(kAV1TestVectors);
 #endif  // CONFIG_AV1_DECODER