Commit 2117fe05 authored by Adrian Grange's avatar Adrian Grange

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
parent 0a64f943
......@@ -668,6 +668,25 @@ static vpx_codec_err_t get_frame_corrupted(vpx_codec_alg_priv_t *ctx,
}
}
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 @@ static vpx_codec_ctrl_fn_map_t ctf_maps[] = {
{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},
};
......
......@@ -73,6 +73,9 @@ enum vp8_dec_control_id {
*/
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_LAST_REF_UPDATES, int *)
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 */
......
......@@ -426,7 +426,6 @@ int main_loop(int argc, const char **argv_) {
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 @@ int main_loop(int argc, const char **argv_) {
}
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 @@ int main_loop(int argc, const char **argv_) {
img = scaled_img;
}
}
if (img) {
unsigned int y;
char out_fn[PATH_MAX];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment