24#include "config/aom_config.h"
31#include "common/args.h"
32#include "common/tools_common.h"
33#include "common/video_writer.h"
34#include "examples/encoder_util.h"
35#include "aom_ports/aom_timer.h"
36#include "av1/ratectrl_rtc.h"
38#define OPTION_BUFFER_SIZE 1024
41 const char *output_filename;
42 char options[OPTION_BUFFER_SIZE];
43 struct AvxInputContext input_ctx;
62static const arg_def_t outputfile =
63 ARG_DEF(
"o",
"output", 1,
"Output filename");
64static const arg_def_t frames_arg =
65 ARG_DEF(
"f",
"frames", 1,
"Number of frames to encode");
66static const arg_def_t threads_arg =
67 ARG_DEF(
"th",
"threads", 1,
"Number of threads to use");
68static const arg_def_t width_arg = ARG_DEF(
"w",
"width", 1,
"Source width");
69static const arg_def_t height_arg = ARG_DEF(
"h",
"height", 1,
"Source height");
70static const arg_def_t timebase_arg =
71 ARG_DEF(
"t",
"timebase", 1,
"Timebase (num/den)");
72static const arg_def_t bitrate_arg = ARG_DEF(
73 "b",
"target-bitrate", 1,
"Encoding bitrate, in kilobits per second");
74static const arg_def_t spatial_layers_arg =
75 ARG_DEF(
"sl",
"spatial-layers", 1,
"Number of spatial SVC layers");
76static const arg_def_t temporal_layers_arg =
77 ARG_DEF(
"tl",
"temporal-layers", 1,
"Number of temporal SVC layers");
78static const arg_def_t layering_mode_arg =
79 ARG_DEF(
"lm",
"layering-mode", 1,
"Temporal layering scheme.");
80static const arg_def_t kf_dist_arg =
81 ARG_DEF(
"k",
"kf-dist", 1,
"Number of frames between keyframes");
82static const arg_def_t scale_factors_arg =
83 ARG_DEF(
"r",
"scale-factors", 1,
"Scale factors (lowest to highest layer)");
84static const arg_def_t min_q_arg =
85 ARG_DEF(NULL,
"min-q", 1,
"Minimum quantizer");
86static const arg_def_t max_q_arg =
87 ARG_DEF(NULL,
"max-q", 1,
"Maximum quantizer");
88static const arg_def_t speed_arg =
89 ARG_DEF(
"sp",
"speed", 1,
"Speed configuration");
90static const arg_def_t aqmode_arg =
91 ARG_DEF(
"aq",
"aqmode", 1,
"AQ mode off/on");
92static const arg_def_t bitrates_arg =
93 ARG_DEF(
"bl",
"bitrates", 1,
94 "Bitrates[spatial_layer * num_temporal_layer + temporal_layer]");
95static const arg_def_t dropframe_thresh_arg =
96 ARG_DEF(NULL,
"drop-frame", 1,
"Temporal resampling threshold (buf %)");
97static const arg_def_t error_resilient_arg =
98 ARG_DEF(NULL,
"error-resilient", 1,
"Error resilient flag");
99static const arg_def_t output_obu_arg =
100 ARG_DEF(NULL,
"output-obu", 1,
101 "Write OBUs when set to 1. Otherwise write IVF files.");
102static const arg_def_t test_decode_arg =
103 ARG_DEF(NULL,
"test-decode", 1,
104 "Attempt to test decoding the output when set to 1. Default is 1.");
105static const arg_def_t psnr_arg =
106 ARG_DEF(NULL,
"psnr", -1,
"Show PSNR in status line.");
107static const arg_def_t ext_rc_arg =
108 ARG_DEF(NULL,
"use-ext-rc", 0,
"Use external rate control.");
109static const struct arg_enum_list tune_content_enum[] = {
110 {
"default", AOM_CONTENT_DEFAULT },
111 {
"screen", AOM_CONTENT_SCREEN },
112 {
"film", AOM_CONTENT_FILM },
115static const arg_def_t tune_content_arg = ARG_DEF_ENUM(
116 NULL,
"tune-content", 1,
"Tune content type", tune_content_enum);
118#if CONFIG_AV1_HIGHBITDEPTH
119static const struct arg_enum_list bitdepth_enum[] = { {
"8",
AOM_BITS_8 },
123static const arg_def_t bitdepth_arg = ARG_DEF_ENUM(
124 "d",
"bit-depth", 1,
"Bit depth for codec 8 or 10. ", bitdepth_enum);
127static const arg_def_t *svc_args[] = {
128 &frames_arg, &outputfile, &width_arg,
129 &height_arg, &timebase_arg, &bitrate_arg,
130 &spatial_layers_arg, &kf_dist_arg, &scale_factors_arg,
131 &min_q_arg, &max_q_arg, &temporal_layers_arg,
132 &layering_mode_arg, &threads_arg, &aqmode_arg,
133#if CONFIG_AV1_HIGHBITDEPTH
136 &speed_arg, &bitrates_arg, &dropframe_thresh_arg,
137 &error_resilient_arg, &output_obu_arg, &test_decode_arg,
138 &tune_content_arg, &psnr_arg, NULL,
141#define zero(Dest) memset(&(Dest), 0, sizeof(Dest))
143static const char *exec_name;
145void usage_exit(
void) {
146 fprintf(stderr,
"Usage: %s <options> input_filename -o output_filename\n",
148 fprintf(stderr,
"Options:\n");
149 arg_show_usage(stderr, svc_args);
153static int file_is_y4m(
const char detect[4]) {
154 return memcmp(detect,
"YUV4", 4) == 0;
157static int fourcc_is_ivf(
const char detect[4]) {
158 if (memcmp(detect,
"DKIF", 4) == 0) {
164static const int option_max_values[ALL_OPTION_TYPES] = { 63, INT_MAX, INT_MAX,
167static const int option_min_values[ALL_OPTION_TYPES] = { 0, 0, 1, 0 };
169static void open_input_file(
struct AvxInputContext *input,
172 input->file = strcmp(input->filename,
"-") ? fopen(input->filename,
"rb")
173 : set_binary_mode(stdin);
175 if (!input->file) fatal(
"Failed to open input file");
177 if (!fseeko(input->file, 0, SEEK_END)) {
181 input->length = ftello(input->file);
186 input->pixel_aspect_ratio.numerator = 1;
187 input->pixel_aspect_ratio.denominator = 1;
192 input->detect.buf_read = fread(input->detect.buf, 1, 4, input->file);
193 input->detect.position = 0;
195 if (input->detect.buf_read == 4 && file_is_y4m(input->detect.buf)) {
196 if (y4m_input_open(&input->y4m, input->file, input->detect.buf, 4, csp,
197 input->only_i420) >= 0) {
198 input->file_type = FILE_TYPE_Y4M;
199 input->width = input->y4m.pic_w;
200 input->height = input->y4m.pic_h;
201 input->pixel_aspect_ratio.numerator = input->y4m.par_n;
202 input->pixel_aspect_ratio.denominator = input->y4m.par_d;
203 input->framerate.numerator = input->y4m.fps_n;
204 input->framerate.denominator = input->y4m.fps_d;
205 input->fmt = input->y4m.aom_fmt;
206 input->bit_depth = static_cast<aom_bit_depth_t>(input->y4m.bit_depth);
208 fatal(
"Unsupported Y4M stream.");
210 }
else if (input->detect.buf_read == 4 && fourcc_is_ivf(input->detect.buf)) {
211 fatal(
"IVF is not supported as input.");
213 input->file_type = FILE_TYPE_RAW;
217static aom_codec_err_t extract_option(LAYER_OPTION_TYPE type,
char *input,
218 int *value0,
int *value1) {
219 if (type == SCALE_FACTOR) {
220 *value0 = (int)strtol(input, &input, 10);
222 *value1 = (int)strtol(input, &input, 10);
224 if (*value0 < option_min_values[SCALE_FACTOR] ||
225 *value1 < option_min_values[SCALE_FACTOR] ||
226 *value0 > option_max_values[SCALE_FACTOR] ||
227 *value1 > option_max_values[SCALE_FACTOR] ||
231 *value0 = atoi(input);
232 if (*value0 < option_min_values[type] || *value0 > option_max_values[type])
240 int *option0,
int *option1) {
244 const char *delim =
",";
252 if (input == NULL || option0 == NULL ||
253 (option1 == NULL && type == SCALE_FACTOR))
256 const size_t input_length = strlen(input);
257 input_string =
reinterpret_cast<char *
>(malloc(input_length + 1));
259 memcpy(input_string, input, input_length + 1);
260 token = strtok(input_string, delim);
261 for (i = 0; i < num_layers; ++i) {
263 res = extract_option(type, token, option0 + i, option1 + i);
265 token = strtok(NULL, delim);
275static void parse_command_line(
int argc,
const char **argv_,
283 char string_options[1024] = { 0 };
288 app_input->layering_mode = 0;
289 app_input->output_obu = 0;
290 app_input->decode = 1;
295 argv = argv_dup(argc - 1, argv_ + 1);
297 fprintf(stderr,
"Error allocating argument list\n");
300 for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) {
303 if (arg_match(&arg, &outputfile, argi)) {
304 app_input->output_filename = arg.val;
305 }
else if (arg_match(&arg, &width_arg, argi)) {
306 enc_cfg->
g_w = arg_parse_uint(&arg);
307 }
else if (arg_match(&arg, &height_arg, argi)) {
308 enc_cfg->
g_h = arg_parse_uint(&arg);
309 }
else if (arg_match(&arg, &timebase_arg, argi)) {
310 enc_cfg->
g_timebase = arg_parse_rational(&arg);
311 }
else if (arg_match(&arg, &bitrate_arg, argi)) {
313 }
else if (arg_match(&arg, &spatial_layers_arg, argi)) {
315 }
else if (arg_match(&arg, &temporal_layers_arg, argi)) {
317 }
else if (arg_match(&arg, &speed_arg, argi)) {
318 app_input->speed = arg_parse_uint(&arg);
319 if (app_input->speed > 11) {
320 aom_tools_warn(
"Mapping speed %d to speed 11.\n", app_input->speed);
322 }
else if (arg_match(&arg, &aqmode_arg, argi)) {
323 app_input->aq_mode = arg_parse_uint(&arg);
324 }
else if (arg_match(&arg, &threads_arg, argi)) {
325 enc_cfg->
g_threads = arg_parse_uint(&arg);
326 }
else if (arg_match(&arg, &layering_mode_arg, argi)) {
327 app_input->layering_mode = arg_parse_int(&arg);
328 }
else if (arg_match(&arg, &kf_dist_arg, argi)) {
331 }
else if (arg_match(&arg, &scale_factors_arg, argi)) {
336 die(
"Failed to parse scale factors: %s\n",
339 }
else if (arg_match(&arg, &min_q_arg, argi)) {
341 }
else if (arg_match(&arg, &max_q_arg, argi)) {
343#if CONFIG_AV1_HIGHBITDEPTH
344 }
else if (arg_match(&arg, &bitdepth_arg, argi)) {
357 die(
"Error: Invalid bit depth selected (%d)\n", enc_cfg->
g_bit_depth);
360 }
else if (arg_match(&arg, &dropframe_thresh_arg, argi)) {
362 }
else if (arg_match(&arg, &error_resilient_arg, argi)) {
365 die(
"Invalid value for error resilient (0, 1): %d.",
367 }
else if (arg_match(&arg, &output_obu_arg, argi)) {
368 app_input->output_obu = arg_parse_uint(&arg);
369 if (app_input->output_obu != 0 && app_input->output_obu != 1)
370 die(
"Invalid value for obu output flag (0, 1): %d.",
371 app_input->output_obu);
372 }
else if (arg_match(&arg, &test_decode_arg, argi)) {
373 app_input->decode = arg_parse_uint(&arg);
374 if (app_input->decode != 0 && app_input->decode != 1)
375 die(
"Invalid value for test decode flag (0, 1): %d.",
377 }
else if (arg_match(&arg, &tune_content_arg, argi)) {
378 app_input->tune_content = arg_parse_enum_or_int(&arg);
379 printf(
"tune content %d\n", app_input->tune_content);
380 }
else if (arg_match(&arg, &psnr_arg, argi)) {
381 app_input->show_psnr = 1;
382 }
else if (arg_match(&arg, &ext_rc_arg, argi)) {
383 app_input->use_external_rc =
true;
390 for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) {
392 if (arg_match(&arg, &bitrates_arg, argi)) {
404 if (strlen(string_options) > 0)
405 strncpy(app_input->options, string_options, OPTION_BUFFER_SIZE);
408 for (argi = argv; *argi; ++argi)
409 if (argi[0][0] ==
'-' && strlen(argi[0]) > 1)
410 die(
"Error: Unrecognized option %s\n", *argi);
412 if (argv[0] == NULL) {
416 app_input->input_ctx.filename = argv[0];
420 if (app_input->input_ctx.file_type == FILE_TYPE_Y4M) {
421 enc_cfg->
g_w = app_input->input_ctx.width;
422 enc_cfg->
g_h = app_input->input_ctx.height;
425 if (enc_cfg->
g_w < 16 || enc_cfg->
g_w % 2 || enc_cfg->
g_h < 16 ||
427 die(
"Invalid resolution: %d x %d\n", enc_cfg->
g_w, enc_cfg->
g_h);
432 "width %u, height: %u\n"
433 "num: %d, den: %d, bitrate: %u\n"
441static int mode_to_num_temporal_layers[12] = {
442 1, 2, 3, 3, 2, 1, 1, 3, 3, 3, 3, 3,
444static int mode_to_num_spatial_layers[12] = {
445 1, 1, 1, 1, 1, 2, 3, 2, 3, 3, 3, 3,
449struct RateControlMetrics {
466 double avg_st_encoding_bitrate;
468 double variance_st_encoding_bitrate;
476static const int REF_FRAMES = 8;
478static const int INTER_REFS_PER_FRAME = 7;
491static int read_frame(
struct AvxInputContext *input_ctx,
aom_image_t *img) {
492 FILE *f = input_ctx->file;
493 y4m_input *y4m = &input_ctx->y4m;
496 if (input_ctx->file_type == FILE_TYPE_Y4M) {
497 if (y4m_input_fetch_frame(y4m, f, img) < 1)
return 0;
499 shortread = read_yuv_frame(input_ctx, img);
505static void close_input_file(
struct AvxInputContext *input) {
507 if (input->file_type == FILE_TYPE_Y4M) y4m_input_close(&input->y4m);
516static void set_rate_control_metrics(
struct RateControlMetrics *rc,
517 double framerate,
int ss_number_layers,
518 int ts_number_layers) {
520 ts_rate_decimator[0] = 1;
521 if (ts_number_layers == 2) {
522 ts_rate_decimator[0] = 2;
523 ts_rate_decimator[1] = 1;
525 if (ts_number_layers == 3) {
526 ts_rate_decimator[0] = 4;
527 ts_rate_decimator[1] = 2;
528 ts_rate_decimator[2] = 1;
532 for (
int sl = 0; sl < ss_number_layers; ++sl) {
533 int i = sl * ts_number_layers;
534 rc->layer_framerate[0] = framerate / ts_rate_decimator[0];
536 1000.0 * rc->layer_target_bitrate[i] / rc->layer_framerate[0];
537 for (
int tl = 0; tl < ts_number_layers; ++tl) {
538 i = sl * ts_number_layers + tl;
540 rc->layer_framerate[tl] = framerate / ts_rate_decimator[tl];
543 (rc->layer_target_bitrate[i] - rc->layer_target_bitrate[i - 1]) /
544 (rc->layer_framerate[tl] - rc->layer_framerate[tl - 1]);
546 rc->layer_input_frames[tl] = 0;
547 rc->layer_enc_frames[tl] = 0;
548 rc->layer_encoding_bitrate[i] = 0.0;
549 rc->layer_avg_frame_size[i] = 0.0;
550 rc->layer_avg_rate_mismatch[i] = 0.0;
553 rc->window_count = 0;
554 rc->window_size = 15;
555 rc->avg_st_encoding_bitrate = 0.0;
556 rc->variance_st_encoding_bitrate = 0.0;
559static void printout_rate_control_summary(
struct RateControlMetrics *rc,
560 int frame_cnt,
int ss_number_layers,
561 int ts_number_layers) {
562 int tot_num_frames = 0;
563 double perc_fluctuation = 0.0;
564 printf(
"Total number of processed frames: %d\n\n", frame_cnt - 1);
565 printf(
"Rate control layer stats for %d layer(s):\n\n", ts_number_layers);
566 for (
int sl = 0; sl < ss_number_layers; ++sl) {
568 for (
int tl = 0; tl < ts_number_layers; ++tl) {
569 int i = sl * ts_number_layers + tl;
570 const int num_dropped =
571 tl > 0 ? rc->layer_input_frames[tl] - rc->layer_enc_frames[tl]
572 : rc->layer_input_frames[tl] - rc->layer_enc_frames[tl] - 1;
573 tot_num_frames += rc->layer_input_frames[tl];
574 rc->layer_encoding_bitrate[i] = 0.001 * rc->layer_framerate[tl] *
575 rc->layer_encoding_bitrate[i] /
577 rc->layer_avg_frame_size[i] =
578 rc->layer_avg_frame_size[i] / rc->layer_enc_frames[tl];
579 rc->layer_avg_rate_mismatch[i] =
580 100.0 * rc->layer_avg_rate_mismatch[i] / rc->layer_enc_frames[tl];
581 printf(
"For layer#: %d %d \n", sl, tl);
582 printf(
"Bitrate (target vs actual): %d %f\n", rc->layer_target_bitrate[i],
583 rc->layer_encoding_bitrate[i]);
584 printf(
"Average frame size (target vs actual): %f %f\n", rc->layer_pfb[i],
585 rc->layer_avg_frame_size[i]);
586 printf(
"Average rate_mismatch: %f\n", rc->layer_avg_rate_mismatch[i]);
588 "Number of input frames, encoded (non-key) frames, "
589 "and perc dropped frames: %d %d %f\n",
590 rc->layer_input_frames[tl], rc->layer_enc_frames[tl],
591 100.0 * num_dropped / rc->layer_input_frames[tl]);
595 rc->avg_st_encoding_bitrate = rc->avg_st_encoding_bitrate / rc->window_count;
596 rc->variance_st_encoding_bitrate =
597 rc->variance_st_encoding_bitrate / rc->window_count -
598 (rc->avg_st_encoding_bitrate * rc->avg_st_encoding_bitrate);
599 perc_fluctuation = 100.0 * sqrt(rc->variance_st_encoding_bitrate) /
600 rc->avg_st_encoding_bitrate;
601 printf(
"Short-time stats, for window of %d frames:\n", rc->window_size);
602 printf(
"Average, rms-variance, and percent-fluct: %f %f %f\n",
603 rc->avg_st_encoding_bitrate, sqrt(rc->variance_st_encoding_bitrate),
605 if (frame_cnt - 1 != tot_num_frames)
606 die(
"Error: Number of input frames not equal to output!\n");
610static void set_layer_pattern(
614 int spatial_layer_id,
int is_key_frame,
int ksvc_mode,
int speed) {
617 int use_rps_example = 0;
619 int enable_longterm_temporal_ref = 1;
620 int shift = (layering_mode == 8) ? 2 : 0;
621 int simulcast_mode = (layering_mode == 11);
622 *use_svc_control = 1;
625 int base_count = superframe_cnt >> 2;
632 for (i = 0; i < INTER_REFS_PER_FRAME; i++) ref_frame_config->
ref_idx[i] = i;
633 for (i = 0; i < INTER_REFS_PER_FRAME; i++) ref_frame_config->
reference[i] = 0;
634 for (i = 0; i < REF_FRAMES; i++) ref_frame_config->
refresh[i] = 0;
641 switch (layering_mode) {
643 if (use_rps_example == 0) {
647 ref_frame_config->
refresh[0] = 1;
648 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
656 int last_idx_refresh = 0;
665 if (superframe_cnt > 1) last_idx = (superframe_cnt - 1) % sh;
667 last_idx_refresh = superframe_cnt % sh;
669 if (superframe_cnt > lag_gld) gld_idx = (superframe_cnt - lag_gld) % sh;
671 if (superframe_cnt > lag_alt)
672 alt_ref_idx = (superframe_cnt - lag_alt) % sh;
675 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
676 ref_frame_config->
ref_idx[i] = last_idx;
678 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = last_idx;
679 ref_frame_config->
ref_idx[SVC_LAST2_FRAME] = last_idx_refresh;
680 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = gld_idx;
681 ref_frame_config->
ref_idx[SVC_ALTREF_FRAME] = alt_ref_idx;
683 ref_frame_config->
refresh[last_idx_refresh] = 1;
685 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
686 ref_frame_config->
reference[SVC_ALTREF_FRAME] = 1;
687 ref_frame_config->
reference[SVC_GOLDEN_FRAME] = 1;
689 if (superframe_cnt % 200 == 0 && superframe_cnt > 0) {
690 ref_frame_config->
reference[SVC_LAST_FRAME] = 0;
691 ref_frame_config->
reference[SVC_ALTREF_FRAME] = 0;
692 ref_frame_config->
reference[SVC_GOLDEN_FRAME] = 1;
696 if (superframe_cnt % 400 == 0 && superframe_cnt > 0) {
697 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = gld_idx;
698 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
699 ref_frame_config->
reference[SVC_ALTREF_FRAME] = 0;
700 ref_frame_config->
reference[SVC_GOLDEN_FRAME] = 0;
710 base_count = superframe_cnt >> 1;
711 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = 3;
714 if (base_count > 0) {
715 lag_index = 5 + (base_count % 3);
716 if (superframe_cnt % 2 != 0) lag_index = 5 + ((base_count + 1) % 3);
719 ref_frame_config->
ref_idx[SVC_ALTREF_FRAME] = lag_index;
720 if (superframe_cnt % 2 == 0) {
723 ref_frame_config->
refresh[0] = 1;
724 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
726 ref_frame_config->
refresh[lag_index] = 1;
728 if (base_count % 32 == 0) ref_frame_config->
refresh[3] = 1;
732 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
736 ref_frame_config->
reference[SVC_GOLDEN_FRAME] = 1;
737 ref_frame_config->
reference[SVC_ALTREF_FRAME] = 1;
745 if (superframe_cnt % 4 == 0) {
749 ref_frame_config->
refresh[0] = 1;
750 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
751 }
else if ((superframe_cnt - 1) % 4 == 0) {
754 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
755 }
else if ((superframe_cnt - 2) % 4 == 0) {
758 ref_frame_config->
refresh[1] = 1;
759 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
760 }
else if ((superframe_cnt - 3) % 4 == 0) {
765 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 1;
766 ref_frame_config->
ref_idx[SVC_LAST2_FRAME] = 0;
767 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
778 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = 3;
781 if (base_count > 0) {
782 lag_index = 5 + (base_count % 3);
783 if (superframe_cnt % 4 != 0) lag_index = 5 + ((base_count + 1) % 3);
786 ref_frame_config->
ref_idx[SVC_ALTREF_FRAME] = lag_index;
787 if (superframe_cnt % 4 == 0) {
791 ref_frame_config->
refresh[0] = 1;
792 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
794 if (base_count % 10 == 0) ref_frame_config->
refresh[3] = 1;
796 ref_frame_config->
refresh[lag_index] = 1;
797 }
else if ((superframe_cnt - 1) % 4 == 0) {
800 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
801 }
else if ((superframe_cnt - 2) % 4 == 0) {
804 ref_frame_config->
refresh[1] = 1;
805 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
806 }
else if ((superframe_cnt - 3) % 4 == 0) {
811 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 1;
812 ref_frame_config->
ref_idx[SVC_LAST2_FRAME] = 0;
813 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
816 ref_frame_config->
reference[SVC_GOLDEN_FRAME] = 1;
817 ref_frame_config->
reference[SVC_ALTREF_FRAME] = 1;
830 if (superframe_cnt % 4 == 0) {
834 ref_frame_config->
refresh[0] = 1;
835 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
836 }
else if ((superframe_cnt - 1) % 4 == 0) {
839 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
840 }
else if ((superframe_cnt - 2) % 4 == 0) {
843 ref_frame_config->
refresh[3] = 1;
844 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
845 }
else if ((superframe_cnt - 3) % 4 == 0) {
848 ref_frame_config->
reference[SVC_GOLDEN_FRAME] = 1;
856 ref_frame_config->
refresh[0] = 1;
857 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
861 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 1;
862 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = 0;
863 ref_frame_config->
refresh[1] = 1;
864 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
865 ref_frame_config->
reference[SVC_GOLDEN_FRAME] = 1;
877 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
878 ref_frame_config->
ref_idx[i] = 0;
879 ref_frame_config->
refresh[0] = 1;
880 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
885 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
886 ref_frame_config->
ref_idx[i] = 0;
887 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 1;
888 ref_frame_config->
refresh[1] = 1;
889 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
890 ref_frame_config->
reference[SVC_GOLDEN_FRAME] = 1;
895 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
896 ref_frame_config->
ref_idx[i] = 1;
897 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 2;
898 ref_frame_config->
refresh[2] = 1;
899 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
900 ref_frame_config->
reference[SVC_GOLDEN_FRAME] = 1;
903 if (enable_longterm_temporal_ref) {
904 ref_frame_config->
ref_idx[SVC_ALTREF_FRAME] = REF_FRAMES - 1;
905 ref_frame_config->
reference[SVC_ALTREF_FRAME] = 1;
906 if (base_count % 10 == 0)
907 ref_frame_config->
refresh[REF_FRAMES - 1] = 1;
913 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
914 if (superframe_cnt % 4 == 0) {
920 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
921 ref_frame_config->
ref_idx[i] = 0;
922 ref_frame_config->
refresh[0] = 1;
925 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
926 ref_frame_config->
ref_idx[i] = 0;
927 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 1;
928 ref_frame_config->
refresh[1] = 1;
930 }
else if ((superframe_cnt - 1) % 4 == 0) {
934 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
935 ref_frame_config->
ref_idx[i] = 0;
936 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = 3;
937 ref_frame_config->
refresh[3] = 1;
942 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
943 ref_frame_config->
ref_idx[i] = 3;
944 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 1;
946 }
else if ((superframe_cnt - 2) % 4 == 0) {
953 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
954 ref_frame_config->
ref_idx[i] = 0;
955 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = 5 - shift;
956 ref_frame_config->
refresh[5 - shift] = 1;
961 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
962 ref_frame_config->
ref_idx[i] = 5 - shift;
963 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 1;
964 ref_frame_config->
ref_idx[SVC_LAST3_FRAME] = 6 - shift;
965 ref_frame_config->
refresh[6 - shift] = 1;
967 }
else if ((superframe_cnt - 3) % 4 == 0) {
974 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
975 ref_frame_config->
ref_idx[i] = 0;
976 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 5 - shift;
977 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = 3;
978 ref_frame_config->
refresh[3] = 1;
982 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
983 ref_frame_config->
ref_idx[i] = 0;
984 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 6 - shift;
985 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = 3;
1002 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
1003 if (superframe_cnt % 4 == 0) {
1009 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1010 ref_frame_config->
ref_idx[i] = 0;
1011 ref_frame_config->
refresh[0] = 1;
1016 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1017 ref_frame_config->
ref_idx[i] = 0;
1018 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 1;
1019 ref_frame_config->
refresh[1] = 1;
1024 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1025 ref_frame_config->
ref_idx[i] = 1;
1026 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 2;
1027 ref_frame_config->
refresh[2] = 1;
1029 }
else if ((superframe_cnt - 1) % 4 == 0) {
1036 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1037 ref_frame_config->
ref_idx[i] = 0;
1038 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = 3;
1039 ref_frame_config->
refresh[3] = 1;
1044 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1045 ref_frame_config->
ref_idx[i] = 3;
1046 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 1;
1047 ref_frame_config->
ref_idx[SVC_LAST2_FRAME] = 4;
1048 ref_frame_config->
refresh[4] = 1;
1053 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1054 ref_frame_config->
ref_idx[i] = 4;
1055 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 2;
1057 }
else if ((superframe_cnt - 2) % 4 == 0) {
1064 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1065 ref_frame_config->
ref_idx[i] = 0;
1066 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = 5 - shift;
1067 ref_frame_config->
refresh[5 - shift] = 1;
1072 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1073 ref_frame_config->
ref_idx[i] = 5 - shift;
1074 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 1;
1075 ref_frame_config->
ref_idx[SVC_LAST3_FRAME] = 6 - shift;
1076 ref_frame_config->
refresh[6 - shift] = 1;
1081 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1082 ref_frame_config->
ref_idx[i] = 6 - shift;
1083 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 2;
1084 ref_frame_config->
ref_idx[SVC_LAST3_FRAME] = 7 - shift;
1085 ref_frame_config->
refresh[7 - shift] = 1;
1087 }
else if ((superframe_cnt - 3) % 4 == 0) {
1094 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1095 ref_frame_config->
ref_idx[i] = 0;
1096 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 5 - shift;
1097 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = 3;
1098 ref_frame_config->
refresh[3] = 1;
1102 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1103 ref_frame_config->
ref_idx[i] = 0;
1104 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 6 - shift;
1105 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = 3;
1106 ref_frame_config->
ref_idx[SVC_LAST2_FRAME] = 4;
1107 ref_frame_config->
refresh[4] = 1;
1111 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1112 ref_frame_config->
ref_idx[i] = 0;
1113 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 7 - shift;
1114 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = 4;
1137 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1140 for (i = 0; i < REF_FRAMES; i++) ref_frame_config->
refresh[i] = 0;
1141 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1142 ref_frame_config->
ref_idx[i] = 0;
1149 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 0;
1150 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = 1;
1151 ref_frame_config->
refresh[0] = 1;
1152 ref_frame_config->
refresh[1] = 1;
1157 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 2;
1158 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = 3;
1159 ref_frame_config->
refresh[2] = 1;
1160 ref_frame_config->
refresh[3] = 1;
1165 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 4;
1166 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = 5;
1167 ref_frame_config->
refresh[4] = 1;
1168 ref_frame_config->
refresh[5] = 1;
1170 }
else if (superframe_cnt % 4 == 0) {
1177 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
1178 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1179 ref_frame_config->
ref_idx[i] = 1;
1180 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 0;
1181 ref_frame_config->
refresh[0] = 1;
1186 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
1187 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1188 ref_frame_config->
ref_idx[i] = 3;
1189 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 2;
1190 ref_frame_config->
refresh[2] = 1;
1195 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
1196 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1197 ref_frame_config->
ref_idx[i] = 5;
1198 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 4;
1199 ref_frame_config->
refresh[4] = 1;
1201 }
else if ((superframe_cnt - 1) % 4 == 0) {
1207 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
1208 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1209 ref_frame_config->
ref_idx[i] = 1;
1210 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 0;
1214 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
1215 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1216 ref_frame_config->
ref_idx[i] = 3;
1217 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 2;
1221 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
1222 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1223 ref_frame_config->
ref_idx[i] = 5;
1224 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 4;
1226 }
else if ((superframe_cnt - 2) % 4 == 0) {
1233 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
1234 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1235 ref_frame_config->
ref_idx[i] = 1;
1236 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 0;
1237 ref_frame_config->
refresh[1] = 1;
1242 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
1243 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1244 ref_frame_config->
ref_idx[i] = 3;
1245 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 2;
1246 ref_frame_config->
refresh[3] = 1;
1251 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
1252 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1253 ref_frame_config->
ref_idx[i] = 5;
1254 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 4;
1255 ref_frame_config->
refresh[5] = 1;
1257 }
else if ((superframe_cnt - 3) % 4 == 0) {
1263 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
1264 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1265 ref_frame_config->
ref_idx[i] = 0;
1266 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 1;
1270 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
1271 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1272 ref_frame_config->
ref_idx[i] = 2;
1273 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 3;
1277 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
1278 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1279 ref_frame_config->
ref_idx[i] = 4;
1280 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 5;
1285 ref_frame_config->
reference[SVC_GOLDEN_FRAME] = 1;
1289 if (!is_key_frame) ref_frame_config->
reference[SVC_GOLDEN_FRAME] = 0;
1294 ref_frame_config->
reference[SVC_LAST_FRAME] = 0;
1301 if (!simulcast_mode && enable_longterm_temporal_ref &&
1303 ref_frame_config->
ref_idx[SVC_ALTREF_FRAME] = REF_FRAMES - 1;
1304 if (!is_key_frame) ref_frame_config->
reference[SVC_ALTREF_FRAME] = 1;
1306 ref_frame_config->
refresh[REF_FRAMES - 1] = 1;
1309 default: assert(0); die(
"Error: Unsupported temporal layering mode!\n");
1313#if CONFIG_AV1_DECODER
1317 const int frames_out) {
1325#if CONFIG_AV1_HIGHBITDEPTH
1333 enc_img.
d_w, enc_img.
d_h, 16);
1334 aom_img_truncate_16_to_8(&enc_hbd_img, &enc_img);
1335 enc_img = enc_hbd_img;
1342 dec_img.
d_w, dec_img.
d_h, 16);
1343 aom_img_truncate_16_to_8(&dec_hbd_img, &dec_img);
1344 dec_img = dec_hbd_img;
1349 if (!aom_compare_img(&enc_img, &dec_img)) {
1350 int y[4], u[4], v[4];
1351#if CONFIG_AV1_HIGHBITDEPTH
1353 aom_find_mismatch_high(&enc_img, &dec_img, y, u, v);
1355 aom_find_mismatch(&enc_img, &dec_img, y, u, v);
1358 aom_find_mismatch(&enc_img, &dec_img, y, u, v);
1361 "Encode/decode mismatch on frame %d at"
1362 " Y[%d, %d] {%d/%d},"
1363 " U[%d, %d] {%d/%d},"
1364 " V[%d, %d] {%d/%d}\n",
1365 frames_out, y[0], y[1], y[2], y[3], u[0], u[1], u[2], u[3], v[0],
1378 uint64_t psnr_sse_total[2];
1379 uint64_t psnr_samples_total[2];
1380 double psnr_totals[2][4];
1384static void show_psnr(
struct psnr_stats *psnr_stream,
double peak) {
1387 if (!psnr_stream->psnr_count[0])
return;
1389 fprintf(stderr,
"\nPSNR (Overall/Avg/Y/U/V)");
1390 ovpsnr = sse_to_psnr((
double)psnr_stream->psnr_samples_total[0], peak,
1391 (
double)psnr_stream->psnr_sse_total[0]);
1392 fprintf(stderr,
" %.3f", ovpsnr);
1394 for (
int i = 0; i < 4; i++) {
1395 fprintf(stderr,
" %.3f",
1396 psnr_stream->psnr_totals[0][i] / psnr_stream->psnr_count[0]);
1398 fprintf(stderr,
"\n");
1401static aom::AV1RateControlRtcConfig create_rtc_rc_config(
1403 aom::AV1RateControlRtcConfig rc_cfg;
1404 rc_cfg.width = cfg.
g_w;
1405 rc_cfg.height = cfg.
g_h;
1415 rc_cfg.max_intra_bitrate_pct = 300;
1418 rc_cfg.ss_number_layers = 1;
1419 rc_cfg.ts_number_layers = 1;
1420 rc_cfg.scaling_factor_num[0] = 1;
1421 rc_cfg.scaling_factor_den[0] = 1;
1422 rc_cfg.layer_target_bitrate[0] =
static_cast<int>(rc_cfg.target_bandwidth);
1423 rc_cfg.max_quantizers[0] = rc_cfg.max_quantizer;
1424 rc_cfg.min_quantizers[0] = rc_cfg.min_quantizer;
1425 rc_cfg.aq_mode = app_input.aq_mode;
1430static int qindex_to_quantizer(
int qindex) {
1433 static const int quantizer_to_qindex[] = {
1434 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48,
1435 52, 56, 60, 64, 68, 72, 76, 80, 84, 88, 92, 96, 100,
1436 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 144, 148, 152,
1437 156, 160, 164, 168, 172, 176, 180, 184, 188, 192, 196, 200, 204,
1438 208, 212, 216, 220, 224, 228, 232, 236, 240, 244, 249, 255,
1440 for (
int quantizer = 0; quantizer < 64; ++quantizer)
1441 if (quantizer_to_qindex[quantizer] >= qindex)
return quantizer;
1450 map.
rows = (cfg->
g_h + 15) / 16;
1451 map.
cols = (cfg->
g_w + 15) / 16;
1454 if (!map.
active_map) die(
"Failed to allocate active map");
1457 for (
unsigned int i = 0; i < map.
rows; ++i) {
1458 for (
unsigned int j = 0; j < map.
cols; ++j) {
1459 int index = map.
cols * i + j;
1461 if (frame_cnt < 300) {
1463 }
else if (frame_cnt >= 300) {
1464 if (i < map.rows / 2 && j >= map.
cols / 2) map.
active_map[index] = 0;
1470 die_codec(codec,
"Failed to set active map");
1475int main(
int argc,
const char **argv) {
1479 AvxVideoWriter *total_layer_file = NULL;
1480 FILE *total_layer_obu_file = NULL;
1489 int frame_duration = 1;
1495#if CONFIG_INTERNAL_STATS
1496 FILE *stats_file = fopen(
"opsnr.stt",
"a");
1497 if (stats_file == NULL) {
1498 die(
"Cannot open opsnr.stt\n");
1501#if CONFIG_AV1_DECODER
1505 struct RateControlMetrics rc;
1506 int64_t cx_time = 0;
1509 double sum_bitrate = 0.0;
1510 double sum_bitrate2 = 0.0;
1511 double framerate = 30.0;
1512 int use_svc_control = 1;
1513 int set_err_resil_frame = 0;
1514 int test_changing_bitrate = 0;
1515 zero(rc.layer_target_bitrate);
1517 memset(&app_input, 0,
sizeof(AppInput));
1518 memset(&svc_params, 0,
sizeof(svc_params));
1522 const int test_dynamic_scaling_single_layer = 0;
1525 const int test_speed_per_layer = 0;
1528 const int test_active_maps = 0;
1531 app_input.input_ctx.framerate.numerator = 30;
1532 app_input.input_ctx.framerate.denominator = 1;
1533 app_input.input_ctx.only_i420 = 0;
1535 app_input.speed = 7;
1536 exec_name = argv[0];
1560 parse_command_line(argc, argv, &app_input, &svc_params, &cfg);
1565 unsigned int width = cfg.
g_w;
1566 unsigned int height = cfg.
g_h;
1568 if (app_input.layering_mode >= 0) {
1569 if (ts_number_layers !=
1570 mode_to_num_temporal_layers[app_input.layering_mode] ||
1572 mode_to_num_spatial_layers[app_input.layering_mode]) {
1573 die(
"Number of layers doesn't match layering mode.");
1578 if (app_input.input_ctx.file_type != FILE_TYPE_Y4M) {
1580 die(
"Failed to allocate image (%dx%d)", width, height);
1589 unsigned int total_rate = 0;
1590 for (i = 0; i < ss_number_layers; i++) {
1596 die(
"Incorrect total target bitrate");
1600 if (ts_number_layers == 2) {
1603 }
else if (ts_number_layers == 3) {
1609 if (app_input.input_ctx.file_type == FILE_TYPE_Y4M) {
1611 cfg.
g_w = app_input.input_ctx.width;
1612 cfg.
g_h = app_input.input_ctx.height;
1614 cfg.
g_timebase.
num = app_input.input_ctx.framerate.denominator;
1615 cfg.
g_timebase.
den = app_input.input_ctx.framerate.numerator;
1618 set_rate_control_metrics(&rc, framerate, ss_number_layers, ts_number_layers);
1621 info.codec_fourcc = get_fourcc_by_aom_encoder(encoder);
1622 info.frame_width = cfg.
g_w;
1623 info.frame_height = cfg.
g_h;
1627 for (
int sl = 0; sl < ss_number_layers; ++sl) {
1628 for (
int tl = 0; tl < ts_number_layers; ++tl) {
1629 i = sl * ts_number_layers + tl;
1630 char file_name[PATH_MAX];
1631 snprintf(file_name,
sizeof(file_name),
"%s_%d.av1",
1632 app_input.output_filename, i);
1633 if (app_input.output_obu) {
1634 obu_files[i] = fopen(file_name,
"wb");
1635 if (!obu_files[i]) die(
"Failed to open %s for writing", file_name);
1637 outfile[i] = aom_video_writer_open(file_name, kContainerIVF, &info);
1638 if (!outfile[i]) die(
"Failed to open %s for writing", file_name);
1642 if (app_input.output_obu) {
1643 total_layer_obu_file = fopen(app_input.output_filename,
"wb");
1644 if (!total_layer_obu_file)
1645 die(
"Failed to open %s for writing", app_input.output_filename);
1648 aom_video_writer_open(app_input.output_filename, kContainerIVF, &info);
1649 if (!total_layer_file)
1650 die(
"Failed to open %s for writing", app_input.output_filename);
1659 die_codec(&codec,
"Failed to initialize encoder");
1661#if CONFIG_AV1_DECODER
1662 if (app_input.decode) {
1664 die_codec(&decoder,
"Failed to initialize decoder");
1695 if (app_input.tune_content == AOM_CONTENT_SCREEN) {
1701 if (app_input.use_external_rc) {
1714 for (i = 0; i < ss_number_layers * ts_number_layers; ++i) {
1718 for (i = 0; i < ss_number_layers; ++i) {
1722 if (ss_number_layers == 2) {
1725 }
else if (ss_number_layers == 3) {
1738 const int max_intra_size_pct = 300;
1740 max_intra_size_pct);
1743 for (
int lx = 0; lx < ts_number_layers * ss_number_layers; lx++) {
1744 cx_time_layer[lx] = 0;
1745 frame_cnt_layer[lx] = 0;
1748 std::unique_ptr<aom::AV1RateControlRTC> rc_api;
1749 if (app_input.use_external_rc) {
1750 const aom::AV1RateControlRtcConfig rc_cfg =
1751 create_rtc_rc_config(cfg, app_input);
1752 rc_api = aom::AV1RateControlRTC::Create(rc_cfg);
1756 struct psnr_stats psnr_stream;
1757 memset(&psnr_stream, 0,
sizeof(psnr_stream));
1758 while (frame_avail || got_data) {
1759 struct aom_usec_timer timer;
1760 frame_avail = read_frame(&(app_input.input_ctx), &raw);
1762 for (
int slx = 0; slx < ss_number_layers; slx++) {
1767 int is_key_frame = (frame_cnt % cfg.
kf_max_dist) == 0;
1769 if (app_input.layering_mode >= 0) {
1772 set_layer_pattern(app_input.layering_mode, frame_cnt, &layer_id,
1773 &ref_frame_config, &ref_frame_comp_pred,
1774 &use_svc_control, slx, is_key_frame,
1775 (app_input.layering_mode == 10), app_input.speed);
1777 if (use_svc_control) {
1781 &ref_frame_comp_pred);
1784 if (test_speed_per_layer) {
1785 int speed_per_layer = 10;
1807 if (ts_number_layers == 2) {
1809 }
else if (ts_number_layers == 3) {
1810 if (frame_cnt % 2 != 0)
1812 else if ((frame_cnt > 1) && ((frame_cnt - 2) % 4 == 0))
1826 const int err_resil_mode =
1833 if (frame_avail && slx == 0) ++rc.layer_input_frames[layer];
1835 if (test_dynamic_scaling_single_layer) {
1838 int frame_2x2 = 200;
1839 int frame_4x4 = 400;
1840 int frame_2x2up = 600;
1841 int frame_orig = 800;
1842 if (frame_cnt >= frame_2x2 && frame_cnt < frame_4x4) {
1846 }
else if (frame_cnt >= frame_4x4 && frame_cnt < frame_2x2up) {
1850 }
else if (frame_cnt >= frame_2x2up && frame_cnt < frame_orig) {
1854 }
else if (frame_cnt >= frame_orig) {
1859 if (frame_cnt == frame_2x2 || frame_cnt == frame_4x4 ||
1860 frame_cnt == frame_2x2up || frame_cnt == frame_orig) {
1866 for (i = 0; i < REF_FRAMES; i++) ref_frame_config.
refresh[i] = 1;
1867 if (use_svc_control) {
1871 &ref_frame_comp_pred);
1877 if (test_changing_bitrate && frame_cnt % 2 == 0) {
1878 if (frame_cnt < 500)
1890 die_codec(&codec,
"Failed to SET_BITRATE_ONE_PASS_CBR");
1894 aom::AV1FrameParamsRTC frame_params;
1896 frame_params.spatial_layer_id = 0;
1897 frame_params.temporal_layer_id = 0;
1898 frame_params.frame_type =
1899 is_key_frame ? aom::kKeyFrame : aom::kInterFrame;
1900 rc_api->ComputeQP(frame_params);
1901 const int current_qp = rc_api->GetQP();
1903 qindex_to_quantizer(current_qp))) {
1904 die_codec(&codec,
"Failed to SET_QUANTIZER_ONE_PASS");
1908 if (test_active_maps) set_active_map(&cfg, &codec, frame_cnt);
1911 aom_usec_timer_start(&timer);
1913 die_codec(&codec,
"Failed to encode frame");
1914 aom_usec_timer_mark(&timer);
1915 cx_time += aom_usec_timer_elapsed(&timer);
1916 cx_time_layer[layer] += aom_usec_timer_elapsed(&timer);
1917 frame_cnt_layer[layer] += 1;
1920 int content_flag = 0;
1923 die_codec(&codec,
"Failed to GET_HIGH_MOTION_CONTENT_SCREEN_RTC");
1928 int ss_layers_write = (app_input.layering_mode == 11)
1932 switch (pkt->
kind) {
1938 int j = sl * ts_number_layers + tl;
1939 if (app_input.output_obu) {
1943 aom_video_writer_write_frame(
1945 reinterpret_cast<const uint8_t *
>(pkt->
data.
frame.
buf),
1949 rc.layer_encoding_bitrate[j] += 8.0 * pkt->
data.
frame.
sz;
1954 if (app_input.output_obu) {
1956 total_layer_obu_file);
1958 aom_video_writer_write_frame(
1960 reinterpret_cast<const uint8_t *
>(pkt->
data.
frame.
buf),
1968 rc.layer_avg_frame_size[j] += 8.0 * pkt->
data.
frame.
sz;
1969 rc.layer_avg_rate_mismatch[j] +=
1970 fabs(8.0 * pkt->
data.
frame.
sz - rc.layer_pfb[j]) /
1982 if (frame_cnt > rc.window_size && slx == ss_number_layers - 1) {
1983 sum_bitrate += 0.001 * 8.0 * pkt->
data.
frame.
sz * framerate;
1984 rc.window_size = (rc.window_size <= 0) ? 1 : rc.window_size;
1985 if (frame_cnt % rc.window_size == 0) {
1986 rc.window_count += 1;
1987 rc.avg_st_encoding_bitrate += sum_bitrate / rc.window_size;
1988 rc.variance_st_encoding_bitrate +=
1989 (sum_bitrate / rc.window_size) *
1990 (sum_bitrate / rc.window_size);
1995 if (frame_cnt > rc.window_size + rc.window_size / 2 &&
1996 slx == ss_number_layers - 1) {
1997 sum_bitrate2 += 0.001 * 8.0 * pkt->
data.
frame.
sz * framerate;
1998 if (frame_cnt > 2 * rc.window_size &&
1999 frame_cnt % rc.window_size == 0) {
2000 rc.window_count += 1;
2001 rc.avg_st_encoding_bitrate += sum_bitrate2 / rc.window_size;
2002 rc.variance_st_encoding_bitrate +=
2003 (sum_bitrate2 / rc.window_size) *
2004 (sum_bitrate2 / rc.window_size);
2009#if CONFIG_AV1_DECODER
2010 if (app_input.decode) {
2013 reinterpret_cast<const uint8_t *
>(pkt->
data.
frame.
buf),
2015 die_codec(&decoder,
"Failed to decode frame");
2021 if (app_input.show_psnr) {
2022 psnr_stream.psnr_sse_total[0] += pkt->
data.
psnr.sse[0];
2023 psnr_stream.psnr_samples_total[0] += pkt->
data.
psnr.samples[0];
2024 for (
int plane = 0; plane < 4; plane++) {
2025 psnr_stream.psnr_totals[0][plane] += pkt->
data.
psnr.psnr[plane];
2027 psnr_stream.psnr_count[0]++;
2033#if CONFIG_AV1_DECODER
2034 if (got_data && app_input.decode) {
2037 if ((ss_number_layers > 1 || ts_number_layers > 1) &&
2040 if (test_decode(&codec, &decoder, frame_cnt)) {
2041#if CONFIG_INTERNAL_STATS
2042 fprintf(stats_file,
"First mismatch occurred in frame %d\n",
2046 fatal(
"Mismatch seen");
2053 pts += frame_duration;
2056 close_input_file(&(app_input.input_ctx));
2057 printout_rate_control_summary(&rc, frame_cnt, ss_number_layers,
2061 for (
int slx = 0; slx < ss_number_layers; slx++)
2062 for (
int tlx = 0; tlx < ts_number_layers; tlx++) {
2063 int lx = slx * ts_number_layers + tlx;
2064 printf(
"Per layer encoding time/FPS stats for encoder: %d %d %d %f %f \n",
2065 slx, tlx, frame_cnt_layer[lx],
2066 (
float)cx_time_layer[lx] / (
double)(frame_cnt_layer[lx] * 1000),
2067 1000000 * (
double)frame_cnt_layer[lx] / (
double)cx_time_layer[lx]);
2071 printf(
"Frame cnt and encoding time/FPS stats for encoding: %d %f %f\n",
2072 frame_cnt, 1000 * (
float)cx_time / (
double)(frame_cnt * 1000000),
2073 1000000 * (
double)frame_cnt / (
double)cx_time);
2075 if (app_input.show_psnr) {
2076 show_psnr(&psnr_stream, 255.0);
2081#if CONFIG_AV1_DECODER
2082 if (app_input.decode) {
2084 die_codec(&decoder,
"Failed to destroy decoder");
2088#if CONFIG_INTERNAL_STATS
2089 fprintf(stats_file,
"No mismatch detected in recon buffers\n");
2094 for (i = 0; i < ss_number_layers * ts_number_layers; ++i)
2095 aom_video_writer_close(outfile[i]);
2096 aom_video_writer_close(total_layer_file);
2098 if (app_input.input_ctx.file_type != FILE_TYPE_Y4M) {
2101 return EXIT_SUCCESS;
Describes the decoder algorithm interface to applications.
Describes the encoder algorithm interface to applications.
@ AOM_CSP_UNKNOWN
Definition aom_image.h:143
enum aom_chroma_sample_position aom_chroma_sample_position_t
List of chroma sample positions.
#define AOM_IMG_FMT_HIGHBITDEPTH
Definition aom_image.h:38
aom_image_t * aom_img_alloc(aom_image_t *img, aom_img_fmt_t fmt, unsigned int d_w, unsigned int d_h, unsigned int align)
Open a descriptor, allocating storage for the underlying image.
@ AOM_IMG_FMT_I420
Definition aom_image.h:45
enum aom_img_fmt aom_img_fmt_t
List of supported image formats.
void aom_img_free(aom_image_t *img)
Close an image descriptor.
Provides definitions for using AOM or AV1 encoder algorithm within the aom Codec Interface.
#define AOM_MAX_LAYERS
Definition aomcx.h:1692
#define AOM_MAX_TS_LAYERS
Definition aomcx.h:1694
aom_codec_iface_t * aom_codec_av1_cx(void)
The interface to the AV1 encoder.
@ AOM_FULL_SUPERFRAME_DROP
Definition aomcx.h:1754
@ AV1E_SET_BITRATE_ONE_PASS_CBR
Codec control to set the target bitrate in kilobits per second, unsigned int parameter....
Definition aomcx.h:1527
@ AV1E_SET_ENABLE_SMOOTH_INTRA
Codec control function to turn on / off smooth intra modes usage, int parameter.
Definition aomcx.h:1070
@ AV1E_SET_ENABLE_TPL_MODEL
Codec control function to enable RDO modulated by frame temporal dependency, unsigned int parameter.
Definition aomcx.h:408
@ AV1E_SET_AQ_MODE
Codec control function to set adaptive quantization mode, unsigned int parameter.
Definition aomcx.h:468
@ AV1E_SET_SVC_LAYER_ID
Codec control function to set the layer id, aom_svc_layer_id_t* parameter.
Definition aomcx.h:1276
@ AV1E_SET_SVC_REF_FRAME_CONFIG
Codec control function to set the reference frame config, aom_svc_ref_frame_config_t* parameter.
Definition aomcx.h:1286
@ AV1E_SET_TUNE_CONTENT
Codec control function to set content type, aom_tune_content parameter.
Definition aomcx.h:497
@ AV1E_SET_CDF_UPDATE_MODE
Codec control function to set CDF update mode, unsigned int parameter.
Definition aomcx.h:506
@ AV1E_SET_ENABLE_ANGLE_DELTA
Codec control function to turn on/off intra angle delta, int parameter.
Definition aomcx.h:1117
@ AV1E_SET_MV_COST_UPD_FREQ
Control to set frequency of the cost updates for motion vectors, unsigned int parameter.
Definition aomcx.h:1254
@ AV1E_SET_INTRA_DEFAULT_TX_ONLY
Control to use default tx type only for intra modes, int parameter.
Definition aomcx.h:1203
@ AV1E_SET_SVC_REF_FRAME_COMP_PRED
Codec control function to set reference frame compound prediction. aom_svc_ref_frame_comp_pred_t* par...
Definition aomcx.h:1391
@ AV1E_SET_ENABLE_INTRABC
Codec control function to turn on/off intra block copy mode, int parameter.
Definition aomcx.h:1113
@ AV1E_SET_ENABLE_WARPED_MOTION
Codec control function to turn on / off warped motion usage at sequence level, int parameter.
Definition aomcx.h:1038
@ AV1E_SET_RTC_EXTERNAL_RC
Codec control function to set flag for rate control used by external encoders.
Definition aomcx.h:1426
@ AV1E_SET_COEFF_COST_UPD_FREQ
Control to set frequency of the cost updates for coefficients, unsigned int parameter.
Definition aomcx.h:1234
@ AV1E_SET_ENABLE_CDEF
Codec control function to encode with CDEF, unsigned int parameter.
Definition aomcx.h:670
@ AOME_SET_ACTIVEMAP
Codec control function to pass an Active map to encoder, aom_active_map_t* parameter.
Definition aomcx.h:190
@ AV1E_SET_DV_COST_UPD_FREQ
Control to set frequency of the cost updates for intrabc motion vectors, unsigned int parameter.
Definition aomcx.h:1357
@ AV1E_SET_SVC_FRAME_DROP_MODE
Codec control to set the frame drop mode for SVC, unsigned int parameter. The valid values are consta...
Definition aomcx.h:1540
@ AV1E_SET_SVC_PARAMS
Codec control function to set SVC parameters, aom_svc_params_t* parameter.
Definition aomcx.h:1281
@ AV1E_SET_ENABLE_FILTER_INTRA
Codec control function to turn on / off filter intra usage at sequence level, int parameter.
Definition aomcx.h:1059
@ AV1E_SET_ENABLE_PALETTE
Codec control function to turn on/off palette mode, int parameter.
Definition aomcx.h:1109
@ AV1E_SET_ENABLE_CFL_INTRA
Codec control function to turn on / off CFL uv intra mode usage, int parameter.
Definition aomcx.h:1088
@ AOME_SET_MAX_INTRA_BITRATE_PCT
Codec control function to set max data rate for intra frames, unsigned int parameter.
Definition aomcx.h:306
@ AV1E_SET_ERROR_RESILIENT_MODE
Codec control function to enable error_resilient_mode, int parameter.
Definition aomcx.h:442
@ AV1E_SET_ENABLE_OBMC
Codec control function to predict with OBMC mode, unsigned int parameter.
Definition aomcx.h:697
@ AV1E_SET_AUTO_TILES
Codec control to set auto tiling, unsigned int parameter. Value of 1 means encoder will set number of...
Definition aomcx.h:1548
@ AV1E_SET_LOOPFILTER_CONTROL
Codec control to control loop filter.
Definition aomcx.h:1406
@ AOME_SET_SCALEMODE
Codec control function to set encoder scaling mode for the next frame to be coded,...
Definition aomcx.h:197
@ AV1E_SET_ENABLE_ORDER_HINT
Codec control function to turn on / off frame order hint (int parameter). Affects: joint compound mod...
Definition aomcx.h:865
@ AV1E_SET_DELTAQ_MODE
Codec control function to set the delta q mode, unsigned int parameter.
Definition aomcx.h:1131
@ AV1E_SET_POSTENCODE_DROP_RTC
Codec control to enable post encode frame drop for RTC encoding, int parameter.
Definition aomcx.h:1564
@ AV1E_SET_ENABLE_GLOBAL_MOTION
Codec control function to turn on / off global motion usage for a sequence, int parameter.
Definition aomcx.h:1028
@ AOME_SET_CPUUSED
Codec control function to set encoder internal speed settings, int parameter.
Definition aomcx.h:220
@ AV1E_GET_HIGH_MOTION_CONTENT_SCREEN_RTC
Codec control to get the high motion content flag, used for screen content realtime (RTC) encoding,...
Definition aomcx.h:1555
@ AV1E_SET_GF_CBR_BOOST_PCT
Boost percentage for Golden Frame in CBR mode, unsigned int parameter.
Definition aomcx.h:339
@ AV1E_SET_QUANTIZER_ONE_PASS
Codec control to set quantizer for the next frame, int parameter.
Definition aomcx.h:1489
@ AV1E_SET_MODE_COST_UPD_FREQ
Control to set frequency of the cost updates for mode, unsigned int parameter.
Definition aomcx.h:1244
@ AV1E_SET_MAX_CONSEC_FRAME_DROP_MS_CBR
Codec control to set the maximum number of consecutive frame drops, in units of time (milliseconds),...
Definition aomcx.h:1570
@ AV1_GET_NEW_FRAME_IMAGE
Codec control function to get a pointer to the new frame.
Definition aom.h:70
const char * aom_codec_iface_name(aom_codec_iface_t *iface)
Return the name for a given interface.
enum aom_bit_depth aom_bit_depth_t
Bit depth for codecThis enumeration determines the bit depth of the codec.
aom_codec_err_t aom_codec_control(aom_codec_ctx_t *ctx, int ctrl_id,...)
Algorithm Control.
long aom_codec_flags_t
Initialization-time Feature Enabling.
Definition aom_codec.h:232
const struct aom_codec_iface aom_codec_iface_t
Codec interface structure.
Definition aom_codec.h:271
aom_codec_err_t aom_codec_destroy(aom_codec_ctx_t *ctx)
Destroy a codec instance.
const char * aom_codec_err_to_string(aom_codec_err_t err)
Convert error number to printable string.
aom_codec_err_t
Algorithm return codes.
Definition aom_codec.h:155
#define AOM_CODEC_CONTROL_TYPECHECKED(ctx, id, data)
aom_codec_control wrapper macro (adds type-checking, less flexible)
Definition aom_codec.h:542
const void * aom_codec_iter_t
Iterator.
Definition aom_codec.h:305
#define AOM_FRAME_IS_KEY
Definition aom_codec.h:288
@ AOM_BITS_8
Definition aom_codec.h:336
@ AOM_BITS_10
Definition aom_codec.h:337
@ AOM_CODEC_INVALID_PARAM
An application-supplied parameter is not valid.
Definition aom_codec.h:200
@ AOM_CODEC_MEM_ERROR
Memory operation failed.
Definition aom_codec.h:163
@ AOM_CODEC_OK
Operation completed without error.
Definition aom_codec.h:157
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.
#define aom_codec_dec_init(ctx, iface, cfg, flags)
Convenience macro for aom_codec_dec_init_ver()
Definition aom_decoder.h:129
const aom_codec_cx_pkt_t * aom_codec_get_cx_data(aom_codec_ctx_t *ctx, aom_codec_iter_t *iter)
Encoded data iterator.
aom_codec_err_t aom_codec_encode(aom_codec_ctx_t *ctx, const aom_image_t *img, aom_codec_pts_t pts, unsigned long duration, aom_enc_frame_flags_t flags)
Encode a frame.
#define aom_codec_enc_init(ctx, iface, cfg, flags)
Convenience macro for aom_codec_enc_init_ver()
Definition aom_encoder.h:943
aom_codec_err_t aom_codec_enc_config_default(aom_codec_iface_t *iface, aom_codec_enc_cfg_t *cfg, unsigned int usage)
Get the default configuration for a usage.
#define AOM_USAGE_REALTIME
usage parameter analogous to AV1 REALTIME mode.
Definition aom_encoder.h:1016
#define AOM_CODEC_USE_HIGHBITDEPTH
Definition aom_encoder.h:80
#define AOM_CODEC_USE_PSNR
Initialization-time Feature Enabling.
Definition aom_encoder.h:79
@ AOM_CBR
Definition aom_encoder.h:187
@ AOM_KF_AUTO
Definition aom_encoder.h:202
@ AOM_CODEC_PSNR_PKT
Definition aom_encoder.h:113
@ AOM_CODEC_CX_FRAME_PKT
Definition aom_encoder.h:110
aom active region map
Definition aomcx.h:1626
unsigned int rows
Definition aomcx.h:1629
unsigned int cols
Definition aomcx.h:1630
unsigned char * active_map
specify an on (1) or off (0) each 16x16 region within a frame
Definition aomcx.h:1628
Codec context structure.
Definition aom_codec.h:315
Encoder output packet.
Definition aom_encoder.h:122
size_t sz
Definition aom_encoder.h:127
enum aom_codec_cx_pkt_kind kind
Definition aom_encoder.h:123
double psnr[4]
Definition aom_encoder.h:145
union aom_codec_cx_pkt::@1 data
struct aom_codec_cx_pkt::@1::@2 frame
aom_codec_frame_flags_t flags
Definition aom_encoder.h:132
void * buf
Definition aom_encoder.h:126
Encoder configuration structure.
Definition aom_encoder.h:387
unsigned int g_input_bit_depth
Bit-depth of the input frames.
Definition aom_encoder.h:475
unsigned int rc_dropframe_thresh
Temporal resampling configuration, if supported by the codec.
Definition aom_encoder.h:540
struct aom_rational g_timebase
Stream timebase units.
Definition aom_encoder.h:489
unsigned int g_usage
Algorithm specific "usage" value.
Definition aom_encoder.h:399
unsigned int rc_buf_sz
Decoder Buffer Size.
Definition aom_encoder.h:705
unsigned int g_h
Height of the frame.
Definition aom_encoder.h:435
enum aom_kf_mode kf_mode
Keyframe placement mode.
Definition aom_encoder.h:768
enum aom_rc_mode rc_end_usage
Rate control algorithm to use.
Definition aom_encoder.h:623
unsigned int g_threads
Maximum number of threads to use.
Definition aom_encoder.h:407
unsigned int kf_min_dist
Keyframe minimum interval.
Definition aom_encoder.h:777
unsigned int g_lag_in_frames
Allow lagged encoding.
Definition aom_encoder.h:518
unsigned int rc_buf_initial_sz
Decoder Buffer Initial Size.
Definition aom_encoder.h:714
unsigned int g_profile
Bitstream profile to use.
Definition aom_encoder.h:417
aom_bit_depth_t g_bit_depth
Bit-depth of the codec.
Definition aom_encoder.h:467
unsigned int g_w
Width of the frame.
Definition aom_encoder.h:426
unsigned int rc_undershoot_pct
Rate control adaptation undershoot control.
Definition aom_encoder.h:681
unsigned int kf_max_dist
Keyframe maximum interval.
Definition aom_encoder.h:786
aom_codec_er_flags_t g_error_resilient
Enable error resilient modes.
Definition aom_encoder.h:497
unsigned int rc_max_quantizer
Maximum (Worst Quality) Quantizer.
Definition aom_encoder.h:668
unsigned int rc_buf_optimal_sz
Decoder Buffer Optimal Size.
Definition aom_encoder.h:723
unsigned int rc_min_quantizer
Minimum (Best Quality) Quantizer.
Definition aom_encoder.h:658
unsigned int rc_target_bitrate
Target data rate.
Definition aom_encoder.h:644
unsigned int rc_resize_mode
Mode for spatial resampling, if supported by the codec.
Definition aom_encoder.h:549
unsigned int rc_overshoot_pct
Rate control adaptation overshoot control.
Definition aom_encoder.h:690
Image Descriptor.
Definition aom_image.h:182
aom_img_fmt_t fmt
Definition aom_image.h:183
unsigned int d_w
Definition aom_image.h:197
unsigned int d_h
Definition aom_image.h:198
int num
Definition aom_encoder.h:165
int den
Definition aom_encoder.h:166
aom image scaling mode
Definition aomcx.h:1638
int temporal_layer_id
Definition aomcx.h:1699
int spatial_layer_id
Definition aomcx.h:1698
int max_quantizers[32]
Definition aomcx.h:1711
int number_spatial_layers
Definition aomcx.h:1709
int layer_target_bitrate[32]
Definition aomcx.h:1716
int framerate_factor[8]
Definition aomcx.h:1718
int min_quantizers[32]
Definition aomcx.h:1712
int scaling_factor_den[4]
Definition aomcx.h:1714
int number_temporal_layers
Definition aomcx.h:1710
int scaling_factor_num[4]
Definition aomcx.h:1713
int use_comp_pred[3]
Definition aomcx.h:1748
int reference[7]
Definition aomcx.h:1738
int refresh[8]
Definition aomcx.h:1741
int ref_idx[7]
Definition aomcx.h:1740