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 // Inspect Decoder
13*77c1e3ccSAndroid Build Coastguard Worker // ================
14*77c1e3ccSAndroid Build Coastguard Worker //
15*77c1e3ccSAndroid Build Coastguard Worker // This is a simple decoder loop that writes JSON stats to stdout. This tool
16*77c1e3ccSAndroid Build Coastguard Worker // can also be compiled with Emscripten and used as a library.
17*77c1e3ccSAndroid Build Coastguard Worker
18*77c1e3ccSAndroid Build Coastguard Worker #include <stdio.h>
19*77c1e3ccSAndroid Build Coastguard Worker #include <stdlib.h>
20*77c1e3ccSAndroid Build Coastguard Worker #include <string.h>
21*77c1e3ccSAndroid Build Coastguard Worker
22*77c1e3ccSAndroid Build Coastguard Worker #ifdef __EMSCRIPTEN__
23*77c1e3ccSAndroid Build Coastguard Worker #include <emscripten.h>
24*77c1e3ccSAndroid Build Coastguard Worker #else
25*77c1e3ccSAndroid Build Coastguard Worker #define EMSCRIPTEN_KEEPALIVE
26*77c1e3ccSAndroid Build Coastguard Worker #endif
27*77c1e3ccSAndroid Build Coastguard Worker
28*77c1e3ccSAndroid Build Coastguard Worker #include "config/aom_config.h"
29*77c1e3ccSAndroid Build Coastguard Worker
30*77c1e3ccSAndroid Build Coastguard Worker #include "aom/aom_decoder.h"
31*77c1e3ccSAndroid Build Coastguard Worker #include "aom/aomdx.h"
32*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/av1_common_int.h"
33*77c1e3ccSAndroid Build Coastguard Worker
34*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_ACCOUNTING
35*77c1e3ccSAndroid Build Coastguard Worker #include "av1/decoder/accounting.h"
36*77c1e3ccSAndroid Build Coastguard Worker #endif
37*77c1e3ccSAndroid Build Coastguard Worker
38*77c1e3ccSAndroid Build Coastguard Worker #include "av1/decoder/inspection.h"
39*77c1e3ccSAndroid Build Coastguard Worker #include "common/args.h"
40*77c1e3ccSAndroid Build Coastguard Worker #include "common/tools_common.h"
41*77c1e3ccSAndroid Build Coastguard Worker #include "common/video_common.h"
42*77c1e3ccSAndroid Build Coastguard Worker #include "common/video_reader.h"
43*77c1e3ccSAndroid Build Coastguard Worker
44*77c1e3ccSAndroid Build Coastguard Worker // Max JSON buffer size.
45*77c1e3ccSAndroid Build Coastguard Worker const int MAX_BUFFER = 1024 * 1024 * 256;
46*77c1e3ccSAndroid Build Coastguard Worker
47*77c1e3ccSAndroid Build Coastguard Worker typedef enum {
48*77c1e3ccSAndroid Build Coastguard Worker ACCOUNTING_LAYER = 1,
49*77c1e3ccSAndroid Build Coastguard Worker BLOCK_SIZE_LAYER = 1 << 1,
50*77c1e3ccSAndroid Build Coastguard Worker TRANSFORM_SIZE_LAYER = 1 << 2,
51*77c1e3ccSAndroid Build Coastguard Worker TRANSFORM_TYPE_LAYER = 1 << 3,
52*77c1e3ccSAndroid Build Coastguard Worker MODE_LAYER = 1 << 4,
53*77c1e3ccSAndroid Build Coastguard Worker SKIP_LAYER = 1 << 5,
54*77c1e3ccSAndroid Build Coastguard Worker FILTER_LAYER = 1 << 6,
55*77c1e3ccSAndroid Build Coastguard Worker CDEF_LAYER = 1 << 7,
56*77c1e3ccSAndroid Build Coastguard Worker REFERENCE_FRAME_LAYER = 1 << 8,
57*77c1e3ccSAndroid Build Coastguard Worker MOTION_VECTORS_LAYER = 1 << 9,
58*77c1e3ccSAndroid Build Coastguard Worker UV_MODE_LAYER = 1 << 10,
59*77c1e3ccSAndroid Build Coastguard Worker CFL_LAYER = 1 << 11,
60*77c1e3ccSAndroid Build Coastguard Worker DUAL_FILTER_LAYER = 1 << 12,
61*77c1e3ccSAndroid Build Coastguard Worker Q_INDEX_LAYER = 1 << 13,
62*77c1e3ccSAndroid Build Coastguard Worker SEGMENT_ID_LAYER = 1 << 14,
63*77c1e3ccSAndroid Build Coastguard Worker MOTION_MODE_LAYER = 1 << 15,
64*77c1e3ccSAndroid Build Coastguard Worker COMPOUND_TYPE_LAYER = 1 << 16,
65*77c1e3ccSAndroid Build Coastguard Worker INTRABC_LAYER = 1 << 17,
66*77c1e3ccSAndroid Build Coastguard Worker PALETTE_LAYER = 1 << 18,
67*77c1e3ccSAndroid Build Coastguard Worker UV_PALETTE_LAYER = 1 << 19,
68*77c1e3ccSAndroid Build Coastguard Worker ALL_LAYERS = (1 << 20) - 1
69*77c1e3ccSAndroid Build Coastguard Worker } LayerType;
70*77c1e3ccSAndroid Build Coastguard Worker
71*77c1e3ccSAndroid Build Coastguard Worker static LayerType layers = 0;
72*77c1e3ccSAndroid Build Coastguard Worker
73*77c1e3ccSAndroid Build Coastguard Worker static int stop_after = 0;
74*77c1e3ccSAndroid Build Coastguard Worker static int compress = 0;
75*77c1e3ccSAndroid Build Coastguard Worker
76*77c1e3ccSAndroid Build Coastguard Worker static const arg_def_t limit_arg =
77*77c1e3ccSAndroid Build Coastguard Worker ARG_DEF(NULL, "limit", 1, "Stop decoding after n frames");
78*77c1e3ccSAndroid Build Coastguard Worker static const arg_def_t dump_all_arg = ARG_DEF("A", "all", 0, "Dump All");
79*77c1e3ccSAndroid Build Coastguard Worker static const arg_def_t compress_arg =
80*77c1e3ccSAndroid Build Coastguard Worker ARG_DEF("x", "compress", 0, "Compress JSON using RLE");
81*77c1e3ccSAndroid Build Coastguard Worker static const arg_def_t dump_accounting_arg =
82*77c1e3ccSAndroid Build Coastguard Worker ARG_DEF("a", "accounting", 0, "Dump Accounting");
83*77c1e3ccSAndroid Build Coastguard Worker static const arg_def_t dump_block_size_arg =
84*77c1e3ccSAndroid Build Coastguard Worker ARG_DEF("bs", "blockSize", 0, "Dump Block Size");
85*77c1e3ccSAndroid Build Coastguard Worker static const arg_def_t dump_motion_vectors_arg =
86*77c1e3ccSAndroid Build Coastguard Worker ARG_DEF("mv", "motionVectors", 0, "Dump Motion Vectors");
87*77c1e3ccSAndroid Build Coastguard Worker static const arg_def_t dump_transform_size_arg =
88*77c1e3ccSAndroid Build Coastguard Worker ARG_DEF("ts", "transformSize", 0, "Dump Transform Size");
89*77c1e3ccSAndroid Build Coastguard Worker static const arg_def_t dump_transform_type_arg =
90*77c1e3ccSAndroid Build Coastguard Worker ARG_DEF("tt", "transformType", 0, "Dump Transform Type");
91*77c1e3ccSAndroid Build Coastguard Worker static const arg_def_t dump_mode_arg = ARG_DEF("m", "mode", 0, "Dump Mode");
92*77c1e3ccSAndroid Build Coastguard Worker static const arg_def_t dump_motion_mode_arg =
93*77c1e3ccSAndroid Build Coastguard Worker ARG_DEF("mm", "motion_mode", 0, "Dump Motion Modes");
94*77c1e3ccSAndroid Build Coastguard Worker static const arg_def_t dump_compound_type_arg =
95*77c1e3ccSAndroid Build Coastguard Worker ARG_DEF("ct", "compound_type", 0, "Dump Compound Types");
96*77c1e3ccSAndroid Build Coastguard Worker static const arg_def_t dump_uv_mode_arg =
97*77c1e3ccSAndroid Build Coastguard Worker ARG_DEF("uvm", "uv_mode", 0, "Dump UV Intra Prediction Modes");
98*77c1e3ccSAndroid Build Coastguard Worker static const arg_def_t dump_skip_arg = ARG_DEF("s", "skip", 0, "Dump Skip");
99*77c1e3ccSAndroid Build Coastguard Worker static const arg_def_t dump_filter_arg =
100*77c1e3ccSAndroid Build Coastguard Worker ARG_DEF("f", "filter", 0, "Dump Filter");
101*77c1e3ccSAndroid Build Coastguard Worker static const arg_def_t dump_cdef_arg = ARG_DEF("c", "cdef", 0, "Dump CDEF");
102*77c1e3ccSAndroid Build Coastguard Worker static const arg_def_t dump_cfl_arg =
103*77c1e3ccSAndroid Build Coastguard Worker ARG_DEF("cfl", "chroma_from_luma", 0, "Dump Chroma from Luma Alphas");
104*77c1e3ccSAndroid Build Coastguard Worker static const arg_def_t dump_dual_filter_type_arg =
105*77c1e3ccSAndroid Build Coastguard Worker ARG_DEF("df", "dualFilterType", 0, "Dump Dual Filter Type");
106*77c1e3ccSAndroid Build Coastguard Worker static const arg_def_t dump_reference_frame_arg =
107*77c1e3ccSAndroid Build Coastguard Worker ARG_DEF("r", "referenceFrame", 0, "Dump Reference Frame");
108*77c1e3ccSAndroid Build Coastguard Worker static const arg_def_t dump_delta_q_arg =
109*77c1e3ccSAndroid Build Coastguard Worker ARG_DEF("dq", "delta_q", 0, "Dump QIndex");
110*77c1e3ccSAndroid Build Coastguard Worker static const arg_def_t dump_seg_id_arg =
111*77c1e3ccSAndroid Build Coastguard Worker ARG_DEF("si", "seg_id", 0, "Dump Segment ID");
112*77c1e3ccSAndroid Build Coastguard Worker static const arg_def_t dump_intrabc_arg =
113*77c1e3ccSAndroid Build Coastguard Worker ARG_DEF("ibc", "intrabc", 0, "Dump If IntraBC Is Used");
114*77c1e3ccSAndroid Build Coastguard Worker static const arg_def_t dump_palette_arg =
115*77c1e3ccSAndroid Build Coastguard Worker ARG_DEF("plt", "palette", 0, "Dump Palette Size");
116*77c1e3ccSAndroid Build Coastguard Worker static const arg_def_t dump_uv_palette_arg =
117*77c1e3ccSAndroid Build Coastguard Worker ARG_DEF("uvp", "uv_palette", 0, "Dump UV Palette Size");
118*77c1e3ccSAndroid Build Coastguard Worker static const arg_def_t usage_arg = ARG_DEF("h", "help", 0, "Help");
119*77c1e3ccSAndroid Build Coastguard Worker static const arg_def_t skip_non_transform_arg = ARG_DEF(
120*77c1e3ccSAndroid Build Coastguard Worker "snt", "skip_non_transform", 1, "Skip is counted as a non transform.");
121*77c1e3ccSAndroid Build Coastguard Worker static const arg_def_t combined_arg =
122*77c1e3ccSAndroid Build Coastguard Worker ARG_DEF("comb", "combined", 1, "combinining parameters into one output.");
123*77c1e3ccSAndroid Build Coastguard Worker
124*77c1e3ccSAndroid Build Coastguard Worker int combined_parm_list[15];
125*77c1e3ccSAndroid Build Coastguard Worker int combined_parm_count = 0;
126*77c1e3ccSAndroid Build Coastguard Worker
127*77c1e3ccSAndroid Build Coastguard Worker static const arg_def_t *main_args[] = { &limit_arg,
128*77c1e3ccSAndroid Build Coastguard Worker &dump_all_arg,
129*77c1e3ccSAndroid Build Coastguard Worker &compress_arg,
130*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_ACCOUNTING
131*77c1e3ccSAndroid Build Coastguard Worker &dump_accounting_arg,
132*77c1e3ccSAndroid Build Coastguard Worker #endif
133*77c1e3ccSAndroid Build Coastguard Worker &dump_block_size_arg,
134*77c1e3ccSAndroid Build Coastguard Worker &dump_transform_size_arg,
135*77c1e3ccSAndroid Build Coastguard Worker &dump_transform_type_arg,
136*77c1e3ccSAndroid Build Coastguard Worker &dump_mode_arg,
137*77c1e3ccSAndroid Build Coastguard Worker &dump_uv_mode_arg,
138*77c1e3ccSAndroid Build Coastguard Worker &dump_motion_mode_arg,
139*77c1e3ccSAndroid Build Coastguard Worker &dump_compound_type_arg,
140*77c1e3ccSAndroid Build Coastguard Worker &dump_skip_arg,
141*77c1e3ccSAndroid Build Coastguard Worker &dump_filter_arg,
142*77c1e3ccSAndroid Build Coastguard Worker &dump_cdef_arg,
143*77c1e3ccSAndroid Build Coastguard Worker &dump_dual_filter_type_arg,
144*77c1e3ccSAndroid Build Coastguard Worker &dump_cfl_arg,
145*77c1e3ccSAndroid Build Coastguard Worker &dump_reference_frame_arg,
146*77c1e3ccSAndroid Build Coastguard Worker &dump_motion_vectors_arg,
147*77c1e3ccSAndroid Build Coastguard Worker &dump_delta_q_arg,
148*77c1e3ccSAndroid Build Coastguard Worker &dump_seg_id_arg,
149*77c1e3ccSAndroid Build Coastguard Worker &dump_intrabc_arg,
150*77c1e3ccSAndroid Build Coastguard Worker &dump_palette_arg,
151*77c1e3ccSAndroid Build Coastguard Worker &dump_uv_palette_arg,
152*77c1e3ccSAndroid Build Coastguard Worker &usage_arg,
153*77c1e3ccSAndroid Build Coastguard Worker &skip_non_transform_arg,
154*77c1e3ccSAndroid Build Coastguard Worker &combined_arg,
155*77c1e3ccSAndroid Build Coastguard Worker NULL };
156*77c1e3ccSAndroid Build Coastguard Worker #define ENUM(name) \
157*77c1e3ccSAndroid Build Coastguard Worker { #name, name }
158*77c1e3ccSAndroid Build Coastguard Worker #define LAST_ENUM \
159*77c1e3ccSAndroid Build Coastguard Worker { NULL, 0 }
160*77c1e3ccSAndroid Build Coastguard Worker typedef struct map_entry {
161*77c1e3ccSAndroid Build Coastguard Worker const char *name;
162*77c1e3ccSAndroid Build Coastguard Worker int value;
163*77c1e3ccSAndroid Build Coastguard Worker } map_entry;
164*77c1e3ccSAndroid Build Coastguard Worker
165*77c1e3ccSAndroid Build Coastguard Worker const map_entry refs_map[] = {
166*77c1e3ccSAndroid Build Coastguard Worker ENUM(INTRA_FRAME), ENUM(LAST_FRAME), ENUM(LAST2_FRAME),
167*77c1e3ccSAndroid Build Coastguard Worker ENUM(LAST3_FRAME), ENUM(GOLDEN_FRAME), ENUM(BWDREF_FRAME),
168*77c1e3ccSAndroid Build Coastguard Worker ENUM(ALTREF2_FRAME), ENUM(ALTREF_FRAME), LAST_ENUM
169*77c1e3ccSAndroid Build Coastguard Worker };
170*77c1e3ccSAndroid Build Coastguard Worker
171*77c1e3ccSAndroid Build Coastguard Worker const map_entry block_size_map[] = {
172*77c1e3ccSAndroid Build Coastguard Worker ENUM(BLOCK_4X4), ENUM(BLOCK_4X8), ENUM(BLOCK_8X4),
173*77c1e3ccSAndroid Build Coastguard Worker ENUM(BLOCK_8X8), ENUM(BLOCK_8X16), ENUM(BLOCK_16X8),
174*77c1e3ccSAndroid Build Coastguard Worker ENUM(BLOCK_16X16), ENUM(BLOCK_16X32), ENUM(BLOCK_32X16),
175*77c1e3ccSAndroid Build Coastguard Worker ENUM(BLOCK_32X32), ENUM(BLOCK_32X64), ENUM(BLOCK_64X32),
176*77c1e3ccSAndroid Build Coastguard Worker ENUM(BLOCK_64X64), ENUM(BLOCK_64X128), ENUM(BLOCK_128X64),
177*77c1e3ccSAndroid Build Coastguard Worker ENUM(BLOCK_128X128), ENUM(BLOCK_4X16), ENUM(BLOCK_16X4),
178*77c1e3ccSAndroid Build Coastguard Worker ENUM(BLOCK_8X32), ENUM(BLOCK_32X8), ENUM(BLOCK_16X64),
179*77c1e3ccSAndroid Build Coastguard Worker ENUM(BLOCK_64X16), LAST_ENUM
180*77c1e3ccSAndroid Build Coastguard Worker };
181*77c1e3ccSAndroid Build Coastguard Worker
182*77c1e3ccSAndroid Build Coastguard Worker #define TX_SKIP -1
183*77c1e3ccSAndroid Build Coastguard Worker
184*77c1e3ccSAndroid Build Coastguard Worker const map_entry tx_size_map[] = {
185*77c1e3ccSAndroid Build Coastguard Worker ENUM(TX_4X4), ENUM(TX_8X8), ENUM(TX_16X16), ENUM(TX_32X32),
186*77c1e3ccSAndroid Build Coastguard Worker ENUM(TX_64X64), ENUM(TX_4X8), ENUM(TX_8X4), ENUM(TX_8X16),
187*77c1e3ccSAndroid Build Coastguard Worker ENUM(TX_16X8), ENUM(TX_16X32), ENUM(TX_32X16), ENUM(TX_32X64),
188*77c1e3ccSAndroid Build Coastguard Worker ENUM(TX_64X32), ENUM(TX_4X16), ENUM(TX_16X4), ENUM(TX_8X32),
189*77c1e3ccSAndroid Build Coastguard Worker ENUM(TX_32X8), ENUM(TX_16X64), ENUM(TX_64X16), LAST_ENUM
190*77c1e3ccSAndroid Build Coastguard Worker };
191*77c1e3ccSAndroid Build Coastguard Worker
192*77c1e3ccSAndroid Build Coastguard Worker const map_entry tx_type_map[] = { ENUM(DCT_DCT),
193*77c1e3ccSAndroid Build Coastguard Worker ENUM(ADST_DCT),
194*77c1e3ccSAndroid Build Coastguard Worker ENUM(DCT_ADST),
195*77c1e3ccSAndroid Build Coastguard Worker ENUM(ADST_ADST),
196*77c1e3ccSAndroid Build Coastguard Worker ENUM(FLIPADST_DCT),
197*77c1e3ccSAndroid Build Coastguard Worker ENUM(DCT_FLIPADST),
198*77c1e3ccSAndroid Build Coastguard Worker ENUM(FLIPADST_FLIPADST),
199*77c1e3ccSAndroid Build Coastguard Worker ENUM(ADST_FLIPADST),
200*77c1e3ccSAndroid Build Coastguard Worker ENUM(FLIPADST_ADST),
201*77c1e3ccSAndroid Build Coastguard Worker ENUM(IDTX),
202*77c1e3ccSAndroid Build Coastguard Worker ENUM(V_DCT),
203*77c1e3ccSAndroid Build Coastguard Worker ENUM(H_DCT),
204*77c1e3ccSAndroid Build Coastguard Worker ENUM(V_ADST),
205*77c1e3ccSAndroid Build Coastguard Worker ENUM(H_ADST),
206*77c1e3ccSAndroid Build Coastguard Worker ENUM(V_FLIPADST),
207*77c1e3ccSAndroid Build Coastguard Worker ENUM(H_FLIPADST),
208*77c1e3ccSAndroid Build Coastguard Worker LAST_ENUM };
209*77c1e3ccSAndroid Build Coastguard Worker const map_entry dual_filter_map[] = { ENUM(REG_REG), ENUM(REG_SMOOTH),
210*77c1e3ccSAndroid Build Coastguard Worker ENUM(REG_SHARP), ENUM(SMOOTH_REG),
211*77c1e3ccSAndroid Build Coastguard Worker ENUM(SMOOTH_SMOOTH), ENUM(SMOOTH_SHARP),
212*77c1e3ccSAndroid Build Coastguard Worker ENUM(SHARP_REG), ENUM(SHARP_SMOOTH),
213*77c1e3ccSAndroid Build Coastguard Worker ENUM(SHARP_SHARP), LAST_ENUM };
214*77c1e3ccSAndroid Build Coastguard Worker
215*77c1e3ccSAndroid Build Coastguard Worker const map_entry prediction_mode_map[] = {
216*77c1e3ccSAndroid Build Coastguard Worker ENUM(DC_PRED), ENUM(V_PRED), ENUM(H_PRED),
217*77c1e3ccSAndroid Build Coastguard Worker ENUM(D45_PRED), ENUM(D135_PRED), ENUM(D113_PRED),
218*77c1e3ccSAndroid Build Coastguard Worker ENUM(D157_PRED), ENUM(D203_PRED), ENUM(D67_PRED),
219*77c1e3ccSAndroid Build Coastguard Worker ENUM(SMOOTH_PRED), ENUM(SMOOTH_V_PRED), ENUM(SMOOTH_H_PRED),
220*77c1e3ccSAndroid Build Coastguard Worker ENUM(PAETH_PRED), ENUM(NEARESTMV), ENUM(NEARMV),
221*77c1e3ccSAndroid Build Coastguard Worker ENUM(GLOBALMV), ENUM(NEWMV), ENUM(NEAREST_NEARESTMV),
222*77c1e3ccSAndroid Build Coastguard Worker ENUM(NEAR_NEARMV), ENUM(NEAREST_NEWMV), ENUM(NEW_NEARESTMV),
223*77c1e3ccSAndroid Build Coastguard Worker ENUM(NEAR_NEWMV), ENUM(NEW_NEARMV), ENUM(GLOBAL_GLOBALMV),
224*77c1e3ccSAndroid Build Coastguard Worker ENUM(NEW_NEWMV), ENUM(INTRA_INVALID), LAST_ENUM
225*77c1e3ccSAndroid Build Coastguard Worker };
226*77c1e3ccSAndroid Build Coastguard Worker
227*77c1e3ccSAndroid Build Coastguard Worker const map_entry motion_mode_map[] = { ENUM(SIMPLE_TRANSLATION),
228*77c1e3ccSAndroid Build Coastguard Worker ENUM(OBMC_CAUSAL), // 2-sided OBMC
229*77c1e3ccSAndroid Build Coastguard Worker ENUM(WARPED_CAUSAL), // 2-sided WARPED
230*77c1e3ccSAndroid Build Coastguard Worker LAST_ENUM };
231*77c1e3ccSAndroid Build Coastguard Worker
232*77c1e3ccSAndroid Build Coastguard Worker const map_entry compound_type_map[] = { ENUM(COMPOUND_AVERAGE),
233*77c1e3ccSAndroid Build Coastguard Worker ENUM(COMPOUND_WEDGE),
234*77c1e3ccSAndroid Build Coastguard Worker ENUM(COMPOUND_DIFFWTD), LAST_ENUM };
235*77c1e3ccSAndroid Build Coastguard Worker
236*77c1e3ccSAndroid Build Coastguard Worker const map_entry uv_prediction_mode_map[] = {
237*77c1e3ccSAndroid Build Coastguard Worker ENUM(UV_DC_PRED), ENUM(UV_V_PRED),
238*77c1e3ccSAndroid Build Coastguard Worker ENUM(UV_H_PRED), ENUM(UV_D45_PRED),
239*77c1e3ccSAndroid Build Coastguard Worker ENUM(UV_D135_PRED), ENUM(UV_D113_PRED),
240*77c1e3ccSAndroid Build Coastguard Worker ENUM(UV_D157_PRED), ENUM(UV_D203_PRED),
241*77c1e3ccSAndroid Build Coastguard Worker ENUM(UV_D67_PRED), ENUM(UV_SMOOTH_PRED),
242*77c1e3ccSAndroid Build Coastguard Worker ENUM(UV_SMOOTH_V_PRED), ENUM(UV_SMOOTH_H_PRED),
243*77c1e3ccSAndroid Build Coastguard Worker ENUM(UV_PAETH_PRED), ENUM(UV_CFL_PRED),
244*77c1e3ccSAndroid Build Coastguard Worker ENUM(UV_MODE_INVALID), LAST_ENUM
245*77c1e3ccSAndroid Build Coastguard Worker };
246*77c1e3ccSAndroid Build Coastguard Worker #define NO_SKIP 0
247*77c1e3ccSAndroid Build Coastguard Worker #define SKIP 1
248*77c1e3ccSAndroid Build Coastguard Worker
249*77c1e3ccSAndroid Build Coastguard Worker const map_entry skip_map[] = { ENUM(SKIP), ENUM(NO_SKIP), LAST_ENUM };
250*77c1e3ccSAndroid Build Coastguard Worker
251*77c1e3ccSAndroid Build Coastguard Worker const map_entry intrabc_map[] = { { "INTRABC", 1 },
252*77c1e3ccSAndroid Build Coastguard Worker { "NO_INTRABC", 0 },
253*77c1e3ccSAndroid Build Coastguard Worker LAST_ENUM };
254*77c1e3ccSAndroid Build Coastguard Worker
255*77c1e3ccSAndroid Build Coastguard Worker const map_entry palette_map[] = {
256*77c1e3ccSAndroid Build Coastguard Worker { "ZERO_COLORS", 0 }, { "TWO_COLORS", 2 }, { "THREE_COLORS", 3 },
257*77c1e3ccSAndroid Build Coastguard Worker { "FOUR_COLORS", 4 }, { "FIVE_COLORS", 5 }, { "SIX_COLORS", 6 },
258*77c1e3ccSAndroid Build Coastguard Worker { "SEVEN_COLORS", 7 }, { "EIGHT_COLORS", 8 }, LAST_ENUM
259*77c1e3ccSAndroid Build Coastguard Worker };
260*77c1e3ccSAndroid Build Coastguard Worker
261*77c1e3ccSAndroid Build Coastguard Worker const map_entry config_map[] = { ENUM(MI_SIZE), LAST_ENUM };
262*77c1e3ccSAndroid Build Coastguard Worker
263*77c1e3ccSAndroid Build Coastguard Worker static const char *exec_name;
264*77c1e3ccSAndroid Build Coastguard Worker
265*77c1e3ccSAndroid Build Coastguard Worker struct parm_offset {
266*77c1e3ccSAndroid Build Coastguard Worker char parm[60];
267*77c1e3ccSAndroid Build Coastguard Worker char offset;
268*77c1e3ccSAndroid Build Coastguard Worker };
269*77c1e3ccSAndroid Build Coastguard Worker struct parm_offset parm_offsets[] = {
270*77c1e3ccSAndroid Build Coastguard Worker { "blockSize", offsetof(insp_mi_data, bsize) },
271*77c1e3ccSAndroid Build Coastguard Worker { "transformSize", offsetof(insp_mi_data, tx_size) },
272*77c1e3ccSAndroid Build Coastguard Worker { "transformType", offsetof(insp_mi_data, tx_type) },
273*77c1e3ccSAndroid Build Coastguard Worker { "dualFilterType", offsetof(insp_mi_data, dual_filter_type) },
274*77c1e3ccSAndroid Build Coastguard Worker { "mode", offsetof(insp_mi_data, mode) },
275*77c1e3ccSAndroid Build Coastguard Worker { "uv_mode", offsetof(insp_mi_data, uv_mode) },
276*77c1e3ccSAndroid Build Coastguard Worker { "motion_mode", offsetof(insp_mi_data, motion_mode) },
277*77c1e3ccSAndroid Build Coastguard Worker { "compound_type", offsetof(insp_mi_data, compound_type) },
278*77c1e3ccSAndroid Build Coastguard Worker { "referenceFrame", offsetof(insp_mi_data, ref_frame) },
279*77c1e3ccSAndroid Build Coastguard Worker { "skip", offsetof(insp_mi_data, skip) },
280*77c1e3ccSAndroid Build Coastguard Worker };
281*77c1e3ccSAndroid Build Coastguard Worker int parm_count = sizeof(parm_offsets) / sizeof(parm_offsets[0]);
282*77c1e3ccSAndroid Build Coastguard Worker
convert_to_indices(char * str,int * indices,int maxCount,int * count)283*77c1e3ccSAndroid Build Coastguard Worker static int convert_to_indices(char *str, int *indices, int maxCount,
284*77c1e3ccSAndroid Build Coastguard Worker int *count) {
285*77c1e3ccSAndroid Build Coastguard Worker *count = 0;
286*77c1e3ccSAndroid Build Coastguard Worker do {
287*77c1e3ccSAndroid Build Coastguard Worker char *comma = strchr(str, ',');
288*77c1e3ccSAndroid Build Coastguard Worker int length = (comma ? (int)(comma - str) : (int)strlen(str));
289*77c1e3ccSAndroid Build Coastguard Worker int i;
290*77c1e3ccSAndroid Build Coastguard Worker for (i = 0; i < parm_count; ++i) {
291*77c1e3ccSAndroid Build Coastguard Worker if (!strncmp(str, parm_offsets[i].parm, length)) {
292*77c1e3ccSAndroid Build Coastguard Worker break;
293*77c1e3ccSAndroid Build Coastguard Worker }
294*77c1e3ccSAndroid Build Coastguard Worker }
295*77c1e3ccSAndroid Build Coastguard Worker if (i == parm_count) return 0;
296*77c1e3ccSAndroid Build Coastguard Worker indices[(*count)++] = i;
297*77c1e3ccSAndroid Build Coastguard Worker if (*count > maxCount) return 0;
298*77c1e3ccSAndroid Build Coastguard Worker str += length + 1;
299*77c1e3ccSAndroid Build Coastguard Worker } while (strlen(str) > 0);
300*77c1e3ccSAndroid Build Coastguard Worker return 1;
301*77c1e3ccSAndroid Build Coastguard Worker }
302*77c1e3ccSAndroid Build Coastguard Worker
303*77c1e3ccSAndroid Build Coastguard Worker insp_frame_data frame_data;
304*77c1e3ccSAndroid Build Coastguard Worker int frame_count = 0;
305*77c1e3ccSAndroid Build Coastguard Worker int decoded_frame_count = 0;
306*77c1e3ccSAndroid Build Coastguard Worker aom_codec_ctx_t codec;
307*77c1e3ccSAndroid Build Coastguard Worker AvxVideoReader *reader = NULL;
308*77c1e3ccSAndroid Build Coastguard Worker const AvxVideoInfo *info = NULL;
309*77c1e3ccSAndroid Build Coastguard Worker aom_image_t *img = NULL;
310*77c1e3ccSAndroid Build Coastguard Worker
on_frame_decoded_dump(char * json)311*77c1e3ccSAndroid Build Coastguard Worker static void on_frame_decoded_dump(char *json) {
312*77c1e3ccSAndroid Build Coastguard Worker #ifdef __EMSCRIPTEN__
313*77c1e3ccSAndroid Build Coastguard Worker EM_ASM_({ Module.on_frame_decoded_json($0); }, json);
314*77c1e3ccSAndroid Build Coastguard Worker #else
315*77c1e3ccSAndroid Build Coastguard Worker printf("%s", json);
316*77c1e3ccSAndroid Build Coastguard Worker #endif
317*77c1e3ccSAndroid Build Coastguard Worker }
318*77c1e3ccSAndroid Build Coastguard Worker
319*77c1e3ccSAndroid Build Coastguard Worker // Writing out the JSON buffer using snprintf is very slow, especially when
320*77c1e3ccSAndroid Build Coastguard Worker // compiled with emscripten, these functions speed things up quite a bit.
put_str(char * buffer,const char * str)321*77c1e3ccSAndroid Build Coastguard Worker static int put_str(char *buffer, const char *str) {
322*77c1e3ccSAndroid Build Coastguard Worker int i;
323*77c1e3ccSAndroid Build Coastguard Worker for (i = 0; str[i] != '\0'; i++) {
324*77c1e3ccSAndroid Build Coastguard Worker buffer[i] = str[i];
325*77c1e3ccSAndroid Build Coastguard Worker }
326*77c1e3ccSAndroid Build Coastguard Worker return i;
327*77c1e3ccSAndroid Build Coastguard Worker }
328*77c1e3ccSAndroid Build Coastguard Worker
put_str_with_escape(char * buffer,const char * str)329*77c1e3ccSAndroid Build Coastguard Worker static int put_str_with_escape(char *buffer, const char *str) {
330*77c1e3ccSAndroid Build Coastguard Worker int i;
331*77c1e3ccSAndroid Build Coastguard Worker int j = 0;
332*77c1e3ccSAndroid Build Coastguard Worker for (i = 0; str[i] != '\0'; i++) {
333*77c1e3ccSAndroid Build Coastguard Worker if (str[i] < ' ') {
334*77c1e3ccSAndroid Build Coastguard Worker continue;
335*77c1e3ccSAndroid Build Coastguard Worker } else if (str[i] == '"' || str[i] == '\\') {
336*77c1e3ccSAndroid Build Coastguard Worker buffer[j++] = '\\';
337*77c1e3ccSAndroid Build Coastguard Worker }
338*77c1e3ccSAndroid Build Coastguard Worker buffer[j++] = str[i];
339*77c1e3ccSAndroid Build Coastguard Worker }
340*77c1e3ccSAndroid Build Coastguard Worker return j;
341*77c1e3ccSAndroid Build Coastguard Worker }
342*77c1e3ccSAndroid Build Coastguard Worker
put_num(char * buffer,char prefix,int num,char suffix)343*77c1e3ccSAndroid Build Coastguard Worker static int put_num(char *buffer, char prefix, int num, char suffix) {
344*77c1e3ccSAndroid Build Coastguard Worker int i = 0;
345*77c1e3ccSAndroid Build Coastguard Worker char *buf = buffer;
346*77c1e3ccSAndroid Build Coastguard Worker int is_neg = 0;
347*77c1e3ccSAndroid Build Coastguard Worker if (prefix) {
348*77c1e3ccSAndroid Build Coastguard Worker buf[i++] = prefix;
349*77c1e3ccSAndroid Build Coastguard Worker }
350*77c1e3ccSAndroid Build Coastguard Worker if (num == 0) {
351*77c1e3ccSAndroid Build Coastguard Worker buf[i++] = '0';
352*77c1e3ccSAndroid Build Coastguard Worker } else {
353*77c1e3ccSAndroid Build Coastguard Worker if (num < 0) {
354*77c1e3ccSAndroid Build Coastguard Worker num = -num;
355*77c1e3ccSAndroid Build Coastguard Worker is_neg = 1;
356*77c1e3ccSAndroid Build Coastguard Worker }
357*77c1e3ccSAndroid Build Coastguard Worker int s = i;
358*77c1e3ccSAndroid Build Coastguard Worker while (num != 0) {
359*77c1e3ccSAndroid Build Coastguard Worker buf[i++] = '0' + (num % 10);
360*77c1e3ccSAndroid Build Coastguard Worker num = num / 10;
361*77c1e3ccSAndroid Build Coastguard Worker }
362*77c1e3ccSAndroid Build Coastguard Worker if (is_neg) {
363*77c1e3ccSAndroid Build Coastguard Worker buf[i++] = '-';
364*77c1e3ccSAndroid Build Coastguard Worker }
365*77c1e3ccSAndroid Build Coastguard Worker int e = i - 1;
366*77c1e3ccSAndroid Build Coastguard Worker while (s < e) {
367*77c1e3ccSAndroid Build Coastguard Worker int t = buf[s];
368*77c1e3ccSAndroid Build Coastguard Worker buf[s] = buf[e];
369*77c1e3ccSAndroid Build Coastguard Worker buf[e] = t;
370*77c1e3ccSAndroid Build Coastguard Worker s++;
371*77c1e3ccSAndroid Build Coastguard Worker e--;
372*77c1e3ccSAndroid Build Coastguard Worker }
373*77c1e3ccSAndroid Build Coastguard Worker }
374*77c1e3ccSAndroid Build Coastguard Worker if (suffix) {
375*77c1e3ccSAndroid Build Coastguard Worker buf[i++] = suffix;
376*77c1e3ccSAndroid Build Coastguard Worker }
377*77c1e3ccSAndroid Build Coastguard Worker return i;
378*77c1e3ccSAndroid Build Coastguard Worker }
379*77c1e3ccSAndroid Build Coastguard Worker
put_map(char * buffer,const map_entry * map)380*77c1e3ccSAndroid Build Coastguard Worker static int put_map(char *buffer, const map_entry *map) {
381*77c1e3ccSAndroid Build Coastguard Worker char *buf = buffer;
382*77c1e3ccSAndroid Build Coastguard Worker const map_entry *entry = map;
383*77c1e3ccSAndroid Build Coastguard Worker while (entry->name != NULL) {
384*77c1e3ccSAndroid Build Coastguard Worker *(buf++) = '"';
385*77c1e3ccSAndroid Build Coastguard Worker buf += put_str(buf, entry->name);
386*77c1e3ccSAndroid Build Coastguard Worker *(buf++) = '"';
387*77c1e3ccSAndroid Build Coastguard Worker buf += put_num(buf, ':', entry->value, 0);
388*77c1e3ccSAndroid Build Coastguard Worker entry++;
389*77c1e3ccSAndroid Build Coastguard Worker if (entry->name != NULL) {
390*77c1e3ccSAndroid Build Coastguard Worker *(buf++) = ',';
391*77c1e3ccSAndroid Build Coastguard Worker }
392*77c1e3ccSAndroid Build Coastguard Worker }
393*77c1e3ccSAndroid Build Coastguard Worker return (int)(buf - buffer);
394*77c1e3ccSAndroid Build Coastguard Worker }
395*77c1e3ccSAndroid Build Coastguard Worker
396*77c1e3ccSAndroid Build Coastguard Worker #if 0
397*77c1e3ccSAndroid Build Coastguard Worker static int put_reference_frame(char *buffer) {
398*77c1e3ccSAndroid Build Coastguard Worker const int mi_rows = frame_data.mi_rows;
399*77c1e3ccSAndroid Build Coastguard Worker const int mi_cols = frame_data.mi_cols;
400*77c1e3ccSAndroid Build Coastguard Worker char *buf = buffer;
401*77c1e3ccSAndroid Build Coastguard Worker int r, c, t;
402*77c1e3ccSAndroid Build Coastguard Worker buf += put_str(buf, " \"referenceFrameMap\": {");
403*77c1e3ccSAndroid Build Coastguard Worker buf += put_map(buf, refs_map);
404*77c1e3ccSAndroid Build Coastguard Worker buf += put_str(buf, "},\n");
405*77c1e3ccSAndroid Build Coastguard Worker buf += put_str(buf, " \"referenceFrame\": [");
406*77c1e3ccSAndroid Build Coastguard Worker for (r = 0; r < mi_rows; ++r) {
407*77c1e3ccSAndroid Build Coastguard Worker *(buf++) = '[';
408*77c1e3ccSAndroid Build Coastguard Worker for (c = 0; c < mi_cols; ++c) {
409*77c1e3ccSAndroid Build Coastguard Worker insp_mi_data *mi = &frame_data.mi_grid[r * mi_cols + c];
410*77c1e3ccSAndroid Build Coastguard Worker buf += put_num(buf, '[', mi->ref_frame[0], 0);
411*77c1e3ccSAndroid Build Coastguard Worker buf += put_num(buf, ',', mi->ref_frame[1], ']');
412*77c1e3ccSAndroid Build Coastguard Worker if (compress) { // RLE
413*77c1e3ccSAndroid Build Coastguard Worker for (t = c + 1; t < mi_cols; ++t) {
414*77c1e3ccSAndroid Build Coastguard Worker insp_mi_data *next_mi = &frame_data.mi_grid[r * mi_cols + t];
415*77c1e3ccSAndroid Build Coastguard Worker if (mi->ref_frame[0] != next_mi->ref_frame[0] ||
416*77c1e3ccSAndroid Build Coastguard Worker mi->ref_frame[1] != next_mi->ref_frame[1]) {
417*77c1e3ccSAndroid Build Coastguard Worker break;
418*77c1e3ccSAndroid Build Coastguard Worker }
419*77c1e3ccSAndroid Build Coastguard Worker }
420*77c1e3ccSAndroid Build Coastguard Worker if (t - c > 1) {
421*77c1e3ccSAndroid Build Coastguard Worker *(buf++) = ',';
422*77c1e3ccSAndroid Build Coastguard Worker buf += put_num(buf, '[', t - c - 1, ']');
423*77c1e3ccSAndroid Build Coastguard Worker c = t - 1;
424*77c1e3ccSAndroid Build Coastguard Worker }
425*77c1e3ccSAndroid Build Coastguard Worker }
426*77c1e3ccSAndroid Build Coastguard Worker if (c < mi_cols - 1) *(buf++) = ',';
427*77c1e3ccSAndroid Build Coastguard Worker }
428*77c1e3ccSAndroid Build Coastguard Worker *(buf++) = ']';
429*77c1e3ccSAndroid Build Coastguard Worker if (r < mi_rows - 1) *(buf++) = ',';
430*77c1e3ccSAndroid Build Coastguard Worker }
431*77c1e3ccSAndroid Build Coastguard Worker buf += put_str(buf, "],\n");
432*77c1e3ccSAndroid Build Coastguard Worker return (int)(buf - buffer);
433*77c1e3ccSAndroid Build Coastguard Worker }
434*77c1e3ccSAndroid Build Coastguard Worker #endif
435*77c1e3ccSAndroid Build Coastguard Worker
put_motion_vectors(char * buffer)436*77c1e3ccSAndroid Build Coastguard Worker static int put_motion_vectors(char *buffer) {
437*77c1e3ccSAndroid Build Coastguard Worker const int mi_rows = frame_data.mi_rows;
438*77c1e3ccSAndroid Build Coastguard Worker const int mi_cols = frame_data.mi_cols;
439*77c1e3ccSAndroid Build Coastguard Worker char *buf = buffer;
440*77c1e3ccSAndroid Build Coastguard Worker int r, c, t;
441*77c1e3ccSAndroid Build Coastguard Worker buf += put_str(buf, " \"motionVectors\": [");
442*77c1e3ccSAndroid Build Coastguard Worker for (r = 0; r < mi_rows; ++r) {
443*77c1e3ccSAndroid Build Coastguard Worker *(buf++) = '[';
444*77c1e3ccSAndroid Build Coastguard Worker for (c = 0; c < mi_cols; ++c) {
445*77c1e3ccSAndroid Build Coastguard Worker insp_mi_data *mi = &frame_data.mi_grid[r * mi_cols + c];
446*77c1e3ccSAndroid Build Coastguard Worker buf += put_num(buf, '[', mi->mv[0].col, 0);
447*77c1e3ccSAndroid Build Coastguard Worker buf += put_num(buf, ',', mi->mv[0].row, 0);
448*77c1e3ccSAndroid Build Coastguard Worker buf += put_num(buf, ',', mi->mv[1].col, 0);
449*77c1e3ccSAndroid Build Coastguard Worker buf += put_num(buf, ',', mi->mv[1].row, ']');
450*77c1e3ccSAndroid Build Coastguard Worker if (compress) { // RLE
451*77c1e3ccSAndroid Build Coastguard Worker for (t = c + 1; t < mi_cols; ++t) {
452*77c1e3ccSAndroid Build Coastguard Worker insp_mi_data *next_mi = &frame_data.mi_grid[r * mi_cols + t];
453*77c1e3ccSAndroid Build Coastguard Worker if (mi->mv[0].col != next_mi->mv[0].col ||
454*77c1e3ccSAndroid Build Coastguard Worker mi->mv[0].row != next_mi->mv[0].row ||
455*77c1e3ccSAndroid Build Coastguard Worker mi->mv[1].col != next_mi->mv[1].col ||
456*77c1e3ccSAndroid Build Coastguard Worker mi->mv[1].row != next_mi->mv[1].row) {
457*77c1e3ccSAndroid Build Coastguard Worker break;
458*77c1e3ccSAndroid Build Coastguard Worker }
459*77c1e3ccSAndroid Build Coastguard Worker }
460*77c1e3ccSAndroid Build Coastguard Worker if (t - c > 1) {
461*77c1e3ccSAndroid Build Coastguard Worker *(buf++) = ',';
462*77c1e3ccSAndroid Build Coastguard Worker buf += put_num(buf, '[', t - c - 1, ']');
463*77c1e3ccSAndroid Build Coastguard Worker c = t - 1;
464*77c1e3ccSAndroid Build Coastguard Worker }
465*77c1e3ccSAndroid Build Coastguard Worker }
466*77c1e3ccSAndroid Build Coastguard Worker if (c < mi_cols - 1) *(buf++) = ',';
467*77c1e3ccSAndroid Build Coastguard Worker }
468*77c1e3ccSAndroid Build Coastguard Worker *(buf++) = ']';
469*77c1e3ccSAndroid Build Coastguard Worker if (r < mi_rows - 1) *(buf++) = ',';
470*77c1e3ccSAndroid Build Coastguard Worker }
471*77c1e3ccSAndroid Build Coastguard Worker buf += put_str(buf, "],\n");
472*77c1e3ccSAndroid Build Coastguard Worker return (int)(buf - buffer);
473*77c1e3ccSAndroid Build Coastguard Worker }
474*77c1e3ccSAndroid Build Coastguard Worker
put_combined(char * buffer)475*77c1e3ccSAndroid Build Coastguard Worker static int put_combined(char *buffer) {
476*77c1e3ccSAndroid Build Coastguard Worker const int mi_rows = frame_data.mi_rows;
477*77c1e3ccSAndroid Build Coastguard Worker const int mi_cols = frame_data.mi_cols;
478*77c1e3ccSAndroid Build Coastguard Worker char *buf = buffer;
479*77c1e3ccSAndroid Build Coastguard Worker int r, c, p;
480*77c1e3ccSAndroid Build Coastguard Worker buf += put_str(buf, " \"");
481*77c1e3ccSAndroid Build Coastguard Worker for (p = 0; p < combined_parm_count; ++p) {
482*77c1e3ccSAndroid Build Coastguard Worker if (p) buf += put_str(buf, "&");
483*77c1e3ccSAndroid Build Coastguard Worker buf += put_str(buf, parm_offsets[combined_parm_list[p]].parm);
484*77c1e3ccSAndroid Build Coastguard Worker }
485*77c1e3ccSAndroid Build Coastguard Worker buf += put_str(buf, "\": [");
486*77c1e3ccSAndroid Build Coastguard Worker for (r = 0; r < mi_rows; ++r) {
487*77c1e3ccSAndroid Build Coastguard Worker *(buf++) = '[';
488*77c1e3ccSAndroid Build Coastguard Worker for (c = 0; c < mi_cols; ++c) {
489*77c1e3ccSAndroid Build Coastguard Worker insp_mi_data *mi = &frame_data.mi_grid[r * mi_cols + c];
490*77c1e3ccSAndroid Build Coastguard Worker *(buf++) = '[';
491*77c1e3ccSAndroid Build Coastguard Worker for (p = 0; p < combined_parm_count; ++p) {
492*77c1e3ccSAndroid Build Coastguard Worker if (p) *(buf++) = ',';
493*77c1e3ccSAndroid Build Coastguard Worker int16_t *v = (int16_t *)(((int8_t *)mi) +
494*77c1e3ccSAndroid Build Coastguard Worker parm_offsets[combined_parm_list[p]].offset);
495*77c1e3ccSAndroid Build Coastguard Worker buf += put_num(buf, 0, v[0], 0);
496*77c1e3ccSAndroid Build Coastguard Worker }
497*77c1e3ccSAndroid Build Coastguard Worker *(buf++) = ']';
498*77c1e3ccSAndroid Build Coastguard Worker if (c < mi_cols - 1) *(buf++) = ',';
499*77c1e3ccSAndroid Build Coastguard Worker }
500*77c1e3ccSAndroid Build Coastguard Worker *(buf++) = ']';
501*77c1e3ccSAndroid Build Coastguard Worker if (r < mi_rows - 1) *(buf++) = ',';
502*77c1e3ccSAndroid Build Coastguard Worker }
503*77c1e3ccSAndroid Build Coastguard Worker buf += put_str(buf, "],\n");
504*77c1e3ccSAndroid Build Coastguard Worker return (int)(buf - buffer);
505*77c1e3ccSAndroid Build Coastguard Worker }
506*77c1e3ccSAndroid Build Coastguard Worker
put_block_info(char * buffer,const map_entry * map,const char * name,size_t offset,int len)507*77c1e3ccSAndroid Build Coastguard Worker static int put_block_info(char *buffer, const map_entry *map, const char *name,
508*77c1e3ccSAndroid Build Coastguard Worker size_t offset, int len) {
509*77c1e3ccSAndroid Build Coastguard Worker const int mi_rows = frame_data.mi_rows;
510*77c1e3ccSAndroid Build Coastguard Worker const int mi_cols = frame_data.mi_cols;
511*77c1e3ccSAndroid Build Coastguard Worker char *buf = buffer;
512*77c1e3ccSAndroid Build Coastguard Worker int r, c, t, i;
513*77c1e3ccSAndroid Build Coastguard Worker if (compress && len == 1) {
514*77c1e3ccSAndroid Build Coastguard Worker die("Can't encode scalars as arrays when RLE compression is enabled.");
515*77c1e3ccSAndroid Build Coastguard Worker }
516*77c1e3ccSAndroid Build Coastguard Worker if (map) {
517*77c1e3ccSAndroid Build Coastguard Worker buf += snprintf(buf, MAX_BUFFER, " \"%sMap\": {", name);
518*77c1e3ccSAndroid Build Coastguard Worker buf += put_map(buf, map);
519*77c1e3ccSAndroid Build Coastguard Worker buf += put_str(buf, "},\n");
520*77c1e3ccSAndroid Build Coastguard Worker }
521*77c1e3ccSAndroid Build Coastguard Worker buf += snprintf(buf, MAX_BUFFER, " \"%s\": [", name);
522*77c1e3ccSAndroid Build Coastguard Worker for (r = 0; r < mi_rows; ++r) {
523*77c1e3ccSAndroid Build Coastguard Worker *(buf++) = '[';
524*77c1e3ccSAndroid Build Coastguard Worker for (c = 0; c < mi_cols; ++c) {
525*77c1e3ccSAndroid Build Coastguard Worker insp_mi_data *mi = &frame_data.mi_grid[r * mi_cols + c];
526*77c1e3ccSAndroid Build Coastguard Worker int16_t *v = (int16_t *)(((int8_t *)mi) + offset);
527*77c1e3ccSAndroid Build Coastguard Worker if (len == 0) {
528*77c1e3ccSAndroid Build Coastguard Worker buf += put_num(buf, 0, v[0], 0);
529*77c1e3ccSAndroid Build Coastguard Worker } else {
530*77c1e3ccSAndroid Build Coastguard Worker buf += put_str(buf, "[");
531*77c1e3ccSAndroid Build Coastguard Worker for (i = 0; i < len; i++) {
532*77c1e3ccSAndroid Build Coastguard Worker buf += put_num(buf, 0, v[i], 0);
533*77c1e3ccSAndroid Build Coastguard Worker if (i < len - 1) {
534*77c1e3ccSAndroid Build Coastguard Worker buf += put_str(buf, ",");
535*77c1e3ccSAndroid Build Coastguard Worker }
536*77c1e3ccSAndroid Build Coastguard Worker }
537*77c1e3ccSAndroid Build Coastguard Worker buf += put_str(buf, "]");
538*77c1e3ccSAndroid Build Coastguard Worker }
539*77c1e3ccSAndroid Build Coastguard Worker if (compress) { // RLE
540*77c1e3ccSAndroid Build Coastguard Worker for (t = c + 1; t < mi_cols; ++t) {
541*77c1e3ccSAndroid Build Coastguard Worker insp_mi_data *next_mi = &frame_data.mi_grid[r * mi_cols + t];
542*77c1e3ccSAndroid Build Coastguard Worker int16_t *nv = (int16_t *)(((int8_t *)next_mi) + offset);
543*77c1e3ccSAndroid Build Coastguard Worker int same = 0;
544*77c1e3ccSAndroid Build Coastguard Worker if (len == 0) {
545*77c1e3ccSAndroid Build Coastguard Worker same = v[0] == nv[0];
546*77c1e3ccSAndroid Build Coastguard Worker } else {
547*77c1e3ccSAndroid Build Coastguard Worker for (i = 0; i < len; i++) {
548*77c1e3ccSAndroid Build Coastguard Worker same = v[i] == nv[i];
549*77c1e3ccSAndroid Build Coastguard Worker if (!same) {
550*77c1e3ccSAndroid Build Coastguard Worker break;
551*77c1e3ccSAndroid Build Coastguard Worker }
552*77c1e3ccSAndroid Build Coastguard Worker }
553*77c1e3ccSAndroid Build Coastguard Worker }
554*77c1e3ccSAndroid Build Coastguard Worker if (!same) {
555*77c1e3ccSAndroid Build Coastguard Worker break;
556*77c1e3ccSAndroid Build Coastguard Worker }
557*77c1e3ccSAndroid Build Coastguard Worker }
558*77c1e3ccSAndroid Build Coastguard Worker if (t - c > 1) {
559*77c1e3ccSAndroid Build Coastguard Worker *(buf++) = ',';
560*77c1e3ccSAndroid Build Coastguard Worker buf += put_num(buf, '[', t - c - 1, ']');
561*77c1e3ccSAndroid Build Coastguard Worker c = t - 1;
562*77c1e3ccSAndroid Build Coastguard Worker }
563*77c1e3ccSAndroid Build Coastguard Worker }
564*77c1e3ccSAndroid Build Coastguard Worker if (c < mi_cols - 1) *(buf++) = ',';
565*77c1e3ccSAndroid Build Coastguard Worker }
566*77c1e3ccSAndroid Build Coastguard Worker *(buf++) = ']';
567*77c1e3ccSAndroid Build Coastguard Worker if (r < mi_rows - 1) *(buf++) = ',';
568*77c1e3ccSAndroid Build Coastguard Worker }
569*77c1e3ccSAndroid Build Coastguard Worker buf += put_str(buf, "],\n");
570*77c1e3ccSAndroid Build Coastguard Worker return (int)(buf - buffer);
571*77c1e3ccSAndroid Build Coastguard Worker }
572*77c1e3ccSAndroid Build Coastguard Worker
573*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_ACCOUNTING
put_accounting(char * buffer)574*77c1e3ccSAndroid Build Coastguard Worker static int put_accounting(char *buffer) {
575*77c1e3ccSAndroid Build Coastguard Worker char *buf = buffer;
576*77c1e3ccSAndroid Build Coastguard Worker int i;
577*77c1e3ccSAndroid Build Coastguard Worker const Accounting *accounting = frame_data.accounting;
578*77c1e3ccSAndroid Build Coastguard Worker if (accounting == NULL) {
579*77c1e3ccSAndroid Build Coastguard Worker printf("XXX\n");
580*77c1e3ccSAndroid Build Coastguard Worker return 0;
581*77c1e3ccSAndroid Build Coastguard Worker }
582*77c1e3ccSAndroid Build Coastguard Worker const int num_syms = accounting->syms.num_syms;
583*77c1e3ccSAndroid Build Coastguard Worker const int num_strs = accounting->syms.dictionary.num_strs;
584*77c1e3ccSAndroid Build Coastguard Worker buf += put_str(buf, " \"symbolsMap\": [");
585*77c1e3ccSAndroid Build Coastguard Worker for (i = 0; i < num_strs; i++) {
586*77c1e3ccSAndroid Build Coastguard Worker buf += snprintf(buf, MAX_BUFFER, "\"%s\"",
587*77c1e3ccSAndroid Build Coastguard Worker accounting->syms.dictionary.strs[i]);
588*77c1e3ccSAndroid Build Coastguard Worker if (i < num_strs - 1) *(buf++) = ',';
589*77c1e3ccSAndroid Build Coastguard Worker }
590*77c1e3ccSAndroid Build Coastguard Worker buf += put_str(buf, "],\n");
591*77c1e3ccSAndroid Build Coastguard Worker buf += put_str(buf, " \"symbols\": [\n ");
592*77c1e3ccSAndroid Build Coastguard Worker AccountingSymbolContext context;
593*77c1e3ccSAndroid Build Coastguard Worker context.x = -2;
594*77c1e3ccSAndroid Build Coastguard Worker context.y = -2;
595*77c1e3ccSAndroid Build Coastguard Worker AccountingSymbol *sym;
596*77c1e3ccSAndroid Build Coastguard Worker for (i = 0; i < num_syms; i++) {
597*77c1e3ccSAndroid Build Coastguard Worker sym = &accounting->syms.syms[i];
598*77c1e3ccSAndroid Build Coastguard Worker if (memcmp(&context, &sym->context, sizeof(AccountingSymbolContext)) != 0) {
599*77c1e3ccSAndroid Build Coastguard Worker buf += put_num(buf, '[', sym->context.x, 0);
600*77c1e3ccSAndroid Build Coastguard Worker buf += put_num(buf, ',', sym->context.y, ']');
601*77c1e3ccSAndroid Build Coastguard Worker } else {
602*77c1e3ccSAndroid Build Coastguard Worker buf += put_num(buf, '[', sym->id, 0);
603*77c1e3ccSAndroid Build Coastguard Worker buf += put_num(buf, ',', sym->bits, 0);
604*77c1e3ccSAndroid Build Coastguard Worker buf += put_num(buf, ',', sym->samples, ']');
605*77c1e3ccSAndroid Build Coastguard Worker }
606*77c1e3ccSAndroid Build Coastguard Worker context = sym->context;
607*77c1e3ccSAndroid Build Coastguard Worker if (i < num_syms - 1) *(buf++) = ',';
608*77c1e3ccSAndroid Build Coastguard Worker }
609*77c1e3ccSAndroid Build Coastguard Worker buf += put_str(buf, "],\n");
610*77c1e3ccSAndroid Build Coastguard Worker return (int)(buf - buffer);
611*77c1e3ccSAndroid Build Coastguard Worker }
612*77c1e3ccSAndroid Build Coastguard Worker #endif
613*77c1e3ccSAndroid Build Coastguard Worker
614*77c1e3ccSAndroid Build Coastguard Worker int skip_non_transform = 0;
615*77c1e3ccSAndroid Build Coastguard Worker
inspect(void * pbi,void * data)616*77c1e3ccSAndroid Build Coastguard Worker static void inspect(void *pbi, void *data) {
617*77c1e3ccSAndroid Build Coastguard Worker /* Fetch frame data. */
618*77c1e3ccSAndroid Build Coastguard Worker ifd_inspect(&frame_data, pbi, skip_non_transform);
619*77c1e3ccSAndroid Build Coastguard Worker
620*77c1e3ccSAndroid Build Coastguard Worker // Show existing frames just show a reference buffer we've already decoded.
621*77c1e3ccSAndroid Build Coastguard Worker // There's no information to show.
622*77c1e3ccSAndroid Build Coastguard Worker if (frame_data.show_existing_frame) return;
623*77c1e3ccSAndroid Build Coastguard Worker
624*77c1e3ccSAndroid Build Coastguard Worker (void)data;
625*77c1e3ccSAndroid Build Coastguard Worker // We allocate enough space and hope we don't write out of bounds. Totally
626*77c1e3ccSAndroid Build Coastguard Worker // unsafe but this speeds things up, especially when compiled to Javascript.
627*77c1e3ccSAndroid Build Coastguard Worker char *buffer = aom_malloc(MAX_BUFFER);
628*77c1e3ccSAndroid Build Coastguard Worker if (!buffer) {
629*77c1e3ccSAndroid Build Coastguard Worker fprintf(stderr, "Error allocating inspect info buffer\n");
630*77c1e3ccSAndroid Build Coastguard Worker abort();
631*77c1e3ccSAndroid Build Coastguard Worker }
632*77c1e3ccSAndroid Build Coastguard Worker char *buf = buffer;
633*77c1e3ccSAndroid Build Coastguard Worker buf += put_str(buf, "{\n");
634*77c1e3ccSAndroid Build Coastguard Worker if (layers & BLOCK_SIZE_LAYER) {
635*77c1e3ccSAndroid Build Coastguard Worker buf += put_block_info(buf, block_size_map, "blockSize",
636*77c1e3ccSAndroid Build Coastguard Worker offsetof(insp_mi_data, bsize), 0);
637*77c1e3ccSAndroid Build Coastguard Worker }
638*77c1e3ccSAndroid Build Coastguard Worker if (layers & TRANSFORM_SIZE_LAYER) {
639*77c1e3ccSAndroid Build Coastguard Worker buf += put_block_info(buf, tx_size_map, "transformSize",
640*77c1e3ccSAndroid Build Coastguard Worker offsetof(insp_mi_data, tx_size), 0);
641*77c1e3ccSAndroid Build Coastguard Worker }
642*77c1e3ccSAndroid Build Coastguard Worker if (layers & TRANSFORM_TYPE_LAYER) {
643*77c1e3ccSAndroid Build Coastguard Worker buf += put_block_info(buf, tx_type_map, "transformType",
644*77c1e3ccSAndroid Build Coastguard Worker offsetof(insp_mi_data, tx_type), 0);
645*77c1e3ccSAndroid Build Coastguard Worker }
646*77c1e3ccSAndroid Build Coastguard Worker if (layers & DUAL_FILTER_LAYER) {
647*77c1e3ccSAndroid Build Coastguard Worker buf += put_block_info(buf, dual_filter_map, "dualFilterType",
648*77c1e3ccSAndroid Build Coastguard Worker offsetof(insp_mi_data, dual_filter_type), 0);
649*77c1e3ccSAndroid Build Coastguard Worker }
650*77c1e3ccSAndroid Build Coastguard Worker if (layers & MODE_LAYER) {
651*77c1e3ccSAndroid Build Coastguard Worker buf += put_block_info(buf, prediction_mode_map, "mode",
652*77c1e3ccSAndroid Build Coastguard Worker offsetof(insp_mi_data, mode), 0);
653*77c1e3ccSAndroid Build Coastguard Worker }
654*77c1e3ccSAndroid Build Coastguard Worker if (layers & UV_MODE_LAYER) {
655*77c1e3ccSAndroid Build Coastguard Worker buf += put_block_info(buf, uv_prediction_mode_map, "uv_mode",
656*77c1e3ccSAndroid Build Coastguard Worker offsetof(insp_mi_data, uv_mode), 0);
657*77c1e3ccSAndroid Build Coastguard Worker }
658*77c1e3ccSAndroid Build Coastguard Worker if (layers & MOTION_MODE_LAYER) {
659*77c1e3ccSAndroid Build Coastguard Worker buf += put_block_info(buf, motion_mode_map, "motion_mode",
660*77c1e3ccSAndroid Build Coastguard Worker offsetof(insp_mi_data, motion_mode), 0);
661*77c1e3ccSAndroid Build Coastguard Worker }
662*77c1e3ccSAndroid Build Coastguard Worker if (layers & COMPOUND_TYPE_LAYER) {
663*77c1e3ccSAndroid Build Coastguard Worker buf += put_block_info(buf, compound_type_map, "compound_type",
664*77c1e3ccSAndroid Build Coastguard Worker offsetof(insp_mi_data, compound_type), 0);
665*77c1e3ccSAndroid Build Coastguard Worker }
666*77c1e3ccSAndroid Build Coastguard Worker if (layers & SKIP_LAYER) {
667*77c1e3ccSAndroid Build Coastguard Worker buf +=
668*77c1e3ccSAndroid Build Coastguard Worker put_block_info(buf, skip_map, "skip", offsetof(insp_mi_data, skip), 0);
669*77c1e3ccSAndroid Build Coastguard Worker }
670*77c1e3ccSAndroid Build Coastguard Worker if (layers & FILTER_LAYER) {
671*77c1e3ccSAndroid Build Coastguard Worker buf +=
672*77c1e3ccSAndroid Build Coastguard Worker put_block_info(buf, NULL, "filter", offsetof(insp_mi_data, filter), 2);
673*77c1e3ccSAndroid Build Coastguard Worker }
674*77c1e3ccSAndroid Build Coastguard Worker if (layers & CDEF_LAYER) {
675*77c1e3ccSAndroid Build Coastguard Worker buf += put_block_info(buf, NULL, "cdef_level",
676*77c1e3ccSAndroid Build Coastguard Worker offsetof(insp_mi_data, cdef_level), 0);
677*77c1e3ccSAndroid Build Coastguard Worker buf += put_block_info(buf, NULL, "cdef_strength",
678*77c1e3ccSAndroid Build Coastguard Worker offsetof(insp_mi_data, cdef_strength), 0);
679*77c1e3ccSAndroid Build Coastguard Worker }
680*77c1e3ccSAndroid Build Coastguard Worker if (layers & CFL_LAYER) {
681*77c1e3ccSAndroid Build Coastguard Worker buf += put_block_info(buf, NULL, "cfl_alpha_idx",
682*77c1e3ccSAndroid Build Coastguard Worker offsetof(insp_mi_data, cfl_alpha_idx), 0);
683*77c1e3ccSAndroid Build Coastguard Worker buf += put_block_info(buf, NULL, "cfl_alpha_sign",
684*77c1e3ccSAndroid Build Coastguard Worker offsetof(insp_mi_data, cfl_alpha_sign), 0);
685*77c1e3ccSAndroid Build Coastguard Worker }
686*77c1e3ccSAndroid Build Coastguard Worker if (layers & Q_INDEX_LAYER) {
687*77c1e3ccSAndroid Build Coastguard Worker buf += put_block_info(buf, NULL, "delta_q",
688*77c1e3ccSAndroid Build Coastguard Worker offsetof(insp_mi_data, current_qindex), 0);
689*77c1e3ccSAndroid Build Coastguard Worker }
690*77c1e3ccSAndroid Build Coastguard Worker if (layers & SEGMENT_ID_LAYER) {
691*77c1e3ccSAndroid Build Coastguard Worker buf += put_block_info(buf, NULL, "seg_id",
692*77c1e3ccSAndroid Build Coastguard Worker offsetof(insp_mi_data, segment_id), 0);
693*77c1e3ccSAndroid Build Coastguard Worker }
694*77c1e3ccSAndroid Build Coastguard Worker if (layers & MOTION_VECTORS_LAYER) {
695*77c1e3ccSAndroid Build Coastguard Worker buf += put_motion_vectors(buf);
696*77c1e3ccSAndroid Build Coastguard Worker }
697*77c1e3ccSAndroid Build Coastguard Worker if (layers & INTRABC_LAYER) {
698*77c1e3ccSAndroid Build Coastguard Worker buf += put_block_info(buf, intrabc_map, "intrabc",
699*77c1e3ccSAndroid Build Coastguard Worker offsetof(insp_mi_data, intrabc), 0);
700*77c1e3ccSAndroid Build Coastguard Worker }
701*77c1e3ccSAndroid Build Coastguard Worker if (layers & PALETTE_LAYER) {
702*77c1e3ccSAndroid Build Coastguard Worker buf += put_block_info(buf, palette_map, "palette",
703*77c1e3ccSAndroid Build Coastguard Worker offsetof(insp_mi_data, palette), 0);
704*77c1e3ccSAndroid Build Coastguard Worker }
705*77c1e3ccSAndroid Build Coastguard Worker if (layers & UV_PALETTE_LAYER) {
706*77c1e3ccSAndroid Build Coastguard Worker buf += put_block_info(buf, palette_map, "uv_palette",
707*77c1e3ccSAndroid Build Coastguard Worker offsetof(insp_mi_data, uv_palette), 0);
708*77c1e3ccSAndroid Build Coastguard Worker }
709*77c1e3ccSAndroid Build Coastguard Worker if (combined_parm_count > 0) buf += put_combined(buf);
710*77c1e3ccSAndroid Build Coastguard Worker if (layers & REFERENCE_FRAME_LAYER) {
711*77c1e3ccSAndroid Build Coastguard Worker buf += put_block_info(buf, refs_map, "referenceFrame",
712*77c1e3ccSAndroid Build Coastguard Worker offsetof(insp_mi_data, ref_frame), 2);
713*77c1e3ccSAndroid Build Coastguard Worker }
714*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_ACCOUNTING
715*77c1e3ccSAndroid Build Coastguard Worker if (layers & ACCOUNTING_LAYER) {
716*77c1e3ccSAndroid Build Coastguard Worker buf += put_accounting(buf);
717*77c1e3ccSAndroid Build Coastguard Worker }
718*77c1e3ccSAndroid Build Coastguard Worker #endif
719*77c1e3ccSAndroid Build Coastguard Worker buf +=
720*77c1e3ccSAndroid Build Coastguard Worker snprintf(buf, MAX_BUFFER, " \"frame\": %d,\n", frame_data.frame_number);
721*77c1e3ccSAndroid Build Coastguard Worker buf += snprintf(buf, MAX_BUFFER, " \"showFrame\": %d,\n",
722*77c1e3ccSAndroid Build Coastguard Worker frame_data.show_frame);
723*77c1e3ccSAndroid Build Coastguard Worker buf += snprintf(buf, MAX_BUFFER, " \"frameType\": %d,\n",
724*77c1e3ccSAndroid Build Coastguard Worker frame_data.frame_type);
725*77c1e3ccSAndroid Build Coastguard Worker buf += snprintf(buf, MAX_BUFFER, " \"baseQIndex\": %d,\n",
726*77c1e3ccSAndroid Build Coastguard Worker frame_data.base_qindex);
727*77c1e3ccSAndroid Build Coastguard Worker buf += snprintf(buf, MAX_BUFFER, " \"tileCols\": %d,\n",
728*77c1e3ccSAndroid Build Coastguard Worker frame_data.tile_mi_cols);
729*77c1e3ccSAndroid Build Coastguard Worker buf += snprintf(buf, MAX_BUFFER, " \"tileRows\": %d,\n",
730*77c1e3ccSAndroid Build Coastguard Worker frame_data.tile_mi_rows);
731*77c1e3ccSAndroid Build Coastguard Worker buf += snprintf(buf, MAX_BUFFER, " \"deltaQPresentFlag\": %d,\n",
732*77c1e3ccSAndroid Build Coastguard Worker frame_data.delta_q_present_flag);
733*77c1e3ccSAndroid Build Coastguard Worker buf += snprintf(buf, MAX_BUFFER, " \"deltaQRes\": %d,\n",
734*77c1e3ccSAndroid Build Coastguard Worker frame_data.delta_q_res);
735*77c1e3ccSAndroid Build Coastguard Worker buf += put_str(buf, " \"config\": {");
736*77c1e3ccSAndroid Build Coastguard Worker buf += put_map(buf, config_map);
737*77c1e3ccSAndroid Build Coastguard Worker buf += put_str(buf, "},\n");
738*77c1e3ccSAndroid Build Coastguard Worker buf += put_str(buf, " \"configString\": \"");
739*77c1e3ccSAndroid Build Coastguard Worker buf += put_str_with_escape(buf, aom_codec_build_config());
740*77c1e3ccSAndroid Build Coastguard Worker buf += put_str(buf, "\"\n");
741*77c1e3ccSAndroid Build Coastguard Worker decoded_frame_count++;
742*77c1e3ccSAndroid Build Coastguard Worker buf += put_str(buf, "},\n");
743*77c1e3ccSAndroid Build Coastguard Worker *(buf++) = 0;
744*77c1e3ccSAndroid Build Coastguard Worker on_frame_decoded_dump(buffer);
745*77c1e3ccSAndroid Build Coastguard Worker aom_free(buffer);
746*77c1e3ccSAndroid Build Coastguard Worker }
747*77c1e3ccSAndroid Build Coastguard Worker
ifd_init_cb(void)748*77c1e3ccSAndroid Build Coastguard Worker static void ifd_init_cb(void) {
749*77c1e3ccSAndroid Build Coastguard Worker aom_inspect_init ii;
750*77c1e3ccSAndroid Build Coastguard Worker ii.inspect_cb = inspect;
751*77c1e3ccSAndroid Build Coastguard Worker ii.inspect_ctx = NULL;
752*77c1e3ccSAndroid Build Coastguard Worker aom_codec_control(&codec, AV1_SET_INSPECTION_CALLBACK, &ii);
753*77c1e3ccSAndroid Build Coastguard Worker }
754*77c1e3ccSAndroid Build Coastguard Worker
755*77c1e3ccSAndroid Build Coastguard Worker EMSCRIPTEN_KEEPALIVE int open_file(char *file);
756*77c1e3ccSAndroid Build Coastguard Worker
757*77c1e3ccSAndroid Build Coastguard Worker EMSCRIPTEN_KEEPALIVE
open_file(char * file)758*77c1e3ccSAndroid Build Coastguard Worker int open_file(char *file) {
759*77c1e3ccSAndroid Build Coastguard Worker if (file == NULL) {
760*77c1e3ccSAndroid Build Coastguard Worker // The JS analyzer puts the .ivf file at this location.
761*77c1e3ccSAndroid Build Coastguard Worker file = "/tmp/input.ivf";
762*77c1e3ccSAndroid Build Coastguard Worker }
763*77c1e3ccSAndroid Build Coastguard Worker reader = aom_video_reader_open(file);
764*77c1e3ccSAndroid Build Coastguard Worker if (!reader) die("Failed to open %s for reading.", file);
765*77c1e3ccSAndroid Build Coastguard Worker info = aom_video_reader_get_info(reader);
766*77c1e3ccSAndroid Build Coastguard Worker aom_codec_iface_t *decoder = get_aom_decoder_by_fourcc(info->codec_fourcc);
767*77c1e3ccSAndroid Build Coastguard Worker if (!decoder) die("Unknown input codec.");
768*77c1e3ccSAndroid Build Coastguard Worker fprintf(stderr, "Using %s\n", aom_codec_iface_name(decoder));
769*77c1e3ccSAndroid Build Coastguard Worker if (aom_codec_dec_init(&codec, decoder, NULL, 0))
770*77c1e3ccSAndroid Build Coastguard Worker die("Failed to initialize decoder.");
771*77c1e3ccSAndroid Build Coastguard Worker ifd_init(&frame_data, info->frame_width, info->frame_height);
772*77c1e3ccSAndroid Build Coastguard Worker ifd_init_cb();
773*77c1e3ccSAndroid Build Coastguard Worker return EXIT_SUCCESS;
774*77c1e3ccSAndroid Build Coastguard Worker }
775*77c1e3ccSAndroid Build Coastguard Worker
776*77c1e3ccSAndroid Build Coastguard Worker Av1DecodeReturn adr;
777*77c1e3ccSAndroid Build Coastguard Worker int have_frame = 0;
778*77c1e3ccSAndroid Build Coastguard Worker const unsigned char *frame;
779*77c1e3ccSAndroid Build Coastguard Worker const unsigned char *end_frame;
780*77c1e3ccSAndroid Build Coastguard Worker size_t frame_size = 0;
781*77c1e3ccSAndroid Build Coastguard Worker struct av1_ref_frame ref_dec;
782*77c1e3ccSAndroid Build Coastguard Worker
783*77c1e3ccSAndroid Build Coastguard Worker EMSCRIPTEN_KEEPALIVE int read_frame(void);
784*77c1e3ccSAndroid Build Coastguard Worker
785*77c1e3ccSAndroid Build Coastguard Worker EMSCRIPTEN_KEEPALIVE
read_frame(void)786*77c1e3ccSAndroid Build Coastguard Worker int read_frame(void) {
787*77c1e3ccSAndroid Build Coastguard Worker img = NULL;
788*77c1e3ccSAndroid Build Coastguard Worker
789*77c1e3ccSAndroid Build Coastguard Worker // This loop skips over any frames that are show_existing_frames, as
790*77c1e3ccSAndroid Build Coastguard Worker // there is nothing to analyze.
791*77c1e3ccSAndroid Build Coastguard Worker do {
792*77c1e3ccSAndroid Build Coastguard Worker if (!have_frame) {
793*77c1e3ccSAndroid Build Coastguard Worker if (!aom_video_reader_read_frame(reader)) return EXIT_FAILURE;
794*77c1e3ccSAndroid Build Coastguard Worker frame = aom_video_reader_get_frame(reader, &frame_size);
795*77c1e3ccSAndroid Build Coastguard Worker
796*77c1e3ccSAndroid Build Coastguard Worker have_frame = 1;
797*77c1e3ccSAndroid Build Coastguard Worker end_frame = frame + frame_size;
798*77c1e3ccSAndroid Build Coastguard Worker }
799*77c1e3ccSAndroid Build Coastguard Worker
800*77c1e3ccSAndroid Build Coastguard Worker if (aom_codec_decode(&codec, frame, (unsigned int)frame_size, &adr) !=
801*77c1e3ccSAndroid Build Coastguard Worker AOM_CODEC_OK) {
802*77c1e3ccSAndroid Build Coastguard Worker die_codec(&codec, "Failed to decode frame.");
803*77c1e3ccSAndroid Build Coastguard Worker }
804*77c1e3ccSAndroid Build Coastguard Worker
805*77c1e3ccSAndroid Build Coastguard Worker frame = adr.buf;
806*77c1e3ccSAndroid Build Coastguard Worker frame_size = end_frame - frame;
807*77c1e3ccSAndroid Build Coastguard Worker if (frame == end_frame) have_frame = 0;
808*77c1e3ccSAndroid Build Coastguard Worker } while (adr.show_existing);
809*77c1e3ccSAndroid Build Coastguard Worker
810*77c1e3ccSAndroid Build Coastguard Worker int got_any_frames = 0;
811*77c1e3ccSAndroid Build Coastguard Worker aom_image_t *frame_img;
812*77c1e3ccSAndroid Build Coastguard Worker ref_dec.idx = adr.idx;
813*77c1e3ccSAndroid Build Coastguard Worker
814*77c1e3ccSAndroid Build Coastguard Worker // ref_dec.idx is the index to the reference buffer idx to AV1_GET_REFERENCE
815*77c1e3ccSAndroid Build Coastguard Worker // if its -1 the decoder didn't update any reference buffer and the only
816*77c1e3ccSAndroid Build Coastguard Worker // way to see the frame is aom_codec_get_frame.
817*77c1e3ccSAndroid Build Coastguard Worker if (ref_dec.idx == -1) {
818*77c1e3ccSAndroid Build Coastguard Worker aom_codec_iter_t iter = NULL;
819*77c1e3ccSAndroid Build Coastguard Worker img = frame_img = aom_codec_get_frame(&codec, &iter);
820*77c1e3ccSAndroid Build Coastguard Worker ++frame_count;
821*77c1e3ccSAndroid Build Coastguard Worker got_any_frames = 1;
822*77c1e3ccSAndroid Build Coastguard Worker } else if (!aom_codec_control(&codec, AV1_GET_REFERENCE, &ref_dec)) {
823*77c1e3ccSAndroid Build Coastguard Worker img = frame_img = &ref_dec.img;
824*77c1e3ccSAndroid Build Coastguard Worker ++frame_count;
825*77c1e3ccSAndroid Build Coastguard Worker got_any_frames = 1;
826*77c1e3ccSAndroid Build Coastguard Worker }
827*77c1e3ccSAndroid Build Coastguard Worker if (!got_any_frames) {
828*77c1e3ccSAndroid Build Coastguard Worker return EXIT_FAILURE;
829*77c1e3ccSAndroid Build Coastguard Worker }
830*77c1e3ccSAndroid Build Coastguard Worker return EXIT_SUCCESS;
831*77c1e3ccSAndroid Build Coastguard Worker }
832*77c1e3ccSAndroid Build Coastguard Worker
833*77c1e3ccSAndroid Build Coastguard Worker EMSCRIPTEN_KEEPALIVE const char *get_aom_codec_build_config(void);
834*77c1e3ccSAndroid Build Coastguard Worker
835*77c1e3ccSAndroid Build Coastguard Worker EMSCRIPTEN_KEEPALIVE
get_aom_codec_build_config(void)836*77c1e3ccSAndroid Build Coastguard Worker const char *get_aom_codec_build_config(void) {
837*77c1e3ccSAndroid Build Coastguard Worker return aom_codec_build_config();
838*77c1e3ccSAndroid Build Coastguard Worker }
839*77c1e3ccSAndroid Build Coastguard Worker
840*77c1e3ccSAndroid Build Coastguard Worker EMSCRIPTEN_KEEPALIVE int get_bit_depth(void);
841*77c1e3ccSAndroid Build Coastguard Worker
842*77c1e3ccSAndroid Build Coastguard Worker EMSCRIPTEN_KEEPALIVE
get_bit_depth(void)843*77c1e3ccSAndroid Build Coastguard Worker int get_bit_depth(void) { return img->bit_depth; }
844*77c1e3ccSAndroid Build Coastguard Worker
845*77c1e3ccSAndroid Build Coastguard Worker EMSCRIPTEN_KEEPALIVE int get_bits_per_sample(void);
846*77c1e3ccSAndroid Build Coastguard Worker
847*77c1e3ccSAndroid Build Coastguard Worker EMSCRIPTEN_KEEPALIVE
get_bits_per_sample(void)848*77c1e3ccSAndroid Build Coastguard Worker int get_bits_per_sample(void) { return img->bps; }
849*77c1e3ccSAndroid Build Coastguard Worker
850*77c1e3ccSAndroid Build Coastguard Worker EMSCRIPTEN_KEEPALIVE int get_image_format(void);
851*77c1e3ccSAndroid Build Coastguard Worker
852*77c1e3ccSAndroid Build Coastguard Worker EMSCRIPTEN_KEEPALIVE
get_image_format(void)853*77c1e3ccSAndroid Build Coastguard Worker int get_image_format(void) { return img->fmt; }
854*77c1e3ccSAndroid Build Coastguard Worker
855*77c1e3ccSAndroid Build Coastguard Worker EMSCRIPTEN_KEEPALIVE unsigned char *get_plane(int plane);
856*77c1e3ccSAndroid Build Coastguard Worker
857*77c1e3ccSAndroid Build Coastguard Worker EMSCRIPTEN_KEEPALIVE
get_plane(int plane)858*77c1e3ccSAndroid Build Coastguard Worker unsigned char *get_plane(int plane) { return img->planes[plane]; }
859*77c1e3ccSAndroid Build Coastguard Worker
860*77c1e3ccSAndroid Build Coastguard Worker EMSCRIPTEN_KEEPALIVE int get_plane_stride(int plane);
861*77c1e3ccSAndroid Build Coastguard Worker
862*77c1e3ccSAndroid Build Coastguard Worker EMSCRIPTEN_KEEPALIVE
get_plane_stride(int plane)863*77c1e3ccSAndroid Build Coastguard Worker int get_plane_stride(int plane) { return img->stride[plane]; }
864*77c1e3ccSAndroid Build Coastguard Worker
865*77c1e3ccSAndroid Build Coastguard Worker EMSCRIPTEN_KEEPALIVE int get_plane_width(int plane);
866*77c1e3ccSAndroid Build Coastguard Worker
867*77c1e3ccSAndroid Build Coastguard Worker EMSCRIPTEN_KEEPALIVE
get_plane_width(int plane)868*77c1e3ccSAndroid Build Coastguard Worker int get_plane_width(int plane) { return aom_img_plane_width(img, plane); }
869*77c1e3ccSAndroid Build Coastguard Worker
870*77c1e3ccSAndroid Build Coastguard Worker EMSCRIPTEN_KEEPALIVE int get_plane_height(int plane);
871*77c1e3ccSAndroid Build Coastguard Worker
872*77c1e3ccSAndroid Build Coastguard Worker EMSCRIPTEN_KEEPALIVE
get_plane_height(int plane)873*77c1e3ccSAndroid Build Coastguard Worker int get_plane_height(int plane) { return aom_img_plane_height(img, plane); }
874*77c1e3ccSAndroid Build Coastguard Worker
875*77c1e3ccSAndroid Build Coastguard Worker EMSCRIPTEN_KEEPALIVE int get_frame_width(void);
876*77c1e3ccSAndroid Build Coastguard Worker
877*77c1e3ccSAndroid Build Coastguard Worker EMSCRIPTEN_KEEPALIVE
get_frame_width(void)878*77c1e3ccSAndroid Build Coastguard Worker int get_frame_width(void) { return info->frame_width; }
879*77c1e3ccSAndroid Build Coastguard Worker
880*77c1e3ccSAndroid Build Coastguard Worker EMSCRIPTEN_KEEPALIVE int get_frame_height(void);
881*77c1e3ccSAndroid Build Coastguard Worker
882*77c1e3ccSAndroid Build Coastguard Worker EMSCRIPTEN_KEEPALIVE
get_frame_height(void)883*77c1e3ccSAndroid Build Coastguard Worker int get_frame_height(void) { return info->frame_height; }
884*77c1e3ccSAndroid Build Coastguard Worker
parse_args(char ** argv)885*77c1e3ccSAndroid Build Coastguard Worker static void parse_args(char **argv) {
886*77c1e3ccSAndroid Build Coastguard Worker char **argi, **argj;
887*77c1e3ccSAndroid Build Coastguard Worker struct arg arg;
888*77c1e3ccSAndroid Build Coastguard Worker (void)dump_accounting_arg;
889*77c1e3ccSAndroid Build Coastguard Worker (void)dump_cdef_arg;
890*77c1e3ccSAndroid Build Coastguard Worker for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) {
891*77c1e3ccSAndroid Build Coastguard Worker arg.argv_step = 1;
892*77c1e3ccSAndroid Build Coastguard Worker if (arg_match(&arg, &dump_block_size_arg, argi)) layers |= BLOCK_SIZE_LAYER;
893*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_ACCOUNTING
894*77c1e3ccSAndroid Build Coastguard Worker else if (arg_match(&arg, &dump_accounting_arg, argi))
895*77c1e3ccSAndroid Build Coastguard Worker layers |= ACCOUNTING_LAYER;
896*77c1e3ccSAndroid Build Coastguard Worker #endif
897*77c1e3ccSAndroid Build Coastguard Worker else if (arg_match(&arg, &dump_transform_size_arg, argi))
898*77c1e3ccSAndroid Build Coastguard Worker layers |= TRANSFORM_SIZE_LAYER;
899*77c1e3ccSAndroid Build Coastguard Worker else if (arg_match(&arg, &dump_transform_type_arg, argi))
900*77c1e3ccSAndroid Build Coastguard Worker layers |= TRANSFORM_TYPE_LAYER;
901*77c1e3ccSAndroid Build Coastguard Worker else if (arg_match(&arg, &dump_mode_arg, argi))
902*77c1e3ccSAndroid Build Coastguard Worker layers |= MODE_LAYER;
903*77c1e3ccSAndroid Build Coastguard Worker else if (arg_match(&arg, &dump_uv_mode_arg, argi))
904*77c1e3ccSAndroid Build Coastguard Worker layers |= UV_MODE_LAYER;
905*77c1e3ccSAndroid Build Coastguard Worker else if (arg_match(&arg, &dump_motion_mode_arg, argi))
906*77c1e3ccSAndroid Build Coastguard Worker layers |= MOTION_MODE_LAYER;
907*77c1e3ccSAndroid Build Coastguard Worker else if (arg_match(&arg, &dump_compound_type_arg, argi))
908*77c1e3ccSAndroid Build Coastguard Worker layers |= COMPOUND_TYPE_LAYER;
909*77c1e3ccSAndroid Build Coastguard Worker else if (arg_match(&arg, &dump_skip_arg, argi))
910*77c1e3ccSAndroid Build Coastguard Worker layers |= SKIP_LAYER;
911*77c1e3ccSAndroid Build Coastguard Worker else if (arg_match(&arg, &dump_filter_arg, argi))
912*77c1e3ccSAndroid Build Coastguard Worker layers |= FILTER_LAYER;
913*77c1e3ccSAndroid Build Coastguard Worker else if (arg_match(&arg, &dump_cdef_arg, argi))
914*77c1e3ccSAndroid Build Coastguard Worker layers |= CDEF_LAYER;
915*77c1e3ccSAndroid Build Coastguard Worker else if (arg_match(&arg, &dump_cfl_arg, argi))
916*77c1e3ccSAndroid Build Coastguard Worker layers |= CFL_LAYER;
917*77c1e3ccSAndroid Build Coastguard Worker else if (arg_match(&arg, &dump_reference_frame_arg, argi))
918*77c1e3ccSAndroid Build Coastguard Worker layers |= REFERENCE_FRAME_LAYER;
919*77c1e3ccSAndroid Build Coastguard Worker else if (arg_match(&arg, &dump_motion_vectors_arg, argi))
920*77c1e3ccSAndroid Build Coastguard Worker layers |= MOTION_VECTORS_LAYER;
921*77c1e3ccSAndroid Build Coastguard Worker else if (arg_match(&arg, &dump_dual_filter_type_arg, argi))
922*77c1e3ccSAndroid Build Coastguard Worker layers |= DUAL_FILTER_LAYER;
923*77c1e3ccSAndroid Build Coastguard Worker else if (arg_match(&arg, &dump_delta_q_arg, argi))
924*77c1e3ccSAndroid Build Coastguard Worker layers |= Q_INDEX_LAYER;
925*77c1e3ccSAndroid Build Coastguard Worker else if (arg_match(&arg, &dump_seg_id_arg, argi))
926*77c1e3ccSAndroid Build Coastguard Worker layers |= SEGMENT_ID_LAYER;
927*77c1e3ccSAndroid Build Coastguard Worker else if (arg_match(&arg, &dump_intrabc_arg, argi))
928*77c1e3ccSAndroid Build Coastguard Worker layers |= INTRABC_LAYER;
929*77c1e3ccSAndroid Build Coastguard Worker else if (arg_match(&arg, &dump_palette_arg, argi))
930*77c1e3ccSAndroid Build Coastguard Worker layers |= PALETTE_LAYER;
931*77c1e3ccSAndroid Build Coastguard Worker else if (arg_match(&arg, &dump_uv_palette_arg, argi))
932*77c1e3ccSAndroid Build Coastguard Worker layers |= UV_PALETTE_LAYER;
933*77c1e3ccSAndroid Build Coastguard Worker else if (arg_match(&arg, &dump_all_arg, argi))
934*77c1e3ccSAndroid Build Coastguard Worker layers |= ALL_LAYERS;
935*77c1e3ccSAndroid Build Coastguard Worker else if (arg_match(&arg, &compress_arg, argi))
936*77c1e3ccSAndroid Build Coastguard Worker compress = 1;
937*77c1e3ccSAndroid Build Coastguard Worker else if (arg_match(&arg, &usage_arg, argi))
938*77c1e3ccSAndroid Build Coastguard Worker usage_exit();
939*77c1e3ccSAndroid Build Coastguard Worker else if (arg_match(&arg, &limit_arg, argi))
940*77c1e3ccSAndroid Build Coastguard Worker stop_after = arg_parse_uint(&arg);
941*77c1e3ccSAndroid Build Coastguard Worker else if (arg_match(&arg, &skip_non_transform_arg, argi))
942*77c1e3ccSAndroid Build Coastguard Worker skip_non_transform = arg_parse_uint(&arg);
943*77c1e3ccSAndroid Build Coastguard Worker else if (arg_match(&arg, &combined_arg, argi))
944*77c1e3ccSAndroid Build Coastguard Worker convert_to_indices(
945*77c1e3ccSAndroid Build Coastguard Worker (char *)arg.val, combined_parm_list,
946*77c1e3ccSAndroid Build Coastguard Worker sizeof(combined_parm_list) / sizeof(combined_parm_list[0]),
947*77c1e3ccSAndroid Build Coastguard Worker &combined_parm_count);
948*77c1e3ccSAndroid Build Coastguard Worker else
949*77c1e3ccSAndroid Build Coastguard Worker argj++;
950*77c1e3ccSAndroid Build Coastguard Worker }
951*77c1e3ccSAndroid Build Coastguard Worker }
952*77c1e3ccSAndroid Build Coastguard Worker
953*77c1e3ccSAndroid Build Coastguard Worker static const char *exec_name;
954*77c1e3ccSAndroid Build Coastguard Worker
usage_exit(void)955*77c1e3ccSAndroid Build Coastguard Worker void usage_exit(void) {
956*77c1e3ccSAndroid Build Coastguard Worker fprintf(stderr, "Usage: %s src_filename <options>\n", exec_name);
957*77c1e3ccSAndroid Build Coastguard Worker fprintf(stderr, "\nOptions:\n");
958*77c1e3ccSAndroid Build Coastguard Worker arg_show_usage(stderr, main_args);
959*77c1e3ccSAndroid Build Coastguard Worker exit(EXIT_FAILURE);
960*77c1e3ccSAndroid Build Coastguard Worker }
961*77c1e3ccSAndroid Build Coastguard Worker
962*77c1e3ccSAndroid Build Coastguard Worker EMSCRIPTEN_KEEPALIVE
main(int argc,char ** argv)963*77c1e3ccSAndroid Build Coastguard Worker int main(int argc, char **argv) {
964*77c1e3ccSAndroid Build Coastguard Worker exec_name = argv[0];
965*77c1e3ccSAndroid Build Coastguard Worker parse_args(argv);
966*77c1e3ccSAndroid Build Coastguard Worker if (argc >= 2) {
967*77c1e3ccSAndroid Build Coastguard Worker open_file(argv[1]);
968*77c1e3ccSAndroid Build Coastguard Worker printf("[\n");
969*77c1e3ccSAndroid Build Coastguard Worker while (1) {
970*77c1e3ccSAndroid Build Coastguard Worker if (stop_after && (decoded_frame_count >= stop_after)) break;
971*77c1e3ccSAndroid Build Coastguard Worker if (read_frame()) break;
972*77c1e3ccSAndroid Build Coastguard Worker }
973*77c1e3ccSAndroid Build Coastguard Worker printf("null\n");
974*77c1e3ccSAndroid Build Coastguard Worker printf("]");
975*77c1e3ccSAndroid Build Coastguard Worker } else {
976*77c1e3ccSAndroid Build Coastguard Worker usage_exit();
977*77c1e3ccSAndroid Build Coastguard Worker }
978*77c1e3ccSAndroid Build Coastguard Worker }
979*77c1e3ccSAndroid Build Coastguard Worker
980*77c1e3ccSAndroid Build Coastguard Worker EMSCRIPTEN_KEEPALIVE void quit(void);
981*77c1e3ccSAndroid Build Coastguard Worker
982*77c1e3ccSAndroid Build Coastguard Worker EMSCRIPTEN_KEEPALIVE
quit(void)983*77c1e3ccSAndroid Build Coastguard Worker void quit(void) {
984*77c1e3ccSAndroid Build Coastguard Worker if (aom_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec");
985*77c1e3ccSAndroid Build Coastguard Worker aom_video_reader_close(reader);
986*77c1e3ccSAndroid Build Coastguard Worker }
987*77c1e3ccSAndroid Build Coastguard Worker
988*77c1e3ccSAndroid Build Coastguard Worker EMSCRIPTEN_KEEPALIVE void set_layers(LayerType v);
989*77c1e3ccSAndroid Build Coastguard Worker
990*77c1e3ccSAndroid Build Coastguard Worker EMSCRIPTEN_KEEPALIVE
set_layers(LayerType v)991*77c1e3ccSAndroid Build Coastguard Worker void set_layers(LayerType v) { layers = v; }
992*77c1e3ccSAndroid Build Coastguard Worker
993*77c1e3ccSAndroid Build Coastguard Worker EMSCRIPTEN_KEEPALIVE void set_compress(int v);
994*77c1e3ccSAndroid Build Coastguard Worker
995*77c1e3ccSAndroid Build Coastguard Worker EMSCRIPTEN_KEEPALIVE
set_compress(int v)996*77c1e3ccSAndroid Build Coastguard Worker void set_compress(int v) { compress = v; }
997