From fb4d0c3cf2b23af406d8950f2ab680678eee4003 Mon Sep 17 00:00:00 2001 From: Miika Metsoila Date: Fri, 3 Nov 2017 15:47:35 +0200 Subject: [PATCH] Move level argument parsing to the correct place and give it initial values --- src/cfg.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++-- src/cli.c | 40 +------------------------------------- src/cli.h | 2 -- src/kvazaar.h | 5 +++++ 4 files changed, 57 insertions(+), 43 deletions(-) diff --git a/src/cfg.c b/src/cfg.c index 5cf1fab9..c0490e36 100644 --- a/src/cfg.c +++ b/src/cfg.c @@ -125,6 +125,9 @@ int kvz_config_init(kvz_config *cfg) cfg->optional_key = NULL; + cfg->level = 62; // hevc level 6.2, the highest + cfg->force_level = true; + return 1; } @@ -1109,10 +1112,56 @@ int kvz_config_parse(kvz_config *cfg, const char *name, const char *value) fclose(f); } - else if OPT("erp-aqp") + else if OPT("erp-aqp") { cfg->erp_aqp = (bool)atobool(value); - else + } + else if (OPT("level") || OPT("force-level")) { + if OPT("force-level") { + cfg->force_level = true; + } else { + cfg->force_level = false; + } + + unsigned int num_first, num_second, level = 0; + int matched_amount = sscanf(value, "%u.%u", &num_first, &num_second); + + if (matched_amount == 2) { + // of form x.y + level = num_first * 10 + num_second; + } + else if (matched_amount == 1) { + // no dot + if (num_first < 10) { + // of form x + level = num_first * 10; + } + else { + // of form xx + level = num_first; + } + } + + // check if the level has a valid value + switch (level) + { + case 10: + case 20: case 21: + case 30: case 31: + case 40: case 41: + case 50: case 51: case 52: + case 60: case 61: case 62: + // a-ok + break; + default: + fprintf(stderr, "invalid level value: \"%s\"", value); + return 0; + } + + cfg->level = level; + } + else { return 0; + } #undef OPT return 1; diff --git a/src/cli.c b/src/cli.c index 315a721b..eae9b636 100644 --- a/src/cli.c +++ b/src/cli.c @@ -123,6 +123,7 @@ static const struct option long_options[] = { { "erp-aqp", no_argument, NULL, 0 }, { "no-erp-aqp", no_argument, NULL, 0 }, { "level", required_argument, NULL, 0 }, + { "force-level", required_argument, NULL, 0 }, {0, 0, 0, 0} }; @@ -235,45 +236,6 @@ cmdline_opts_t* cmdline_opts_parse(const kvz_api *const api, int argc, char *arg goto done; } else if (!strcmp(name, "loop-input")) { opts->loop_input = true; - } else if (!strcmp(name, "level")) { - unsigned int num_first, num_second, level = 0; - int matched_amount = sscanf(optarg, "%u.%u", &num_first, &num_second); - - if (matched_amount == 2) { - // of form x.y - level = num_first * 10 + num_second; - } else if (matched_amount == 1) { - // no dot - if (num_first < 10) { - // of form x - level = num_first * 10; - } else { - // of form xx - level = num_first; - } - } - - // check if the level has a valid value - switch (level) - { - case 10: - case 20: case 21: - case 30: case 31: - case 40: case 41: - case 50: case 51: case 52: - case 60: case 61: case 62: - // a-ok - break; - default: - fprintf(stderr, "invalid level value: \"%s\"", optarg); - ok = 0; - goto done; - } - - // DEBUG - fprintf(stderr, "lvl: %u", level); - - opts->level = level; } else if (!api->config_parse(opts->config, name, optarg)) { fprintf(stderr, "invalid argument: %s=%s\n", name, optarg); ok = 0; diff --git a/src/cli.h b/src/cli.h index 5554067b..be042a3e 100644 --- a/src/cli.h +++ b/src/cli.h @@ -47,8 +47,6 @@ typedef struct cmdline_opts_t { bool version; /** \brief Whether to loop input */ bool loop_input; - /* \brief The HEVC level */ - uint8_t level; } cmdline_opts_t; cmdline_opts_t* cmdline_opts_parse(const kvz_api *api, int argc, char *argv[]); diff --git a/src/kvazaar.h b/src/kvazaar.h index e34cfc3f..ee18ac1d 100644 --- a/src/kvazaar.h +++ b/src/kvazaar.h @@ -351,6 +351,11 @@ typedef struct kvz_config * \brief Use adaptive QP for 360 video with equirectangular projection. */ int32_t erp_aqp; + + /** \brief The HEVC level */ + uint8_t level; + /** \brief Whether we ignore and just warn from all of the errors about the output not conforming to the level's requirements. */ + uint8_t force_level; } kvz_config; /**