X-Git-Url: https://granicus.if.org/sourcecode?a=blobdiff_plain;f=vpxdec.c;h=f99d1e43704f6d749122cfba7de29f9f51040ee3;hb=fa99c376e509ef52ed8370019538b23e76477ddb;hp=091522f067d1c94abd773a20287990c8ca8125fa;hpb=7f77a1c3c96ec582fa6b8682320d60fb389be94b;p=libvpx diff --git a/vpxdec.c b/vpxdec.c index 091522f06..1bef4bd4a 100644 --- a/vpxdec.c +++ b/vpxdec.c @@ -28,7 +28,7 @@ #include "vpx_ports/mem_ops.h" #include "vpx_ports/vpx_timer.h" -#if CONFIG_VP8_DECODER || CONFIG_VP9_DECODER +#if CONFIG_VP8_DECODER || CONFIG_VP9_DECODER || CONFIG_VP10_DECODER #include "vpx/vp8dx.h" #endif @@ -47,84 +47,84 @@ struct VpxDecInputContext { struct WebmInputContext *webm_ctx; }; -static const arg_def_t looparg = ARG_DEF(NULL, "loops", 1, - "Number of times to decode the file"); -static const arg_def_t codecarg = ARG_DEF(NULL, "codec", 1, - "Codec to use"); -static const arg_def_t use_yv12 = ARG_DEF(NULL, "yv12", 0, - "Output raw YV12 frames"); -static const arg_def_t use_i420 = ARG_DEF(NULL, "i420", 0, - "Output raw I420 frames"); -static const arg_def_t flipuvarg = ARG_DEF(NULL, "flipuv", 0, - "Flip the chroma planes in the output"); -static const arg_def_t rawvideo = ARG_DEF(NULL, "rawvideo", 0, - "Output raw YUV frames"); -static const arg_def_t noblitarg = ARG_DEF(NULL, "noblit", 0, - "Don't process the decoded frames"); -static const arg_def_t progressarg = ARG_DEF(NULL, "progress", 0, - "Show progress after each frame decodes"); -static const arg_def_t limitarg = ARG_DEF(NULL, "limit", 1, - "Stop decoding after n frames"); -static const arg_def_t skiparg = ARG_DEF(NULL, "skip", 1, - "Skip the first n input frames"); -static const arg_def_t postprocarg = ARG_DEF(NULL, "postproc", 0, - "Postprocess decoded frames"); -static const arg_def_t summaryarg = ARG_DEF(NULL, "summary", 0, - "Show timing summary"); -static const arg_def_t outputfile = ARG_DEF("o", "output", 1, - "Output file name pattern (see below)"); -static const arg_def_t threadsarg = ARG_DEF("t", "threads", 1, - "Max threads to use"); -static const arg_def_t verbosearg = ARG_DEF("v", "verbose", 0, - "Show version string"); -static const arg_def_t error_concealment = ARG_DEF(NULL, "error-concealment", 0, - "Enable decoder error-concealment"); -static const arg_def_t scalearg = ARG_DEF("S", "scale", 0, - "Scale output frames uniformly"); -static const arg_def_t continuearg = - ARG_DEF("k", "keep-going", 0, "(debug) Continue decoding after error"); - -static const arg_def_t fb_arg = - ARG_DEF(NULL, "frame-buffers", 1, "Number of frame buffers to use"); - -static const arg_def_t md5arg = ARG_DEF(NULL, "md5", 0, - "Compute the MD5 sum of the decoded frame"); -#if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH +static const arg_def_t looparg = ARG_DEF( + NULL, "loops", 1, "Number of times to decode the file"); +static const arg_def_t codecarg = ARG_DEF( + NULL, "codec", 1, "Codec to use"); +static const arg_def_t use_yv12 = ARG_DEF( + NULL, "yv12", 0, "Output raw YV12 frames"); +static const arg_def_t use_i420 = ARG_DEF( + NULL, "i420", 0, "Output raw I420 frames"); +static const arg_def_t flipuvarg = ARG_DEF( + NULL, "flipuv", 0, "Flip the chroma planes in the output"); +static const arg_def_t rawvideo = ARG_DEF( + NULL, "rawvideo", 0, "Output raw YUV frames"); +static const arg_def_t noblitarg = ARG_DEF( + NULL, "noblit", 0, "Don't process the decoded frames"); +static const arg_def_t progressarg = ARG_DEF( + NULL, "progress", 0, "Show progress after each frame decodes"); +static const arg_def_t limitarg = ARG_DEF( + NULL, "limit", 1, "Stop decoding after n frames"); +static const arg_def_t skiparg = ARG_DEF( + NULL, "skip", 1, "Skip the first n input frames"); +static const arg_def_t postprocarg = ARG_DEF( + NULL, "postproc", 0, "Postprocess decoded frames"); +static const arg_def_t summaryarg = ARG_DEF( + NULL, "summary", 0, "Show timing summary"); +static const arg_def_t outputfile = ARG_DEF( + "o", "output", 1, "Output file name pattern (see below)"); +static const arg_def_t threadsarg = ARG_DEF( + "t", "threads", 1, "Max threads to use"); +static const arg_def_t frameparallelarg = ARG_DEF( + NULL, "frame-parallel", 0, "Frame parallel decode"); +static const arg_def_t verbosearg = ARG_DEF( + "v", "verbose", 0, "Show version string"); +static const arg_def_t error_concealment = ARG_DEF( + NULL, "error-concealment", 0, "Enable decoder error-concealment"); +static const arg_def_t scalearg = ARG_DEF( + "S", "scale", 0, "Scale output frames uniformly"); +static const arg_def_t continuearg = ARG_DEF( + "k", "keep-going", 0, "(debug) Continue decoding after error"); +static const arg_def_t fb_arg = ARG_DEF( + NULL, "frame-buffers", 1, "Number of frame buffers to use"); +static const arg_def_t md5arg = ARG_DEF( + NULL, "md5", 0, "Compute the MD5 sum of the decoded frame"); +#if CONFIG_VP9_HIGHBITDEPTH static const arg_def_t outbitdeptharg = ARG_DEF( - NULL, "output-bit-depth", 1, - "Output bit-depth for decoded frames"); + NULL, "output-bit-depth", 1, "Output bit-depth for decoded frames"); #endif static const arg_def_t *all_args[] = { &codecarg, &use_yv12, &use_i420, &flipuvarg, &rawvideo, &noblitarg, &progressarg, &limitarg, &skiparg, &postprocarg, &summaryarg, &outputfile, - &threadsarg, &verbosearg, &scalearg, &fb_arg, + &threadsarg, &frameparallelarg, &verbosearg, &scalearg, &fb_arg, &md5arg, &error_concealment, &continuearg, -#if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH +#if CONFIG_VP9_HIGHBITDEPTH &outbitdeptharg, #endif NULL }; #if CONFIG_VP8_DECODER -static const arg_def_t addnoise_level = ARG_DEF(NULL, "noise-level", 1, - "Enable VP8 postproc add noise"); -static const arg_def_t deblock = ARG_DEF(NULL, "deblock", 0, - "Enable VP8 deblocking"); -static const arg_def_t demacroblock_level = ARG_DEF(NULL, "demacroblock-level", 1, - "Enable VP8 demacroblocking, w/ level"); -static const arg_def_t pp_debug_info = ARG_DEF(NULL, "pp-debug-info", 1, - "Enable VP8 visible debug info"); -static const arg_def_t pp_disp_ref_frame = ARG_DEF(NULL, "pp-dbg-ref-frame", 1, - "Display only selected reference frame per macro block"); -static const arg_def_t pp_disp_mb_modes = ARG_DEF(NULL, "pp-dbg-mb-modes", 1, - "Display only selected macro block modes"); -static const arg_def_t pp_disp_b_modes = ARG_DEF(NULL, "pp-dbg-b-modes", 1, - "Display only selected block modes"); -static const arg_def_t pp_disp_mvs = ARG_DEF(NULL, "pp-dbg-mvs", 1, - "Draw only selected motion vectors"); -static const arg_def_t mfqe = ARG_DEF(NULL, "mfqe", 0, - "Enable multiframe quality enhancement"); +static const arg_def_t addnoise_level = ARG_DEF( + NULL, "noise-level", 1, "Enable VP8 postproc add noise"); +static const arg_def_t deblock = ARG_DEF( + NULL, "deblock", 0, "Enable VP8 deblocking"); +static const arg_def_t demacroblock_level = ARG_DEF( + NULL, "demacroblock-level", 1, "Enable VP8 demacroblocking, w/ level"); +static const arg_def_t pp_debug_info = ARG_DEF( + NULL, "pp-debug-info", 1, "Enable VP8 visible debug info"); +static const arg_def_t pp_disp_ref_frame = ARG_DEF( + NULL, "pp-dbg-ref-frame", 1, + "Display only selected reference frame per macro block"); +static const arg_def_t pp_disp_mb_modes = ARG_DEF( + NULL, "pp-dbg-mb-modes", 1, "Display only selected macro block modes"); +static const arg_def_t pp_disp_b_modes = ARG_DEF( + NULL, "pp-dbg-b-modes", 1, "Display only selected block modes"); +static const arg_def_t pp_disp_mvs = ARG_DEF( + NULL, "pp-dbg-mvs", 1, "Draw only selected motion vectors"); +static const arg_def_t mfqe = ARG_DEF( + NULL, "mfqe", 0, "Enable multiframe quality enhancement"); static const arg_def_t *vp8_pp_args[] = { &addnoise_level, &deblock, &demacroblock_level, &pp_debug_info, @@ -134,9 +134,9 @@ static const arg_def_t *vp8_pp_args[] = { #endif #if CONFIG_LIBYUV -static INLINE int vpx_image_scale(vpx_image_t *src, vpx_image_t *dst, +static INLINE int libyuv_scale(vpx_image_t *src, vpx_image_t *dst, FilterModeEnum mode) { -#if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH +#if CONFIG_VP9_HIGHBITDEPTH if (src->fmt == VPX_IMG_FMT_I42016) { assert(dst->fmt == VPX_IMG_FMT_I42016); return I420Scale_16((uint16_t*)src->planes[VPX_PLANE_Y], @@ -170,7 +170,7 @@ static INLINE int vpx_image_scale(vpx_image_t *src, vpx_image_t *dst, } #endif -void usage_exit() { +void usage_exit(void) { int i; fprintf(stderr, "Usage: %s filename\n\n" @@ -257,8 +257,7 @@ static int read_frame(struct VpxDecInputContext *input, uint8_t **buf, switch (input->vpx_input_ctx->file_type) { #if CONFIG_WEBM_IO case FILE_TYPE_WEBM: - return webm_read_frame(input->webm_ctx, - buf, bytes_in_buffer, buffer_size); + return webm_read_frame(input->webm_ctx, buf, bytes_in_buffer); #endif case FILE_TYPE_RAW: return raw_read_frame(input->vpx_input_ctx->file, @@ -279,7 +278,8 @@ static void update_image_md5(const vpx_image_t *img, const int planes[3], const int plane = planes[i]; const unsigned char *buf = img->planes[plane]; const int stride = img->stride[plane]; - const int w = vpx_img_plane_width(img, plane); + const int w = vpx_img_plane_width(img, plane) * + ((img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? 2 : 1); const int h = vpx_img_plane_height(img, plane); for (y = 0; y < h; ++y) { @@ -292,7 +292,7 @@ static void update_image_md5(const vpx_image_t *img, const int planes[3], static void write_image_file(const vpx_image_t *img, const int planes[3], FILE *file) { int i, y; -#if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH +#if CONFIG_VP9_HIGHBITDEPTH const int bytes_per_sample = ((img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? 2 : 1); #else const int bytes_per_sample = 1; @@ -312,7 +312,7 @@ static void write_image_file(const vpx_image_t *img, const int planes[3], } } -int file_is_raw(struct VpxInputContext *input) { +static int file_is_raw(struct VpxInputContext *input) { uint8_t buf[32]; int is_raw = 0; vpx_codec_stream_info_t si; @@ -343,7 +343,7 @@ int file_is_raw(struct VpxInputContext *input) { return is_raw; } -void show_progress(int frame_in, int frame_out, uint64_t dx_time) { +static void show_progress(int frame_in, int frame_out, uint64_t dx_time) { fprintf(stderr, "%d decoded frames/%d showed frames in %"PRId64" us (%.2f fps)\r", frame_in, frame_out, dx_time, @@ -365,8 +365,8 @@ struct ExternalFrameBufferList { // Application private data passed into the set function. |min_size| is the // minimum size in bytes needed to decode the next frame. |fb| pointer to the // frame buffer. -int get_vp9_frame_buffer(void *cb_priv, size_t min_size, - vpx_codec_frame_buffer_t *fb) { +static int get_vp9_frame_buffer(void *cb_priv, size_t min_size, + vpx_codec_frame_buffer_t *fb) { int i; struct ExternalFrameBufferList *const ext_fb_list = (struct ExternalFrameBufferList *)cb_priv; @@ -384,7 +384,7 @@ int get_vp9_frame_buffer(void *cb_priv, size_t min_size, if (ext_fb_list->ext_fb[i].size < min_size) { free(ext_fb_list->ext_fb[i].data); - ext_fb_list->ext_fb[i].data = (uint8_t *)malloc(min_size); + ext_fb_list->ext_fb[i].data = (uint8_t *)calloc(min_size, sizeof(uint8_t)); if (!ext_fb_list->ext_fb[i].data) return -1; @@ -403,8 +403,8 @@ int get_vp9_frame_buffer(void *cb_priv, size_t min_size, // Callback used by libvpx when there are no references to the frame buffer. // |cb_priv| user private data passed into the set function. |fb| pointer // to the frame buffer. -int release_vp9_frame_buffer(void *cb_priv, - vpx_codec_frame_buffer_t *fb) { +static int release_vp9_frame_buffer(void *cb_priv, + vpx_codec_frame_buffer_t *fb) { struct ExternalFrameBuffer *const ext_fb = (struct ExternalFrameBuffer *)fb->priv; (void)cb_priv; @@ -412,9 +412,9 @@ int release_vp9_frame_buffer(void *cb_priv, return 0; } -void generate_filename(const char *pattern, char *out, size_t q_len, - unsigned int d_w, unsigned int d_h, - unsigned int frame_in) { +static void generate_filename(const char *pattern, char *out, size_t q_len, + unsigned int d_w, unsigned int d_h, + unsigned int frame_in) { const char *p = pattern; char *q = out; @@ -521,184 +521,22 @@ static FILE *open_outfile(const char *name) { } else { FILE *file = fopen(name, "wb"); if (!file) - fatal("Failed to output file %s", name); + fatal("Failed to open output file '%s'", name); return file; } } -#if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH -static void high_img_upshift(vpx_image_t *dst, vpx_image_t *src, - int input_shift) { - const int offset = input_shift > 0 ? (1 << (input_shift - 1)) : 0; - int plane; - if (dst->d_w != src->d_w || dst->d_h != src->d_h || - dst->x_chroma_shift != src->x_chroma_shift || - dst->y_chroma_shift != src->y_chroma_shift || - dst->fmt != src->fmt || input_shift < 0) { - fatal("Unsupported image conversion"); - } - switch (src->fmt) { - case VPX_IMG_FMT_I42016: - case VPX_IMG_FMT_I42216: - case VPX_IMG_FMT_I44416: - break; - default: - fatal("Unsupported image conversion"); - break; - } - for (plane = 0; plane < 3; plane++) { - int w = src->d_w; - int h = src->d_h; - int x, y; - if (plane) { - w >>= src->x_chroma_shift; - h >>= src->y_chroma_shift; - } - for (y = 0; y < h; y++) { - uint16_t *p_src = (uint16_t *)(src->planes[plane] + - y * src->stride[plane]); - uint16_t *p_dst = (uint16_t *)(dst->planes[plane] + - y * dst->stride[plane]); - for (x = 0; x < w; x++) - *p_dst++ = (*p_src++ << input_shift) + offset; - } - } -} - -static void low_img_upshift(vpx_image_t *dst, vpx_image_t *src, - int input_shift) { - const int offset = input_shift > 0 ? (1 << (input_shift - 1)) : 0; - int plane; - if (dst->d_w != src->d_w || dst->d_h != src->d_h || - dst->x_chroma_shift != src->x_chroma_shift || - dst->y_chroma_shift != src->y_chroma_shift || - dst->fmt != src->fmt + VPX_IMG_FMT_HIGHBITDEPTH || - input_shift < 0) { - fatal("Unsupported image conversion"); - } - switch (src->fmt) { - case VPX_IMG_FMT_I420: - case VPX_IMG_FMT_I422: - case VPX_IMG_FMT_I444: - break; - default: - fatal("Unsupported image conversion"); - break; - } - for (plane = 0; plane < 3; plane++) { - int w = src->d_w; - int h = src->d_h; - int x, y; - if (plane) { - w >>= src->x_chroma_shift; - h >>= src->y_chroma_shift; - } - for (y = 0; y < h; y++) { - uint8_t *p_src = src->planes[plane] + y * src->stride[plane]; - uint16_t *p_dst = (uint16_t *)(dst->planes[plane] + - y * dst->stride[plane]); - for (x = 0; x < w; x++) { - *p_dst++ = (*p_src++ << input_shift) + offset; - } - } - } -} - -static void img_upshift(vpx_image_t *dst, vpx_image_t *src, - int input_shift) { - if (src->fmt & VPX_IMG_FMT_HIGHBITDEPTH) { - high_img_upshift(dst, src, input_shift); - } else { - low_img_upshift(dst, src, input_shift); - } -} - -static void high_img_downshift(vpx_image_t *dst, vpx_image_t *src, - int down_shift) { - int plane; - if (dst->d_w != src->d_w || dst->d_h != src->d_h || - dst->x_chroma_shift != src->x_chroma_shift || - dst->y_chroma_shift != src->y_chroma_shift || - dst->fmt != src->fmt || down_shift < 0) { - fatal("Unsupported image conversion"); - } - switch (src->fmt) { - case VPX_IMG_FMT_I42016: - case VPX_IMG_FMT_I42216: - case VPX_IMG_FMT_I44416: - break; - default: - fatal("Unsupported image conversion"); - break; - } - for (plane = 0; plane < 3; plane++) { - int w = src->d_w; - int h = src->d_h; - int x, y; - if (plane) { - w >>= src->x_chroma_shift; - h >>= src->y_chroma_shift; - } - for (y = 0; y < h; y++) { - uint16_t *p_src = (uint16_t *)(src->planes[plane] + - y * src->stride[plane]); - uint16_t *p_dst = (uint16_t *)(dst->planes[plane] + - y * dst->stride[plane]); - for (x = 0; x < w; x++) - *p_dst++ = *p_src++ >> down_shift; - } - } -} - -static void low_img_downshift(vpx_image_t *dst, vpx_image_t *src, - int down_shift) { - int plane; - if (dst->d_w != src->d_w || dst->d_h != src->d_h || - dst->x_chroma_shift != src->x_chroma_shift || - dst->y_chroma_shift != src->y_chroma_shift || - src->fmt != dst->fmt + VPX_IMG_FMT_HIGHBITDEPTH || - down_shift < 0) { - fatal("Unsupported image conversion"); - } - switch (dst->fmt) { - case VPX_IMG_FMT_I420: - case VPX_IMG_FMT_I422: - case VPX_IMG_FMT_I444: - break; - default: - fatal("Unsupported image conversion"); - break; - } - for (plane = 0; plane < 3; plane++) { - int w = src->d_w; - int h = src->d_h; - int x, y; - if (plane) { - w >>= src->x_chroma_shift; - h >>= src->y_chroma_shift; - } - for (y = 0; y < h; y++) { - uint16_t *p_src = (uint16_t *)(src->planes[plane] + - y * src->stride[plane]); - uint8_t *p_dst = dst->planes[plane] + y * dst->stride[plane]; - for (x = 0; x < w; x++) { - *p_dst++ = *p_src++ >> down_shift; - } - } - } -} - -static void img_downshift(vpx_image_t *dst, vpx_image_t *src, - int down_shift) { - if (dst->fmt & VPX_IMG_FMT_HIGHBITDEPTH) { - high_img_downshift(dst, src, down_shift); - } else { - low_img_downshift(dst, src, down_shift); - } +#if CONFIG_VP9_HIGHBITDEPTH +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_) { +static int main_loop(int argc, const char **argv_) { vpx_codec_ctx_t decoder; char *fn = NULL; int i; @@ -706,7 +544,7 @@ int main_loop(int argc, const char **argv_) { size_t bytes_in_buffer = 0, buffer_size = 0; FILE *infile; int frame_in = 0, frame_out = 0, flipuv = 0, noblit = 0; - int do_md5 = 0, progress = 0; + int do_md5 = 0, progress = 0, frame_parallel = 0; int stop_after = 0, postproc = 0, summary = 0, quiet = 1; int arg_skip = 0; int ec_enabled = 0; @@ -722,8 +560,8 @@ int main_loop(int argc, const char **argv_) { int opt_yv12 = 0; int opt_i420 = 0; vpx_codec_dec_cfg_t cfg = {0, 0, 0}; -#if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH - int output_bit_depth = 0; +#if CONFIG_VP9_HIGHBITDEPTH + unsigned int output_bit_depth = 0; #endif #if CONFIG_VP8_DECODER vp8_postproc_cfg_t vp8_pp_cfg = {0}; @@ -736,10 +574,10 @@ int main_loop(int argc, const char **argv_) { int dec_flags = 0; int do_scale = 0; vpx_image_t *scaled_img = NULL; -#if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH +#if CONFIG_VP9_HIGHBITDEPTH vpx_image_t *img_shifted = NULL; #endif - int frame_avail, got_data; + int frame_avail, got_data, flush_decoder = 0; int num_external_frame_buffers = 0; struct ExternalFrameBufferList ext_fb_list = {0, NULL}; @@ -779,9 +617,6 @@ int main_loop(int argc, const char **argv_) { use_y4m = 0; flipuv = 1; opt_yv12 = 1; -#if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH - output_bit_depth = 8; // For yv12 8-bit depth output is assumed -#endif } else if (arg_match(&arg, &use_i420, argi)) { use_y4m = 0; flipuv = 0; @@ -806,6 +641,10 @@ int main_loop(int argc, const char **argv_) { summary = 1; else if (arg_match(&arg, &threadsarg, argi)) cfg.threads = arg_parse_uint(&arg); +#if CONFIG_VP9_DECODER || CONFIG_VP10_DECODER + else if (arg_match(&arg, &frameparallelarg, argi)) + frame_parallel = 1; +#endif else if (arg_match(&arg, &verbosearg, argi)) quiet = 0; else if (arg_match(&arg, &scalearg, argi)) @@ -814,7 +653,7 @@ int main_loop(int argc, const char **argv_) { num_external_frame_buffers = arg_parse_uint(&arg); else if (arg_match(&arg, &continuearg, argi)) keep_going = 1; -#if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH +#if CONFIG_VP9_HIGHBITDEPTH else if (arg_match(&arg, &outbitdeptharg, argi)) { output_bit_depth = arg_parse_uint(&arg); } @@ -882,15 +721,15 @@ int main_loop(int argc, const char **argv_) { /* Handle non-option arguments */ fn = argv[0]; - if (!fn) + if (!fn) { + free(argv); usage_exit(); - + } /* Open file */ infile = strcmp(fn, "-") ? fopen(fn, "rb") : set_binary_mode(stdin); if (!infile) { - fprintf(stderr, "Failed to open file '%s'", strcmp(fn, "-") ? fn : "stdin"); - return EXIT_FAILURE; + fatal("Failed to open input file '%s'", strcmp(fn, "-") ? fn : "stdin"); } #if CONFIG_OS_SUPPORT /* Make sure we don't dump to the terminal, unless forced to with -o - */ @@ -933,7 +772,7 @@ int main_loop(int argc, const char **argv_) { if (use_y4m && !noblit) { if (!single_file) { fprintf(stderr, "YUV4MPEG2 not supported with output patterns," - " try --i420 or --yv12.\n"); + " try --i420 or --yv12 or --rawvideo.\n"); return EXIT_FAILURE; } @@ -958,7 +797,8 @@ int main_loop(int argc, const char **argv_) { interface = get_vpx_decoder_by_index(0); dec_flags = (postproc ? VPX_CODEC_USE_POSTPROC : 0) | - (ec_enabled ? VPX_CODEC_USE_ERROR_CONCEALMENT : 0); + (ec_enabled ? VPX_CODEC_USE_ERROR_CONCEALMENT : 0) | + (frame_parallel ? VPX_CODEC_USE_FRAME_THREADING : 0); if (vpx_codec_dec_init(&decoder, interface->codec_interface(), &cfg, dec_flags)) { fprintf(stderr, "Failed to initialize decoder: %s\n", @@ -970,34 +810,42 @@ int main_loop(int argc, const char **argv_) { fprintf(stderr, "%s\n", decoder.name); #if CONFIG_VP8_DECODER - if (vp8_pp_cfg.post_proc_flag && vpx_codec_control(&decoder, VP8_SET_POSTPROC, &vp8_pp_cfg)) { - fprintf(stderr, "Failed to configure postproc: %s\n", vpx_codec_error(&decoder)); + fprintf(stderr, "Failed to configure postproc: %s\n", + vpx_codec_error(&decoder)); return EXIT_FAILURE; } if (vp8_dbg_color_ref_frame - && vpx_codec_control(&decoder, VP8_SET_DBG_COLOR_REF_FRAME, vp8_dbg_color_ref_frame)) { - fprintf(stderr, "Failed to configure reference block visualizer: %s\n", vpx_codec_error(&decoder)); + && vpx_codec_control(&decoder, VP8_SET_DBG_COLOR_REF_FRAME, + vp8_dbg_color_ref_frame)) { + fprintf(stderr, "Failed to configure reference block visualizer: %s\n", + vpx_codec_error(&decoder)); return EXIT_FAILURE; } if (vp8_dbg_color_mb_modes - && vpx_codec_control(&decoder, VP8_SET_DBG_COLOR_MB_MODES, vp8_dbg_color_mb_modes)) { - fprintf(stderr, "Failed to configure macro block visualizer: %s\n", vpx_codec_error(&decoder)); + && vpx_codec_control(&decoder, VP8_SET_DBG_COLOR_MB_MODES, + vp8_dbg_color_mb_modes)) { + fprintf(stderr, "Failed to configure macro block visualizer: %s\n", + vpx_codec_error(&decoder)); return EXIT_FAILURE; } if (vp8_dbg_color_b_modes - && vpx_codec_control(&decoder, VP8_SET_DBG_COLOR_B_MODES, vp8_dbg_color_b_modes)) { - fprintf(stderr, "Failed to configure block visualizer: %s\n", vpx_codec_error(&decoder)); + && vpx_codec_control(&decoder, VP8_SET_DBG_COLOR_B_MODES, + vp8_dbg_color_b_modes)) { + fprintf(stderr, "Failed to configure block visualizer: %s\n", + vpx_codec_error(&decoder)); return EXIT_FAILURE; } if (vp8_dbg_display_mv - && vpx_codec_control(&decoder, VP8_SET_DBG_DISPLAY_MV, vp8_dbg_display_mv)) { - fprintf(stderr, "Failed to configure motion vector visualizer: %s\n", vpx_codec_error(&decoder)); + && vpx_codec_control(&decoder, VP8_SET_DBG_DISPLAY_MV, + vp8_dbg_display_mv)) { + fprintf(stderr, "Failed to configure motion vector visualizer: %s\n", + vpx_codec_error(&decoder)); return EXIT_FAILURE; } #endif @@ -1032,7 +880,7 @@ int main_loop(int argc, const char **argv_) { vpx_codec_iter_t iter = NULL; vpx_image_t *img; struct vpx_usec_timer timer; - int corrupted; + int corrupted = 0; frame_avail = 0; if (!stop_after || frame_in < stop_after) { @@ -1056,11 +904,22 @@ int main_loop(int argc, const char **argv_) { vpx_usec_timer_mark(&timer); dx_time += vpx_usec_timer_elapsed(&timer); + } else { + flush_decoder = 1; } + } else { + flush_decoder = 1; } vpx_usec_timer_start(&timer); + if (flush_decoder) { + // Flush the decoder in frame parallel decode. + if (vpx_codec_decode(&decoder, NULL, 0, NULL, 0)) { + warn("Failed to flush decoder: %s", vpx_codec_error(&decoder)); + } + } + got_data = 0; if ((img = vpx_codec_get_frame(&decoder, &iter))) { ++frame_out; @@ -1070,9 +929,11 @@ int main_loop(int argc, const char **argv_) { vpx_usec_timer_mark(&timer); dx_time += (unsigned int)vpx_usec_timer_elapsed(&timer); - if (vpx_codec_control(&decoder, VP8D_GET_FRAME_CORRUPTED, &corrupted)) { + if (!frame_parallel && + vpx_codec_control(&decoder, VP8D_GET_FRAME_CORRUPTED, &corrupted)) { warn("Failed VP8_GET_FRAME_CORRUPTED: %s", vpx_codec_error(&decoder)); - goto fail; + if (!keep_going) + goto fail; } frames_corrupted += corrupted; @@ -1091,28 +952,28 @@ int main_loop(int argc, const char **argv_) { // these is set to 0, use the display size set in the first frame // header. If that is unavailable, use the raw decoded size of the // first decoded frame. - int display_width = vpx_input_ctx.width; - int display_height = vpx_input_ctx.height; - if (!display_width || !display_height) { - int display_size[2]; + int render_width = vpx_input_ctx.width; + int render_height = vpx_input_ctx.height; + if (!render_width || !render_height) { + int render_size[2]; if (vpx_codec_control(&decoder, VP9D_GET_DISPLAY_SIZE, - display_size)) { + render_size)) { // As last resort use size of first frame as display size. - display_width = img->d_w; - display_height = img->d_h; + render_width = img->d_w; + render_height = img->d_h; } else { - display_width = display_size[0]; - display_height = display_size[1]; + render_width = render_size[0]; + render_height = render_size[1]; } } - scaled_img = vpx_img_alloc(NULL, img->fmt, display_width, - display_height, 16); + scaled_img = vpx_img_alloc(NULL, img->fmt, render_width, + render_height, 16); scaled_img->bit_depth = img->bit_depth; } if (img->d_w != scaled_img->d_w || img->d_h != scaled_img->d_h) { #if CONFIG_LIBYUV - vpx_image_scale(img, scaled_img, kFilterBox); + libyuv_scale(img, scaled_img, kFilterBox); img = scaled_img; #else fprintf(stderr, "Failed to scale output frame: %s.\n" @@ -1123,29 +984,32 @@ int main_loop(int argc, const char **argv_) { #endif } } -#if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH +#if CONFIG_VP9_HIGHBITDEPTH // Default to codec bit depth if output bit depth not set - if (!output_bit_depth) { + if (!output_bit_depth && single_file && !do_md5) { output_bit_depth = img->bit_depth; } // Shift up or down if necessary - if (output_bit_depth != img->bit_depth) { + if (output_bit_depth != 0 && output_bit_depth != img->bit_depth) { + const vpx_img_fmt_t shifted_fmt = output_bit_depth == 8 ? + img->fmt ^ (img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) : + img->fmt | VPX_IMG_FMT_HIGHBITDEPTH; + if (img_shifted && + img_shifted_realloc_required(img, img_shifted, shifted_fmt)) { + vpx_img_free(img_shifted); + img_shifted = NULL; + } if (!img_shifted) { - if (output_bit_depth == 8) { - img_shifted = vpx_img_alloc( - NULL, img->fmt - VPX_IMG_FMT_HIGHBITDEPTH, - img->d_w, img->d_h, 16); - } else { - img_shifted = vpx_img_alloc( - NULL, img->fmt | VPX_IMG_FMT_HIGHBITDEPTH, - 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 = output_bit_depth; } if (output_bit_depth > img->bit_depth) { - img_upshift(img_shifted, img, output_bit_depth - img->bit_depth); + vpx_img_upshift(img_shifted, img, + output_bit_depth - img->bit_depth); } else { - img_downshift(img_shifted, img, img->bit_depth - output_bit_depth); + vpx_img_downshift(img_shifted, img, + img->bit_depth - output_bit_depth); } img = img_shifted; } @@ -1155,6 +1019,10 @@ int main_loop(int argc, const char **argv_) { if (use_y4m) { char buf[Y4M_BUFFER_SIZE] = {0}; size_t len = 0; + if (img->fmt == VPX_IMG_FMT_I440 || img->fmt == VPX_IMG_FMT_I44016) { + fprintf(stderr, "Cannot produce y4m output for 440 sampling.\n"); + goto fail; + } if (frame_out == 1) { // Y4M file header len = y4m_write_file_header(buf, sizeof(buf), @@ -1217,9 +1085,6 @@ int main_loop(int argc, const char **argv_) { } } } - - if (stop_after && frame_in >= stop_after) - break; } if (summary || progress) { @@ -1256,7 +1121,7 @@ fail: free(buf); if (scaled_img) vpx_img_free(scaled_img); -#if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH +#if CONFIG_VP9_HIGHBITDEPTH if (img_shifted) vpx_img_free(img_shifted); #endif