John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1 | /* |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 3 | * |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 4 | * This source code is subject to the terms of the BSD 2 Clause License and |
| 5 | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
| 6 | * was not distributed with this source code in the LICENSE file, you can |
| 7 | * obtain it at www.aomedia.org/license/software. If the Alliance for Open |
| 8 | * Media Patent License 1.0 was not distributed with this source code in the |
| 9 | * PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 10 | */ |
| 11 | |
John Koleszar | da58436 | 2013-05-06 15:52:06 -0700 | [diff] [blame] | 12 | #include <assert.h> |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 13 | #include <stdio.h> |
| 14 | #include <stdlib.h> |
| 15 | #include <stdarg.h> |
| 16 | #include <string.h> |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 17 | #include <limits.h> |
Tero Rintaluoma | 11a222f | 2011-01-24 11:21:40 +0200 | [diff] [blame] | 18 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 19 | #include "./aom_config.h" |
James Zern | 1e681d9 | 2014-08-15 21:00:09 -0700 | [diff] [blame] | 20 | |
| 21 | #if CONFIG_LIBYUV |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 22 | #include "third_party/libyuv/include/libyuv/scale.h" |
James Zern | 1e681d9 | 2014-08-15 21:00:09 -0700 | [diff] [blame] | 23 | #endif |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 24 | |
| 25 | #include "./args.h" |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 26 | #include "./ivfdec.h" |
| 27 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 28 | #include "aom/aom_decoder.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 29 | #include "aom_ports/mem_ops.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 30 | #include "aom_ports/aom_timer.h" |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 31 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 32 | #if CONFIG_AV1_DECODER |
| 33 | #include "aom/aomdx.h" |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 34 | #endif |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 35 | |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 36 | #include "./md5_utils.h" |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 37 | |
| 38 | #include "./tools_common.h" |
James Zern | b6cce76 | 2014-05-10 17:44:12 -0700 | [diff] [blame] | 39 | #if CONFIG_WEBM_IO |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 40 | #include "./webmdec.h" |
James Zern | b6cce76 | 2014-05-10 17:44:12 -0700 | [diff] [blame] | 41 | #endif |
Dmitry Kovalev | 5ab63583 | 2014-01-17 17:02:37 -0800 | [diff] [blame] | 42 | #include "./y4menc.h" |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 43 | |
| 44 | static const char *exec_name; |
| 45 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 46 | struct AvxDecInputContext { |
| 47 | struct AvxInputContext *aom_input_ctx; |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 48 | struct WebmInputContext *webm_ctx; |
| 49 | }; |
| 50 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 51 | static const arg_def_t looparg = |
| 52 | ARG_DEF(NULL, "loops", 1, "Number of times to decode the file"); |
| 53 | static const arg_def_t codecarg = ARG_DEF(NULL, "codec", 1, "Codec to use"); |
| 54 | static const arg_def_t use_yv12 = |
| 55 | ARG_DEF(NULL, "yv12", 0, "Output raw YV12 frames"); |
| 56 | static const arg_def_t use_i420 = |
| 57 | ARG_DEF(NULL, "i420", 0, "Output raw I420 frames"); |
| 58 | static const arg_def_t flipuvarg = |
| 59 | ARG_DEF(NULL, "flipuv", 0, "Flip the chroma planes in the output"); |
| 60 | static const arg_def_t rawvideo = |
| 61 | ARG_DEF(NULL, "rawvideo", 0, "Output raw YUV frames"); |
| 62 | static const arg_def_t noblitarg = |
| 63 | ARG_DEF(NULL, "noblit", 0, "Don't process the decoded frames"); |
| 64 | static const arg_def_t progressarg = |
| 65 | ARG_DEF(NULL, "progress", 0, "Show progress after each frame decodes"); |
| 66 | static const arg_def_t limitarg = |
| 67 | ARG_DEF(NULL, "limit", 1, "Stop decoding after n frames"); |
| 68 | static const arg_def_t skiparg = |
| 69 | ARG_DEF(NULL, "skip", 1, "Skip the first n input frames"); |
| 70 | static const arg_def_t postprocarg = |
| 71 | ARG_DEF(NULL, "postproc", 0, "Postprocess decoded frames"); |
| 72 | static const arg_def_t summaryarg = |
| 73 | ARG_DEF(NULL, "summary", 0, "Show timing summary"); |
| 74 | static const arg_def_t outputfile = |
| 75 | ARG_DEF("o", "output", 1, "Output file name pattern (see below)"); |
| 76 | static const arg_def_t threadsarg = |
| 77 | ARG_DEF("t", "threads", 1, "Max threads to use"); |
| 78 | static const arg_def_t frameparallelarg = |
| 79 | ARG_DEF(NULL, "frame-parallel", 0, "Frame parallel decode"); |
| 80 | static const arg_def_t verbosearg = |
| 81 | ARG_DEF("v", "verbose", 0, "Show version string"); |
| 82 | static const arg_def_t error_concealment = |
| 83 | ARG_DEF(NULL, "error-concealment", 0, "Enable decoder error-concealment"); |
| 84 | static const arg_def_t scalearg = |
| 85 | ARG_DEF("S", "scale", 0, "Scale output frames uniformly"); |
| 86 | static const arg_def_t continuearg = |
| 87 | ARG_DEF("k", "keep-going", 0, "(debug) Continue decoding after error"); |
| 88 | static const arg_def_t fb_arg = |
| 89 | ARG_DEF(NULL, "frame-buffers", 1, "Number of frame buffers to use"); |
| 90 | static const arg_def_t md5arg = |
| 91 | ARG_DEF(NULL, "md5", 0, "Compute the MD5 sum of the decoded frame"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 92 | #if CONFIG_AOM_HIGHBITDEPTH |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 93 | static const arg_def_t outbitdeptharg = |
| 94 | ARG_DEF(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 |
Geza Lore | 490ba1a | 2016-03-11 17:42:49 +0000 | [diff] [blame] | 96 | #if CONFIG_EXT_TILE |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 97 | static const arg_def_t tiler = ARG_DEF(NULL, "tile-row", 1, |
| 98 | "Row index of tile to decode " |
| 99 | "(-1 for all rows)"); |
| 100 | static const arg_def_t tilec = ARG_DEF(NULL, "tile-column", 1, |
| 101 | "Column index of tile to decode " |
| 102 | "(-1 for all columns)"); |
Geza Lore | 490ba1a | 2016-03-11 17:42:49 +0000 | [diff] [blame] | 103 | #endif // CONFIG_EXT_TILE |
Dmitry Kovalev | d24f4e4 | 2013-12-27 16:10:18 -0800 | [diff] [blame] | 104 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 105 | static const arg_def_t *all_args[] = { &codecarg, |
| 106 | &use_yv12, |
| 107 | &use_i420, |
| 108 | &flipuvarg, |
| 109 | &rawvideo, |
| 110 | &noblitarg, |
| 111 | &progressarg, |
| 112 | &limitarg, |
| 113 | &skiparg, |
| 114 | &postprocarg, |
| 115 | &summaryarg, |
| 116 | &outputfile, |
| 117 | &threadsarg, |
| 118 | &frameparallelarg, |
| 119 | &verbosearg, |
| 120 | &scalearg, |
| 121 | &fb_arg, |
| 122 | &md5arg, |
| 123 | &error_concealment, |
| 124 | &continuearg, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 125 | #if CONFIG_AOM_HIGHBITDEPTH |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 126 | &outbitdeptharg, |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 127 | #endif |
Geza Lore | 490ba1a | 2016-03-11 17:42:49 +0000 | [diff] [blame] | 128 | #if CONFIG_EXT_TILE |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 129 | &tiler, |
| 130 | &tilec, |
Geza Lore | 490ba1a | 2016-03-11 17:42:49 +0000 | [diff] [blame] | 131 | #endif // CONFIG_EXT_TILE |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 132 | NULL }; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 133 | |
James Zern | 1e681d9 | 2014-08-15 21:00:09 -0700 | [diff] [blame] | 134 | #if CONFIG_LIBYUV |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 135 | static INLINE int libyuv_scale(aom_image_t *src, aom_image_t *dst, |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 136 | FilterModeEnum mode) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 137 | #if CONFIG_AOM_HIGHBITDEPTH |
| 138 | if (src->fmt == AOM_IMG_FMT_I42016) { |
| 139 | assert(dst->fmt == AOM_IMG_FMT_I42016); |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 140 | return I420Scale_16( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 141 | (uint16_t *)src->planes[AOM_PLANE_Y], src->stride[AOM_PLANE_Y] / 2, |
| 142 | (uint16_t *)src->planes[AOM_PLANE_U], src->stride[AOM_PLANE_U] / 2, |
| 143 | (uint16_t *)src->planes[AOM_PLANE_V], src->stride[AOM_PLANE_V] / 2, |
| 144 | src->d_w, src->d_h, (uint16_t *)dst->planes[AOM_PLANE_Y], |
| 145 | dst->stride[AOM_PLANE_Y] / 2, (uint16_t *)dst->planes[AOM_PLANE_U], |
| 146 | dst->stride[AOM_PLANE_U] / 2, (uint16_t *)dst->planes[AOM_PLANE_V], |
| 147 | dst->stride[AOM_PLANE_V] / 2, dst->d_w, dst->d_h, mode); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 148 | } |
| 149 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 150 | assert(src->fmt == AOM_IMG_FMT_I420); |
| 151 | assert(dst->fmt == AOM_IMG_FMT_I420); |
| 152 | return I420Scale(src->planes[AOM_PLANE_Y], src->stride[AOM_PLANE_Y], |
| 153 | src->planes[AOM_PLANE_U], src->stride[AOM_PLANE_U], |
| 154 | src->planes[AOM_PLANE_V], src->stride[AOM_PLANE_V], src->d_w, |
| 155 | src->d_h, dst->planes[AOM_PLANE_Y], dst->stride[AOM_PLANE_Y], |
| 156 | dst->planes[AOM_PLANE_U], dst->stride[AOM_PLANE_U], |
| 157 | dst->planes[AOM_PLANE_V], dst->stride[AOM_PLANE_V], dst->d_w, |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 158 | dst->d_h, mode); |
Dmitry Kovalev | 3c05481 | 2014-01-17 12:19:19 -0800 | [diff] [blame] | 159 | } |
James Zern | 1e681d9 | 2014-08-15 21:00:09 -0700 | [diff] [blame] | 160 | #endif |
Dmitry Kovalev | 3c05481 | 2014-01-17 12:19:19 -0800 | [diff] [blame] | 161 | |
James Zern | 59e7a47 | 2015-05-09 10:33:26 -0700 | [diff] [blame] | 162 | void usage_exit(void) { |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 163 | int i; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 164 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 165 | fprintf(stderr, |
| 166 | "Usage: %s <options> filename\n\n" |
| 167 | "Options:\n", |
| 168 | exec_name); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 169 | arg_show_usage(stderr, all_args); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 170 | fprintf(stderr, |
| 171 | "\nOutput File Patterns:\n\n" |
| 172 | " The -o argument specifies the name of the file(s) to " |
| 173 | "write to. If the\n argument does not include any escape " |
| 174 | "characters, the output will be\n written to a single file. " |
| 175 | "Otherwise, the filename will be calculated by\n expanding " |
John Koleszar | 3707c34 | 2012-11-06 10:09:36 -0800 | [diff] [blame] | 176 | "the following escape characters:\n"); |
| 177 | fprintf(stderr, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 178 | "\n\t%%w - Frame width" |
| 179 | "\n\t%%h - Frame height" |
| 180 | "\n\t%%<n> - Frame number, zero padded to <n> places (1..9)" |
| 181 | "\n\n Pattern arguments are only supported in conjunction " |
| 182 | "with the --yv12 and\n --i420 options. If the -o option is " |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 183 | "not specified, the output will be\n directed to stdout.\n"); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 184 | fprintf(stderr, "\nIncluded decoders:\n\n"); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 185 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 186 | for (i = 0; i < get_aom_decoder_count(); ++i) { |
| 187 | const AvxInterface *const decoder = get_aom_decoder_by_index(i); |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 188 | fprintf(stderr, " %-6s - %s\n", decoder->name, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 189 | aom_codec_iface_name(decoder->codec_interface())); |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 190 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 191 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 192 | exit(EXIT_FAILURE); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 193 | } |
| 194 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 195 | static int raw_read_frame(FILE *infile, uint8_t **buffer, size_t *bytes_read, |
| 196 | size_t *buffer_size) { |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 197 | char raw_hdr[RAW_FRAME_HDR_SZ]; |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 198 | size_t frame_size = 0; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 199 | |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 200 | if (fread(raw_hdr, RAW_FRAME_HDR_SZ, 1, infile) != 1) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 201 | if (!feof(infile)) warn("Failed to read RAW frame size\n"); |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 202 | } else { |
James Zern | 75d7ee3 | 2014-02-04 20:06:28 -0800 | [diff] [blame] | 203 | const size_t kCorruptFrameThreshold = 256 * 1024 * 1024; |
| 204 | const size_t kFrameTooSmallThreshold = 256 * 1024; |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 205 | frame_size = mem_get_le32(raw_hdr); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 206 | |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 207 | if (frame_size > kCorruptFrameThreshold) { |
| 208 | warn("Read invalid frame size (%u)\n", (unsigned int)frame_size); |
| 209 | frame_size = 0; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 210 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 211 | |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 212 | if (frame_size < kFrameTooSmallThreshold) { |
| 213 | warn("Warning: Read invalid frame size (%u) - not a raw file?\n", |
| 214 | (unsigned int)frame_size); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 215 | } |
| 216 | |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 217 | if (frame_size > *buffer_size) { |
| 218 | uint8_t *new_buf = realloc(*buffer, 2 * frame_size); |
| 219 | if (new_buf) { |
| 220 | *buffer = new_buf; |
| 221 | *buffer_size = 2 * frame_size; |
| 222 | } else { |
| 223 | warn("Failed to allocate compressed data buffer\n"); |
| 224 | frame_size = 0; |
| 225 | } |
| 226 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 227 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 228 | |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 229 | if (!feof(infile)) { |
| 230 | if (fread(*buffer, 1, frame_size, infile) != frame_size) { |
| 231 | warn("Failed to read full frame\n"); |
| 232 | return 1; |
| 233 | } |
| 234 | *bytes_read = frame_size; |
| 235 | } |
| 236 | |
| 237 | return 0; |
| 238 | } |
| 239 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 240 | static int read_frame(struct AvxDecInputContext *input, uint8_t **buf, |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 241 | size_t *bytes_in_buffer, size_t *buffer_size) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 242 | switch (input->aom_input_ctx->file_type) { |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 243 | #if CONFIG_WEBM_IO |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 244 | case FILE_TYPE_WEBM: |
Vignesh Venkatasubramanian | fa99c37 | 2016-04-25 13:46:42 -0700 | [diff] [blame] | 245 | return webm_read_frame(input->webm_ctx, buf, bytes_in_buffer); |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 246 | #endif |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 247 | case FILE_TYPE_RAW: |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 248 | return raw_read_frame(input->aom_input_ctx->file, buf, bytes_in_buffer, |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 249 | buffer_size); |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 250 | case FILE_TYPE_IVF: |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 251 | return ivf_read_frame(input->aom_input_ctx->file, buf, bytes_in_buffer, |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 252 | buffer_size); |
| 253 | default: return 1; |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 254 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 255 | } |
| 256 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 257 | static void update_image_md5(const aom_image_t *img, const int planes[3], |
Dmitry Kovalev | cf46bc7 | 2014-01-17 10:57:55 -0800 | [diff] [blame] | 258 | MD5Context *md5) { |
| 259 | int i, y; |
| 260 | |
| 261 | for (i = 0; i < 3; ++i) { |
| 262 | const int plane = planes[i]; |
| 263 | const unsigned char *buf = img->planes[plane]; |
| 264 | const int stride = img->stride[plane]; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 265 | const int w = aom_img_plane_width(img, plane) * |
| 266 | ((img->fmt & AOM_IMG_FMT_HIGHBITDEPTH) ? 2 : 1); |
| 267 | const int h = aom_img_plane_height(img, plane); |
Dmitry Kovalev | cf46bc7 | 2014-01-17 10:57:55 -0800 | [diff] [blame] | 268 | |
| 269 | for (y = 0; y < h; ++y) { |
| 270 | MD5Update(md5, buf, w); |
| 271 | buf += stride; |
| 272 | } |
| 273 | } |
| 274 | } |
| 275 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 276 | static void write_image_file(const aom_image_t *img, const int planes[3], |
Dmitry Kovalev | cf46bc7 | 2014-01-17 10:57:55 -0800 | [diff] [blame] | 277 | FILE *file) { |
| 278 | int i, y; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 279 | #if CONFIG_AOM_HIGHBITDEPTH |
| 280 | const int bytes_per_sample = ((img->fmt & AOM_IMG_FMT_HIGHBITDEPTH) ? 2 : 1); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 281 | #else |
| 282 | const int bytes_per_sample = 1; |
| 283 | #endif |
Dmitry Kovalev | cf46bc7 | 2014-01-17 10:57:55 -0800 | [diff] [blame] | 284 | |
| 285 | for (i = 0; i < 3; ++i) { |
| 286 | const int plane = planes[i]; |
| 287 | const unsigned char *buf = img->planes[plane]; |
| 288 | const int stride = img->stride[plane]; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 289 | const int w = aom_img_plane_width(img, plane); |
| 290 | const int h = aom_img_plane_height(img, plane); |
Dmitry Kovalev | cf46bc7 | 2014-01-17 10:57:55 -0800 | [diff] [blame] | 291 | |
| 292 | for (y = 0; y < h; ++y) { |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 293 | fwrite(buf, bytes_per_sample, w, file); |
Dmitry Kovalev | cf46bc7 | 2014-01-17 10:57:55 -0800 | [diff] [blame] | 294 | buf += stride; |
| 295 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 296 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 297 | } |
| 298 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 299 | static int file_is_raw(struct AvxInputContext *input) { |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 300 | uint8_t buf[32]; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 301 | int is_raw = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 302 | aom_codec_stream_info_t si; |
John Koleszar | cfe3f91 | 2010-10-20 10:49:12 -0400 | [diff] [blame] | 303 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 304 | si.sz = sizeof(si); |
John Koleszar | 19255b8 | 2010-11-23 13:40:31 -0500 | [diff] [blame] | 305 | |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 306 | if (fread(buf, 1, 32, input->file) == 32) { |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 307 | int i; |
John Koleszar | cfe3f91 | 2010-10-20 10:49:12 -0400 | [diff] [blame] | 308 | |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 309 | if (mem_get_le32(buf) < 256 * 1024 * 1024) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 310 | for (i = 0; i < get_aom_decoder_count(); ++i) { |
| 311 | const AvxInterface *const decoder = get_aom_decoder_by_index(i); |
| 312 | if (!aom_codec_peek_stream_info(decoder->codec_interface(), buf + 4, |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 313 | 32 - 4, &si)) { |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 314 | is_raw = 1; |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 315 | input->fourcc = decoder->fourcc; |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 316 | input->width = si.w; |
| 317 | input->height = si.h; |
| 318 | input->framerate.numerator = 30; |
| 319 | input->framerate.denominator = 1; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 320 | break; |
| 321 | } |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 322 | } |
| 323 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 324 | } |
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 | rewind(input->file); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 327 | return is_raw; |
John Koleszar | cfe3f91 | 2010-10-20 10:49:12 -0400 | [diff] [blame] | 328 | } |
| 329 | |
James Zern | 6a2e0f0 | 2015-05-09 10:42:31 -0700 | [diff] [blame] | 330 | 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] | 331 | fprintf(stderr, |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 332 | "%d decoded frames/%d showed frames in %" PRId64 " us (%.2f fps)\r", |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 333 | frame_in, frame_out, dx_time, |
James Yu | 6d15132 | 2014-02-22 14:51:11 +0800 | [diff] [blame] | 334 | (double)frame_out * 1000000.0 / (double)dx_time); |
John Koleszar | 5d12e04 | 2010-10-21 17:28:34 -0400 | [diff] [blame] | 335 | } |
| 336 | |
Frank Galligan | a4f30a5 | 2014-02-06 17:13:08 -0800 | [diff] [blame] | 337 | struct ExternalFrameBuffer { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 338 | uint8_t *data; |
Frank Galligan | a4f30a5 | 2014-02-06 17:13:08 -0800 | [diff] [blame] | 339 | size_t size; |
| 340 | int in_use; |
| 341 | }; |
| 342 | |
| 343 | struct ExternalFrameBufferList { |
| 344 | int num_external_frame_buffers; |
| 345 | struct ExternalFrameBuffer *ext_fb; |
| 346 | }; |
| 347 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 348 | // Callback used by libaom to request an external frame buffer. |cb_priv| |
Frank Galligan | a4f30a5 | 2014-02-06 17:13:08 -0800 | [diff] [blame] | 349 | // Application private data passed into the set function. |min_size| is the |
| 350 | // minimum size in bytes needed to decode the next frame. |fb| pointer to the |
| 351 | // frame buffer. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 352 | static int get_av1_frame_buffer(void *cb_priv, size_t min_size, |
| 353 | aom_codec_frame_buffer_t *fb) { |
Frank Galligan | a4f30a5 | 2014-02-06 17:13:08 -0800 | [diff] [blame] | 354 | int i; |
| 355 | struct ExternalFrameBufferList *const ext_fb_list = |
| 356 | (struct ExternalFrameBufferList *)cb_priv; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 357 | if (ext_fb_list == NULL) return -1; |
Frank Galligan | a4f30a5 | 2014-02-06 17:13:08 -0800 | [diff] [blame] | 358 | |
| 359 | // Find a free frame buffer. |
| 360 | for (i = 0; i < ext_fb_list->num_external_frame_buffers; ++i) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 361 | if (!ext_fb_list->ext_fb[i].in_use) break; |
Frank Galligan | a4f30a5 | 2014-02-06 17:13:08 -0800 | [diff] [blame] | 362 | } |
| 363 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 364 | if (i == ext_fb_list->num_external_frame_buffers) return -1; |
Frank Galligan | a4f30a5 | 2014-02-06 17:13:08 -0800 | [diff] [blame] | 365 | |
| 366 | if (ext_fb_list->ext_fb[i].size < min_size) { |
| 367 | free(ext_fb_list->ext_fb[i].data); |
Frank Galligan | 175d9df | 2014-09-11 08:39:38 -0700 | [diff] [blame] | 368 | ext_fb_list->ext_fb[i].data = (uint8_t *)calloc(min_size, sizeof(uint8_t)); |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 369 | if (!ext_fb_list->ext_fb[i].data) return -1; |
Frank Galligan | a4f30a5 | 2014-02-06 17:13:08 -0800 | [diff] [blame] | 370 | |
| 371 | ext_fb_list->ext_fb[i].size = min_size; |
| 372 | } |
| 373 | |
| 374 | fb->data = ext_fb_list->ext_fb[i].data; |
| 375 | fb->size = ext_fb_list->ext_fb[i].size; |
| 376 | ext_fb_list->ext_fb[i].in_use = 1; |
| 377 | |
| 378 | // Set the frame buffer's private data to point at the external frame buffer. |
| 379 | fb->priv = &ext_fb_list->ext_fb[i]; |
| 380 | return 0; |
| 381 | } |
| 382 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 383 | // Callback used by libaom when there are no references to the frame buffer. |
Frank Galligan | a4f30a5 | 2014-02-06 17:13:08 -0800 | [diff] [blame] | 384 | // |cb_priv| user private data passed into the set function. |fb| pointer |
| 385 | // to the frame buffer. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 386 | static int release_av1_frame_buffer(void *cb_priv, |
| 387 | aom_codec_frame_buffer_t *fb) { |
Frank Galligan | a4f30a5 | 2014-02-06 17:13:08 -0800 | [diff] [blame] | 388 | struct ExternalFrameBuffer *const ext_fb = |
| 389 | (struct ExternalFrameBuffer *)fb->priv; |
| 390 | (void)cb_priv; |
| 391 | ext_fb->in_use = 0; |
| 392 | return 0; |
| 393 | } |
| 394 | |
James Zern | 6a2e0f0 | 2015-05-09 10:42:31 -0700 | [diff] [blame] | 395 | static void generate_filename(const char *pattern, char *out, size_t q_len, |
| 396 | unsigned int d_w, unsigned int d_h, |
| 397 | unsigned int frame_in) { |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 398 | const char *p = pattern; |
| 399 | char *q = out; |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 400 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 401 | do { |
| 402 | char *next_pat = strchr(p, '%'); |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 403 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 404 | if (p == next_pat) { |
| 405 | size_t pat_len; |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 406 | |
John Koleszar | 3707c34 | 2012-11-06 10:09:36 -0800 | [diff] [blame] | 407 | /* parse the pattern */ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 408 | q[q_len - 1] = '\0'; |
| 409 | switch (p[1]) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 410 | case 'w': snprintf(q, q_len - 1, "%d", d_w); break; |
| 411 | case 'h': snprintf(q, q_len - 1, "%d", d_h); break; |
| 412 | case '1': snprintf(q, q_len - 1, "%d", frame_in); break; |
| 413 | case '2': snprintf(q, q_len - 1, "%02d", frame_in); break; |
| 414 | case '3': snprintf(q, q_len - 1, "%03d", frame_in); break; |
| 415 | case '4': snprintf(q, q_len - 1, "%04d", frame_in); break; |
| 416 | case '5': snprintf(q, q_len - 1, "%05d", frame_in); break; |
| 417 | case '6': snprintf(q, q_len - 1, "%06d", frame_in); break; |
| 418 | case '7': snprintf(q, q_len - 1, "%07d", frame_in); break; |
| 419 | case '8': snprintf(q, q_len - 1, "%08d", frame_in); break; |
| 420 | case '9': snprintf(q, q_len - 1, "%09d", frame_in); break; |
| 421 | default: die("Unrecognized pattern %%%c\n", p[1]); break; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 422 | } |
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 | pat_len = strlen(q); |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 425 | if (pat_len >= q_len - 1) die("Output filename too long.\n"); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 426 | q += pat_len; |
| 427 | p += 2; |
| 428 | q_len -= pat_len; |
| 429 | } else { |
| 430 | size_t copy_len; |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 431 | |
John Koleszar | 3707c34 | 2012-11-06 10:09:36 -0800 | [diff] [blame] | 432 | /* copy the next segment */ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 433 | if (!next_pat) |
| 434 | copy_len = strlen(p); |
| 435 | else |
| 436 | copy_len = next_pat - p; |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 437 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 438 | if (copy_len >= q_len - 1) die("Output filename too long.\n"); |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 439 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 440 | memcpy(q, p, copy_len); |
| 441 | q[copy_len] = '\0'; |
| 442 | q += copy_len; |
| 443 | p += copy_len; |
| 444 | q_len -= copy_len; |
| 445 | } |
| 446 | } while (*p); |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 447 | } |
| 448 | |
Dmitry Kovalev | 347b306 | 2014-01-22 09:04:07 -0800 | [diff] [blame] | 449 | static int is_single_file(const char *outfile_pattern) { |
| 450 | const char *p = outfile_pattern; |
| 451 | |
| 452 | do { |
| 453 | p = strchr(p, '%'); |
| 454 | if (p && p[1] >= '1' && p[1] <= '9') |
| 455 | return 0; // pattern contains sequence number, so it's not unique |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 456 | if (p) p++; |
Dmitry Kovalev | 347b306 | 2014-01-22 09:04:07 -0800 | [diff] [blame] | 457 | } while (p); |
| 458 | |
| 459 | return 1; |
| 460 | } |
| 461 | |
| 462 | static void print_md5(unsigned char digest[16], const char *filename) { |
| 463 | int i; |
| 464 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 465 | for (i = 0; i < 16; ++i) printf("%02x", digest[i]); |
Dmitry Kovalev | 347b306 | 2014-01-22 09:04:07 -0800 | [diff] [blame] | 466 | printf(" %s\n", filename); |
| 467 | } |
| 468 | |
| 469 | static FILE *open_outfile(const char *name) { |
| 470 | if (strcmp("-", name) == 0) { |
| 471 | set_binary_mode(stdout); |
| 472 | return stdout; |
| 473 | } else { |
| 474 | FILE *file = fopen(name, "wb"); |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 475 | if (!file) fatal("Failed to open output file '%s'", name); |
Dmitry Kovalev | 347b306 | 2014-01-22 09:04:07 -0800 | [diff] [blame] | 476 | return file; |
| 477 | } |
| 478 | } |
| 479 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 480 | #if CONFIG_AOM_HIGHBITDEPTH |
| 481 | static int img_shifted_realloc_required(const aom_image_t *img, |
| 482 | const aom_image_t *shifted, |
| 483 | aom_img_fmt_t required_fmt) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 484 | return img->d_w != shifted->d_w || img->d_h != shifted->d_h || |
Deb Mukherjee | 9ed23de | 2014-09-25 15:46:50 -0700 | [diff] [blame] | 485 | required_fmt != shifted->fmt; |
| 486 | } |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 487 | #endif |
| 488 | |
James Zern | 6a2e0f0 | 2015-05-09 10:42:31 -0700 | [diff] [blame] | 489 | static int main_loop(int argc, const char **argv_) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 490 | aom_codec_ctx_t decoder; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 491 | char *fn = NULL; |
| 492 | int i; |
James Zern | 360e444 | 2016-11-16 21:53:55 -0800 | [diff] [blame] | 493 | int ret = EXIT_FAILURE; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 494 | uint8_t *buf = NULL; |
| 495 | size_t bytes_in_buffer = 0, buffer_size = 0; |
| 496 | FILE *infile; |
| 497 | int frame_in = 0, frame_out = 0, flipuv = 0, noblit = 0; |
| 498 | int do_md5 = 0, progress = 0, frame_parallel = 0; |
| 499 | int stop_after = 0, postproc = 0, summary = 0, quiet = 1; |
| 500 | int arg_skip = 0; |
| 501 | int ec_enabled = 0; |
| 502 | int keep_going = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 503 | const AvxInterface *interface = NULL; |
| 504 | const AvxInterface *fourcc_interface = NULL; |
James Yu | 6d15132 | 2014-02-22 14:51:11 +0800 | [diff] [blame] | 505 | uint64_t dx_time = 0; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 506 | struct arg arg; |
| 507 | char **argv, **argi, **argj; |
Dmitry Kovalev | 347b306 | 2014-01-22 09:04:07 -0800 | [diff] [blame] | 508 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 509 | int single_file; |
| 510 | int use_y4m = 1; |
| 511 | int opt_yv12 = 0; |
| 512 | int opt_i420 = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 513 | aom_codec_dec_cfg_t cfg = { 0, 0, 0 }; |
| 514 | #if CONFIG_AOM_HIGHBITDEPTH |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 515 | unsigned int output_bit_depth = 0; |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 516 | #endif |
Geza Lore | 490ba1a | 2016-03-11 17:42:49 +0000 | [diff] [blame] | 517 | #if CONFIG_EXT_TILE |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 518 | int tile_row = -1; |
| 519 | int tile_col = -1; |
Geza Lore | 490ba1a | 2016-03-11 17:42:49 +0000 | [diff] [blame] | 520 | #endif // CONFIG_EXT_TILE |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 521 | int frames_corrupted = 0; |
| 522 | int dec_flags = 0; |
| 523 | int do_scale = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 524 | aom_image_t *scaled_img = NULL; |
| 525 | #if CONFIG_AOM_HIGHBITDEPTH |
| 526 | aom_image_t *img_shifted = NULL; |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 527 | #endif |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 528 | int frame_avail, got_data, flush_decoder = 0; |
| 529 | int num_external_frame_buffers = 0; |
| 530 | struct ExternalFrameBufferList ext_fb_list = { 0, NULL }; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 531 | |
Dmitry Kovalev | 347b306 | 2014-01-22 09:04:07 -0800 | [diff] [blame] | 532 | const char *outfile_pattern = NULL; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 533 | char outfile_name[PATH_MAX] = { 0 }; |
Dmitry Kovalev | 347b306 | 2014-01-22 09:04:07 -0800 | [diff] [blame] | 534 | FILE *outfile = NULL; |
| 535 | |
| 536 | MD5Context md5_ctx; |
| 537 | unsigned char md5_digest[16]; |
| 538 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 539 | struct AvxDecInputContext input = { NULL, NULL }; |
| 540 | struct AvxInputContext aom_input_ctx; |
James Zern | b6cce76 | 2014-05-10 17:44:12 -0700 | [diff] [blame] | 541 | #if CONFIG_WEBM_IO |
Jim Bankoski | 7ae3269 | 2014-08-19 06:44:10 -0700 | [diff] [blame] | 542 | struct WebmInputContext webm_ctx; |
| 543 | memset(&(webm_ctx), 0, sizeof(webm_ctx)); |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 544 | input.webm_ctx = &webm_ctx; |
James Zern | b6cce76 | 2014-05-10 17:44:12 -0700 | [diff] [blame] | 545 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 546 | input.aom_input_ctx = &aom_input_ctx; |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 547 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 548 | /* Parse command line */ |
| 549 | exec_name = argv_[0]; |
| 550 | argv = argv_dup(argc - 1, argv_ + 1); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 551 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 552 | for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) { |
| 553 | memset(&arg, 0, sizeof(arg)); |
| 554 | arg.argv_step = 1; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 555 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 556 | if (arg_match(&arg, &codecarg, argi)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 557 | interface = get_aom_decoder_by_name(arg.val); |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 558 | if (!interface) |
| 559 | die("Error: Unrecognized argument (%s) to --codec\n", arg.val); |
John Koleszar | 9596a4c | 2013-06-12 16:08:35 -0700 | [diff] [blame] | 560 | } else if (arg_match(&arg, &looparg, argi)) { |
| 561 | // no-op |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 562 | } else if (arg_match(&arg, &outputfile, argi)) |
| 563 | outfile_pattern = arg.val; |
| 564 | else if (arg_match(&arg, &use_yv12, argi)) { |
| 565 | use_y4m = 0; |
| 566 | flipuv = 1; |
Deb Mukherjee | 090f4d4 | 2014-07-16 09:37:13 -0700 | [diff] [blame] | 567 | opt_yv12 = 1; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 568 | } else if (arg_match(&arg, &use_i420, argi)) { |
| 569 | use_y4m = 0; |
| 570 | flipuv = 0; |
Deb Mukherjee | 090f4d4 | 2014-07-16 09:37:13 -0700 | [diff] [blame] | 571 | opt_i420 = 1; |
| 572 | } else if (arg_match(&arg, &rawvideo, argi)) { |
| 573 | use_y4m = 0; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 574 | } else if (arg_match(&arg, &flipuvarg, argi)) |
| 575 | flipuv = 1; |
| 576 | else if (arg_match(&arg, &noblitarg, argi)) |
| 577 | noblit = 1; |
| 578 | else if (arg_match(&arg, &progressarg, argi)) |
| 579 | progress = 1; |
| 580 | else if (arg_match(&arg, &limitarg, argi)) |
| 581 | stop_after = arg_parse_uint(&arg); |
Yaowu Xu | c394ffc | 2012-10-11 15:12:35 -0700 | [diff] [blame] | 582 | else if (arg_match(&arg, &skiparg, argi)) |
| 583 | arg_skip = arg_parse_uint(&arg); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 584 | else if (arg_match(&arg, &postprocarg, argi)) |
| 585 | postproc = 1; |
| 586 | else if (arg_match(&arg, &md5arg, argi)) |
| 587 | do_md5 = 1; |
| 588 | else if (arg_match(&arg, &summaryarg, argi)) |
| 589 | summary = 1; |
| 590 | else if (arg_match(&arg, &threadsarg, argi)) |
| 591 | cfg.threads = arg_parse_uint(&arg); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 592 | #if CONFIG_AV1_DECODER |
hkuang | 1f841c3 | 2015-03-06 13:03:18 -0800 | [diff] [blame] | 593 | else if (arg_match(&arg, &frameparallelarg, argi)) |
| 594 | frame_parallel = 1; |
| 595 | #endif |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 596 | else if (arg_match(&arg, &verbosearg, argi)) |
| 597 | quiet = 0; |
John Koleszar | 7d8fc26 | 2013-02-25 16:58:47 -0800 | [diff] [blame] | 598 | else if (arg_match(&arg, &scalearg, argi)) |
| 599 | do_scale = 1; |
Frank Galligan | a4f30a5 | 2014-02-06 17:13:08 -0800 | [diff] [blame] | 600 | else if (arg_match(&arg, &fb_arg, argi)) |
| 601 | num_external_frame_buffers = arg_parse_uint(&arg); |
James Zern | 7690d88 | 2014-08-22 18:01:28 -0700 | [diff] [blame] | 602 | else if (arg_match(&arg, &continuearg, argi)) |
| 603 | keep_going = 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 604 | #if CONFIG_AOM_HIGHBITDEPTH |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 605 | else if (arg_match(&arg, &outbitdeptharg, argi)) { |
| 606 | output_bit_depth = arg_parse_uint(&arg); |
| 607 | } |
| 608 | #endif |
Geza Lore | 490ba1a | 2016-03-11 17:42:49 +0000 | [diff] [blame] | 609 | #if CONFIG_EXT_TILE |
| 610 | else if (arg_match(&arg, &tiler, argi)) |
| 611 | tile_row = arg_parse_int(&arg); |
| 612 | else if (arg_match(&arg, &tilec, argi)) |
| 613 | tile_col = arg_parse_int(&arg); |
| 614 | #endif // CONFIG_EXT_TILE |
John Koleszar | cfe3f91 | 2010-10-20 10:49:12 -0400 | [diff] [blame] | 615 | else |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 616 | argj++; |
| 617 | } |
| 618 | |
| 619 | /* Check for unrecognized options */ |
| 620 | for (argi = argv; *argi; argi++) |
| 621 | if (argi[0][0] == '-' && strlen(argi[0]) > 1) |
| 622 | die("Error: Unrecognized option %s\n", *argi); |
| 623 | |
| 624 | /* Handle non-option arguments */ |
| 625 | fn = argv[0]; |
| 626 | |
Hanno Böck | b5d0a20 | 2015-02-24 15:48:21 -0800 | [diff] [blame] | 627 | if (!fn) { |
| 628 | free(argv); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 629 | usage_exit(); |
Hanno Böck | b5d0a20 | 2015-02-24 15:48:21 -0800 | [diff] [blame] | 630 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 631 | /* Open file */ |
| 632 | infile = strcmp(fn, "-") ? fopen(fn, "rb") : set_binary_mode(stdin); |
| 633 | |
| 634 | if (!infile) { |
James Zern | 6b993f0 | 2015-02-05 21:06:29 -0800 | [diff] [blame] | 635 | fatal("Failed to open input file '%s'", strcmp(fn, "-") ? fn : "stdin"); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 636 | } |
| 637 | #if CONFIG_OS_SUPPORT |
| 638 | /* Make sure we don't dump to the terminal, unless forced to with -o - */ |
| 639 | if (!outfile_pattern && isatty(fileno(stdout)) && !do_md5 && !noblit) { |
| 640 | fprintf(stderr, |
| 641 | "Not dumping raw video to your terminal. Use '-o -' to " |
| 642 | "override.\n"); |
| 643 | return EXIT_FAILURE; |
| 644 | } |
| 645 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 646 | input.aom_input_ctx->file = infile; |
| 647 | if (file_is_ivf(input.aom_input_ctx)) |
| 648 | input.aom_input_ctx->file_type = FILE_TYPE_IVF; |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 649 | #if CONFIG_WEBM_IO |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 650 | else if (file_is_webm(input.webm_ctx, input.aom_input_ctx)) |
| 651 | input.aom_input_ctx->file_type = FILE_TYPE_WEBM; |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 652 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 653 | else if (file_is_raw(input.aom_input_ctx)) |
| 654 | input.aom_input_ctx->file_type = FILE_TYPE_RAW; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 655 | else { |
| 656 | fprintf(stderr, "Unrecognized input file type.\n"); |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 657 | #if !CONFIG_WEBM_IO |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 658 | fprintf(stderr, "aomdec was built without WebM container support.\n"); |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 659 | #endif |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 660 | return EXIT_FAILURE; |
| 661 | } |
| 662 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 663 | outfile_pattern = outfile_pattern ? outfile_pattern : "-"; |
Dmitry Kovalev | 347b306 | 2014-01-22 09:04:07 -0800 | [diff] [blame] | 664 | single_file = is_single_file(outfile_pattern); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 665 | |
Dmitry Kovalev | 347b306 | 2014-01-22 09:04:07 -0800 | [diff] [blame] | 666 | if (!noblit && single_file) { |
| 667 | generate_filename(outfile_pattern, outfile_name, PATH_MAX, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 668 | aom_input_ctx.width, aom_input_ctx.height, 0); |
Dmitry Kovalev | 347b306 | 2014-01-22 09:04:07 -0800 | [diff] [blame] | 669 | if (do_md5) |
| 670 | MD5Init(&md5_ctx); |
| 671 | else |
| 672 | outfile = open_outfile(outfile_name); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | if (use_y4m && !noblit) { |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 676 | if (!single_file) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 677 | fprintf(stderr, |
| 678 | "YUV4MPEG2 not supported with output patterns," |
Deb Mukherjee | a30774c | 2014-10-01 12:17:37 -0700 | [diff] [blame] | 679 | " try --i420 or --yv12 or --rawvideo.\n"); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 680 | return EXIT_FAILURE; |
| 681 | } |
| 682 | |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 683 | #if CONFIG_WEBM_IO |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 684 | if (aom_input_ctx.file_type == FILE_TYPE_WEBM) { |
| 685 | if (webm_guess_framerate(input.webm_ctx, input.aom_input_ctx)) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 686 | fprintf(stderr, |
| 687 | "Failed to guess framerate -- error parsing " |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 688 | "webm file?\n"); |
Timothy B. Terriberry | 7f9db41 | 2010-05-26 19:36:20 -0400 | [diff] [blame] | 689 | return EXIT_FAILURE; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 690 | } |
Dmitry Kovalev | 5ab63583 | 2014-01-17 17:02:37 -0800 | [diff] [blame] | 691 | } |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 692 | #endif |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 693 | } |
| 694 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 695 | fourcc_interface = get_aom_decoder_by_fourcc(aom_input_ctx.fourcc); |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 696 | if (interface && fourcc_interface && interface != fourcc_interface) |
| 697 | warn("Header indicates codec: %s\n", fourcc_interface->name); |
| 698 | else |
| 699 | interface = fourcc_interface; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 700 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 701 | if (!interface) interface = get_aom_decoder_by_index(0); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 702 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 703 | dec_flags = (postproc ? AOM_CODEC_USE_POSTPROC : 0) | |
| 704 | (ec_enabled ? AOM_CODEC_USE_ERROR_CONCEALMENT : 0) | |
| 705 | (frame_parallel ? AOM_CODEC_USE_FRAME_THREADING : 0); |
| 706 | if (aom_codec_dec_init(&decoder, interface->codec_interface(), &cfg, |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 707 | dec_flags)) { |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 708 | fprintf(stderr, "Failed to initialize decoder: %s\n", |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 709 | aom_codec_error(&decoder)); |
James Zern | 360e444 | 2016-11-16 21:53:55 -0800 | [diff] [blame] | 710 | goto fail2; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 711 | } |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 712 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 713 | if (!quiet) fprintf(stderr, "%s\n", decoder.name); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 714 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 715 | #if CONFIG_AV1_DECODER && CONFIG_EXT_TILE |
| 716 | if (strncmp(decoder.name, "WebM Project AV1", 17) == 0) { |
| 717 | if (aom_codec_control(&decoder, AV1_SET_DECODE_TILE_ROW, tile_row)) { |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 718 | fprintf(stderr, "Failed to set decode_tile_row: %s\n", |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 719 | aom_codec_error(&decoder)); |
James Zern | 360e444 | 2016-11-16 21:53:55 -0800 | [diff] [blame] | 720 | goto fail; |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 721 | } |
| 722 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 723 | if (aom_codec_control(&decoder, AV1_SET_DECODE_TILE_COL, tile_col)) { |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 724 | fprintf(stderr, "Failed to set decode_tile_col: %s\n", |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 725 | aom_codec_error(&decoder)); |
James Zern | 360e444 | 2016-11-16 21:53:55 -0800 | [diff] [blame] | 726 | goto fail; |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 727 | } |
| 728 | } |
| 729 | #endif |
Yaowu Xu | c394ffc | 2012-10-11 15:12:35 -0700 | [diff] [blame] | 730 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 731 | if (arg_skip) fprintf(stderr, "Skipping first %d frames.\n", arg_skip); |
Yaowu Xu | c394ffc | 2012-10-11 15:12:35 -0700 | [diff] [blame] | 732 | while (arg_skip) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 733 | if (read_frame(&input, &buf, &bytes_in_buffer, &buffer_size)) break; |
Yaowu Xu | c394ffc | 2012-10-11 15:12:35 -0700 | [diff] [blame] | 734 | arg_skip--; |
| 735 | } |
| 736 | |
Frank Galligan | a4f30a5 | 2014-02-06 17:13:08 -0800 | [diff] [blame] | 737 | if (num_external_frame_buffers > 0) { |
| 738 | ext_fb_list.num_external_frame_buffers = num_external_frame_buffers; |
| 739 | ext_fb_list.ext_fb = (struct ExternalFrameBuffer *)calloc( |
| 740 | num_external_frame_buffers, sizeof(*ext_fb_list.ext_fb)); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 741 | if (aom_codec_set_frame_buffer_functions(&decoder, get_av1_frame_buffer, |
| 742 | release_av1_frame_buffer, |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 743 | &ext_fb_list)) { |
Frank Galligan | a4f30a5 | 2014-02-06 17:13:08 -0800 | [diff] [blame] | 744 | fprintf(stderr, "Failed to configure external frame buffers: %s\n", |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 745 | aom_codec_error(&decoder)); |
James Zern | 360e444 | 2016-11-16 21:53:55 -0800 | [diff] [blame] | 746 | goto fail; |
Frank Galligan | a4f30a5 | 2014-02-06 17:13:08 -0800 | [diff] [blame] | 747 | } |
| 748 | } |
| 749 | |
Scott LaVarnway | c3ae212 | 2013-06-07 12:39:03 -0400 | [diff] [blame] | 750 | frame_avail = 1; |
| 751 | got_data = 0; |
| 752 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 753 | /* Decode file */ |
Scott LaVarnway | c3ae212 | 2013-06-07 12:39:03 -0400 | [diff] [blame] | 754 | while (frame_avail || got_data) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 755 | aom_codec_iter_t iter = NULL; |
| 756 | aom_image_t *img; |
| 757 | struct aom_usec_timer timer; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 758 | int corrupted = 0; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 759 | |
Scott LaVarnway | c3ae212 | 2013-06-07 12:39:03 -0400 | [diff] [blame] | 760 | frame_avail = 0; |
| 761 | if (!stop_after || frame_in < stop_after) { |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 762 | if (!read_frame(&input, &buf, &bytes_in_buffer, &buffer_size)) { |
Scott LaVarnway | c3ae212 | 2013-06-07 12:39:03 -0400 | [diff] [blame] | 763 | frame_avail = 1; |
| 764 | frame_in++; |
| 765 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 766 | aom_usec_timer_start(&timer); |
Scott LaVarnway | c3ae212 | 2013-06-07 12:39:03 -0400 | [diff] [blame] | 767 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 768 | if (aom_codec_decode(&decoder, buf, (unsigned int)bytes_in_buffer, NULL, |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 769 | 0)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 770 | const char *detail = aom_codec_error_detail(&decoder); |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 771 | warn("Failed to decode frame %d: %s", frame_in, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 772 | aom_codec_error(&decoder)); |
Scott LaVarnway | c3ae212 | 2013-06-07 12:39:03 -0400 | [diff] [blame] | 773 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 774 | if (detail) warn("Additional information: %s", detail); |
| 775 | if (!keep_going) goto fail; |
Scott LaVarnway | c3ae212 | 2013-06-07 12:39:03 -0400 | [diff] [blame] | 776 | } |
| 777 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 778 | aom_usec_timer_mark(&timer); |
| 779 | dx_time += aom_usec_timer_elapsed(&timer); |
hkuang | 1f841c3 | 2015-03-06 13:03:18 -0800 | [diff] [blame] | 780 | } else { |
| 781 | flush_decoder = 1; |
Scott LaVarnway | c3ae212 | 2013-06-07 12:39:03 -0400 | [diff] [blame] | 782 | } |
hkuang | 1f841c3 | 2015-03-06 13:03:18 -0800 | [diff] [blame] | 783 | } else { |
| 784 | flush_decoder = 1; |
Scott LaVarnway | c3ae212 | 2013-06-07 12:39:03 -0400 | [diff] [blame] | 785 | } |
| 786 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 787 | aom_usec_timer_start(&timer); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 788 | |
hkuang | 1f841c3 | 2015-03-06 13:03:18 -0800 | [diff] [blame] | 789 | if (flush_decoder) { |
| 790 | // Flush the decoder in frame parallel decode. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 791 | if (aom_codec_decode(&decoder, NULL, 0, NULL, 0)) { |
| 792 | warn("Failed to flush decoder: %s", aom_codec_error(&decoder)); |
hkuang | 1f841c3 | 2015-03-06 13:03:18 -0800 | [diff] [blame] | 793 | } |
| 794 | } |
| 795 | |
Scott LaVarnway | c3ae212 | 2013-06-07 12:39:03 -0400 | [diff] [blame] | 796 | got_data = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 797 | if ((img = aom_codec_get_frame(&decoder, &iter))) { |
Scott LaVarnway | c3ae212 | 2013-06-07 12:39:03 -0400 | [diff] [blame] | 798 | ++frame_out; |
| 799 | got_data = 1; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 800 | } |
| 801 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 802 | aom_usec_timer_mark(&timer); |
| 803 | dx_time += (unsigned int)aom_usec_timer_elapsed(&timer); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 804 | |
hkuang | 1f841c3 | 2015-03-06 13:03:18 -0800 | [diff] [blame] | 805 | if (!frame_parallel && |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 806 | aom_codec_control(&decoder, AOMD_GET_FRAME_CORRUPTED, &corrupted)) { |
| 807 | warn("Failed AOM_GET_FRAME_CORRUPTED: %s", aom_codec_error(&decoder)); |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 808 | if (!keep_going) goto fail; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 809 | } |
| 810 | frames_corrupted += corrupted; |
| 811 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 812 | if (progress) show_progress(frame_in, frame_out, dx_time); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 813 | |
Dmitry Kovalev | f2acb45 | 2014-01-23 17:20:34 -0800 | [diff] [blame] | 814 | if (!noblit && img) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 815 | const int PLANES_YUV[] = { AOM_PLANE_Y, AOM_PLANE_U, AOM_PLANE_V }; |
| 816 | const int PLANES_YVU[] = { AOM_PLANE_Y, AOM_PLANE_V, AOM_PLANE_U }; |
Dmitry Kovalev | f2acb45 | 2014-01-23 17:20:34 -0800 | [diff] [blame] | 817 | const int *planes = flipuv ? PLANES_YVU : PLANES_YUV; |
John Koleszar | da58436 | 2013-05-06 15:52:06 -0700 | [diff] [blame] | 818 | |
Dmitry Kovalev | f2acb45 | 2014-01-23 17:20:34 -0800 | [diff] [blame] | 819 | if (do_scale) { |
Adrian Grange | 482c39c | 2013-12-13 10:15:03 -0800 | [diff] [blame] | 820 | if (frame_out == 1) { |
| 821 | // If the output frames are to be scaled to a fixed display size then |
| 822 | // use the width and height specified in the container. If either of |
| 823 | // 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] | 824 | // header. If that is unavailable, use the raw decoded size of the |
| 825 | // first decoded frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 826 | int render_width = aom_input_ctx.width; |
| 827 | int render_height = aom_input_ctx.height; |
Ronald S. Bultje | 36ffe64 | 2015-09-25 21:34:29 -0400 | [diff] [blame] | 828 | if (!render_width || !render_height) { |
| 829 | int render_size[2]; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 830 | if (aom_codec_control(&decoder, AV1D_GET_DISPLAY_SIZE, |
Ronald S. Bultje | 36ffe64 | 2015-09-25 21:34:29 -0400 | [diff] [blame] | 831 | render_size)) { |
Adrian Grange | 482c39c | 2013-12-13 10:15:03 -0800 | [diff] [blame] | 832 | // As last resort use size of first frame as display size. |
Ronald S. Bultje | 36ffe64 | 2015-09-25 21:34:29 -0400 | [diff] [blame] | 833 | render_width = img->d_w; |
| 834 | render_height = img->d_h; |
Adrian Grange | 482c39c | 2013-12-13 10:15:03 -0800 | [diff] [blame] | 835 | } else { |
Ronald S. Bultje | 36ffe64 | 2015-09-25 21:34:29 -0400 | [diff] [blame] | 836 | render_width = render_size[0]; |
| 837 | render_height = render_size[1]; |
Adrian Grange | 482c39c | 2013-12-13 10:15:03 -0800 | [diff] [blame] | 838 | } |
Adrian Grange | 2117fe0 | 2013-11-19 14:01:44 -0800 | [diff] [blame] | 839 | } |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 840 | scaled_img = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 841 | aom_img_alloc(NULL, img->fmt, render_width, render_height, 16); |
Deb Mukherjee | 449e5f2 | 2014-07-11 11:43:31 -0700 | [diff] [blame] | 842 | scaled_img->bit_depth = img->bit_depth; |
John Koleszar | 7d8fc26 | 2013-02-25 16:58:47 -0800 | [diff] [blame] | 843 | } |
Adrian Grange | 482c39c | 2013-12-13 10:15:03 -0800 | [diff] [blame] | 844 | |
Dmitry Kovalev | 3c05481 | 2014-01-17 12:19:19 -0800 | [diff] [blame] | 845 | 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] | 846 | #if CONFIG_LIBYUV |
Tom Finegan | 8ef2ce8 | 2014-12-12 11:57:04 -0800 | [diff] [blame] | 847 | libyuv_scale(img, scaled_img, kFilterBox); |
John Koleszar | 7d8fc26 | 2013-02-25 16:58:47 -0800 | [diff] [blame] | 848 | img = scaled_img; |
Deb Mukherjee | 47031c0 | 2014-05-16 18:52:01 -0700 | [diff] [blame] | 849 | #else |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 850 | fprintf(stderr, |
| 851 | "Failed to scale output frame: %s.\n" |
Deb Mukherjee | 47031c0 | 2014-05-16 18:52:01 -0700 | [diff] [blame] | 852 | "Scaling is disabled in this configuration. " |
| 853 | "To enable scaling, configure with --enable-libyuv\n", |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 854 | aom_codec_error(&decoder)); |
James Zern | 360e444 | 2016-11-16 21:53:55 -0800 | [diff] [blame] | 855 | goto fail; |
Deb Mukherjee | 47031c0 | 2014-05-16 18:52:01 -0700 | [diff] [blame] | 856 | #endif |
John Koleszar | 7d8fc26 | 2013-02-25 16:58:47 -0800 | [diff] [blame] | 857 | } |
| 858 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 859 | #if CONFIG_AOM_HIGHBITDEPTH |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 860 | // Default to codec bit depth if output bit depth not set |
Ronald S. Bultje | eba342a | 2015-09-11 16:55:19 -0400 | [diff] [blame] | 861 | if (!output_bit_depth && single_file && !do_md5) { |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 862 | output_bit_depth = img->bit_depth; |
| 863 | } |
| 864 | // Shift up or down if necessary |
Ronald S. Bultje | eba342a | 2015-09-11 16:55:19 -0400 | [diff] [blame] | 865 | if (output_bit_depth != 0 && output_bit_depth != img->bit_depth) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 866 | const aom_img_fmt_t shifted_fmt = |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 867 | output_bit_depth == 8 |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 868 | ? img->fmt ^ (img->fmt & AOM_IMG_FMT_HIGHBITDEPTH) |
| 869 | : img->fmt | AOM_IMG_FMT_HIGHBITDEPTH; |
Deb Mukherjee | 9ed23de | 2014-09-25 15:46:50 -0700 | [diff] [blame] | 870 | if (img_shifted && |
| 871 | img_shifted_realloc_required(img, img_shifted, shifted_fmt)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 872 | aom_img_free(img_shifted); |
Deb Mukherjee | 9ed23de | 2014-09-25 15:46:50 -0700 | [diff] [blame] | 873 | img_shifted = NULL; |
| 874 | } |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 875 | if (!img_shifted) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 876 | img_shifted = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 877 | aom_img_alloc(NULL, shifted_fmt, img->d_w, img->d_h, 16); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 878 | img_shifted->bit_depth = output_bit_depth; |
| 879 | } |
| 880 | if (output_bit_depth > img->bit_depth) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 881 | aom_img_upshift(img_shifted, img, output_bit_depth - img->bit_depth); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 882 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 883 | aom_img_downshift(img_shifted, img, |
Deb Mukherjee | 7a2a611 | 2014-10-06 20:46:11 -0700 | [diff] [blame] | 884 | img->bit_depth - output_bit_depth); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 885 | } |
| 886 | img = img_shifted; |
| 887 | } |
| 888 | #endif |
Dmitry Kovalev | 3c05481 | 2014-01-17 12:19:19 -0800 | [diff] [blame] | 889 | |
Geza Lore | 490ba1a | 2016-03-11 17:42:49 +0000 | [diff] [blame] | 890 | #if CONFIG_EXT_TILE |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 891 | aom_input_ctx.width = img->d_w; |
| 892 | aom_input_ctx.height = img->d_h; |
Geza Lore | 490ba1a | 2016-03-11 17:42:49 +0000 | [diff] [blame] | 893 | #endif // CONFIG_EXT_TILE |
| 894 | |
Dmitry Kovalev | f2acb45 | 2014-01-23 17:20:34 -0800 | [diff] [blame] | 895 | if (single_file) { |
Dmitry Kovalev | 5260b39 | 2014-01-28 11:12:58 -0800 | [diff] [blame] | 896 | if (use_y4m) { |
Urvang Joshi | 4145bf0 | 2016-10-17 14:53:33 -0700 | [diff] [blame] | 897 | char y4m_buf[Y4M_BUFFER_SIZE] = { 0 }; |
Dmitry Kovalev | 5260b39 | 2014-01-28 11:12:58 -0800 | [diff] [blame] | 898 | size_t len = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 899 | if (img->fmt == AOM_IMG_FMT_I440 || img->fmt == AOM_IMG_FMT_I44016) { |
Deb Mukherjee | a30774c | 2014-10-01 12:17:37 -0700 | [diff] [blame] | 900 | fprintf(stderr, "Cannot produce y4m output for 440 sampling.\n"); |
| 901 | goto fail; |
| 902 | } |
Dmitry Kovalev | 5260b39 | 2014-01-28 11:12:58 -0800 | [diff] [blame] | 903 | if (frame_out == 1) { |
| 904 | // Y4M file header |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 905 | len = y4m_write_file_header( |
Urvang Joshi | 4145bf0 | 2016-10-17 14:53:33 -0700 | [diff] [blame] | 906 | y4m_buf, sizeof(y4m_buf), aom_input_ctx.width, |
| 907 | aom_input_ctx.height, &aom_input_ctx.framerate, img->fmt, |
| 908 | img->bit_depth); |
Dmitry Kovalev | 5260b39 | 2014-01-28 11:12:58 -0800 | [diff] [blame] | 909 | if (do_md5) { |
Urvang Joshi | 4145bf0 | 2016-10-17 14:53:33 -0700 | [diff] [blame] | 910 | MD5Update(&md5_ctx, (md5byte *)y4m_buf, (unsigned int)len); |
Dmitry Kovalev | 5260b39 | 2014-01-28 11:12:58 -0800 | [diff] [blame] | 911 | } else { |
Urvang Joshi | 4145bf0 | 2016-10-17 14:53:33 -0700 | [diff] [blame] | 912 | fputs(y4m_buf, outfile); |
Dmitry Kovalev | 5260b39 | 2014-01-28 11:12:58 -0800 | [diff] [blame] | 913 | } |
| 914 | } |
| 915 | |
| 916 | // Y4M frame header |
Urvang Joshi | 4145bf0 | 2016-10-17 14:53:33 -0700 | [diff] [blame] | 917 | len = y4m_write_frame_header(y4m_buf, sizeof(y4m_buf)); |
Dmitry Kovalev | 5260b39 | 2014-01-28 11:12:58 -0800 | [diff] [blame] | 918 | if (do_md5) { |
Urvang Joshi | 4145bf0 | 2016-10-17 14:53:33 -0700 | [diff] [blame] | 919 | MD5Update(&md5_ctx, (md5byte *)y4m_buf, (unsigned int)len); |
Dmitry Kovalev | 5260b39 | 2014-01-28 11:12:58 -0800 | [diff] [blame] | 920 | } else { |
Urvang Joshi | 4145bf0 | 2016-10-17 14:53:33 -0700 | [diff] [blame] | 921 | fputs(y4m_buf, outfile); |
Dmitry Kovalev | 5260b39 | 2014-01-28 11:12:58 -0800 | [diff] [blame] | 922 | } |
Deb Mukherjee | 090f4d4 | 2014-07-16 09:37:13 -0700 | [diff] [blame] | 923 | } else { |
| 924 | if (frame_out == 1) { |
| 925 | // Check if --yv12 or --i420 options are consistent with the |
| 926 | // bit-stream decoded |
| 927 | if (opt_i420) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 928 | if (img->fmt != AOM_IMG_FMT_I420 && |
| 929 | img->fmt != AOM_IMG_FMT_I42016) { |
Deb Mukherjee | 090f4d4 | 2014-07-16 09:37:13 -0700 | [diff] [blame] | 930 | fprintf(stderr, "Cannot produce i420 output for bit-stream.\n"); |
| 931 | goto fail; |
| 932 | } |
| 933 | } |
| 934 | if (opt_yv12) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 935 | if ((img->fmt != AOM_IMG_FMT_I420 && |
| 936 | img->fmt != AOM_IMG_FMT_YV12) || |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 937 | img->bit_depth != 8) { |
Deb Mukherjee | 090f4d4 | 2014-07-16 09:37:13 -0700 | [diff] [blame] | 938 | fprintf(stderr, "Cannot produce yv12 output for bit-stream.\n"); |
| 939 | goto fail; |
| 940 | } |
| 941 | } |
| 942 | } |
Dmitry Kovalev | 5260b39 | 2014-01-28 11:12:58 -0800 | [diff] [blame] | 943 | } |
| 944 | |
Dmitry Kovalev | f2acb45 | 2014-01-23 17:20:34 -0800 | [diff] [blame] | 945 | if (do_md5) { |
| 946 | update_image_md5(img, planes, &md5_ctx); |
Dmitry Kovalev | cf46bc7 | 2014-01-17 10:57:55 -0800 | [diff] [blame] | 947 | } else { |
Dmitry Kovalev | f2acb45 | 2014-01-23 17:20:34 -0800 | [diff] [blame] | 948 | write_image_file(img, planes, outfile); |
| 949 | } |
| 950 | } else { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 951 | generate_filename(outfile_pattern, outfile_name, PATH_MAX, img->d_w, |
| 952 | img->d_h, frame_in); |
Dmitry Kovalev | f2acb45 | 2014-01-23 17:20:34 -0800 | [diff] [blame] | 953 | if (do_md5) { |
| 954 | MD5Init(&md5_ctx); |
| 955 | update_image_md5(img, planes, &md5_ctx); |
| 956 | MD5Final(md5_digest, &md5_ctx); |
| 957 | print_md5(md5_digest, outfile_name); |
| 958 | } else { |
| 959 | outfile = open_outfile(outfile_name); |
| 960 | write_image_file(img, planes, outfile); |
| 961 | fclose(outfile); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 962 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 963 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 964 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | if (summary || progress) { |
| 968 | show_progress(frame_in, frame_out, dx_time); |
| 969 | fprintf(stderr, "\n"); |
| 970 | } |
| 971 | |
James Zern | 360e444 | 2016-11-16 21:53:55 -0800 | [diff] [blame] | 972 | if (frames_corrupted) { |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 973 | fprintf(stderr, "WARNING: %d frames corrupted.\n", frames_corrupted); |
James Zern | 360e444 | 2016-11-16 21:53:55 -0800 | [diff] [blame] | 974 | } else { |
| 975 | ret = EXIT_SUCCESS; |
| 976 | } |
John Koleszar | 4226f0c | 2011-04-27 12:04:48 -0400 | [diff] [blame] | 977 | |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 978 | fail: |
| 979 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 980 | if (aom_codec_destroy(&decoder)) { |
Adrian Grange | d427fab | 2013-11-21 17:19:04 -0800 | [diff] [blame] | 981 | fprintf(stderr, "Failed to destroy decoder: %s\n", |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 982 | aom_codec_error(&decoder)); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 983 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 984 | |
James Zern | 360e444 | 2016-11-16 21:53:55 -0800 | [diff] [blame] | 985 | fail2: |
| 986 | |
Dmitry Kovalev | 347b306 | 2014-01-22 09:04:07 -0800 | [diff] [blame] | 987 | if (!noblit && single_file) { |
| 988 | if (do_md5) { |
| 989 | MD5Final(md5_digest, &md5_ctx); |
| 990 | print_md5(md5_digest, outfile_name); |
| 991 | } else { |
| 992 | fclose(outfile); |
| 993 | } |
| 994 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 995 | |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 996 | #if CONFIG_WEBM_IO |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 997 | if (input.aom_input_ctx->file_type == FILE_TYPE_WEBM) |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 998 | webm_free(input.webm_ctx); |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 999 | #endif |
| 1000 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1001 | if (input.aom_input_ctx->file_type != FILE_TYPE_WEBM) free(buf); |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 1002 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1003 | if (scaled_img) aom_img_free(scaled_img); |
| 1004 | #if CONFIG_AOM_HIGHBITDEPTH |
| 1005 | if (img_shifted) aom_img_free(img_shifted); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1006 | #endif |
Adrian Grange | d427fab | 2013-11-21 17:19:04 -0800 | [diff] [blame] | 1007 | |
Frank Galligan | a4f30a5 | 2014-02-06 17:13:08 -0800 | [diff] [blame] | 1008 | for (i = 0; i < ext_fb_list.num_external_frame_buffers; ++i) { |
| 1009 | free(ext_fb_list.ext_fb[i].data); |
| 1010 | } |
| 1011 | free(ext_fb_list.ext_fb); |
| 1012 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 1013 | fclose(infile); |
| 1014 | free(argv); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1015 | |
James Zern | 360e444 | 2016-11-16 21:53:55 -0800 | [diff] [blame] | 1016 | return ret; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1017 | } |
John Koleszar | 9596a4c | 2013-06-12 16:08:35 -0700 | [diff] [blame] | 1018 | |
| 1019 | int main(int argc, const char **argv_) { |
| 1020 | unsigned int loops = 1, i; |
| 1021 | char **argv, **argi, **argj; |
| 1022 | struct arg arg; |
| 1023 | int error = 0; |
| 1024 | |
| 1025 | argv = argv_dup(argc - 1, argv_ + 1); |
| 1026 | for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) { |
| 1027 | memset(&arg, 0, sizeof(arg)); |
| 1028 | arg.argv_step = 1; |
| 1029 | |
| 1030 | if (arg_match(&arg, &looparg, argi)) { |
| 1031 | loops = arg_parse_uint(&arg); |
| 1032 | break; |
| 1033 | } |
| 1034 | } |
| 1035 | free(argv); |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1036 | for (i = 0; !error && i < loops; i++) error = main_loop(argc, argv_); |
John Koleszar | 9596a4c | 2013-06-12 16:08:35 -0700 | [diff] [blame] | 1037 | return error; |
| 1038 | } |