Adjustments to using the key & value API in aomenc.
This patch contains several adjustments that was brought up in the
previous commit
(https://aomedia-review.googlesource.com/c/aom/+/129381).
BUG=aomedia:2875
Change-Id: I497337e259088181b44a253b0c7135e67083fb49
(cherry picked from commit 67c3ce0c54220d9d16aaf5c9499a1064338d12ae)
diff --git a/apps/aomenc.c b/apps/aomenc.c
index 2061ece..6ff67dd 100644
--- a/apps/aomenc.c
+++ b/apps/aomenc.c
@@ -315,14 +315,9 @@
&g_av1_codec_arg_defs.sframe_mode,
NULL };
-// The first part of this array should match the control IDs in the array
-// av1_arg_ctrl_map. To add a new option with its control ID, insert the option
-// before the comment "Option that supports the control ID API ends here."
-// Alternatively, to add a new option supported by the key & value API, just
-// append the option to this array.
// TODO(bohanli): Currently all options are supported by the key & value API.
// Consider removing the control ID usages?
-const arg_def_t *av1_args[] = {
+const arg_def_t *av1_ctrl_args[] = {
&g_av1_codec_arg_defs.cpu_used_av1,
&g_av1_codec_arg_defs.auto_altref,
&g_av1_codec_arg_defs.sharpness,
@@ -428,10 +423,14 @@
&g_av1_codec_arg_defs.input_chroma_subsampling_y,
#if CONFIG_TUNE_VMAF
&g_av1_codec_arg_defs.vmaf_model_path,
-#endif // Option that supports the control ID API ends here.
+#endif
&g_av1_codec_arg_defs.subgop_config_str,
&g_av1_codec_arg_defs.subgop_config_path,
- NULL
+ NULL,
+};
+
+const arg_def_t *av1_key_val_args[] = {
+ NULL,
};
static const arg_def_t *no_args[] = { NULL };
@@ -455,7 +454,8 @@
arg_show_usage(fout, kf_args);
#if CONFIG_AV1_ENCODER
fprintf(fout, "\nAV1 Specific Options:\n");
- arg_show_usage(fout, av1_args);
+ arg_show_usage(fout, av1_ctrl_args);
+ arg_show_usage(fout, av1_key_val_args);
#endif
fprintf(fout,
"\nStream timebase (--timebase):\n"
@@ -481,6 +481,7 @@
#if CONFIG_AV1_ENCODER
#define ARG_CTRL_CNT_MAX NELEMENTS(av1_arg_ctrl_map)
+#define ARG_KEY_VAL_CNT_MAX NELEMENTS(av1_key_val_args)
#endif
#if !CONFIG_WEBM_IO
@@ -498,7 +499,7 @@
stereo_format_t stereo_fmt;
int arg_ctrls[ARG_CTRL_CNT_MAX][2];
int arg_ctrl_cnt;
- const char *arg_key_vals[ARG_CTRL_CNT_MAX][2];
+ const char *arg_key_vals[ARG_KEY_VAL_CNT_MAX][2];
int arg_key_val_cnt;
int write_webm;
const char *film_grain_filename;
@@ -802,7 +803,7 @@
// so we simply append it.
if (key == AV1E_SET_TARGET_SEQ_LEVEL_IDX) {
j = config->arg_ctrl_cnt;
- assert(j < (int)ARG_CTRL_CNT_MAX);
+ assert(j < ARG_CTRL_CNT_MAX);
config->arg_ctrls[j][0] = key;
config->arg_ctrls[j][1] = arg_parse_enum_or_int(arg);
++config->arg_ctrl_cnt;
@@ -816,7 +817,7 @@
if (config->arg_ctrls[j][0] == key) break;
/* Update/insert */
- assert(j < (int)ARG_CTRL_CNT_MAX);
+ assert(j < ARG_CTRL_CNT_MAX);
config->arg_ctrls[j][0] = key;
config->arg_ctrls[j][1] = arg_parse_enum_or_int(arg);
@@ -824,6 +825,7 @@
warn("auto-alt-ref > 1 is deprecated... setting auto-alt-ref=1\n");
config->arg_ctrls[j][1] = 1;
}
+
if (j == config->arg_ctrl_cnt) config->arg_ctrl_cnt++;
}
@@ -850,14 +852,14 @@
}
static void set_config_arg_key_vals(struct stream_config *config,
- const char *name, const char *val) {
+ const char *name, const struct arg *arg) {
int j;
-
+ const char *val = arg->val;
// For target level, the settings should accumulate rather than overwrite,
// so we simply append it.
if (strcmp(name, "target-seq-level-idx") == 0) {
j = config->arg_key_val_cnt;
- assert(j < (int)ARG_CTRL_CNT_MAX);
+ assert(j < ARG_KEY_VAL_CNT_MAX);
config->arg_key_vals[j][0] = name;
config->arg_key_vals[j][1] = val;
++config->arg_key_val_cnt;
@@ -871,10 +873,18 @@
if (strcmp(name, config->arg_key_vals[j][0]) == 0) break;
/* Update/insert */
- assert(j < (int)ARG_CTRL_CNT_MAX);
+ assert(j < ARG_KEY_VAL_CNT_MAX);
config->arg_key_vals[j][0] = name;
config->arg_key_vals[j][1] = val;
+ if (strcmp(name, g_av1_codec_arg_defs.auto_altref.long_name) == 0) {
+ int auto_altref = arg_parse_int(arg);
+ if (auto_altref > 1) {
+ warn("auto-alt-ref > 1 is deprecated... setting auto-alt-ref=1\n");
+ config->arg_key_vals[j][1] = "1";
+ }
+ }
+
if (j == config->arg_key_val_cnt) config->arg_key_val_cnt++;
}
@@ -882,7 +892,8 @@
struct stream_state *stream, char **argv) {
char **argi, **argj;
struct arg arg;
- static const arg_def_t **args_list = no_args;
+ static const arg_def_t **ctrl_args = no_args;
+ static const arg_def_t **key_val_args = no_args;
static const int *ctrl_args_map = NULL;
struct stream_config *config = &stream->config;
int eos_mark_found = 0;
@@ -894,8 +905,9 @@
} else if (strcmp(get_short_name_by_aom_encoder(global->codec), "av1") == 0) {
// TODO(jingning): Reuse AV1 specific encoder configuration parameters.
// Consider to expand this set for AV1 encoder control.
- args_list = av1_args;
+ ctrl_args = av1_ctrl_args;
ctrl_args_map = av1_arg_ctrl_map;
+ key_val_args = av1_key_val_args;
#endif
}
@@ -1104,21 +1116,24 @@
++config->arg_ctrl_cnt;
} else {
int i, match = 0;
- // check if the ctrl APIs supports this arg
- for (i = 0; ctrl_args_map && ctrl_args_map[i] && args_list[i]; i++) {
- if (arg_match(&arg, args_list[i], argi)) {
- match = 1;
- if (ctrl_args_map) {
+ // check if the control ID API supports this arg
+ if (ctrl_args_map) {
+ for (i = 0; ctrl_args[i]; i++) {
+ if (arg_match(&arg, ctrl_args[i], argi)) {
+ match = 1;
set_config_arg_ctrls(config, ctrl_args_map[i], &arg);
+ break;
}
}
}
- // check if the key & value API supports this arg
- for (i = 0; !match && args_list[i]; i++) {
- if (arg_match(&arg, args_list[i], argi)) {
- match = 1;
- set_config_arg_key_vals(config, args_list[i]->long_name, arg.val);
- break;
+ if (!match) {
+ // check if the key & value API supports this arg
+ for (i = 0; key_val_args[i]; i++) {
+ if (arg_match(&arg, key_val_args[i], argi)) {
+ match = 1;
+ set_config_arg_key_vals(config, key_val_args[i]->long_name, &arg);
+ break;
+ }
}
}
if (!match) argj++;
diff --git a/av1/av1_cx_iface.c b/av1/av1_cx_iface.c
index dfb6bbb..c31d23c 100644
--- a/av1/av1_cx_iface.c
+++ b/av1/av1_cx_iface.c
@@ -30,7 +30,6 @@
#include "av1/arg_defs.h"
#include "common/args_helper.h"
-#include "common/tools_common.h"
#include "aom_dsp/psnr.h"
#include "aom_ports/aom_timer.h"
@@ -3154,10 +3153,6 @@
} else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.auto_altref, argv,
err_string)) {
extra_cfg.enable_auto_alt_ref = arg_parse_uint_helper(&arg, err_string);
- if (strlen(err_string) == 0 && extra_cfg.enable_auto_alt_ref > 1) {
- warn("auto-alt-ref > 1 is deprecated... setting auto-alt-ref=1\n");
- extra_cfg.enable_auto_alt_ref = 1;
- }
} else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.noise_sens, argv,
err_string)) {
extra_cfg.noise_sensitivity = arg_parse_uint_helper(&arg, err_string);