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