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