Move level argument parsing to the correct place and give it initial values

This commit is contained in:
Miika Metsoila 2017-11-03 15:47:35 +02:00
parent 61a31054e1
commit fb4d0c3cf2
4 changed files with 57 additions and 43 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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[]);

View file

@ -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;
/**