Revert "Extend the external fb interface to allocate individual planes."

This reverts commit 6dd7f2b50a65373aa906d678cb5a29fb65531a55.

conversion warnings, crashes in 32-bit builds

Change-Id: I529ead34cd93c862dd07c9a29d8542dda2fc20ea
diff --git a/test/external_frame_buffer_test.cc b/test/external_frame_buffer_test.cc
index 0fefbb2..2570f44 100644
--- a/test/external_frame_buffer_test.cc
+++ b/test/external_frame_buffer_test.cc
@@ -23,16 +23,9 @@
 
 namespace {
 
-const int kCodedFrameBufferTypeParam = 1;
-const int kVideoNameParam = 2;
+const int kVideoNameParam = 1;
 
 struct ExternalFrameBuffer {
-  // The first two fields are used when fb->type is equal to
-  // VPX_CODEC_FRAME_BUFFER_TYPE_PLANES
-  uint8_t *plane[VP9_MAXIMUM_EXTERNAL_PLANES];
-  int stride[VP9_MAXIMUM_EXTERNAL_PLANES];
-  // The following two fields are used when fb->type is equal to
-  // VPX_CODEC_FRAME_BUFFER_TYPE_SIZE
   uint8_t *data;
   size_t size;
   int in_use;
@@ -41,17 +34,12 @@
 // Class to manipulate a list of external frame buffers.
 class ExternalFrameBufferList {
  public:
-  explicit ExternalFrameBufferList(vpx_codec_frame_buffer_type_t type)
+  ExternalFrameBufferList()
       : num_buffers_(0),
-        ext_fb_list_(NULL),
-        type_(type),
-        alignment_(32) {}
+        ext_fb_list_(NULL) {}
 
   virtual ~ExternalFrameBufferList() {
     for (int i = 0; i < num_buffers_; ++i) {
-      for (int plane = 0; plane < VP9_MAXIMUM_EXTERNAL_PLANES; ++plane) {
-        delete [] ext_fb_list_[i].plane[plane];
-      }
       delete [] ext_fb_list_[i].data;
     }
     delete [] ext_fb_list_;
@@ -75,44 +63,17 @@
   // external frame buffer. Returns < 0 on an error.
   int GetFreeFrameBuffer(size_t min_size, vpx_codec_frame_buffer_t *fb) {
     EXPECT_TRUE(fb != NULL);
-    EXPECT_TRUE(fb->fmt == VPX_IMG_FMT_I420 || fb->fmt == VPX_IMG_FMT_I444 ||
-                fb->fmt == VPX_IMG_FMT_I422 || fb->fmt == VPX_IMG_FMT_I440)
-        << " fmt is: " << fb->fmt;
-
     const int idx = FindFreeBufferIndex();
     if (idx == num_buffers_)
       return -1;
 
-    if (type_ == VPX_CODEC_FRAME_BUFFER_TYPE_SIZE) {
-      if (ext_fb_list_[idx].size < min_size) {
-        delete [] ext_fb_list_[idx].data;
-        ext_fb_list_[idx].data = new uint8_t[min_size];
-        memset(ext_fb_list_[idx].data, 0, min_size);
-        ext_fb_list_[idx].size = min_size;
-      }
-    } else {
-      EXPECT_EQ(VPX_CODEC_FRAME_BUFFER_TYPE_PLANES, type_);
-      for (int plane = 0; plane < 3; ++plane) {
-        size_t plane_stride = fb->width;
-        size_t plane_height = fb->height;
-
-        if (plane > 0 && fb->fmt != VPX_IMG_FMT_I444) {
-          if (fb->fmt != VPX_IMG_FMT_I440)
-            plane_stride /= 2;
-          if (fb->fmt == VPX_IMG_FMT_I420 || fb->fmt == VPX_IMG_FMT_I440)
-            plane_height /= 2;
-        }
-        plane_stride += alignment_ - plane_stride % alignment_;
-
-        delete [] ext_fb_list_[idx].plane[plane];
-        ext_fb_list_[idx].plane[plane] =
-            new uint8_t[plane_height * plane_stride];
-        memset(ext_fb_list_[idx].plane[plane], 0, plane_height * plane_stride);
-        ext_fb_list_[idx].stride[plane] = plane_stride;
-      }
+    if (ext_fb_list_[idx].size < min_size) {
+      delete [] ext_fb_list_[idx].data;
+      ext_fb_list_[idx].data = new uint8_t[min_size];
+      memset(ext_fb_list_[idx].data, 0, min_size);
+      ext_fb_list_[idx].size = min_size;
     }
 
-    fb->type = type_;
     SetFrameBuffer(idx, fb);
     return 0;
   }
@@ -125,27 +86,12 @@
     if (idx == num_buffers_)
       return -1;
 
-    if (type_ == VPX_CODEC_FRAME_BUFFER_TYPE_SIZE) {
+    if (ext_fb_list_[idx].size < min_size) {
       delete [] ext_fb_list_[idx].data;
       ext_fb_list_[idx].data = NULL;
       ext_fb_list_[idx].size = min_size;
-    } else {
-      EXPECT_EQ(VPX_CODEC_FRAME_BUFFER_TYPE_PLANES, type_);
-      for (int plane = 0; plane < 3; ++plane) {
-        size_t plane_stride = fb->width;
-        if (plane > 0 && fb->fmt != VPX_IMG_FMT_I444) {
-          if (fb->fmt != VPX_IMG_FMT_I440)
-            plane_stride /= 2;
-        }
-        plane_stride += alignment_ - plane_stride % alignment_;
-
-        delete [] ext_fb_list_[idx].plane[plane];
-        ext_fb_list_[idx].plane[plane] = NULL;
-        ext_fb_list_[idx].stride[plane] = plane_stride;
-      }
     }
 
-    fb->type = type_;
     SetFrameBuffer(idx, fb);
     return 0;
   }
@@ -174,22 +120,10 @@
     if (img->fb_priv != NULL) {
       const struct ExternalFrameBuffer *const ext_fb =
           reinterpret_cast<ExternalFrameBuffer*>(img->fb_priv);
-      if (ext_fb->data != NULL) {
-        ASSERT_TRUE(img->planes[0] >= ext_fb->data &&
-                    img->planes[0] < (ext_fb->data + ext_fb->size));
-      } else {
-        for (int plane = 0; plane < VP9_MAXIMUM_EXTERNAL_PLANES; ++plane) {
-          if (ext_fb->stride[plane]) {
-            EXPECT_EQ(img->planes[plane], ext_fb->plane[plane]);
-            EXPECT_EQ(img->stride[plane], ext_fb->stride[plane]);
-          }
-        }
-      }
-    }
-  }
 
-  void set_alignment(int alignment) {
-    alignment_ = alignment;
+      ASSERT_TRUE(img->planes[0] >= ext_fb->data &&
+                  img->planes[0] < (ext_fb->data + ext_fb->size));
+    }
   }
 
  private:
@@ -211,10 +145,6 @@
     ASSERT_TRUE(fb != NULL);
     fb->data = ext_fb_list_[idx].data;
     fb->size = ext_fb_list_[idx].size;
-    for (int plane = 0; plane < VP9_MAXIMUM_EXTERNAL_PLANES; ++plane) {
-      fb->plane[plane] = ext_fb_list_[idx].plane[plane];
-      fb->stride[plane] = ext_fb_list_[idx].stride[plane];
-    }
     ASSERT_EQ(0, ext_fb_list_[idx].in_use);
     ext_fb_list_[idx].in_use = 1;
     fb->priv = &ext_fb_list_[idx];
@@ -222,8 +152,6 @@
 
   int num_buffers_;
   ExternalFrameBuffer *ext_fb_list_;
-  vpx_codec_frame_buffer_type_t type_;
-  int alignment_;
 };
 
 #if CONFIG_WEBM_IO
@@ -275,14 +203,12 @@
 // Class for testing passing in external frame buffers to libvpx.
 class ExternalFrameBufferMD5Test
     : public ::libvpx_test::DecoderTest,
-      public ::libvpx_test::CodecTestWith2Params<vpx_codec_frame_buffer_type_t,
-                                                 const char*> {
+      public ::libvpx_test::CodecTestWithParam<const char*> {
  protected:
   ExternalFrameBufferMD5Test()
       : DecoderTest(GET_PARAM(::libvpx_test::kCodecFactoryParam)),
         md5_file_(NULL),
-        num_buffers_(0),
-        fb_list_(GET_PARAM(kCodedFrameBufferTypeParam)) {}
+        num_buffers_(0) {}
 
   virtual ~ExternalFrameBufferMD5Test() {
     if (md5_file_ != NULL)
@@ -358,15 +284,12 @@
 const char kVP9TestFile[] = "vp90-2-02-size-lf-1920x1080.webm";
 
 // Class for testing passing in external frame buffers to libvpx.
-class ExternalFrameBufferTest
-    : public ::libvpx_test::CodecTestWithParam<vpx_codec_frame_buffer_type_t> {
+class ExternalFrameBufferTest : public ::testing::Test {
  protected:
   ExternalFrameBufferTest()
       : video_(NULL),
         decoder_(NULL),
-        num_buffers_(0),
-        frame_buffer_functions_set_(false),
-        fb_list_(GET_PARAM(kCodedFrameBufferTypeParam)) {}
+        num_buffers_(0) {}
 
   virtual void SetUp() {
     video_ = new libvpx_test::WebMVideoSource(kVP9TestFile);
@@ -389,7 +312,6 @@
       int num_buffers,
       vpx_get_frame_buffer_cb_fn_t cb_get,
       vpx_release_frame_buffer_cb_fn_t cb_release) {
-    frame_buffer_functions_set_ = true;
     if (num_buffers > 0) {
       num_buffers_ = num_buffers;
       EXPECT_TRUE(fb_list_.CreateBufferList(num_buffers_));
@@ -398,10 +320,6 @@
     return decoder_->SetFrameBufferFunctions(cb_get, cb_release, &fb_list_);
   }
 
-  void SetBufferAlignment(int alignment) {
-    fb_list_.set_alignment(alignment);
-  }
-
   vpx_codec_err_t DecodeOneFrame() {
     const vpx_codec_err_t res =
         decoder_->DecodeFrame(video_->cxdata(), video_->frame_size());
@@ -429,15 +347,13 @@
 
     // Get decompressed data
     while ((img = dec_iter.Next()) != NULL) {
-      if (frame_buffer_functions_set_)
-        fb_list_.CheckXImageFrameBuffer(img);
+      fb_list_.CheckXImageFrameBuffer(img);
     }
   }
 
   libvpx_test::WebMVideoSource *video_;
   libvpx_test::VP9Decoder *decoder_;
   int num_buffers_;
-  bool frame_buffer_functions_set_;
   ExternalFrameBufferList fb_list_;
 };
 #endif  // CONFIG_WEBM_IO
@@ -488,7 +404,7 @@
 }
 
 #if CONFIG_WEBM_IO
-TEST_P(ExternalFrameBufferTest, MinFrameBuffers) {
+TEST_F(ExternalFrameBufferTest, MinFrameBuffers) {
   // Minimum number of external frame buffers for VP9 is
   // #VP9_MAXIMUM_REF_BUFFERS + #VPX_MAXIMUM_WORK_BUFFERS.
   const int num_buffers = VP9_MAXIMUM_REF_BUFFERS + VPX_MAXIMUM_WORK_BUFFERS;
@@ -498,7 +414,7 @@
   ASSERT_EQ(VPX_CODEC_OK, DecodeRemainingFrames());
 }
 
-TEST_P(ExternalFrameBufferTest, EightJitterBuffers) {
+TEST_F(ExternalFrameBufferTest, EightJitterBuffers) {
   // Number of buffers equals #VP9_MAXIMUM_REF_BUFFERS +
   // #VPX_MAXIMUM_WORK_BUFFERS + eight jitter buffers.
   const int jitter_buffers = 8;
@@ -510,7 +426,7 @@
   ASSERT_EQ(VPX_CODEC_OK, DecodeRemainingFrames());
 }
 
-TEST_P(ExternalFrameBufferTest, NotEnoughBuffers) {
+TEST_F(ExternalFrameBufferTest, NotEnoughBuffers) {
   // Minimum number of external frame buffers for VP9 is
   // #VP9_MAXIMUM_REF_BUFFERS + #VPX_MAXIMUM_WORK_BUFFERS. Most files will
   // only use 5 frame buffers at one time.
@@ -522,7 +438,7 @@
   ASSERT_EQ(VPX_CODEC_MEM_ERROR, DecodeRemainingFrames());
 }
 
-TEST_P(ExternalFrameBufferTest, NoRelease) {
+TEST_F(ExternalFrameBufferTest, NoRelease) {
   const int num_buffers = VP9_MAXIMUM_REF_BUFFERS + VPX_MAXIMUM_WORK_BUFFERS;
   ASSERT_EQ(VPX_CODEC_OK,
             SetFrameBufferFunctions(num_buffers, get_vp9_frame_buffer,
@@ -531,7 +447,7 @@
   ASSERT_EQ(VPX_CODEC_MEM_ERROR, DecodeRemainingFrames());
 }
 
-TEST_P(ExternalFrameBufferTest, NullRealloc) {
+TEST_F(ExternalFrameBufferTest, NullRealloc) {
   const int num_buffers = VP9_MAXIMUM_REF_BUFFERS + VPX_MAXIMUM_WORK_BUFFERS;
   ASSERT_EQ(VPX_CODEC_OK,
             SetFrameBufferFunctions(num_buffers, get_vp9_zero_frame_buffer,
@@ -539,11 +455,7 @@
   ASSERT_EQ(VPX_CODEC_MEM_ERROR, DecodeOneFrame());
 }
 
-TEST_P(ExternalFrameBufferTest, ReallocOneLessByte) {
-  if (GET_PARAM(kCodedFrameBufferTypeParam) ==
-      VPX_CODEC_FRAME_BUFFER_TYPE_PLANES)
-    return;
-
+TEST_F(ExternalFrameBufferTest, ReallocOneLessByte) {
   const int num_buffers = VP9_MAXIMUM_REF_BUFFERS + VPX_MAXIMUM_WORK_BUFFERS;
   ASSERT_EQ(VPX_CODEC_OK,
             SetFrameBufferFunctions(
@@ -552,50 +464,29 @@
   ASSERT_EQ(VPX_CODEC_MEM_ERROR, DecodeOneFrame());
 }
 
-TEST_P(ExternalFrameBufferTest, NullGetFunction) {
+TEST_F(ExternalFrameBufferTest, NullGetFunction) {
   const int num_buffers = VP9_MAXIMUM_REF_BUFFERS + VPX_MAXIMUM_WORK_BUFFERS;
   ASSERT_EQ(VPX_CODEC_INVALID_PARAM,
             SetFrameBufferFunctions(num_buffers, NULL,
                                     release_vp9_frame_buffer));
 }
 
-TEST_P(ExternalFrameBufferTest, NullReleaseFunction) {
+TEST_F(ExternalFrameBufferTest, NullReleaseFunction) {
   const int num_buffers = VP9_MAXIMUM_REF_BUFFERS + VPX_MAXIMUM_WORK_BUFFERS;
   ASSERT_EQ(VPX_CODEC_INVALID_PARAM,
             SetFrameBufferFunctions(num_buffers, get_vp9_frame_buffer, NULL));
 }
 
-TEST_P(ExternalFrameBufferTest, SetAfterDecode) {
+TEST_F(ExternalFrameBufferTest, SetAfterDecode) {
   const int num_buffers = VP9_MAXIMUM_REF_BUFFERS + VPX_MAXIMUM_WORK_BUFFERS;
   ASSERT_EQ(VPX_CODEC_OK, DecodeOneFrame());
   ASSERT_EQ(VPX_CODEC_ERROR,
             SetFrameBufferFunctions(
                 num_buffers, get_vp9_frame_buffer, release_vp9_frame_buffer));
 }
-
-TEST_P(ExternalFrameBufferTest, InvalidAlignement) {
-  if (GET_PARAM(kCodedFrameBufferTypeParam) ==
-      VPX_CODEC_FRAME_BUFFER_TYPE_SIZE)
-    return;
-  const int num_buffers =
-      VP9_MAXIMUM_REF_BUFFERS + VPX_MAXIMUM_WORK_BUFFERS;
-  ASSERT_EQ(VPX_CODEC_OK,
-            SetFrameBufferFunctions(
-                num_buffers, get_vp9_frame_buffer, release_vp9_frame_buffer));
-  SetBufferAlignment(15);
-  ASSERT_EQ(VPX_CODEC_MEM_ERROR, DecodeRemainingFrames());
-}
-
-VP9_INSTANTIATE_TEST_CASE(ExternalFrameBufferTest,
-                          ::testing::Values(
-                              VPX_CODEC_FRAME_BUFFER_TYPE_SIZE,
-                              VPX_CODEC_FRAME_BUFFER_TYPE_PLANES));
-
 #endif  // CONFIG_WEBM_IO
 
 VP9_INSTANTIATE_TEST_CASE(ExternalFrameBufferMD5Test,
-                          ::testing::Values(VPX_CODEC_FRAME_BUFFER_TYPE_SIZE,
-                                            VPX_CODEC_FRAME_BUFFER_TYPE_PLANES),
                           ::testing::ValuesIn(libvpx_test::kVP9TestVectors,
                                               libvpx_test::kVP9TestVectors +
                                               libvpx_test::kNumVP9TestVectors));
diff --git a/vpx/vpx_frame_buffer.h b/vpx/vpx_frame_buffer.h
index 6157048..9036459 100644
--- a/vpx/vpx_frame_buffer.h
+++ b/vpx/vpx_frame_buffer.h
@@ -19,7 +19,6 @@
 extern "C" {
 #endif
 
-#include "./vpx_image.h"
 #include "./vpx_integer.h"
 
 /*!\brief The maximum number of work buffers used by libvpx.
@@ -33,60 +32,24 @@
  */
 #define VP9_MAXIMUM_REF_BUFFERS 8
 
-/*!\brief The maximum number of planes that can be allocated by an external
- * frame buffer.
- */
-#define VP9_MAXIMUM_EXTERNAL_PLANES 3
-
-/*!\brief External frame buffer allocation type.
- * This enum defines if the external frame buffer contains one allocation for
- * all the planes contained in the frame buffer, or one allocation per plane.
- */
-typedef enum vpx_codec_frame_buffer_type {
-  VPX_CODEC_FRAME_BUFFER_TYPE_SIZE = 1,
-  VPX_CODEC_FRAME_BUFFER_TYPE_PLANES = 2
-} vpx_codec_frame_buffer_type_t;
-
 /*!\brief External frame buffer
  *
  * This structure holds allocated frame buffers used by the decoder.
  */
 typedef struct vpx_codec_frame_buffer {
-  vpx_img_fmt_t fmt;  /**< Requested framebuffer format. */
-  size_t width;  /**< Logical width of the frame. */
-  size_t height;  /**< Logical height of the frame. */
-
-  /*! Whether data and size, or plane and stride should be used. */
-  vpx_codec_frame_buffer_type_t type;
-
   uint8_t *data;  /**< Pointer to the data buffer */
   size_t size;  /**< Size of data in bytes */
-
-  /*! Pointers for each plane buffer */
-  uint8_t *plane[VP9_MAXIMUM_EXTERNAL_PLANES];
-  int stride[VP9_MAXIMUM_EXTERNAL_PLANES]; /**< Strides for each plane */
-
   void *priv;  /**< Frame's private data */
 } vpx_codec_frame_buffer_t;
 
 /*!\brief get frame buffer callback prototype
  *
- * This callback is invoked by the decoder to allocate storage for the frame
- * buffer in order for the decode call to complete.
- * The callback can allocate one buffer for all the frame buffers, or one buffer
- * per plane with the number and size of planes determined by fb->fmt.
- * If the application decides to allocate only one buffer, fb->type must be set
- * to #VPX_CODEC_FRAME_BUFFER_SIZE, the buffer size must be at least |min_size|
- * in bytes and the pointer to the buffer must be assigned to fb->data.
- * Then the callback must set fb->size to the allocated size.
- * The application does not need to align the allocated data.
- * If the application decides to allocate one buffer per plane, fb->type must be
- * set to #VPX_CODEC_FRAME_BUFFER_PLANES, the buffer pointers must be assigned
- * to fb->plane, and their strides to fb->stride.
- * The application provided buffers and strides must be aligned to 32 bytes.
- * The callback must zero out all the buffers allocated.
- *
- * The callback is triggered when the decoder needs a frame buffer to
+ * This callback is invoked by the decoder to retrieve data for the frame
+ * buffer in order for the decode call to complete. The callback must
+ * allocate at least min_size in bytes and assign it to fb->data. The callback
+ * must zero out all the data allocated. Then the callback must set fb->size
+ * to the allocated size. The application does not need to align the allocated
+ * data. The callback is triggered when the decoder needs a frame buffer to
  * decode a compressed image into. This function may be called more than once
  * for every call to vpx_codec_decode. The application may set fb->priv to
  * some data which will be passed back in the ximage and the release function
diff --git a/vpx_scale/generic/yv12config.c b/vpx_scale/generic/yv12config.c
index a1db6c1..e8fee52 100644
--- a/vpx_scale/generic/yv12config.c
+++ b/vpx_scale/generic/yv12config.c
@@ -178,51 +178,23 @@
       if (external_frame_size != (size_t)external_frame_size)
         return -1;
 
-      fb->type = VPX_CODEC_FRAME_BUFFER_TYPE_SIZE;
-      if (ybf->subsampling_y) {
-        fb->fmt = ybf->subsampling_x ? VPX_IMG_FMT_I420 : VPX_IMG_FMT_I440;
-      } else {
-        fb->fmt = ybf->subsampling_x ? VPX_IMG_FMT_I422 : VPX_IMG_FMT_I444;
-      }
-      fb->width = aligned_width + border * 2;
-      fb->height = aligned_height + border * 2;
-
       // Allocation to hold larger frame, or first allocation.
       if (cb(cb_priv, (size_t)external_frame_size, fb) < 0)
         return -1;
 
-      if (fb->type == VPX_CODEC_FRAME_BUFFER_TYPE_SIZE) {
-        if (fb->data == NULL || fb->size < external_frame_size)
-          return -1;
+      if (fb->data == NULL || fb->size < external_frame_size)
+        return -1;
 
-        ybf->buffer_alloc = (uint8_t *)yv12_align_addr(fb->data, 32);
+      ybf->buffer_alloc = (uint8_t *)yv12_align_addr(fb->data, 32);
 
 #if defined(__has_feature)
 #if __has_feature(memory_sanitizer)
-        // This memset is needed for fixing the issue of using uninitialized
-        // value in msan test. It will cause a perf loss, so only do this for
-        // msan test.
-        memset(ybf->buffer_alloc, 0, (int)frame_size);
+      // This memset is needed for fixing the issue of using uninitialized
+      // value in msan test. It will cause a perf loss, so only do this for
+      // msan test.
+      memset(ybf->buffer_alloc, 0, (int)frame_size);
 #endif
 #endif
-      } else {  // VPX_CODEC_FRAME_BUFFER_TYPE_PLANES
-        if (fb->plane[0] == NULL || fb->plane[1] == NULL ||
-            fb->plane[2] == NULL || !fb->stride[0] || !fb->stride[1] ||
-            !fb->stride[2])
-          return -1;
-        // buffers should be 32 bytes aligned.
-        if ((fb->stride[0] & 0x1f) || (fb->stride[1] & 0x1f))
-          return -3;
-
-        if (fb->stride[1] != fb->stride[2])
-          return -3;
-        ybf->y_stride = fb->stride[0];
-        ybf->uv_stride = fb->stride[1];
-
-        ybf->y_buffer = fb->plane[0];
-        ybf->u_buffer = fb->plane[1];
-        ybf->v_buffer = fb->plane[2];
-      }
     } else if (frame_size > (size_t)ybf->buffer_alloc_sz) {
       // Allocation to hold larger frame, or first allocation.
       vpx_free(ybf->buffer_alloc);
@@ -255,11 +227,13 @@
     ybf->y_crop_height = height;
     ybf->y_width  = aligned_width;
     ybf->y_height = aligned_height;
+    ybf->y_stride = y_stride;
 
     ybf->uv_crop_width = (width + ss_x) >> ss_x;
     ybf->uv_crop_height = (height + ss_y) >> ss_y;
     ybf->uv_width = uv_width;
     ybf->uv_height = uv_height;
+    ybf->uv_stride = uv_stride;
 
     ybf->border = border;
     ybf->frame_size = (int)frame_size;
@@ -267,28 +241,24 @@
     ybf->subsampling_y = ss_y;
 
     buf = ybf->buffer_alloc;
-    if (buf != NULL) {
-      ybf->y_stride = y_stride;
-      ybf->uv_stride = uv_stride;
 #if CONFIG_VP9_HIGHBITDEPTH
-      if (use_highbitdepth) {
-        // Store uint16 addresses when using 16bit framebuffers
-        buf = CONVERT_TO_BYTEPTR(ybf->buffer_alloc);
-        ybf->flags = YV12_FLAG_HIGHBITDEPTH;
-      } else {
-        ybf->flags = 0;
-      }
+    if (use_highbitdepth) {
+      // Store uint16 addresses when using 16bit framebuffers
+      buf = CONVERT_TO_BYTEPTR(ybf->buffer_alloc);
+      ybf->flags = YV12_FLAG_HIGHBITDEPTH;
+    } else {
+      ybf->flags = 0;
+    }
 #endif  // CONFIG_VP9_HIGHBITDEPTH
 
-      ybf->y_buffer = (uint8_t *)yv12_align_addr(
-          buf + (border * y_stride) + border, vp9_byte_align);
-      ybf->u_buffer = (uint8_t *)yv12_align_addr(
-          buf + yplane_size + (uv_border_h * uv_stride) + uv_border_w,
-          vp9_byte_align);
-      ybf->v_buffer = (uint8_t *)yv12_align_addr(
-          buf + yplane_size + uvplane_size + (uv_border_h * uv_stride) +
-          uv_border_w, vp9_byte_align);
-    }
+    ybf->y_buffer = (uint8_t *)yv12_align_addr(
+        buf + (border * y_stride) + border, vp9_byte_align);
+    ybf->u_buffer = (uint8_t *)yv12_align_addr(
+        buf + yplane_size + (uv_border_h * uv_stride) + uv_border_w,
+        vp9_byte_align);
+    ybf->v_buffer = (uint8_t *)yv12_align_addr(
+        buf + yplane_size + uvplane_size + (uv_border_h * uv_stride) +
+        uv_border_w, vp9_byte_align);
 
     ybf->corrupted = 0; /* assume not corrupted by errors */
     return 0;