John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1 | /* |
John Koleszar | c2140b8 | 2010-09-09 08:16:39 -0400 | [diff] [blame] | 2 | * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 3 | * |
John Koleszar | 94c52e4 | 2010-06-18 12:39:21 -0400 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license |
John Koleszar | 09202d8 | 2010-06-04 16:19:40 -0400 | [diff] [blame] | 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
John Koleszar | 94c52e4 | 2010-06-18 12:39:21 -0400 | [diff] [blame] | 7 | * in the file PATENTS. All contributing project authors may |
John Koleszar | 09202d8 | 2010-06-04 16:19:40 -0400 | [diff] [blame] | 8 | * be found in the AUTHORS file in the root of the source tree. |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 9 | */ |
| 10 | |
John Koleszar | da58436 | 2013-05-06 15:52:06 -0700 | [diff] [blame] | 11 | #include <assert.h> |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 12 | #include <stdio.h> |
| 13 | #include <stdlib.h> |
| 14 | #include <stdarg.h> |
| 15 | #include <string.h> |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 16 | #include <limits.h> |
Tero Rintaluoma | 11a222f | 2011-01-24 11:21:40 +0200 | [diff] [blame] | 17 | |
James Zern | 1e681d9 | 2014-08-15 21:00:09 -0700 | [diff] [blame] | 18 | #include "./vpx_config.h" |
| 19 | |
| 20 | #if CONFIG_LIBYUV |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 21 | #include "third_party/libyuv/include/libyuv/scale.h" |
James Zern | 1e681d9 | 2014-08-15 21:00:09 -0700 | [diff] [blame] | 22 | #endif |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 23 | |
| 24 | #include "./args.h" |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 25 | #include "./ivfdec.h" |
| 26 | |
John Koleszar | b749234 | 2010-05-24 11:39:59 -0400 | [diff] [blame] | 27 | #include "vpx/vpx_decoder.h" |
Dmitry Kovalev | 4334c07 | 2014-02-26 16:32:09 -0800 | [diff] [blame] | 28 | #include "vpx_ports/mem_ops.h" |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 29 | #include "vpx_ports/vpx_timer.h" |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 30 | |
John Koleszar | 7b8dfcb | 2012-11-06 16:59:01 -0800 | [diff] [blame] | 31 | #if CONFIG_VP8_DECODER || CONFIG_VP9_DECODER |
John Koleszar | b749234 | 2010-05-24 11:39:59 -0400 | [diff] [blame] | 32 | #include "vpx/vp8dx.h" |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 33 | #endif |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 34 | |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 35 | #include "./md5_utils.h" |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 36 | |
| 37 | #include "./tools_common.h" |
James Zern | b6cce76 | 2014-05-10 17:44:12 -0700 | [diff] [blame] | 38 | #if CONFIG_WEBM_IO |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 39 | #include "./webmdec.h" |
James Zern | b6cce76 | 2014-05-10 17:44:12 -0700 | [diff] [blame] | 40 | #endif |
Dmitry Kovalev | 5ab6358 | 2014-01-17 17:02:37 -0800 | [diff] [blame] | 41 | #include "./y4menc.h" |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 42 | |
| 43 | static const char *exec_name; |
| 44 | |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 45 | struct VpxDecInputContext { |
| 46 | struct VpxInputContext *vpx_input_ctx; |
| 47 | struct WebmInputContext *webm_ctx; |
| 48 | }; |
| 49 | |
Deb Mukherjee | a349ee3 | 2014-10-13 14:27:53 -0700 | [diff] [blame] | 50 | static const arg_def_t looparg = ARG_DEF( |
| 51 | NULL, "loops", 1, "Number of times to decode the file"); |
| 52 | static const arg_def_t codecarg = ARG_DEF( |
| 53 | NULL, "codec", 1, "Codec to use"); |
| 54 | static const arg_def_t use_yv12 = ARG_DEF( |
| 55 | NULL, "yv12", 0, "Output raw YV12 frames"); |
| 56 | static const arg_def_t use_i420 = ARG_DEF( |
| 57 | NULL, "i420", 0, "Output raw I420 frames"); |
| 58 | static const arg_def_t flipuvarg = ARG_DEF( |
| 59 | NULL, "flipuv", 0, "Flip the chroma planes in the output"); |
| 60 | static const arg_def_t rawvideo = ARG_DEF( |
| 61 | NULL, "rawvideo", 0, "Output raw YUV frames"); |
| 62 | static const arg_def_t noblitarg = ARG_DEF( |
| 63 | NULL, "noblit", 0, "Don't process the decoded frames"); |
| 64 | static const arg_def_t progressarg = ARG_DEF( |
| 65 | NULL, "progress", 0, "Show progress after each frame decodes"); |
| 66 | static const arg_def_t limitarg = ARG_DEF( |
| 67 | NULL, "limit", 1, "Stop decoding after n frames"); |
| 68 | static const arg_def_t skiparg = ARG_DEF( |
| 69 | NULL, "skip", 1, "Skip the first n input frames"); |
| 70 | static const arg_def_t postprocarg = ARG_DEF( |
| 71 | NULL, "postproc", 0, "Postprocess decoded frames"); |
| 72 | static const arg_def_t summaryarg = ARG_DEF( |
| 73 | NULL, "summary", 0, "Show timing summary"); |
| 74 | static const arg_def_t outputfile = ARG_DEF( |
| 75 | "o", "output", 1, "Output file name pattern (see below)"); |
| 76 | static const arg_def_t threadsarg = ARG_DEF( |
| 77 | "t", "threads", 1, "Max threads to use"); |
hkuang | 1f841c3 | 2015-03-06 13:03:18 -0800 | [diff] [blame^] | 78 | static const arg_def_t frameparallelarg = ARG_DEF( |
| 79 | NULL, "frame-parallel", 0, "Frame parallel decode"); |
Deb Mukherjee | a349ee3 | 2014-10-13 14:27:53 -0700 | [diff] [blame] | 80 | static const arg_def_t verbosearg = ARG_DEF( |
| 81 | "v", "verbose", 0, "Show version string"); |
| 82 | static const arg_def_t error_concealment = ARG_DEF( |
| 83 | NULL, "error-concealment", 0, "Enable decoder error-concealment"); |
| 84 | static const arg_def_t scalearg = ARG_DEF( |
| 85 | "S", "scale", 0, "Scale output frames uniformly"); |
| 86 | static const arg_def_t continuearg = ARG_DEF( |
| 87 | "k", "keep-going", 0, "(debug) Continue decoding after error"); |
| 88 | static const arg_def_t fb_arg = ARG_DEF( |
| 89 | NULL, "frame-buffers", 1, "Number of frame buffers to use"); |
| 90 | static const arg_def_t md5arg = ARG_DEF( |
| 91 | NULL, "md5", 0, "Compute the MD5 sum of the decoded frame"); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 92 | #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH |
| 93 | static const arg_def_t outbitdeptharg = ARG_DEF( |
Deb Mukherjee | a349ee3 | 2014-10-13 14:27:53 -0700 | [diff] [blame] | 94 | NULL, "output-bit-depth", 1, "Output bit-depth for decoded frames"); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 95 | #endif |
Dmitry Kovalev | d24f4e4 | 2013-12-27 16:10:18 -0800 | [diff] [blame] | 96 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 97 | static const arg_def_t *all_args[] = { |
Deb Mukherjee | 090f4d4 | 2014-07-16 09:37:13 -0700 | [diff] [blame] | 98 | &codecarg, &use_yv12, &use_i420, &flipuvarg, &rawvideo, &noblitarg, |
Yaowu Xu | c394ffc | 2012-10-11 15:12:35 -0700 | [diff] [blame] | 99 | &progressarg, &limitarg, &skiparg, &postprocarg, &summaryarg, &outputfile, |
hkuang | 1f841c3 | 2015-03-06 13:03:18 -0800 | [diff] [blame^] | 100 | &threadsarg, &frameparallelarg, &verbosearg, &scalearg, &fb_arg, |
James Zern | 95853db | 2014-07-01 19:02:15 -0700 | [diff] [blame] | 101 | &md5arg, &error_concealment, &continuearg, |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 102 | #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH |
| 103 | &outbitdeptharg, |
| 104 | #endif |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 105 | NULL |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 106 | }; |
| 107 | |
John Koleszar | a9c7597 | 2012-11-08 17:09:30 -0800 | [diff] [blame] | 108 | #if CONFIG_VP8_DECODER |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 109 | static const arg_def_t addnoise_level = ARG_DEF(NULL, "noise-level", 1, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 110 | "Enable VP8 postproc add noise"); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 111 | static const arg_def_t deblock = ARG_DEF(NULL, "deblock", 0, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 112 | "Enable VP8 deblocking"); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 113 | static const arg_def_t demacroblock_level = ARG_DEF(NULL, "demacroblock-level", 1, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 114 | "Enable VP8 demacroblocking, w/ level"); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 115 | static const arg_def_t pp_debug_info = ARG_DEF(NULL, "pp-debug-info", 1, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 116 | "Enable VP8 visible debug info"); |
Fritz Koenig | 647df00 | 2010-11-04 16:03:36 -0700 | [diff] [blame] | 117 | static const arg_def_t pp_disp_ref_frame = ARG_DEF(NULL, "pp-dbg-ref-frame", 1, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 118 | "Display only selected reference frame per macro block"); |
Fritz Koenig | 647df00 | 2010-11-04 16:03:36 -0700 | [diff] [blame] | 119 | static const arg_def_t pp_disp_mb_modes = ARG_DEF(NULL, "pp-dbg-mb-modes", 1, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 120 | "Display only selected macro block modes"); |
Fritz Koenig | 647df00 | 2010-11-04 16:03:36 -0700 | [diff] [blame] | 121 | static const arg_def_t pp_disp_b_modes = ARG_DEF(NULL, "pp-dbg-b-modes", 1, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 122 | "Display only selected block modes"); |
Fritz Koenig | 647df00 | 2010-11-04 16:03:36 -0700 | [diff] [blame] | 123 | static const arg_def_t pp_disp_mvs = ARG_DEF(NULL, "pp-dbg-mvs", 1, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 124 | "Draw only selected motion vectors"); |
John Koleszar | 3707c34 | 2012-11-06 10:09:36 -0800 | [diff] [blame] | 125 | static const arg_def_t mfqe = ARG_DEF(NULL, "mfqe", 0, |
| 126 | "Enable multiframe quality enhancement"); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 127 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 128 | static const arg_def_t *vp8_pp_args[] = { |
| 129 | &addnoise_level, &deblock, &demacroblock_level, &pp_debug_info, |
John Koleszar | 3707c34 | 2012-11-06 10:09:36 -0800 | [diff] [blame] | 130 | &pp_disp_ref_frame, &pp_disp_mb_modes, &pp_disp_b_modes, &pp_disp_mvs, &mfqe, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 131 | NULL |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 132 | }; |
| 133 | #endif |
| 134 | |
James Zern | 1e681d9 | 2014-08-15 21:00:09 -0700 | [diff] [blame] | 135 | #if CONFIG_LIBYUV |
Tom Finegan | 8ef2ce8 | 2014-12-12 11:57:04 -0800 | [diff] [blame] | 136 | static INLINE int libyuv_scale(vpx_image_t *src, vpx_image_t *dst, |
Jim Bankoski | f452961 | 2014-08-12 16:51:07 -0700 | [diff] [blame] | 137 | FilterModeEnum mode) { |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 138 | #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH |
| 139 | if (src->fmt == VPX_IMG_FMT_I42016) { |
| 140 | assert(dst->fmt == VPX_IMG_FMT_I42016); |
| 141 | return I420Scale_16((uint16_t*)src->planes[VPX_PLANE_Y], |
| 142 | src->stride[VPX_PLANE_Y]/2, |
| 143 | (uint16_t*)src->planes[VPX_PLANE_U], |
| 144 | src->stride[VPX_PLANE_U]/2, |
| 145 | (uint16_t*)src->planes[VPX_PLANE_V], |
| 146 | src->stride[VPX_PLANE_V]/2, |
| 147 | src->d_w, src->d_h, |
| 148 | (uint16_t*)dst->planes[VPX_PLANE_Y], |
| 149 | dst->stride[VPX_PLANE_Y]/2, |
| 150 | (uint16_t*)dst->planes[VPX_PLANE_U], |
| 151 | dst->stride[VPX_PLANE_U]/2, |
| 152 | (uint16_t*)dst->planes[VPX_PLANE_V], |
| 153 | dst->stride[VPX_PLANE_V]/2, |
| 154 | dst->d_w, dst->d_h, |
| 155 | mode); |
| 156 | } |
| 157 | #endif |
Dmitry Kovalev | 3c05481 | 2014-01-17 12:19:19 -0800 | [diff] [blame] | 158 | assert(src->fmt == VPX_IMG_FMT_I420); |
| 159 | assert(dst->fmt == VPX_IMG_FMT_I420); |
| 160 | return I420Scale(src->planes[VPX_PLANE_Y], src->stride[VPX_PLANE_Y], |
| 161 | src->planes[VPX_PLANE_U], src->stride[VPX_PLANE_U], |
| 162 | src->planes[VPX_PLANE_V], src->stride[VPX_PLANE_V], |
| 163 | src->d_w, src->d_h, |
| 164 | dst->planes[VPX_PLANE_Y], dst->stride[VPX_PLANE_Y], |
| 165 | dst->planes[VPX_PLANE_U], dst->stride[VPX_PLANE_U], |
| 166 | dst->planes[VPX_PLANE_V], dst->stride[VPX_PLANE_V], |
| 167 | dst->d_w, dst->d_h, |
| 168 | mode); |
| 169 | } |
James Zern | 1e681d9 | 2014-08-15 21:00:09 -0700 | [diff] [blame] | 170 | #endif |
Dmitry Kovalev | 3c05481 | 2014-01-17 12:19:19 -0800 | [diff] [blame] | 171 | |
Tom Finegan | 03848f5 | 2013-11-05 10:02:18 -0800 | [diff] [blame] | 172 | void usage_exit() { |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 173 | int i; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 174 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 175 | fprintf(stderr, "Usage: %s <options> filename\n\n" |
| 176 | "Options:\n", exec_name); |
| 177 | arg_show_usage(stderr, all_args); |
John Koleszar | a9c7597 | 2012-11-08 17:09:30 -0800 | [diff] [blame] | 178 | #if CONFIG_VP8_DECODER |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 179 | fprintf(stderr, "\nVP8 Postprocessing Options:\n"); |
| 180 | arg_show_usage(stderr, vp8_pp_args); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 181 | #endif |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 182 | fprintf(stderr, |
| 183 | "\nOutput File Patterns:\n\n" |
| 184 | " The -o argument specifies the name of the file(s) to " |
| 185 | "write to. If the\n argument does not include any escape " |
| 186 | "characters, the output will be\n written to a single file. " |
| 187 | "Otherwise, the filename will be calculated by\n expanding " |
John Koleszar | 3707c34 | 2012-11-06 10:09:36 -0800 | [diff] [blame] | 188 | "the following escape characters:\n"); |
| 189 | fprintf(stderr, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 190 | "\n\t%%w - Frame width" |
| 191 | "\n\t%%h - Frame height" |
| 192 | "\n\t%%<n> - Frame number, zero padded to <n> places (1..9)" |
| 193 | "\n\n Pattern arguments are only supported in conjunction " |
| 194 | "with the --yv12 and\n --i420 options. If the -o option is " |
| 195 | "not specified, the output will be\n directed to stdout.\n" |
| 196 | ); |
| 197 | fprintf(stderr, "\nIncluded decoders:\n\n"); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 198 | |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 199 | for (i = 0; i < get_vpx_decoder_count(); ++i) { |
| 200 | const VpxInterface *const decoder = get_vpx_decoder_by_index(i); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 201 | fprintf(stderr, " %-6s - %s\n", |
Deb Mukherjee | f332c63 | 2014-07-15 16:55:12 -0700 | [diff] [blame] | 202 | decoder->name, vpx_codec_iface_name(decoder->codec_interface())); |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 203 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 204 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 205 | exit(EXIT_FAILURE); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 206 | } |
| 207 | |
Dmitry Kovalev | 0eac753 | 2014-01-13 11:57:55 -0800 | [diff] [blame] | 208 | static int raw_read_frame(FILE *infile, uint8_t **buffer, |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 209 | size_t *bytes_read, size_t *buffer_size) { |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 210 | char raw_hdr[RAW_FRAME_HDR_SZ]; |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 211 | size_t frame_size = 0; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 212 | |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 213 | if (fread(raw_hdr, RAW_FRAME_HDR_SZ, 1, infile) != 1) { |
| 214 | if (!feof(infile)) |
| 215 | warn("Failed to read RAW frame size\n"); |
| 216 | } else { |
James Zern | 75d7ee3 | 2014-02-04 20:06:28 -0800 | [diff] [blame] | 217 | const size_t kCorruptFrameThreshold = 256 * 1024 * 1024; |
| 218 | const size_t kFrameTooSmallThreshold = 256 * 1024; |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 219 | frame_size = mem_get_le32(raw_hdr); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 220 | |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 221 | if (frame_size > kCorruptFrameThreshold) { |
| 222 | warn("Read invalid frame size (%u)\n", (unsigned int)frame_size); |
| 223 | frame_size = 0; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 224 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 225 | |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 226 | if (frame_size < kFrameTooSmallThreshold) { |
| 227 | warn("Warning: Read invalid frame size (%u) - not a raw file?\n", |
| 228 | (unsigned int)frame_size); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 229 | } |
| 230 | |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 231 | if (frame_size > *buffer_size) { |
| 232 | uint8_t *new_buf = realloc(*buffer, 2 * frame_size); |
| 233 | if (new_buf) { |
| 234 | *buffer = new_buf; |
| 235 | *buffer_size = 2 * frame_size; |
| 236 | } else { |
| 237 | warn("Failed to allocate compressed data buffer\n"); |
| 238 | frame_size = 0; |
| 239 | } |
| 240 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 241 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 242 | |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 243 | if (!feof(infile)) { |
| 244 | if (fread(*buffer, 1, frame_size, infile) != frame_size) { |
| 245 | warn("Failed to read full frame\n"); |
| 246 | return 1; |
| 247 | } |
| 248 | *bytes_read = frame_size; |
| 249 | } |
| 250 | |
| 251 | return 0; |
| 252 | } |
| 253 | |
| 254 | static int read_frame(struct VpxDecInputContext *input, uint8_t **buf, |
| 255 | size_t *bytes_in_buffer, size_t *buffer_size) { |
| 256 | switch (input->vpx_input_ctx->file_type) { |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 257 | #if CONFIG_WEBM_IO |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 258 | case FILE_TYPE_WEBM: |
| 259 | return webm_read_frame(input->webm_ctx, |
| 260 | buf, bytes_in_buffer, buffer_size); |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 261 | #endif |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 262 | case FILE_TYPE_RAW: |
Dmitry Kovalev | 0eac753 | 2014-01-13 11:57:55 -0800 | [diff] [blame] | 263 | return raw_read_frame(input->vpx_input_ctx->file, |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 264 | buf, bytes_in_buffer, buffer_size); |
| 265 | case FILE_TYPE_IVF: |
Dmitry Kovalev | 0eac753 | 2014-01-13 11:57:55 -0800 | [diff] [blame] | 266 | return ivf_read_frame(input->vpx_input_ctx->file, |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 267 | buf, bytes_in_buffer, buffer_size); |
| 268 | default: |
| 269 | return 1; |
| 270 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 271 | } |
| 272 | |
Dmitry Kovalev | cf46bc7 | 2014-01-17 10:57:55 -0800 | [diff] [blame] | 273 | static void update_image_md5(const vpx_image_t *img, const int planes[3], |
| 274 | MD5Context *md5) { |
| 275 | int i, y; |
| 276 | |
| 277 | for (i = 0; i < 3; ++i) { |
| 278 | const int plane = planes[i]; |
| 279 | const unsigned char *buf = img->planes[plane]; |
| 280 | const int stride = img->stride[plane]; |
Deb Mukherjee | bec307a | 2014-10-20 23:51:58 -0700 | [diff] [blame] | 281 | const int w = vpx_img_plane_width(img, plane) * |
| 282 | ((img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? 2 : 1); |
Dmitry Kovalev | 2bdd43d | 2014-02-12 18:36:36 -0800 | [diff] [blame] | 283 | const int h = vpx_img_plane_height(img, plane); |
Dmitry Kovalev | cf46bc7 | 2014-01-17 10:57:55 -0800 | [diff] [blame] | 284 | |
| 285 | for (y = 0; y < h; ++y) { |
| 286 | MD5Update(md5, buf, w); |
| 287 | buf += stride; |
| 288 | } |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | static void write_image_file(const vpx_image_t *img, const int planes[3], |
| 293 | FILE *file) { |
| 294 | int i, y; |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 295 | #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH |
| 296 | const int bytes_per_sample = ((img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? 2 : 1); |
| 297 | #else |
| 298 | const int bytes_per_sample = 1; |
| 299 | #endif |
Dmitry Kovalev | cf46bc7 | 2014-01-17 10:57:55 -0800 | [diff] [blame] | 300 | |
| 301 | for (i = 0; i < 3; ++i) { |
| 302 | const int plane = planes[i]; |
| 303 | const unsigned char *buf = img->planes[plane]; |
| 304 | const int stride = img->stride[plane]; |
Dmitry Kovalev | 2bdd43d | 2014-02-12 18:36:36 -0800 | [diff] [blame] | 305 | const int w = vpx_img_plane_width(img, plane); |
| 306 | const int h = vpx_img_plane_height(img, plane); |
Dmitry Kovalev | cf46bc7 | 2014-01-17 10:57:55 -0800 | [diff] [blame] | 307 | |
| 308 | for (y = 0; y < h; ++y) { |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 309 | fwrite(buf, bytes_per_sample, w, file); |
Dmitry Kovalev | cf46bc7 | 2014-01-17 10:57:55 -0800 | [diff] [blame] | 310 | buf += stride; |
| 311 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 312 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 313 | } |
| 314 | |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 315 | int file_is_raw(struct VpxInputContext *input) { |
| 316 | uint8_t buf[32]; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 317 | int is_raw = 0; |
| 318 | vpx_codec_stream_info_t si; |
John Koleszar | cfe3f91 | 2010-10-20 10:49:12 -0400 | [diff] [blame] | 319 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 320 | si.sz = sizeof(si); |
John Koleszar | 19255b8 | 2010-11-23 13:40:31 -0500 | [diff] [blame] | 321 | |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 322 | if (fread(buf, 1, 32, input->file) == 32) { |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 323 | int i; |
John Koleszar | cfe3f91 | 2010-10-20 10:49:12 -0400 | [diff] [blame] | 324 | |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 325 | if (mem_get_le32(buf) < 256 * 1024 * 1024) { |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 326 | for (i = 0; i < get_vpx_decoder_count(); ++i) { |
| 327 | const VpxInterface *const decoder = get_vpx_decoder_by_index(i); |
Deb Mukherjee | f332c63 | 2014-07-15 16:55:12 -0700 | [diff] [blame] | 328 | if (!vpx_codec_peek_stream_info(decoder->codec_interface(), |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 329 | buf + 4, 32 - 4, &si)) { |
| 330 | is_raw = 1; |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 331 | input->fourcc = decoder->fourcc; |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 332 | input->width = si.w; |
| 333 | input->height = si.h; |
| 334 | input->framerate.numerator = 30; |
| 335 | input->framerate.denominator = 1; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 336 | break; |
| 337 | } |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 338 | } |
| 339 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 340 | } |
John Koleszar | cfe3f91 | 2010-10-20 10:49:12 -0400 | [diff] [blame] | 341 | |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 342 | rewind(input->file); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 343 | return is_raw; |
John Koleszar | cfe3f91 | 2010-10-20 10:49:12 -0400 | [diff] [blame] | 344 | } |
| 345 | |
James Yu | 6d15132 | 2014-02-22 14:51:11 +0800 | [diff] [blame] | 346 | void show_progress(int frame_in, int frame_out, uint64_t dx_time) { |
| 347 | fprintf(stderr, |
| 348 | "%d decoded frames/%d showed frames in %"PRId64" us (%.2f fps)\r", |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 349 | frame_in, frame_out, dx_time, |
James Yu | 6d15132 | 2014-02-22 14:51:11 +0800 | [diff] [blame] | 350 | (double)frame_out * 1000000.0 / (double)dx_time); |
John Koleszar | 5d12e04 | 2010-10-21 17:28:34 -0400 | [diff] [blame] | 351 | } |
| 352 | |
Frank Galligan | a4f30a5 | 2014-02-06 17:13:08 -0800 | [diff] [blame] | 353 | struct ExternalFrameBuffer { |
| 354 | uint8_t* data; |
| 355 | size_t size; |
| 356 | int in_use; |
| 357 | }; |
| 358 | |
| 359 | struct ExternalFrameBufferList { |
| 360 | int num_external_frame_buffers; |
| 361 | struct ExternalFrameBuffer *ext_fb; |
| 362 | }; |
| 363 | |
| 364 | // Callback used by libvpx to request an external frame buffer. |cb_priv| |
| 365 | // Application private data passed into the set function. |min_size| is the |
| 366 | // minimum size in bytes needed to decode the next frame. |fb| pointer to the |
| 367 | // frame buffer. |
| 368 | int get_vp9_frame_buffer(void *cb_priv, size_t min_size, |
| 369 | vpx_codec_frame_buffer_t *fb) { |
| 370 | int i; |
| 371 | struct ExternalFrameBufferList *const ext_fb_list = |
| 372 | (struct ExternalFrameBufferList *)cb_priv; |
| 373 | if (ext_fb_list == NULL) |
| 374 | return -1; |
| 375 | |
| 376 | // Find a free frame buffer. |
| 377 | for (i = 0; i < ext_fb_list->num_external_frame_buffers; ++i) { |
| 378 | if (!ext_fb_list->ext_fb[i].in_use) |
| 379 | break; |
| 380 | } |
| 381 | |
| 382 | if (i == ext_fb_list->num_external_frame_buffers) |
| 383 | return -1; |
| 384 | |
| 385 | if (ext_fb_list->ext_fb[i].size < min_size) { |
| 386 | free(ext_fb_list->ext_fb[i].data); |
Frank Galligan | 175d9df | 2014-09-11 08:39:38 -0700 | [diff] [blame] | 387 | ext_fb_list->ext_fb[i].data = (uint8_t *)calloc(min_size, sizeof(uint8_t)); |
Frank Galligan | a4f30a5 | 2014-02-06 17:13:08 -0800 | [diff] [blame] | 388 | if (!ext_fb_list->ext_fb[i].data) |
| 389 | return -1; |
| 390 | |
| 391 | ext_fb_list->ext_fb[i].size = min_size; |
| 392 | } |
| 393 | |
| 394 | fb->data = ext_fb_list->ext_fb[i].data; |
| 395 | fb->size = ext_fb_list->ext_fb[i].size; |
| 396 | ext_fb_list->ext_fb[i].in_use = 1; |
| 397 | |
| 398 | // Set the frame buffer's private data to point at the external frame buffer. |
| 399 | fb->priv = &ext_fb_list->ext_fb[i]; |
| 400 | return 0; |
| 401 | } |
| 402 | |
| 403 | // Callback used by libvpx when there are no references to the frame buffer. |
| 404 | // |cb_priv| user private data passed into the set function. |fb| pointer |
| 405 | // to the frame buffer. |
| 406 | int release_vp9_frame_buffer(void *cb_priv, |
| 407 | vpx_codec_frame_buffer_t *fb) { |
| 408 | struct ExternalFrameBuffer *const ext_fb = |
| 409 | (struct ExternalFrameBuffer *)fb->priv; |
| 410 | (void)cb_priv; |
| 411 | ext_fb->in_use = 0; |
| 412 | return 0; |
| 413 | } |
| 414 | |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 415 | void generate_filename(const char *pattern, char *out, size_t q_len, |
| 416 | unsigned int d_w, unsigned int d_h, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 417 | unsigned int frame_in) { |
| 418 | const char *p = pattern; |
| 419 | char *q = out; |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 420 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 421 | do { |
| 422 | char *next_pat = strchr(p, '%'); |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 423 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 424 | if (p == next_pat) { |
| 425 | size_t pat_len; |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 426 | |
John Koleszar | 3707c34 | 2012-11-06 10:09:36 -0800 | [diff] [blame] | 427 | /* parse the pattern */ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 428 | q[q_len - 1] = '\0'; |
| 429 | switch (p[1]) { |
| 430 | case 'w': |
| 431 | snprintf(q, q_len - 1, "%d", d_w); |
| 432 | break; |
| 433 | case 'h': |
| 434 | snprintf(q, q_len - 1, "%d", d_h); |
| 435 | break; |
| 436 | case '1': |
| 437 | snprintf(q, q_len - 1, "%d", frame_in); |
| 438 | break; |
| 439 | case '2': |
| 440 | snprintf(q, q_len - 1, "%02d", frame_in); |
| 441 | break; |
| 442 | case '3': |
| 443 | snprintf(q, q_len - 1, "%03d", frame_in); |
| 444 | break; |
| 445 | case '4': |
| 446 | snprintf(q, q_len - 1, "%04d", frame_in); |
| 447 | break; |
| 448 | case '5': |
| 449 | snprintf(q, q_len - 1, "%05d", frame_in); |
| 450 | break; |
| 451 | case '6': |
| 452 | snprintf(q, q_len - 1, "%06d", frame_in); |
| 453 | break; |
| 454 | case '7': |
| 455 | snprintf(q, q_len - 1, "%07d", frame_in); |
| 456 | break; |
| 457 | case '8': |
| 458 | snprintf(q, q_len - 1, "%08d", frame_in); |
| 459 | break; |
| 460 | case '9': |
| 461 | snprintf(q, q_len - 1, "%09d", frame_in); |
| 462 | break; |
| 463 | default: |
| 464 | die("Unrecognized pattern %%%c\n", p[1]); |
Jim Bankoski | 5c41891 | 2014-08-01 07:11:43 -0700 | [diff] [blame] | 465 | break; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 466 | } |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 467 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 468 | pat_len = strlen(q); |
| 469 | if (pat_len >= q_len - 1) |
| 470 | die("Output filename too long.\n"); |
| 471 | q += pat_len; |
| 472 | p += 2; |
| 473 | q_len -= pat_len; |
| 474 | } else { |
| 475 | size_t copy_len; |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 476 | |
John Koleszar | 3707c34 | 2012-11-06 10:09:36 -0800 | [diff] [blame] | 477 | /* copy the next segment */ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 478 | if (!next_pat) |
| 479 | copy_len = strlen(p); |
| 480 | else |
| 481 | copy_len = next_pat - p; |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 482 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 483 | if (copy_len >= q_len - 1) |
| 484 | die("Output filename too long.\n"); |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 485 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 486 | memcpy(q, p, copy_len); |
| 487 | q[copy_len] = '\0'; |
| 488 | q += copy_len; |
| 489 | p += copy_len; |
| 490 | q_len -= copy_len; |
| 491 | } |
| 492 | } while (*p); |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 493 | } |
| 494 | |
Dmitry Kovalev | 347b306 | 2014-01-22 09:04:07 -0800 | [diff] [blame] | 495 | static int is_single_file(const char *outfile_pattern) { |
| 496 | const char *p = outfile_pattern; |
| 497 | |
| 498 | do { |
| 499 | p = strchr(p, '%'); |
| 500 | if (p && p[1] >= '1' && p[1] <= '9') |
| 501 | return 0; // pattern contains sequence number, so it's not unique |
| 502 | if (p) |
| 503 | p++; |
| 504 | } while (p); |
| 505 | |
| 506 | return 1; |
| 507 | } |
| 508 | |
| 509 | static void print_md5(unsigned char digest[16], const char *filename) { |
| 510 | int i; |
| 511 | |
| 512 | for (i = 0; i < 16; ++i) |
| 513 | printf("%02x", digest[i]); |
| 514 | printf(" %s\n", filename); |
| 515 | } |
| 516 | |
| 517 | static FILE *open_outfile(const char *name) { |
| 518 | if (strcmp("-", name) == 0) { |
| 519 | set_binary_mode(stdout); |
| 520 | return stdout; |
| 521 | } else { |
| 522 | FILE *file = fopen(name, "wb"); |
| 523 | if (!file) |
James Zern | 6b993f0 | 2015-02-05 21:06:29 -0800 | [diff] [blame] | 524 | fatal("Failed to open output file '%s'", name); |
Dmitry Kovalev | 347b306 | 2014-01-22 09:04:07 -0800 | [diff] [blame] | 525 | return file; |
| 526 | } |
| 527 | } |
| 528 | |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 529 | #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH |
Deb Mukherjee | 9ed23de | 2014-09-25 15:46:50 -0700 | [diff] [blame] | 530 | static int img_shifted_realloc_required(const vpx_image_t *img, |
| 531 | const vpx_image_t *shifted, |
| 532 | vpx_img_fmt_t required_fmt) { |
| 533 | return img->d_w != shifted->d_w || |
| 534 | img->d_h != shifted->d_h || |
| 535 | required_fmt != shifted->fmt; |
| 536 | } |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 537 | #endif |
| 538 | |
John Koleszar | 9596a4c | 2013-06-12 16:08:35 -0700 | [diff] [blame] | 539 | int main_loop(int argc, const char **argv_) { |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 540 | vpx_codec_ctx_t decoder; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 541 | char *fn = NULL; |
Alex Converse | 2eccbd0 | 2014-02-13 17:02:50 -0800 | [diff] [blame] | 542 | int i; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 543 | uint8_t *buf = NULL; |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 544 | size_t bytes_in_buffer = 0, buffer_size = 0; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 545 | FILE *infile; |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 546 | int frame_in = 0, frame_out = 0, flipuv = 0, noblit = 0; |
hkuang | 1f841c3 | 2015-03-06 13:03:18 -0800 | [diff] [blame^] | 547 | int do_md5 = 0, progress = 0, frame_parallel = 0; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 548 | int stop_after = 0, postproc = 0, summary = 0, quiet = 1; |
Yaowu Xu | c394ffc | 2012-10-11 15:12:35 -0700 | [diff] [blame] | 549 | int arg_skip = 0; |
John Koleszar | 3707c34 | 2012-11-06 10:09:36 -0800 | [diff] [blame] | 550 | int ec_enabled = 0; |
James Zern | 95853db | 2014-07-01 19:02:15 -0700 | [diff] [blame] | 551 | int keep_going = 0; |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 552 | const VpxInterface *interface = NULL; |
| 553 | const VpxInterface *fourcc_interface = NULL; |
James Yu | 6d15132 | 2014-02-22 14:51:11 +0800 | [diff] [blame] | 554 | uint64_t dx_time = 0; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 555 | struct arg arg; |
| 556 | char **argv, **argi, **argj; |
Dmitry Kovalev | 347b306 | 2014-01-22 09:04:07 -0800 | [diff] [blame] | 557 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 558 | int single_file; |
| 559 | int use_y4m = 1; |
Deb Mukherjee | 090f4d4 | 2014-07-16 09:37:13 -0700 | [diff] [blame] | 560 | int opt_yv12 = 0; |
| 561 | int opt_i420 = 0; |
Jim Bankoski | 5c41891 | 2014-08-01 07:11:43 -0700 | [diff] [blame] | 562 | vpx_codec_dec_cfg_t cfg = {0, 0, 0}; |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 563 | #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH |
| 564 | int output_bit_depth = 0; |
| 565 | #endif |
John Koleszar | a9c7597 | 2012-11-08 17:09:30 -0800 | [diff] [blame] | 566 | #if CONFIG_VP8_DECODER |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 567 | vp8_postproc_cfg_t vp8_pp_cfg = {0}; |
| 568 | int vp8_dbg_color_ref_frame = 0; |
| 569 | int vp8_dbg_color_mb_modes = 0; |
| 570 | int vp8_dbg_color_b_modes = 0; |
| 571 | int vp8_dbg_display_mv = 0; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 572 | #endif |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 573 | int frames_corrupted = 0; |
| 574 | int dec_flags = 0; |
John Koleszar | 83f2a11 | 2013-03-11 12:30:29 -0700 | [diff] [blame] | 575 | int do_scale = 0; |
John Koleszar | 7d8fc26 | 2013-02-25 16:58:47 -0800 | [diff] [blame] | 576 | vpx_image_t *scaled_img = NULL; |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 577 | #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH |
| 578 | vpx_image_t *img_shifted = NULL; |
| 579 | #endif |
hkuang | 1f841c3 | 2015-03-06 13:03:18 -0800 | [diff] [blame^] | 580 | int frame_avail, got_data, flush_decoder = 0; |
Frank Galligan | a4f30a5 | 2014-02-06 17:13:08 -0800 | [diff] [blame] | 581 | int num_external_frame_buffers = 0; |
Jim Bankoski | 5c41891 | 2014-08-01 07:11:43 -0700 | [diff] [blame] | 582 | struct ExternalFrameBufferList ext_fb_list = {0, NULL}; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 583 | |
Dmitry Kovalev | 347b306 | 2014-01-22 09:04:07 -0800 | [diff] [blame] | 584 | const char *outfile_pattern = NULL; |
| 585 | char outfile_name[PATH_MAX] = {0}; |
| 586 | FILE *outfile = NULL; |
| 587 | |
| 588 | MD5Context md5_ctx; |
| 589 | unsigned char md5_digest[16]; |
| 590 | |
Jim Bankoski | 5c41891 | 2014-08-01 07:11:43 -0700 | [diff] [blame] | 591 | struct VpxDecInputContext input = {NULL, NULL}; |
| 592 | struct VpxInputContext vpx_input_ctx; |
James Zern | b6cce76 | 2014-05-10 17:44:12 -0700 | [diff] [blame] | 593 | #if CONFIG_WEBM_IO |
Jim Bankoski | 7ae3269 | 2014-08-19 06:44:10 -0700 | [diff] [blame] | 594 | struct WebmInputContext webm_ctx; |
| 595 | memset(&(webm_ctx), 0, sizeof(webm_ctx)); |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 596 | input.webm_ctx = &webm_ctx; |
James Zern | b6cce76 | 2014-05-10 17:44:12 -0700 | [diff] [blame] | 597 | #endif |
| 598 | input.vpx_input_ctx = &vpx_input_ctx; |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 599 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 600 | /* Parse command line */ |
| 601 | exec_name = argv_[0]; |
| 602 | argv = argv_dup(argc - 1, argv_ + 1); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 603 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 604 | for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) { |
| 605 | memset(&arg, 0, sizeof(arg)); |
| 606 | arg.argv_step = 1; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 607 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 608 | if (arg_match(&arg, &codecarg, argi)) { |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 609 | interface = get_vpx_decoder_by_name(arg.val); |
| 610 | if (!interface) |
| 611 | die("Error: Unrecognized argument (%s) to --codec\n", arg.val); |
John Koleszar | 9596a4c | 2013-06-12 16:08:35 -0700 | [diff] [blame] | 612 | } else if (arg_match(&arg, &looparg, argi)) { |
| 613 | // no-op |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 614 | } else if (arg_match(&arg, &outputfile, argi)) |
| 615 | outfile_pattern = arg.val; |
| 616 | else if (arg_match(&arg, &use_yv12, argi)) { |
| 617 | use_y4m = 0; |
| 618 | flipuv = 1; |
Deb Mukherjee | 090f4d4 | 2014-07-16 09:37:13 -0700 | [diff] [blame] | 619 | opt_yv12 = 1; |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 620 | #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH |
| 621 | output_bit_depth = 8; // For yv12 8-bit depth output is assumed |
| 622 | #endif |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 623 | } else if (arg_match(&arg, &use_i420, argi)) { |
| 624 | use_y4m = 0; |
| 625 | flipuv = 0; |
Deb Mukherjee | 090f4d4 | 2014-07-16 09:37:13 -0700 | [diff] [blame] | 626 | opt_i420 = 1; |
| 627 | } else if (arg_match(&arg, &rawvideo, argi)) { |
| 628 | use_y4m = 0; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 629 | } else if (arg_match(&arg, &flipuvarg, argi)) |
| 630 | flipuv = 1; |
| 631 | else if (arg_match(&arg, &noblitarg, argi)) |
| 632 | noblit = 1; |
| 633 | else if (arg_match(&arg, &progressarg, argi)) |
| 634 | progress = 1; |
| 635 | else if (arg_match(&arg, &limitarg, argi)) |
| 636 | stop_after = arg_parse_uint(&arg); |
Yaowu Xu | c394ffc | 2012-10-11 15:12:35 -0700 | [diff] [blame] | 637 | else if (arg_match(&arg, &skiparg, argi)) |
| 638 | arg_skip = arg_parse_uint(&arg); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 639 | else if (arg_match(&arg, &postprocarg, argi)) |
| 640 | postproc = 1; |
| 641 | else if (arg_match(&arg, &md5arg, argi)) |
| 642 | do_md5 = 1; |
| 643 | else if (arg_match(&arg, &summaryarg, argi)) |
| 644 | summary = 1; |
| 645 | else if (arg_match(&arg, &threadsarg, argi)) |
| 646 | cfg.threads = arg_parse_uint(&arg); |
hkuang | 1f841c3 | 2015-03-06 13:03:18 -0800 | [diff] [blame^] | 647 | #if CONFIG_VP9_DECODER |
| 648 | else if (arg_match(&arg, &frameparallelarg, argi)) |
| 649 | frame_parallel = 1; |
| 650 | #endif |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 651 | else if (arg_match(&arg, &verbosearg, argi)) |
| 652 | quiet = 0; |
John Koleszar | 7d8fc26 | 2013-02-25 16:58:47 -0800 | [diff] [blame] | 653 | else if (arg_match(&arg, &scalearg, argi)) |
| 654 | do_scale = 1; |
Frank Galligan | a4f30a5 | 2014-02-06 17:13:08 -0800 | [diff] [blame] | 655 | else if (arg_match(&arg, &fb_arg, argi)) |
| 656 | num_external_frame_buffers = arg_parse_uint(&arg); |
James Zern | 7690d88 | 2014-08-22 18:01:28 -0700 | [diff] [blame] | 657 | else if (arg_match(&arg, &continuearg, argi)) |
| 658 | keep_going = 1; |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 659 | #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH |
| 660 | else if (arg_match(&arg, &outbitdeptharg, argi)) { |
| 661 | output_bit_depth = arg_parse_uint(&arg); |
| 662 | } |
| 663 | #endif |
John Koleszar | a9c7597 | 2012-11-08 17:09:30 -0800 | [diff] [blame] | 664 | #if CONFIG_VP8_DECODER |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 665 | else if (arg_match(&arg, &addnoise_level, argi)) { |
| 666 | postproc = 1; |
| 667 | vp8_pp_cfg.post_proc_flag |= VP8_ADDNOISE; |
| 668 | vp8_pp_cfg.noise_level = arg_parse_uint(&arg); |
| 669 | } else if (arg_match(&arg, &demacroblock_level, argi)) { |
| 670 | postproc = 1; |
| 671 | vp8_pp_cfg.post_proc_flag |= VP8_DEMACROBLOCK; |
| 672 | vp8_pp_cfg.deblocking_level = arg_parse_uint(&arg); |
| 673 | } else if (arg_match(&arg, &deblock, argi)) { |
| 674 | postproc = 1; |
| 675 | vp8_pp_cfg.post_proc_flag |= VP8_DEBLOCK; |
John Koleszar | 3707c34 | 2012-11-06 10:09:36 -0800 | [diff] [blame] | 676 | } else if (arg_match(&arg, &mfqe, argi)) { |
| 677 | postproc = 1; |
| 678 | vp8_pp_cfg.post_proc_flag |= VP8_MFQE; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 679 | } else if (arg_match(&arg, &pp_debug_info, argi)) { |
| 680 | unsigned int level = arg_parse_uint(&arg); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 681 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 682 | postproc = 1; |
| 683 | vp8_pp_cfg.post_proc_flag &= ~0x7; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 684 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 685 | if (level) |
| 686 | vp8_pp_cfg.post_proc_flag |= level; |
| 687 | } else if (arg_match(&arg, &pp_disp_ref_frame, argi)) { |
| 688 | unsigned int flags = arg_parse_int(&arg); |
| 689 | if (flags) { |
| 690 | postproc = 1; |
| 691 | vp8_dbg_color_ref_frame = flags; |
| 692 | } |
| 693 | } else if (arg_match(&arg, &pp_disp_mb_modes, argi)) { |
| 694 | unsigned int flags = arg_parse_int(&arg); |
| 695 | if (flags) { |
| 696 | postproc = 1; |
| 697 | vp8_dbg_color_mb_modes = flags; |
| 698 | } |
| 699 | } else if (arg_match(&arg, &pp_disp_b_modes, argi)) { |
| 700 | unsigned int flags = arg_parse_int(&arg); |
| 701 | if (flags) { |
| 702 | postproc = 1; |
| 703 | vp8_dbg_color_b_modes = flags; |
| 704 | } |
| 705 | } else if (arg_match(&arg, &pp_disp_mvs, argi)) { |
| 706 | unsigned int flags = arg_parse_int(&arg); |
| 707 | if (flags) { |
| 708 | postproc = 1; |
| 709 | vp8_dbg_display_mv = flags; |
| 710 | } |
John Koleszar | 3707c34 | 2012-11-06 10:09:36 -0800 | [diff] [blame] | 711 | } else if (arg_match(&arg, &error_concealment, argi)) { |
| 712 | ec_enabled = 1; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 713 | } |
James Zern | 7690d88 | 2014-08-22 18:01:28 -0700 | [diff] [blame] | 714 | #endif // CONFIG_VP8_DECODER |
John Koleszar | cfe3f91 | 2010-10-20 10:49:12 -0400 | [diff] [blame] | 715 | else |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 716 | argj++; |
| 717 | } |
| 718 | |
| 719 | /* Check for unrecognized options */ |
| 720 | for (argi = argv; *argi; argi++) |
| 721 | if (argi[0][0] == '-' && strlen(argi[0]) > 1) |
| 722 | die("Error: Unrecognized option %s\n", *argi); |
| 723 | |
| 724 | /* Handle non-option arguments */ |
| 725 | fn = argv[0]; |
| 726 | |
Hanno Böck | b5d0a20 | 2015-02-24 15:48:21 -0800 | [diff] [blame] | 727 | if (!fn) { |
| 728 | free(argv); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 729 | usage_exit(); |
Hanno Böck | b5d0a20 | 2015-02-24 15:48:21 -0800 | [diff] [blame] | 730 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 731 | /* Open file */ |
| 732 | infile = strcmp(fn, "-") ? fopen(fn, "rb") : set_binary_mode(stdin); |
| 733 | |
| 734 | if (!infile) { |
James Zern | 6b993f0 | 2015-02-05 21:06:29 -0800 | [diff] [blame] | 735 | fatal("Failed to open input file '%s'", strcmp(fn, "-") ? fn : "stdin"); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 736 | } |
| 737 | #if CONFIG_OS_SUPPORT |
| 738 | /* Make sure we don't dump to the terminal, unless forced to with -o - */ |
| 739 | if (!outfile_pattern && isatty(fileno(stdout)) && !do_md5 && !noblit) { |
| 740 | fprintf(stderr, |
| 741 | "Not dumping raw video to your terminal. Use '-o -' to " |
| 742 | "override.\n"); |
| 743 | return EXIT_FAILURE; |
| 744 | } |
| 745 | #endif |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 746 | input.vpx_input_ctx->file = infile; |
| 747 | if (file_is_ivf(input.vpx_input_ctx)) |
| 748 | input.vpx_input_ctx->file_type = FILE_TYPE_IVF; |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 749 | #if CONFIG_WEBM_IO |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 750 | else if (file_is_webm(input.webm_ctx, input.vpx_input_ctx)) |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 751 | input.vpx_input_ctx->file_type = FILE_TYPE_WEBM; |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 752 | #endif |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 753 | else if (file_is_raw(input.vpx_input_ctx)) |
| 754 | input.vpx_input_ctx->file_type = FILE_TYPE_RAW; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 755 | else { |
| 756 | fprintf(stderr, "Unrecognized input file type.\n"); |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 757 | #if !CONFIG_WEBM_IO |
| 758 | fprintf(stderr, "vpxdec was built without WebM container support.\n"); |
| 759 | #endif |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 760 | return EXIT_FAILURE; |
| 761 | } |
| 762 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 763 | outfile_pattern = outfile_pattern ? outfile_pattern : "-"; |
Dmitry Kovalev | 347b306 | 2014-01-22 09:04:07 -0800 | [diff] [blame] | 764 | single_file = is_single_file(outfile_pattern); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 765 | |
Dmitry Kovalev | 347b306 | 2014-01-22 09:04:07 -0800 | [diff] [blame] | 766 | if (!noblit && single_file) { |
| 767 | generate_filename(outfile_pattern, outfile_name, PATH_MAX, |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 768 | vpx_input_ctx.width, vpx_input_ctx.height, 0); |
Dmitry Kovalev | 347b306 | 2014-01-22 09:04:07 -0800 | [diff] [blame] | 769 | if (do_md5) |
| 770 | MD5Init(&md5_ctx); |
| 771 | else |
| 772 | outfile = open_outfile(outfile_name); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | if (use_y4m && !noblit) { |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 776 | if (!single_file) { |
| 777 | fprintf(stderr, "YUV4MPEG2 not supported with output patterns," |
Deb Mukherjee | a30774c | 2014-10-01 12:17:37 -0700 | [diff] [blame] | 778 | " try --i420 or --yv12 or --rawvideo.\n"); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 779 | return EXIT_FAILURE; |
| 780 | } |
| 781 | |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 782 | #if CONFIG_WEBM_IO |
Dmitry Kovalev | 5ab6358 | 2014-01-17 17:02:37 -0800 | [diff] [blame] | 783 | if (vpx_input_ctx.file_type == FILE_TYPE_WEBM) { |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 784 | if (webm_guess_framerate(input.webm_ctx, input.vpx_input_ctx)) { |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 785 | fprintf(stderr, "Failed to guess framerate -- error parsing " |
| 786 | "webm file?\n"); |
Timothy B. Terriberry | 7f9db41 | 2010-05-26 19:36:20 -0400 | [diff] [blame] | 787 | return EXIT_FAILURE; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 788 | } |
Dmitry Kovalev | 5ab6358 | 2014-01-17 17:02:37 -0800 | [diff] [blame] | 789 | } |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 790 | #endif |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 791 | } |
| 792 | |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 793 | fourcc_interface = get_vpx_decoder_by_fourcc(vpx_input_ctx.fourcc); |
| 794 | if (interface && fourcc_interface && interface != fourcc_interface) |
| 795 | warn("Header indicates codec: %s\n", fourcc_interface->name); |
| 796 | else |
| 797 | interface = fourcc_interface; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 798 | |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 799 | if (!interface) |
| 800 | interface = get_vpx_decoder_by_index(0); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 801 | |
John Koleszar | 3707c34 | 2012-11-06 10:09:36 -0800 | [diff] [blame] | 802 | dec_flags = (postproc ? VPX_CODEC_USE_POSTPROC : 0) | |
hkuang | 1f841c3 | 2015-03-06 13:03:18 -0800 | [diff] [blame^] | 803 | (ec_enabled ? VPX_CODEC_USE_ERROR_CONCEALMENT : 0) | |
| 804 | (frame_parallel ? VPX_CODEC_USE_FRAME_THREADING : 0); |
Deb Mukherjee | f332c63 | 2014-07-15 16:55:12 -0700 | [diff] [blame] | 805 | if (vpx_codec_dec_init(&decoder, interface->codec_interface(), |
| 806 | &cfg, dec_flags)) { |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 807 | fprintf(stderr, "Failed to initialize decoder: %s\n", |
| 808 | vpx_codec_error(&decoder)); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 809 | return EXIT_FAILURE; |
| 810 | } |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 811 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 812 | if (!quiet) |
| 813 | fprintf(stderr, "%s\n", decoder.name); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 814 | |
John Koleszar | a9c7597 | 2012-11-08 17:09:30 -0800 | [diff] [blame] | 815 | #if CONFIG_VP8_DECODER |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 816 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 817 | if (vp8_pp_cfg.post_proc_flag |
| 818 | && vpx_codec_control(&decoder, VP8_SET_POSTPROC, &vp8_pp_cfg)) { |
| 819 | fprintf(stderr, "Failed to configure postproc: %s\n", vpx_codec_error(&decoder)); |
| 820 | return EXIT_FAILURE; |
| 821 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 822 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 823 | if (vp8_dbg_color_ref_frame |
| 824 | && vpx_codec_control(&decoder, VP8_SET_DBG_COLOR_REF_FRAME, vp8_dbg_color_ref_frame)) { |
| 825 | fprintf(stderr, "Failed to configure reference block visualizer: %s\n", vpx_codec_error(&decoder)); |
| 826 | return EXIT_FAILURE; |
| 827 | } |
Fritz Koenig | 647df00 | 2010-11-04 16:03:36 -0700 | [diff] [blame] | 828 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 829 | if (vp8_dbg_color_mb_modes |
| 830 | && vpx_codec_control(&decoder, VP8_SET_DBG_COLOR_MB_MODES, vp8_dbg_color_mb_modes)) { |
| 831 | fprintf(stderr, "Failed to configure macro block visualizer: %s\n", vpx_codec_error(&decoder)); |
| 832 | return EXIT_FAILURE; |
| 833 | } |
Fritz Koenig | 647df00 | 2010-11-04 16:03:36 -0700 | [diff] [blame] | 834 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 835 | if (vp8_dbg_color_b_modes |
| 836 | && vpx_codec_control(&decoder, VP8_SET_DBG_COLOR_B_MODES, vp8_dbg_color_b_modes)) { |
| 837 | fprintf(stderr, "Failed to configure block visualizer: %s\n", vpx_codec_error(&decoder)); |
| 838 | return EXIT_FAILURE; |
| 839 | } |
Fritz Koenig | 647df00 | 2010-11-04 16:03:36 -0700 | [diff] [blame] | 840 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 841 | if (vp8_dbg_display_mv |
| 842 | && vpx_codec_control(&decoder, VP8_SET_DBG_DISPLAY_MV, vp8_dbg_display_mv)) { |
| 843 | fprintf(stderr, "Failed to configure motion vector visualizer: %s\n", vpx_codec_error(&decoder)); |
| 844 | return EXIT_FAILURE; |
| 845 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 846 | #endif |
| 847 | |
Yaowu Xu | c394ffc | 2012-10-11 15:12:35 -0700 | [diff] [blame] | 848 | |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 849 | if (arg_skip) |
Adrian Grange | 475d1d6 | 2013-11-20 09:49:33 -0800 | [diff] [blame] | 850 | fprintf(stderr, "Skipping first %d frames.\n", arg_skip); |
Yaowu Xu | c394ffc | 2012-10-11 15:12:35 -0700 | [diff] [blame] | 851 | while (arg_skip) { |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 852 | if (read_frame(&input, &buf, &bytes_in_buffer, &buffer_size)) |
Yaowu Xu | c394ffc | 2012-10-11 15:12:35 -0700 | [diff] [blame] | 853 | break; |
| 854 | arg_skip--; |
| 855 | } |
| 856 | |
Frank Galligan | a4f30a5 | 2014-02-06 17:13:08 -0800 | [diff] [blame] | 857 | if (num_external_frame_buffers > 0) { |
| 858 | ext_fb_list.num_external_frame_buffers = num_external_frame_buffers; |
| 859 | ext_fb_list.ext_fb = (struct ExternalFrameBuffer *)calloc( |
| 860 | num_external_frame_buffers, sizeof(*ext_fb_list.ext_fb)); |
| 861 | if (vpx_codec_set_frame_buffer_functions( |
| 862 | &decoder, get_vp9_frame_buffer, release_vp9_frame_buffer, |
| 863 | &ext_fb_list)) { |
| 864 | fprintf(stderr, "Failed to configure external frame buffers: %s\n", |
| 865 | vpx_codec_error(&decoder)); |
| 866 | return EXIT_FAILURE; |
| 867 | } |
| 868 | } |
| 869 | |
Scott LaVarnway | c3ae212 | 2013-06-07 12:39:03 -0400 | [diff] [blame] | 870 | frame_avail = 1; |
| 871 | got_data = 0; |
| 872 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 873 | /* Decode file */ |
Scott LaVarnway | c3ae212 | 2013-06-07 12:39:03 -0400 | [diff] [blame] | 874 | while (frame_avail || got_data) { |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 875 | vpx_codec_iter_t iter = NULL; |
| 876 | vpx_image_t *img; |
| 877 | struct vpx_usec_timer timer; |
| 878 | int corrupted; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 879 | |
Scott LaVarnway | c3ae212 | 2013-06-07 12:39:03 -0400 | [diff] [blame] | 880 | frame_avail = 0; |
| 881 | if (!stop_after || frame_in < stop_after) { |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 882 | if (!read_frame(&input, &buf, &bytes_in_buffer, &buffer_size)) { |
Scott LaVarnway | c3ae212 | 2013-06-07 12:39:03 -0400 | [diff] [blame] | 883 | frame_avail = 1; |
| 884 | frame_in++; |
| 885 | |
| 886 | vpx_usec_timer_start(&timer); |
| 887 | |
Jim Bankoski | 24025c0 | 2014-02-14 07:27:10 -0800 | [diff] [blame] | 888 | if (vpx_codec_decode(&decoder, buf, (unsigned int)bytes_in_buffer, |
| 889 | NULL, 0)) { |
Scott LaVarnway | c3ae212 | 2013-06-07 12:39:03 -0400 | [diff] [blame] | 890 | const char *detail = vpx_codec_error_detail(&decoder); |
Tom Finegan | f225b1e | 2013-11-18 15:50:58 -0800 | [diff] [blame] | 891 | warn("Failed to decode frame %d: %s", |
| 892 | frame_in, vpx_codec_error(&decoder)); |
Scott LaVarnway | c3ae212 | 2013-06-07 12:39:03 -0400 | [diff] [blame] | 893 | |
| 894 | if (detail) |
Tom Finegan | f225b1e | 2013-11-18 15:50:58 -0800 | [diff] [blame] | 895 | warn("Additional information: %s", detail); |
James Zern | 95853db | 2014-07-01 19:02:15 -0700 | [diff] [blame] | 896 | if (!keep_going) |
| 897 | goto fail; |
Scott LaVarnway | c3ae212 | 2013-06-07 12:39:03 -0400 | [diff] [blame] | 898 | } |
| 899 | |
| 900 | vpx_usec_timer_mark(&timer); |
James Yu | 6d15132 | 2014-02-22 14:51:11 +0800 | [diff] [blame] | 901 | dx_time += vpx_usec_timer_elapsed(&timer); |
hkuang | 1f841c3 | 2015-03-06 13:03:18 -0800 | [diff] [blame^] | 902 | } else { |
| 903 | flush_decoder = 1; |
Scott LaVarnway | c3ae212 | 2013-06-07 12:39:03 -0400 | [diff] [blame] | 904 | } |
hkuang | 1f841c3 | 2015-03-06 13:03:18 -0800 | [diff] [blame^] | 905 | } else { |
| 906 | flush_decoder = 1; |
Scott LaVarnway | c3ae212 | 2013-06-07 12:39:03 -0400 | [diff] [blame] | 907 | } |
| 908 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 909 | vpx_usec_timer_start(&timer); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 910 | |
hkuang | 1f841c3 | 2015-03-06 13:03:18 -0800 | [diff] [blame^] | 911 | if (flush_decoder) { |
| 912 | // Flush the decoder in frame parallel decode. |
| 913 | if (vpx_codec_decode(&decoder, NULL, 0, NULL, 0)) { |
| 914 | warn("Failed to flush decoder: %s", vpx_codec_error(&decoder)); |
| 915 | } |
| 916 | } |
| 917 | |
Scott LaVarnway | c3ae212 | 2013-06-07 12:39:03 -0400 | [diff] [blame] | 918 | got_data = 0; |
| 919 | if ((img = vpx_codec_get_frame(&decoder, &iter))) { |
| 920 | ++frame_out; |
| 921 | got_data = 1; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 922 | } |
| 923 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 924 | vpx_usec_timer_mark(&timer); |
John Koleszar | 3707c34 | 2012-11-06 10:09:36 -0800 | [diff] [blame] | 925 | dx_time += (unsigned int)vpx_usec_timer_elapsed(&timer); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 926 | |
hkuang | 1f841c3 | 2015-03-06 13:03:18 -0800 | [diff] [blame^] | 927 | if (!frame_parallel && |
| 928 | vpx_codec_control(&decoder, VP8D_GET_FRAME_CORRUPTED, &corrupted)) { |
Tom Finegan | f225b1e | 2013-11-18 15:50:58 -0800 | [diff] [blame] | 929 | warn("Failed VP8_GET_FRAME_CORRUPTED: %s", vpx_codec_error(&decoder)); |
James Zern | fcbf3e4 | 2014-12-17 19:20:00 -0800 | [diff] [blame] | 930 | if (!keep_going) |
| 931 | goto fail; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 932 | } |
| 933 | frames_corrupted += corrupted; |
| 934 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 935 | if (progress) |
| 936 | show_progress(frame_in, frame_out, dx_time); |
| 937 | |
Dmitry Kovalev | f2acb45 | 2014-01-23 17:20:34 -0800 | [diff] [blame] | 938 | if (!noblit && img) { |
| 939 | const int PLANES_YUV[] = {VPX_PLANE_Y, VPX_PLANE_U, VPX_PLANE_V}; |
| 940 | const int PLANES_YVU[] = {VPX_PLANE_Y, VPX_PLANE_V, VPX_PLANE_U}; |
| 941 | const int *planes = flipuv ? PLANES_YVU : PLANES_YUV; |
John Koleszar | da58436 | 2013-05-06 15:52:06 -0700 | [diff] [blame] | 942 | |
Dmitry Kovalev | f2acb45 | 2014-01-23 17:20:34 -0800 | [diff] [blame] | 943 | if (do_scale) { |
Adrian Grange | 482c39c | 2013-12-13 10:15:03 -0800 | [diff] [blame] | 944 | if (frame_out == 1) { |
| 945 | // If the output frames are to be scaled to a fixed display size then |
| 946 | // use the width and height specified in the container. If either of |
| 947 | // these is set to 0, use the display size set in the first frame |
Adrian Grange | 82f6af6 | 2014-01-22 09:36:07 -0800 | [diff] [blame] | 948 | // header. If that is unavailable, use the raw decoded size of the |
| 949 | // first decoded frame. |
Dmitry Kovalev | 3c05481 | 2014-01-17 12:19:19 -0800 | [diff] [blame] | 950 | int display_width = vpx_input_ctx.width; |
| 951 | int display_height = vpx_input_ctx.height; |
Adrian Grange | 482c39c | 2013-12-13 10:15:03 -0800 | [diff] [blame] | 952 | if (!display_width || !display_height) { |
| 953 | int display_size[2]; |
| 954 | if (vpx_codec_control(&decoder, VP9D_GET_DISPLAY_SIZE, |
| 955 | display_size)) { |
| 956 | // As last resort use size of first frame as display size. |
| 957 | display_width = img->d_w; |
| 958 | display_height = img->d_h; |
| 959 | } else { |
| 960 | display_width = display_size[0]; |
| 961 | display_height = display_size[1]; |
| 962 | } |
Adrian Grange | 2117fe0 | 2013-11-19 14:01:44 -0800 | [diff] [blame] | 963 | } |
Deb Mukherjee | e9f85d3 | 2014-08-22 13:14:58 -0700 | [diff] [blame] | 964 | scaled_img = vpx_img_alloc(NULL, img->fmt, display_width, |
Adrian Grange | 482c39c | 2013-12-13 10:15:03 -0800 | [diff] [blame] | 965 | display_height, 16); |
Deb Mukherjee | 449e5f2 | 2014-07-11 11:43:31 -0700 | [diff] [blame] | 966 | scaled_img->bit_depth = img->bit_depth; |
John Koleszar | 7d8fc26 | 2013-02-25 16:58:47 -0800 | [diff] [blame] | 967 | } |
Adrian Grange | 482c39c | 2013-12-13 10:15:03 -0800 | [diff] [blame] | 968 | |
Dmitry Kovalev | 3c05481 | 2014-01-17 12:19:19 -0800 | [diff] [blame] | 969 | if (img->d_w != scaled_img->d_w || img->d_h != scaled_img->d_h) { |
Deb Mukherjee | 47031c0 | 2014-05-16 18:52:01 -0700 | [diff] [blame] | 970 | #if CONFIG_LIBYUV |
Tom Finegan | 8ef2ce8 | 2014-12-12 11:57:04 -0800 | [diff] [blame] | 971 | libyuv_scale(img, scaled_img, kFilterBox); |
John Koleszar | 7d8fc26 | 2013-02-25 16:58:47 -0800 | [diff] [blame] | 972 | img = scaled_img; |
Deb Mukherjee | 47031c0 | 2014-05-16 18:52:01 -0700 | [diff] [blame] | 973 | #else |
| 974 | fprintf(stderr, "Failed to scale output frame: %s.\n" |
| 975 | "Scaling is disabled in this configuration. " |
| 976 | "To enable scaling, configure with --enable-libyuv\n", |
| 977 | vpx_codec_error(&decoder)); |
| 978 | return EXIT_FAILURE; |
| 979 | #endif |
John Koleszar | 7d8fc26 | 2013-02-25 16:58:47 -0800 | [diff] [blame] | 980 | } |
| 981 | } |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 982 | #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH |
| 983 | // Default to codec bit depth if output bit depth not set |
| 984 | if (!output_bit_depth) { |
| 985 | output_bit_depth = img->bit_depth; |
| 986 | } |
| 987 | // Shift up or down if necessary |
| 988 | if (output_bit_depth != img->bit_depth) { |
Deb Mukherjee | 9ed23de | 2014-09-25 15:46:50 -0700 | [diff] [blame] | 989 | const vpx_img_fmt_t shifted_fmt = output_bit_depth == 8 ? |
| 990 | img->fmt ^ (img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) : |
| 991 | img->fmt | VPX_IMG_FMT_HIGHBITDEPTH; |
| 992 | if (img_shifted && |
| 993 | img_shifted_realloc_required(img, img_shifted, shifted_fmt)) { |
| 994 | vpx_img_free(img_shifted); |
| 995 | img_shifted = NULL; |
| 996 | } |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 997 | if (!img_shifted) { |
Deb Mukherjee | 9ed23de | 2014-09-25 15:46:50 -0700 | [diff] [blame] | 998 | img_shifted = vpx_img_alloc(NULL, shifted_fmt, |
| 999 | img->d_w, img->d_h, 16); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1000 | img_shifted->bit_depth = output_bit_depth; |
| 1001 | } |
| 1002 | if (output_bit_depth > img->bit_depth) { |
Deb Mukherjee | 7a2a611 | 2014-10-06 20:46:11 -0700 | [diff] [blame] | 1003 | vpx_img_upshift(img_shifted, img, |
| 1004 | output_bit_depth - img->bit_depth); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1005 | } else { |
Deb Mukherjee | 7a2a611 | 2014-10-06 20:46:11 -0700 | [diff] [blame] | 1006 | vpx_img_downshift(img_shifted, img, |
| 1007 | img->bit_depth - output_bit_depth); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1008 | } |
| 1009 | img = img_shifted; |
| 1010 | } |
| 1011 | #endif |
Dmitry Kovalev | 3c05481 | 2014-01-17 12:19:19 -0800 | [diff] [blame] | 1012 | |
Dmitry Kovalev | f2acb45 | 2014-01-23 17:20:34 -0800 | [diff] [blame] | 1013 | if (single_file) { |
Dmitry Kovalev | 5260b39 | 2014-01-28 11:12:58 -0800 | [diff] [blame] | 1014 | if (use_y4m) { |
| 1015 | char buf[Y4M_BUFFER_SIZE] = {0}; |
| 1016 | size_t len = 0; |
Deb Mukherjee | a30774c | 2014-10-01 12:17:37 -0700 | [diff] [blame] | 1017 | if (img->fmt == VPX_IMG_FMT_I440 || img->fmt == VPX_IMG_FMT_I44016) { |
| 1018 | fprintf(stderr, "Cannot produce y4m output for 440 sampling.\n"); |
| 1019 | goto fail; |
| 1020 | } |
Dmitry Kovalev | 5260b39 | 2014-01-28 11:12:58 -0800 | [diff] [blame] | 1021 | if (frame_out == 1) { |
| 1022 | // Y4M file header |
| 1023 | len = y4m_write_file_header(buf, sizeof(buf), |
| 1024 | vpx_input_ctx.width, |
| 1025 | vpx_input_ctx.height, |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 1026 | &vpx_input_ctx.framerate, |
Deb Mukherjee | 449e5f2 | 2014-07-11 11:43:31 -0700 | [diff] [blame] | 1027 | img->fmt, img->bit_depth); |
Dmitry Kovalev | 5260b39 | 2014-01-28 11:12:58 -0800 | [diff] [blame] | 1028 | if (do_md5) { |
Jim Bankoski | 24025c0 | 2014-02-14 07:27:10 -0800 | [diff] [blame] | 1029 | MD5Update(&md5_ctx, (md5byte *)buf, (unsigned int)len); |
Dmitry Kovalev | 5260b39 | 2014-01-28 11:12:58 -0800 | [diff] [blame] | 1030 | } else { |
| 1031 | fputs(buf, outfile); |
| 1032 | } |
| 1033 | } |
| 1034 | |
| 1035 | // Y4M frame header |
| 1036 | len = y4m_write_frame_header(buf, sizeof(buf)); |
| 1037 | if (do_md5) { |
Jim Bankoski | 24025c0 | 2014-02-14 07:27:10 -0800 | [diff] [blame] | 1038 | MD5Update(&md5_ctx, (md5byte *)buf, (unsigned int)len); |
Dmitry Kovalev | 5260b39 | 2014-01-28 11:12:58 -0800 | [diff] [blame] | 1039 | } else { |
| 1040 | fputs(buf, outfile); |
| 1041 | } |
Deb Mukherjee | 090f4d4 | 2014-07-16 09:37:13 -0700 | [diff] [blame] | 1042 | } else { |
| 1043 | if (frame_out == 1) { |
| 1044 | // Check if --yv12 or --i420 options are consistent with the |
| 1045 | // bit-stream decoded |
| 1046 | if (opt_i420) { |
| 1047 | if (img->fmt != VPX_IMG_FMT_I420 && |
| 1048 | img->fmt != VPX_IMG_FMT_I42016) { |
| 1049 | fprintf(stderr, "Cannot produce i420 output for bit-stream.\n"); |
| 1050 | goto fail; |
| 1051 | } |
| 1052 | } |
| 1053 | if (opt_yv12) { |
| 1054 | if ((img->fmt != VPX_IMG_FMT_I420 && |
| 1055 | img->fmt != VPX_IMG_FMT_YV12) || img->bit_depth != 8) { |
| 1056 | fprintf(stderr, "Cannot produce yv12 output for bit-stream.\n"); |
| 1057 | goto fail; |
| 1058 | } |
| 1059 | } |
| 1060 | } |
Dmitry Kovalev | 5260b39 | 2014-01-28 11:12:58 -0800 | [diff] [blame] | 1061 | } |
| 1062 | |
Dmitry Kovalev | f2acb45 | 2014-01-23 17:20:34 -0800 | [diff] [blame] | 1063 | if (do_md5) { |
| 1064 | update_image_md5(img, planes, &md5_ctx); |
Dmitry Kovalev | cf46bc7 | 2014-01-17 10:57:55 -0800 | [diff] [blame] | 1065 | } else { |
Dmitry Kovalev | f2acb45 | 2014-01-23 17:20:34 -0800 | [diff] [blame] | 1066 | write_image_file(img, planes, outfile); |
| 1067 | } |
| 1068 | } else { |
| 1069 | generate_filename(outfile_pattern, outfile_name, PATH_MAX, |
| 1070 | img->d_w, img->d_h, frame_in); |
| 1071 | if (do_md5) { |
| 1072 | MD5Init(&md5_ctx); |
| 1073 | update_image_md5(img, planes, &md5_ctx); |
| 1074 | MD5Final(md5_digest, &md5_ctx); |
| 1075 | print_md5(md5_digest, outfile_name); |
| 1076 | } else { |
| 1077 | outfile = open_outfile(outfile_name); |
| 1078 | write_image_file(img, planes, outfile); |
| 1079 | fclose(outfile); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 1080 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 1081 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1082 | } |
| 1083 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 1084 | if (stop_after && frame_in >= stop_after) |
| 1085 | break; |
| 1086 | } |
| 1087 | |
| 1088 | if (summary || progress) { |
| 1089 | show_progress(frame_in, frame_out, dx_time); |
| 1090 | fprintf(stderr, "\n"); |
| 1091 | } |
| 1092 | |
| 1093 | if (frames_corrupted) |
| 1094 | fprintf(stderr, "WARNING: %d frames corrupted.\n", frames_corrupted); |
John Koleszar | 4226f0c | 2011-04-27 12:04:48 -0400 | [diff] [blame] | 1095 | |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1096 | fail: |
| 1097 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 1098 | if (vpx_codec_destroy(&decoder)) { |
Adrian Grange | d427fab | 2013-11-21 17:19:04 -0800 | [diff] [blame] | 1099 | fprintf(stderr, "Failed to destroy decoder: %s\n", |
| 1100 | vpx_codec_error(&decoder)); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 1101 | return EXIT_FAILURE; |
| 1102 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1103 | |
Dmitry Kovalev | 347b306 | 2014-01-22 09:04:07 -0800 | [diff] [blame] | 1104 | if (!noblit && single_file) { |
| 1105 | if (do_md5) { |
| 1106 | MD5Final(md5_digest, &md5_ctx); |
| 1107 | print_md5(md5_digest, outfile_name); |
| 1108 | } else { |
| 1109 | fclose(outfile); |
| 1110 | } |
| 1111 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1112 | |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 1113 | #if CONFIG_WEBM_IO |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 1114 | if (input.vpx_input_ctx->file_type == FILE_TYPE_WEBM) |
| 1115 | webm_free(input.webm_ctx); |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 1116 | #endif |
| 1117 | |
| 1118 | if (input.vpx_input_ctx->file_type != FILE_TYPE_WEBM) |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 1119 | free(buf); |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 1120 | |
Adrian Grange | d427fab | 2013-11-21 17:19:04 -0800 | [diff] [blame] | 1121 | if (scaled_img) vpx_img_free(scaled_img); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1122 | #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH |
| 1123 | if (img_shifted) vpx_img_free(img_shifted); |
| 1124 | #endif |
Adrian Grange | d427fab | 2013-11-21 17:19:04 -0800 | [diff] [blame] | 1125 | |
Frank Galligan | a4f30a5 | 2014-02-06 17:13:08 -0800 | [diff] [blame] | 1126 | for (i = 0; i < ext_fb_list.num_external_frame_buffers; ++i) { |
| 1127 | free(ext_fb_list.ext_fb[i].data); |
| 1128 | } |
| 1129 | free(ext_fb_list.ext_fb); |
| 1130 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 1131 | fclose(infile); |
| 1132 | free(argv); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1133 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 1134 | return frames_corrupted ? EXIT_FAILURE : EXIT_SUCCESS; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1135 | } |
John Koleszar | 9596a4c | 2013-06-12 16:08:35 -0700 | [diff] [blame] | 1136 | |
| 1137 | int main(int argc, const char **argv_) { |
| 1138 | unsigned int loops = 1, i; |
| 1139 | char **argv, **argi, **argj; |
| 1140 | struct arg arg; |
| 1141 | int error = 0; |
| 1142 | |
| 1143 | argv = argv_dup(argc - 1, argv_ + 1); |
| 1144 | for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) { |
| 1145 | memset(&arg, 0, sizeof(arg)); |
| 1146 | arg.argv_step = 1; |
| 1147 | |
| 1148 | if (arg_match(&arg, &looparg, argi)) { |
| 1149 | loops = arg_parse_uint(&arg); |
| 1150 | break; |
| 1151 | } |
| 1152 | } |
| 1153 | free(argv); |
| 1154 | for (i = 0; !error && i < loops; i++) |
| 1155 | error = main_loop(argc, argv_); |
| 1156 | return error; |
| 1157 | } |