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