From 7dc3cdba0c51f73e42191eb8bc5000ecbf4464cc Mon Sep 17 00:00:00 2001 From: Alexander Voronov Date: Wed, 10 Sep 2014 14:55:19 +0400 Subject: [PATCH] Make --output-bit-depth option working with variable resolution. Buffer for bit-depth conversion was allocated only on the first frame. The next frame with resolution different from the first one led to decoding error. With this changes decoder performs buffer reallocation in such case. Change-Id: I3a701ca8df53a60246354876856624e70efe81aa --- vpxdec.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/vpxdec.c b/vpxdec.c index 63a9c0a4d..8b6b08e67 100644 --- a/vpxdec.c +++ b/vpxdec.c @@ -692,6 +692,14 @@ static void img_downshift(vpx_image_t *dst, vpx_image_t *src, low_img_downshift(dst, src, down_shift); } } + +static int img_shifted_realloc_required(const vpx_image_t *img, + const vpx_image_t *shifted, + vpx_img_fmt_t required_fmt) { + return img->d_w != shifted->d_w || + img->d_h != shifted->d_h || + required_fmt != shifted->fmt; +} #endif int main_loop(int argc, const char **argv_) { @@ -1127,14 +1135,17 @@ int main_loop(int argc, const char **argv_) { out_bit_depth = img->bit_depth; // Shift up or down if necessary if (out_bit_depth != img->bit_depth) { + vpx_img_fmt_t shifted_fmt = out_bit_depth == 8 + ? img->fmt ^ (img->fmt & VPX_IMG_FMT_HIGH) + : img->fmt | VPX_IMG_FMT_HIGH; + if (img_shifted && + img_shifted_realloc_required(img, img_shifted, shifted_fmt)) { + vpx_img_free(img_shifted); + img_shifted = NULL; + } if (!img_shifted) { - if (out_bit_depth == 8) { - img_shifted = vpx_img_alloc(NULL, img->fmt - VPX_IMG_FMT_HIGH, - img->d_w, img->d_h, 16); - } else { - img_shifted = vpx_img_alloc(NULL, img->fmt | VPX_IMG_FMT_HIGH, - img->d_w, img->d_h, 16); - } + img_shifted = vpx_img_alloc(NULL, shifted_fmt, + img->d_w, img->d_h, 16); img_shifted->bit_depth = out_bit_depth; } if (out_bit_depth > img->bit_depth) {