23 #include <emscripten.h>
25 #define EMSCRIPTEN_KEEPALIVE
28 #include "config/aom_config.h"
32 #include "av1/common/av1_common_int.h"
35 #include "av1/decoder/accounting.h"
38 #include "av1/decoder/inspection.h"
39 #include "common/args.h"
40 #include "common/tools_common.h"
41 #include "common/video_common.h"
42 #include "common/video_reader.h"
45 const int MAX_BUFFER = 1024 * 1024 * 256;
49 BLOCK_SIZE_LAYER = 1 << 1,
50 TRANSFORM_SIZE_LAYER = 1 << 2,
51 TRANSFORM_TYPE_LAYER = 1 << 3,
54 FILTER_LAYER = 1 << 6,
56 REFERENCE_FRAME_LAYER = 1 << 8,
57 MOTION_VECTORS_LAYER = 1 << 9,
58 UV_MODE_LAYER = 1 << 10,
60 DUAL_FILTER_LAYER = 1 << 12,
61 Q_INDEX_LAYER = 1 << 13,
62 SEGMENT_ID_LAYER = 1 << 14,
63 MOTION_MODE_LAYER = 1 << 15,
64 COMPOUND_TYPE_LAYER = 1 << 16,
65 INTRABC_LAYER = 1 << 17,
66 PALETTE_LAYER = 1 << 18,
67 UV_PALETTE_LAYER = 1 << 19,
69 ALL_LAYERS = (1 << 21) - 1
72 static LayerType layers = 0;
74 static int stop_after = 0;
75 static int compress = 0;
77 static const arg_def_t limit_arg =
78 ARG_DEF(NULL,
"limit", 1,
"Stop decoding after n frames");
79 static const arg_def_t dump_all_arg = ARG_DEF(
"A",
"all", 0,
"Dump All");
80 static const arg_def_t compress_arg =
81 ARG_DEF(
"x",
"compress", 0,
"Compress JSON using RLE");
82 static const arg_def_t dump_accounting_arg =
83 ARG_DEF(
"a",
"accounting", 0,
"Dump Accounting");
84 static const arg_def_t dump_block_size_arg =
85 ARG_DEF(
"bs",
"blockSize", 0,
"Dump Block Size");
86 static const arg_def_t dump_motion_vectors_arg =
87 ARG_DEF(
"mv",
"motionVectors", 0,
"Dump Motion Vectors");
88 static const arg_def_t dump_transform_size_arg =
89 ARG_DEF(
"ts",
"transformSize", 0,
"Dump Transform Size");
90 static const arg_def_t dump_transform_type_arg =
91 ARG_DEF(
"tt",
"transformType", 0,
"Dump Transform Type");
92 static const arg_def_t dump_mode_arg = ARG_DEF(
"m",
"mode", 0,
"Dump Mode");
93 static const arg_def_t dump_motion_mode_arg =
94 ARG_DEF(
"mm",
"motion_mode", 0,
"Dump Motion Modes");
95 static const arg_def_t dump_compound_type_arg =
96 ARG_DEF(
"ct",
"compound_type", 0,
"Dump Compound Types");
97 static const arg_def_t dump_uv_mode_arg =
98 ARG_DEF(
"uvm",
"uv_mode", 0,
"Dump UV Intra Prediction Modes");
99 static const arg_def_t dump_skip_arg = ARG_DEF(
"s",
"skip", 0,
"Dump Skip");
100 static const arg_def_t dump_filter_arg =
101 ARG_DEF(
"f",
"filter", 0,
"Dump Filter");
102 static const arg_def_t dump_cdef_arg = ARG_DEF(
"c",
"cdef", 0,
"Dump CDEF");
103 static const arg_def_t dump_cfl_arg =
104 ARG_DEF(
"cfl",
"chroma_from_luma", 0,
"Dump Chroma from Luma Alphas");
105 static const arg_def_t dump_dual_filter_type_arg =
106 ARG_DEF(
"df",
"dualFilterType", 0,
"Dump Dual Filter Type");
107 static const arg_def_t dump_reference_frame_arg =
108 ARG_DEF(
"r",
"referenceFrame", 0,
"Dump Reference Frame");
109 static const arg_def_t dump_delta_q_arg =
110 ARG_DEF(
"dq",
"delta_q", 0,
"Dump QIndex");
111 static const arg_def_t dump_seg_id_arg =
112 ARG_DEF(
"si",
"seg_id", 0,
"Dump Segment ID");
113 static const arg_def_t dump_intrabc_arg =
114 ARG_DEF(
"ibc",
"intrabc", 0,
"Dump If IntraBC Is Used");
115 static const arg_def_t dump_palette_arg =
116 ARG_DEF(
"plt",
"palette", 0,
"Dump Palette Size");
117 static const arg_def_t dump_uv_palette_arg =
118 ARG_DEF(
"uvp",
"uv_palette", 0,
"Dump UV Palette Size");
119 static const arg_def_t dump_bits_arg =
120 ARG_DEF(
"sb",
"sb_bits", 0,
"Dump Bits of each superblock");
121 static const arg_def_t usage_arg = ARG_DEF(
"h",
"help", 0,
"Help");
122 static const arg_def_t skip_non_transform_arg = ARG_DEF(
123 "snt",
"skip_non_transform", 1,
"Skip is counted as a non transform.");
124 static const arg_def_t combined_arg =
125 ARG_DEF(
"comb",
"combined", 1,
"combinining parameters into one output.");
127 int combined_parm_list[15];
128 int combined_parm_count = 0;
130 static const arg_def_t *main_args[] = { &limit_arg,
133 #if CONFIG_ACCOUNTING
134 &dump_accounting_arg,
136 &dump_block_size_arg,
137 &dump_transform_size_arg,
138 &dump_transform_type_arg,
141 &dump_motion_mode_arg,
142 &dump_compound_type_arg,
146 &dump_dual_filter_type_arg,
148 &dump_reference_frame_arg,
149 &dump_motion_vectors_arg,
154 &dump_uv_palette_arg,
157 &skip_non_transform_arg,
160 #define ENUM(name) { #name, name }
161 #define LAST_ENUM { NULL, 0 }
162 typedef struct map_entry {
167 const map_entry refs_map[] = {
168 ENUM(INTRA_FRAME), ENUM(LAST_FRAME), ENUM(LAST2_FRAME),
169 ENUM(LAST3_FRAME), ENUM(GOLDEN_FRAME), ENUM(BWDREF_FRAME),
170 ENUM(ALTREF2_FRAME), ENUM(ALTREF_FRAME), LAST_ENUM
173 const map_entry block_size_map[] = {
174 ENUM(BLOCK_4X4), ENUM(BLOCK_4X8), ENUM(BLOCK_8X4),
175 ENUM(BLOCK_8X8), ENUM(BLOCK_8X16), ENUM(BLOCK_16X8),
176 ENUM(BLOCK_16X16), ENUM(BLOCK_16X32), ENUM(BLOCK_32X16),
177 ENUM(BLOCK_32X32), ENUM(BLOCK_32X64), ENUM(BLOCK_64X32),
178 ENUM(BLOCK_64X64), ENUM(BLOCK_64X128), ENUM(BLOCK_128X64),
179 ENUM(BLOCK_128X128), ENUM(BLOCK_4X16), ENUM(BLOCK_16X4),
180 ENUM(BLOCK_8X32), ENUM(BLOCK_32X8), ENUM(BLOCK_16X64),
181 ENUM(BLOCK_64X16), LAST_ENUM
186 const map_entry tx_size_map[] = {
187 ENUM(TX_4X4), ENUM(TX_8X8), ENUM(TX_16X16), ENUM(TX_32X32),
188 ENUM(TX_64X64), ENUM(TX_4X8), ENUM(TX_8X4), ENUM(TX_8X16),
189 ENUM(TX_16X8), ENUM(TX_16X32), ENUM(TX_32X16), ENUM(TX_32X64),
190 ENUM(TX_64X32), ENUM(TX_4X16), ENUM(TX_16X4), ENUM(TX_8X32),
191 ENUM(TX_32X8), ENUM(TX_16X64), ENUM(TX_64X16), LAST_ENUM
194 const map_entry tx_type_map[] = { ENUM(DCT_DCT),
200 ENUM(FLIPADST_FLIPADST),
211 const map_entry dual_filter_map[] = { ENUM(REG_REG), ENUM(REG_SMOOTH),
212 ENUM(REG_SHARP), ENUM(SMOOTH_REG),
213 ENUM(SMOOTH_SMOOTH), ENUM(SMOOTH_SHARP),
214 ENUM(SHARP_REG), ENUM(SHARP_SMOOTH),
215 ENUM(SHARP_SHARP), LAST_ENUM };
217 const map_entry prediction_mode_map[] = {
218 ENUM(DC_PRED), ENUM(V_PRED), ENUM(H_PRED),
219 ENUM(D45_PRED), ENUM(D135_PRED), ENUM(D113_PRED),
220 ENUM(D157_PRED), ENUM(D203_PRED), ENUM(D67_PRED),
221 ENUM(SMOOTH_PRED), ENUM(SMOOTH_V_PRED), ENUM(SMOOTH_H_PRED),
222 ENUM(PAETH_PRED), ENUM(NEARESTMV), ENUM(NEARMV),
223 ENUM(GLOBALMV), ENUM(NEWMV), ENUM(NEAREST_NEARESTMV),
224 ENUM(NEAR_NEARMV), ENUM(NEAREST_NEWMV), ENUM(NEW_NEARESTMV),
225 ENUM(NEAR_NEWMV), ENUM(NEW_NEARMV), ENUM(GLOBAL_GLOBALMV),
226 ENUM(NEW_NEWMV), ENUM(INTRA_INVALID), LAST_ENUM
229 const map_entry motion_mode_map[] = { ENUM(SIMPLE_TRANSLATION),
234 const map_entry compound_type_map[] = { ENUM(COMPOUND_AVERAGE),
235 ENUM(COMPOUND_WEDGE),
236 ENUM(COMPOUND_DIFFWTD), LAST_ENUM };
238 const map_entry uv_prediction_mode_map[] = {
239 ENUM(UV_DC_PRED), ENUM(UV_V_PRED),
240 ENUM(UV_H_PRED), ENUM(UV_D45_PRED),
241 ENUM(UV_D135_PRED), ENUM(UV_D113_PRED),
242 ENUM(UV_D157_PRED), ENUM(UV_D203_PRED),
243 ENUM(UV_D67_PRED), ENUM(UV_SMOOTH_PRED),
244 ENUM(UV_SMOOTH_V_PRED), ENUM(UV_SMOOTH_H_PRED),
245 ENUM(UV_PAETH_PRED), ENUM(UV_CFL_PRED),
246 ENUM(UV_MODE_INVALID), LAST_ENUM
251 const map_entry skip_map[] = { ENUM(SKIP), ENUM(NO_SKIP), LAST_ENUM };
253 const map_entry intrabc_map[] = { {
"INTRABC", 1 },
257 const map_entry palette_map[] = {
258 {
"ZERO_COLORS", 0 }, {
"TWO_COLORS", 2 }, {
"THREE_COLORS", 3 },
259 {
"FOUR_COLORS", 4 }, {
"FIVE_COLORS", 5 }, {
"SIX_COLORS", 6 },
260 {
"SEVEN_COLORS", 7 }, {
"EIGHT_COLORS", 8 }, LAST_ENUM
263 const map_entry config_map[] = { ENUM(MI_SIZE), LAST_ENUM };
265 static const char *exec_name;
271 struct parm_offset parm_offsets[] = {
272 {
"blockSize", offsetof(insp_mi_data, bsize) },
273 {
"transformSize", offsetof(insp_mi_data, tx_size) },
274 {
"transformType", offsetof(insp_mi_data, tx_type) },
275 {
"dualFilterType", offsetof(insp_mi_data, dual_filter_type) },
276 {
"mode", offsetof(insp_mi_data, mode) },
277 {
"uv_mode", offsetof(insp_mi_data, uv_mode) },
278 {
"motion_mode", offsetof(insp_mi_data, motion_mode) },
279 {
"compound_type", offsetof(insp_mi_data, compound_type) },
280 {
"referenceFrame", offsetof(insp_mi_data, ref_frame) },
281 {
"skip", offsetof(insp_mi_data, skip) },
282 {
"sb_bits", offsetof(insp_mi_data, sb_bits) },
284 int parm_count =
sizeof(parm_offsets) /
sizeof(parm_offsets[0]);
286 static int convert_to_indices(
char *str,
int *indices,
int maxCount,
290 char *comma = strchr(str,
',');
291 int length = (comma ? (int)(comma - str) : (int)strlen(str));
293 for (i = 0; i < parm_count; ++i) {
294 if (!strncmp(str, parm_offsets[i].parm, length)) {
298 if (i == parm_count)
return 0;
299 indices[(*count)++] = i;
300 if (*count > maxCount)
return 0;
302 }
while (strlen(str) > 0);
306 insp_frame_data frame_data;
308 int decoded_frame_count = 0;
310 AvxVideoReader *reader = NULL;
311 const AvxVideoInfo *info = NULL;
314 static void on_frame_decoded_dump(
char *json) {
315 #ifdef __EMSCRIPTEN__
316 EM_ASM_({ Module.on_frame_decoded_json($0); }, json);
324 static int put_str(
char *buffer,
const char *str) {
326 for (i = 0; str[i] !=
'\0'; i++) {
332 static int put_str_with_escape(
char *buffer,
const char *str) {
335 for (i = 0; str[i] !=
'\0'; i++) {
338 }
else if (str[i] ==
'"' || str[i] ==
'\\') {
341 buffer[j++] = str[i];
346 static int put_num(
char *buffer,
char prefix,
int num,
char suffix) {
362 buf[i++] =
'0' + (num % 10);
383 static int put_map(
char *buffer,
const map_entry *map) {
385 const map_entry *entry = map;
386 while (entry->name != NULL) {
388 buf += put_str(buf, entry->name);
390 buf += put_num(buf,
':', entry->value, 0);
392 if (entry->name != NULL) {
396 return (
int)(buf - buffer);
400 static int put_reference_frame(
char *buffer) {
401 const int mi_rows = frame_data.mi_rows;
402 const int mi_cols = frame_data.mi_cols;
405 buf += put_str(buf,
" \"referenceFrameMap\": {");
406 buf += put_map(buf, refs_map);
407 buf += put_str(buf,
"},\n");
408 buf += put_str(buf,
" \"referenceFrame\": [");
409 for (r = 0; r < mi_rows; ++r) {
411 for (c = 0; c < mi_cols; ++c) {
412 insp_mi_data *mi = &frame_data.mi_grid[r * mi_cols + c];
413 buf += put_num(buf,
'[', mi->ref_frame[0], 0);
414 buf += put_num(buf,
',', mi->ref_frame[1],
']');
416 for (t = c + 1; t < mi_cols; ++t) {
417 insp_mi_data *next_mi = &frame_data.mi_grid[r * mi_cols + t];
418 if (mi->ref_frame[0] != next_mi->ref_frame[0] ||
419 mi->ref_frame[1] != next_mi->ref_frame[1]) {
425 buf += put_num(buf,
'[', t - c - 1,
']');
429 if (c < mi_cols - 1) *(buf++) =
',';
432 if (r < mi_rows - 1) *(buf++) =
',';
434 buf += put_str(buf,
"],\n");
435 return (
int)(buf - buffer);
439 static int put_motion_vectors(
char *buffer) {
440 const int mi_rows = frame_data.mi_rows;
441 const int mi_cols = frame_data.mi_cols;
444 buf += put_str(buf,
" \"motionVectors\": [");
445 for (r = 0; r < mi_rows; ++r) {
447 for (c = 0; c < mi_cols; ++c) {
448 insp_mi_data *mi = &frame_data.mi_grid[r * mi_cols + c];
449 buf += put_num(buf,
'[', mi->mv[0].col, 0);
450 buf += put_num(buf,
',', mi->mv[0].row, 0);
451 buf += put_num(buf,
',', mi->mv[1].col, 0);
452 buf += put_num(buf,
',', mi->mv[1].row,
']');
454 for (t = c + 1; t < mi_cols; ++t) {
455 insp_mi_data *next_mi = &frame_data.mi_grid[r * mi_cols + t];
456 if (mi->mv[0].col != next_mi->mv[0].col ||
457 mi->mv[0].row != next_mi->mv[0].row ||
458 mi->mv[1].col != next_mi->mv[1].col ||
459 mi->mv[1].row != next_mi->mv[1].row) {
465 buf += put_num(buf,
'[', t - c - 1,
']');
469 if (c < mi_cols - 1) *(buf++) =
',';
472 if (r < mi_rows - 1) *(buf++) =
',';
474 buf += put_str(buf,
"],\n");
475 return (
int)(buf - buffer);
478 static int put_combined(
char *buffer) {
479 const int mi_rows = frame_data.mi_rows;
480 const int mi_cols = frame_data.mi_cols;
483 buf += put_str(buf,
" \"");
484 for (p = 0; p < combined_parm_count; ++p) {
485 if (p) buf += put_str(buf,
"&");
486 buf += put_str(buf, parm_offsets[combined_parm_list[p]].parm);
488 buf += put_str(buf,
"\": [");
489 for (r = 0; r < mi_rows; ++r) {
491 for (c = 0; c < mi_cols; ++c) {
492 insp_mi_data *mi = &frame_data.mi_grid[r * mi_cols + c];
494 for (p = 0; p < combined_parm_count; ++p) {
495 if (p) *(buf++) =
',';
496 int16_t *v = (int16_t *)(((int8_t *)mi) +
497 parm_offsets[combined_parm_list[p]].offset);
498 buf += put_num(buf, 0, v[0], 0);
501 if (c < mi_cols - 1) *(buf++) =
',';
504 if (r < mi_rows - 1) *(buf++) =
',';
506 buf += put_str(buf,
"],\n");
507 return (
int)(buf - buffer);
510 static int put_block_info(
char *buffer,
const map_entry *map,
const char *name,
511 size_t offset,
int len) {
512 const int mi_rows = frame_data.mi_rows;
513 const int mi_cols = frame_data.mi_cols;
516 if (compress && len == 1) {
517 die(
"Can't encode scalars as arrays when RLE compression is enabled.");
520 buf += snprintf(buf, MAX_BUFFER,
" \"%sMap\": {", name);
521 buf += put_map(buf, map);
522 buf += put_str(buf,
"},\n");
524 buf += snprintf(buf, MAX_BUFFER,
" \"%s\": [", name);
525 for (r = 0; r < mi_rows; ++r) {
527 for (c = 0; c < mi_cols; ++c) {
528 insp_mi_data *mi = &frame_data.mi_grid[r * mi_cols + c];
529 int16_t *v = (int16_t *)(((int8_t *)mi) + offset);
531 buf += put_num(buf, 0, v[0], 0);
533 buf += put_str(buf,
"[");
534 for (i = 0; i < len; i++) {
535 buf += put_num(buf, 0, v[i], 0);
537 buf += put_str(buf,
",");
540 buf += put_str(buf,
"]");
543 for (t = c + 1; t < mi_cols; ++t) {
544 insp_mi_data *next_mi = &frame_data.mi_grid[r * mi_cols + t];
545 int16_t *nv = (int16_t *)(((int8_t *)next_mi) + offset);
548 same = v[0] == nv[0];
550 for (i = 0; i < len; i++) {
551 same = v[i] == nv[i];
563 buf += put_num(buf,
'[', t - c - 1,
']');
567 if (c < mi_cols - 1) *(buf++) =
',';
570 if (r < mi_rows - 1) *(buf++) =
',';
572 buf += put_str(buf,
"],\n");
573 return (
int)(buf - buffer);
576 #if CONFIG_ACCOUNTING
577 static int put_accounting(
char *buffer) {
580 const Accounting *accounting = frame_data.accounting;
581 if (accounting == NULL) {
585 const int num_syms = accounting->syms.num_syms;
586 const int num_strs = accounting->syms.dictionary.num_strs;
587 buf += put_str(buf,
" \"symbolsMap\": [");
588 for (i = 0; i < num_strs; i++) {
589 buf += snprintf(buf, MAX_BUFFER,
"\"%s\"",
590 accounting->syms.dictionary.strs[i]);
591 if (i < num_strs - 1) *(buf++) =
',';
593 buf += put_str(buf,
"],\n");
594 buf += put_str(buf,
" \"symbols\": [\n ");
595 AccountingSymbolContext context;
598 AccountingSymbol *sym;
599 for (i = 0; i < num_syms; i++) {
600 sym = &accounting->syms.syms[i];
601 if (memcmp(&context, &sym->context,
sizeof(AccountingSymbolContext)) != 0) {
602 buf += put_num(buf,
'[', sym->context.x, 0);
603 buf += put_num(buf,
',', sym->context.y,
']');
605 buf += put_num(buf,
'[', sym->id, 0);
606 buf += put_num(buf,
',', sym->bits, 0);
607 buf += put_num(buf,
',', sym->samples,
']');
609 context = sym->context;
610 if (i < num_syms - 1) *(buf++) =
',';
612 buf += put_str(buf,
"],\n");
613 return (
int)(buf - buffer);
617 int skip_non_transform = 0;
619 static void inspect(
void *pbi,
void *data) {
621 ifd_inspect(&frame_data, pbi, skip_non_transform);
625 if (frame_data.show_existing_frame)
return;
630 char *buffer = malloc(MAX_BUFFER);
632 fprintf(stderr,
"Error allocating inspect info buffer\n");
636 buf += put_str(buf,
"{\n");
637 if (layers & BLOCK_SIZE_LAYER) {
638 buf += put_block_info(buf, block_size_map,
"blockSize",
639 offsetof(insp_mi_data, bsize), 0);
641 if (layers & TRANSFORM_SIZE_LAYER) {
642 buf += put_block_info(buf, tx_size_map,
"transformSize",
643 offsetof(insp_mi_data, tx_size), 0);
645 if (layers & TRANSFORM_TYPE_LAYER) {
646 buf += put_block_info(buf, tx_type_map,
"transformType",
647 offsetof(insp_mi_data, tx_type), 0);
649 if (layers & DUAL_FILTER_LAYER) {
650 buf += put_block_info(buf, dual_filter_map,
"dualFilterType",
651 offsetof(insp_mi_data, dual_filter_type), 0);
653 if (layers & MODE_LAYER) {
654 buf += put_block_info(buf, prediction_mode_map,
"mode",
655 offsetof(insp_mi_data, mode), 0);
657 if (layers & UV_MODE_LAYER) {
658 buf += put_block_info(buf, uv_prediction_mode_map,
"uv_mode",
659 offsetof(insp_mi_data, uv_mode), 0);
661 if (layers & MOTION_MODE_LAYER) {
662 buf += put_block_info(buf, motion_mode_map,
"motion_mode",
663 offsetof(insp_mi_data, motion_mode), 0);
665 if (layers & COMPOUND_TYPE_LAYER) {
666 buf += put_block_info(buf, compound_type_map,
"compound_type",
667 offsetof(insp_mi_data, compound_type), 0);
669 if (layers & SKIP_LAYER) {
671 put_block_info(buf, skip_map,
"skip", offsetof(insp_mi_data, skip), 0);
673 if (layers & FILTER_LAYER) {
675 put_block_info(buf, NULL,
"filter", offsetof(insp_mi_data, filter), 2);
677 if (layers & CDEF_LAYER) {
678 buf += put_block_info(buf, NULL,
"cdef_level",
679 offsetof(insp_mi_data, cdef_level), 0);
680 buf += put_block_info(buf, NULL,
"cdef_strength",
681 offsetof(insp_mi_data, cdef_strength), 0);
683 if (layers & CFL_LAYER) {
684 buf += put_block_info(buf, NULL,
"cfl_alpha_idx",
685 offsetof(insp_mi_data, cfl_alpha_idx), 0);
686 buf += put_block_info(buf, NULL,
"cfl_alpha_sign",
687 offsetof(insp_mi_data, cfl_alpha_sign), 0);
689 if (layers & Q_INDEX_LAYER) {
690 buf += put_block_info(buf, NULL,
"delta_q",
691 offsetof(insp_mi_data, current_qindex), 0);
693 if (layers & SEGMENT_ID_LAYER) {
694 buf += put_block_info(buf, NULL,
"seg_id",
695 offsetof(insp_mi_data, segment_id), 0);
697 if (layers & MOTION_VECTORS_LAYER) {
698 buf += put_motion_vectors(buf);
700 if (layers & INTRABC_LAYER) {
701 buf += put_block_info(buf, intrabc_map,
"intrabc",
702 offsetof(insp_mi_data, intrabc), 0);
704 if (layers & PALETTE_LAYER) {
705 buf += put_block_info(buf, palette_map,
"palette",
706 offsetof(insp_mi_data, palette), 0);
708 if (layers & UV_PALETTE_LAYER) {
709 buf += put_block_info(buf, palette_map,
"uv_palette",
710 offsetof(insp_mi_data, uv_palette), 0);
712 if (layers & BITS_LAYER) {
713 buf += put_block_info(buf, NULL,
"sb_bits", offsetof(insp_mi_data, sb_bits),
716 if (combined_parm_count > 0) buf += put_combined(buf);
717 if (layers & REFERENCE_FRAME_LAYER) {
718 buf += put_block_info(buf, refs_map,
"referenceFrame",
719 offsetof(insp_mi_data, ref_frame), 2);
721 #if CONFIG_ACCOUNTING
722 if (layers & ACCOUNTING_LAYER) {
723 buf += put_accounting(buf);
727 snprintf(buf, MAX_BUFFER,
" \"frame\": %d,\n", frame_data.frame_number);
728 buf += snprintf(buf, MAX_BUFFER,
" \"showFrame\": %d,\n",
729 frame_data.show_frame);
730 buf += snprintf(buf, MAX_BUFFER,
" \"frameType\": %d,\n",
731 frame_data.frame_type);
732 buf += snprintf(buf, MAX_BUFFER,
" \"baseQIndex\": %d,\n",
733 frame_data.base_qindex);
734 buf += snprintf(buf, MAX_BUFFER,
" \"tileCols\": %d,\n",
735 frame_data.tile_mi_cols);
736 buf += snprintf(buf, MAX_BUFFER,
" \"tileRows\": %d,\n",
737 frame_data.tile_mi_rows);
738 buf += snprintf(buf, MAX_BUFFER,
" \"deltaQPresentFlag\": %d,\n",
739 frame_data.delta_q_present_flag);
740 buf += snprintf(buf, MAX_BUFFER,
" \"deltaQRes\": %d,\n",
741 frame_data.delta_q_res);
742 buf += put_str(buf,
" \"config\": {");
743 buf += put_map(buf, config_map);
744 buf += put_str(buf,
"},\n");
745 buf += put_str(buf,
" \"configString\": \"");
747 buf += put_str(buf,
"\"\n");
748 decoded_frame_count++;
749 buf += put_str(buf,
"},\n");
751 on_frame_decoded_dump(buffer);
755 static void ifd_init_cb(
void) {
762 EMSCRIPTEN_KEEPALIVE
int open_file(
char *file);
765 int open_file(
char *file) {
768 file =
"/tmp/input.ivf";
770 reader = aom_video_reader_open(file);
771 if (!reader) die(
"Failed to open %s for reading.", file);
772 info = aom_video_reader_get_info(reader);
774 if (!decoder) die(
"Unknown input codec.");
777 die(
"Failed to initialize decoder.");
778 ifd_init(&frame_data, info->frame_width, info->frame_height);
785 const unsigned char *frame;
786 const unsigned char *end_frame;
787 size_t frame_size = 0;
790 EMSCRIPTEN_KEEPALIVE
int read_frame(
void);
793 int read_frame(
void) {
800 if (!aom_video_reader_read_frame(reader))
return EXIT_FAILURE;
801 frame = aom_video_reader_get_frame(reader, &frame_size);
804 end_frame = frame + frame_size;
809 die_codec(&codec,
"Failed to decode frame.");
813 frame_size = end_frame - frame;
814 if (frame == end_frame) have_frame = 0;
817 int got_any_frames = 0;
819 ref_dec.idx = adr.
idx;
824 if (ref_dec.idx == -1) {
830 img = frame_img = &ref_dec.img;
834 if (!got_any_frames) {
840 EMSCRIPTEN_KEEPALIVE
const char *get_aom_codec_build_config(
void);
843 const char *get_aom_codec_build_config(
void) {
847 EMSCRIPTEN_KEEPALIVE
int get_bit_depth(
void);
850 int get_bit_depth(
void) {
return img->
bit_depth; }
852 EMSCRIPTEN_KEEPALIVE
int get_bits_per_sample(
void);
855 int get_bits_per_sample(
void) {
return img->
bps; }
857 EMSCRIPTEN_KEEPALIVE
int get_image_format(
void);
860 int get_image_format(
void) {
return img->
fmt; }
862 EMSCRIPTEN_KEEPALIVE
unsigned char *get_plane(
int plane);
865 unsigned char *get_plane(
int plane) {
return img->
planes[plane]; }
867 EMSCRIPTEN_KEEPALIVE
int get_plane_stride(
int plane);
870 int get_plane_stride(
int plane) {
return img->
stride[plane]; }
872 EMSCRIPTEN_KEEPALIVE
int get_plane_width(
int plane);
877 EMSCRIPTEN_KEEPALIVE
int get_plane_height(
int plane);
882 EMSCRIPTEN_KEEPALIVE
int get_frame_width(
void);
885 int get_frame_width(
void) {
return info->frame_width; }
887 EMSCRIPTEN_KEEPALIVE
int get_frame_height(
void);
890 int get_frame_height(
void) {
return info->frame_height; }
892 static void parse_args(
char **argv) {
895 (void)dump_accounting_arg;
897 for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) {
899 if (arg_match(&arg, &dump_block_size_arg, argi)) layers |= BLOCK_SIZE_LAYER;
900 #if CONFIG_ACCOUNTING
901 else if (arg_match(&arg, &dump_accounting_arg, argi))
902 layers |= ACCOUNTING_LAYER;
904 else if (arg_match(&arg, &dump_transform_size_arg, argi))
905 layers |= TRANSFORM_SIZE_LAYER;
906 else if (arg_match(&arg, &dump_transform_type_arg, argi))
907 layers |= TRANSFORM_TYPE_LAYER;
908 else if (arg_match(&arg, &dump_mode_arg, argi))
909 layers |= MODE_LAYER;
910 else if (arg_match(&arg, &dump_uv_mode_arg, argi))
911 layers |= UV_MODE_LAYER;
912 else if (arg_match(&arg, &dump_motion_mode_arg, argi))
913 layers |= MOTION_MODE_LAYER;
914 else if (arg_match(&arg, &dump_compound_type_arg, argi))
915 layers |= COMPOUND_TYPE_LAYER;
916 else if (arg_match(&arg, &dump_skip_arg, argi))
917 layers |= SKIP_LAYER;
918 else if (arg_match(&arg, &dump_filter_arg, argi))
919 layers |= FILTER_LAYER;
920 else if (arg_match(&arg, &dump_cdef_arg, argi))
921 layers |= CDEF_LAYER;
922 else if (arg_match(&arg, &dump_cfl_arg, argi))
924 else if (arg_match(&arg, &dump_reference_frame_arg, argi))
925 layers |= REFERENCE_FRAME_LAYER;
926 else if (arg_match(&arg, &dump_motion_vectors_arg, argi))
927 layers |= MOTION_VECTORS_LAYER;
928 else if (arg_match(&arg, &dump_dual_filter_type_arg, argi))
929 layers |= DUAL_FILTER_LAYER;
930 else if (arg_match(&arg, &dump_delta_q_arg, argi))
931 layers |= Q_INDEX_LAYER;
932 else if (arg_match(&arg, &dump_seg_id_arg, argi))
933 layers |= SEGMENT_ID_LAYER;
934 else if (arg_match(&arg, &dump_intrabc_arg, argi))
935 layers |= INTRABC_LAYER;
936 else if (arg_match(&arg, &dump_palette_arg, argi))
937 layers |= PALETTE_LAYER;
938 else if (arg_match(&arg, &dump_uv_palette_arg, argi))
939 layers |= UV_PALETTE_LAYER;
940 else if (arg_match(&arg, &dump_bits_arg, argi))
941 layers |= BITS_LAYER;
942 else if (arg_match(&arg, &dump_all_arg, argi))
943 layers |= ALL_LAYERS;
944 else if (arg_match(&arg, &compress_arg, argi))
946 else if (arg_match(&arg, &usage_arg, argi))
948 else if (arg_match(&arg, &limit_arg, argi))
949 stop_after = arg_parse_uint(&arg);
950 else if (arg_match(&arg, &skip_non_transform_arg, argi))
951 skip_non_transform = arg_parse_uint(&arg);
952 else if (arg_match(&arg, &combined_arg, argi))
954 (
char *)arg.val, combined_parm_list,
955 sizeof(combined_parm_list) /
sizeof(combined_parm_list[0]),
956 &combined_parm_count);
962 static const char *exec_name;
964 void usage_exit(
void) {
965 fprintf(stderr,
"Usage: %s src_filename <options>\n", exec_name);
966 fprintf(stderr,
"\nOptions:\n");
967 arg_show_usage(stderr, main_args);
972 int main(
int argc,
char **argv) {
979 if (stop_after && (decoded_frame_count >= stop_after))
break;
980 if (read_frame())
break;
989 EMSCRIPTEN_KEEPALIVE
void quit(
void);
994 aom_video_reader_close(reader);
997 EMSCRIPTEN_KEEPALIVE
void set_layers(LayerType v);
1000 void set_layers(LayerType v) { layers = v; }
1002 EMSCRIPTEN_KEEPALIVE
void set_compress(
int v);
1004 EMSCRIPTEN_KEEPALIVE
1005 void set_compress(
int v) { compress = v; }
Codec control function to get a pointer to a reference frame.
Definition: aom.h:51
Operation completed without error.
Definition: aom_codec.h:157
int show_existing
Definition: aomdx.h:84
aom_inspect_cb inspect_cb
Definition: aomdx.h:66
aom_image_t * aom_codec_get_frame(aom_codec_ctx_t *ctx, aom_codec_iter_t *iter)
Decoded frames iterator.
unsigned char * planes[3]
Definition: aom_image.h:244
int idx
Definition: aomdx.h:82
Codec context structure.
Definition: aom_codec.h:315
const unsigned char * buf
Definition: aomdx.h:80
Describes the decoder algorithm interface to applications.
Image Descriptor.
Definition: aom_image.h:211
aom_codec_err_t aom_codec_decode(aom_codec_ctx_t *ctx, const uint8_t *data, size_t data_sz, void *user_priv)
Decode data.
const struct aom_codec_iface aom_codec_iface_t
Codec interface structure.
Definition: aom_codec.h:271
#define aom_codec_dec_init(ctx, iface, cfg, flags)
Convenience macro for aom_codec_dec_init_ver()
Definition: aom_decoder.h:133
const char * aom_codec_iface_name(aom_codec_iface_t *iface)
Return the name for a given interface.
aom_codec_err_t aom_codec_destroy(aom_codec_ctx_t *ctx)
Destroy a codec instance.
Codec control function to set an aom_inspect_cb callback that is invoked each time a frame is decoded...
Definition: aomdx.h:382
int aom_img_plane_width(const aom_image_t *img, int plane)
Get the width of a plane.
void * inspect_ctx
Definition: aomdx.h:69
const char * aom_codec_build_config(void)
Return the build configuration.
AV1 specific reference frame data struct.
Definition: aom.h:89
int aom_img_plane_height(const aom_image_t *img, int plane)
Get the height of a plane.
Structure to hold inspection callback and context.
Definition: aomdx.h:64
const void * aom_codec_iter_t
Iterator.
Definition: aom_codec.h:305
int bps
Definition: aom_image.h:253
Provides definitions for using AOM or AV1 within the aom Decoder interface.
int stride[3]
Definition: aom_image.h:250
Structure to collect a buffer index when inspecting.
Definition: aomdx.h:78
unsigned int bit_depth
Definition: aom_image.h:223
aom_codec_err_t aom_codec_control(aom_codec_ctx_t *ctx, int ctrl_id,...)
Algorithm Control.
aom_img_fmt_t fmt
Definition: aom_image.h:212
struct Accounting Accounting
Definition: aomdx.h:50