shithub: libvpx

Download patch

ref: 2117fe059319e87b101c39fe13bf523523c5a394
parent: 0a64f943fccc194a16c53af461f81bd48d840d71
author: Adrian Grange <agrange@google.com>
date: Tue Nov 19 09:01:44 EST 2013

Fix decoder to handle display size correctly

The decoder ignored the display width & height
specified in the frame header.

This patch adds a control, VP9D_GET_DISPLAY_SIZE, to
allow the application to obtain the display width and
height from the frame header.

vpxdec has been modified to scale the output frame to
this size.

Should the request for the display size fail vpxdec will
use the native width and height of the raw decoded
frame instead.

Change-Id: I25db04407426dac730263720c75a7dd6400af68a

--- a/vp9/vp9_dx_iface.c
+++ b/vp9/vp9_dx_iface.c
@@ -668,6 +668,25 @@
   }
 }
 
+static vpx_codec_err_t get_display_size(vpx_codec_alg_priv_t *ctx,
+                                        int ctrl_id,
+                                        va_list args) {
+  int *const display_size = va_arg(args, int *);
+
+  if (display_size) {
+    const VP9D_COMP *const pbi = (VP9D_COMP *)ctx->pbi;
+    if (pbi) {
+      display_size[0] = pbi->common.display_width;
+      display_size[1] = pbi->common.display_height;
+    } else {
+      return VPX_CODEC_ERROR;
+    }
+    return VPX_CODEC_OK;
+  } else {
+    return VPX_CODEC_INVALID_PARAM;
+  }
+}
+
 static vpx_codec_err_t set_invert_tile_order(vpx_codec_alg_priv_t *ctx,
                                              int ctr_id,
                                              va_list args) {
@@ -686,6 +705,7 @@
   {VP8D_GET_LAST_REF_UPDATES,     get_last_ref_updates},
   {VP8D_GET_FRAME_CORRUPTED,      get_frame_corrupted},
   {VP9_GET_REFERENCE,             get_reference},
+  {VP9D_GET_DISPLAY_SIZE,         get_display_size},
   {VP9_INVERT_TILE_DECODE_ORDER,  set_invert_tile_order},
   { -1, NULL},
 };
--- a/vpx/vp8dx.h
+++ b/vpx/vp8dx.h
@@ -73,6 +73,9 @@
    */
   VP8D_SET_DECRYPTOR,
 
+  /** control function to get the display dimensions for the current frame. */
+  VP9D_GET_DISPLAY_SIZE,
+
   /** For testing. */
   VP9_INVERT_TILE_DECODE_ORDER,
 
@@ -105,6 +108,7 @@
 VPX_CTRL_USE_TYPE(VP8D_GET_FRAME_CORRUPTED,    int *)
 VPX_CTRL_USE_TYPE(VP8D_GET_LAST_REF_USED,      int *)
 VPX_CTRL_USE_TYPE(VP8D_SET_DECRYPTOR,          vp8_decrypt_init *)
+VPX_CTRL_USE_TYPE(VP9D_GET_DISPLAY_SIZE,       int *)
 VPX_CTRL_USE_TYPE(VP9_INVERT_TILE_DECODE_ORDER, int)
 
 /*! @} - end defgroup vp8_decoder */
--- a/vpxdec.c
+++ b/vpxdec.c
@@ -426,7 +426,6 @@
   int                     frames_corrupted = 0;
   int                     dec_flags = 0;
   int                     do_scale = 0;
-  int                     stream_w = 0, stream_h = 0;
   vpx_image_t             *scaled_img = NULL;
   int                     frame_avail, got_data;
 
@@ -771,9 +770,18 @@
       }
 
       if (do_scale) {
+        int stream_w = 0, stream_h = 0;
         if (img && frame_out == 1) {
-          stream_w = img->d_w;
-          stream_h = img->d_h;
+          int display_size[2];
+          if (vpx_codec_control(&decoder, VP9D_GET_DISPLAY_SIZE,
+                                display_size)) {
+            // Fallback to use raw image size if display size not available.
+            stream_w = img->d_w;
+            stream_h = img->d_h;
+          } else {
+            stream_w = display_size[0];
+            stream_h = display_size[1];
+          }
           scaled_img = vpx_img_alloc(NULL, VPX_IMG_FMT_I420,
                                      stream_w, stream_h, 16);
         }
@@ -794,7 +802,6 @@
           img = scaled_img;
         }
       }
-
       if (img) {
         unsigned int y;
         char out_fn[PATH_MAX];