From 7e507fd615b3cade34ff331387fb1ea04105b2a5 Mon Sep 17 00:00:00 2001 From: Ari Koivula Date: Mon, 10 Mar 2014 15:53:23 +0200 Subject: [PATCH] Add --input-res CLI parameter. - Also set default width and height to 0 because it makes no sense to assume dimensions. It's kind of like defaulting to the most common altitude when the altimeter is broken. - Add config_validate to have a place for checks on overall cfg state. --- src/config.c | 31 +++++++++++++++++++++++++++---- src/config.h | 1 + src/encmain.c | 16 ++++++++++++++-- 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/config.c b/src/config.c index ce4a1a42..32984907 100644 --- a/src/config.c +++ b/src/config.c @@ -56,8 +56,8 @@ int config_init(config *cfg) cfg->output = NULL; cfg->debug = NULL; cfg->frames = 0; - cfg->width = 320; - cfg->height = 240; + cfg->width = 0; + cfg->height = 0; cfg->qp = 32; cfg->intra_period = 0; cfg->deblock_enable = 1; @@ -181,6 +181,11 @@ static int config_parse(config *cfg, const char *name, const char *value) cfg->width = atoi(value); OPT("height") cfg->height = atoi(value); + OPT("input-res") { + if (2 != sscanf(value, "%dx%d", &cfg->width, &cfg->height)) { + cfg->width = cfg->height = 0; + } + } OPT("frames") cfg->frames = atoi(value); OPT("qp") @@ -276,11 +281,12 @@ int config_read(config *cfg,int argc, char *argv[]) { "output", required_argument, NULL, 'o' }, { "debug", required_argument, NULL, 'd' }, { "width", required_argument, NULL, 'w' }, - { "height", required_argument, NULL, 'h' }, - { "frames", required_argument, NULL, 'n' }, + { "height", required_argument, NULL, 'h' }, // deprecated + { "frames", required_argument, NULL, 'n' }, // deprecated { "qp", required_argument, NULL, 'q' }, { "period", required_argument, NULL, 'p' }, { "ref", required_argument, NULL, 'r' }, + { "input-res", required_argument, NULL, 0 }, { "no-deblock", no_argument, NULL, 0 }, { "deblock", required_argument, NULL, 0 }, { "no-sao", no_argument, NULL, 0 }, @@ -332,3 +338,20 @@ int config_read(config *cfg,int argc, char *argv[]) return 1; } + +/** + * \brief A function that does additional checks after config_init. + * + * Add checks that don't make sense to have in config_init here. + * This should be called when cfg is in it's final state. + * + * \return 0 if config fails, otherwise 1. + */ +int config_validate(config *cfg) +{ + if (cfg->width == 0 || cfg->height == 0) { + fprintf(stderr, "Input error: one of the dimensions is 0: dims=%dx%d", cfg->width, cfg->height); + return 0; + } + return 1; +} diff --git a/src/config.h b/src/config.h index 8bb1074d..13e20f72 100644 --- a/src/config.h +++ b/src/config.h @@ -69,5 +69,6 @@ config *config_alloc(void); int config_init(config *cfg); int config_destroy(config *cfg); int config_read(config *cfg,int argc, char *argv[]); +int config_validate(config *cfg); #endif diff --git a/src/encmain.c b/src/encmain.c index bff01674..5f86cd59 100644 --- a/src/encmain.c +++ b/src/encmain.c @@ -88,11 +88,12 @@ int main(int argc, char *argv[]) fprintf(stderr, "Usage:\n" - "kvazaar -i -w -h -o \n" + "kvazaar -i -w --input-res : -o \n" "\n" "Optional parameters:\n" " -n, --frames : Number of frames to code [all]\n" " --seek : First frame to code [0]\n" + " --input-res x : Input resolution (width x height)\n" " -q, --qp : Quantization Parameter [32]\n" " -p, --period : Period of intra pictures [0]\n" " 0: only first picture is intra\n" @@ -126,7 +127,12 @@ int main(int argc, char *argv[]) " --colormatrix : Specify color matrix setting [\"undef\"]\n" " - undef, bt709, fcc, bt470bg, smpte170m,\n" " smpte240m, GBR, YCgCo, bt2020nc, bt2020c\n" - " --chromaloc : Specify chroma sample location (0 to 5) [0]\n"); + " --chromaloc : Specify chroma sample location (0 to 5) [0]\n" + "\n" + " Deprecated parameters: (might be removed at some point)\n" + " Use --input-res:\n" + " -w, --width : Width of input in pixels\n" + " -h, --height : Height of input in pixels\n"); if (cfg) config_destroy(cfg); @@ -134,6 +140,12 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } + // Do more validation to make sure the parameters we have make sense. + if (!config_validate(cfg)) { + config_destroy(cfg); + return EXIT_FAILURE; + } + // Dig CPU features with cpuid kvz_cpu_cpuid(&ecx,&edx); printf("CPU features enabled: ");