Commit 182cbe43 authored by Anton Khirnov's avatar Anton Khirnov

avtools: parse loglevel before all the other options.

This way it can be applied to cmdutils too -- e.g. showing the banner
and printing startup messages.
parent 4ca59d19
...@@ -4019,6 +4019,7 @@ int main(int argc, char **argv) ...@@ -4019,6 +4019,7 @@ int main(int argc, char **argv)
reset_options(&o); reset_options(&o);
av_log_set_flags(AV_LOG_SKIP_REPEATED); av_log_set_flags(AV_LOG_SKIP_REPEATED);
parse_loglevel(argc, argv, options);
avcodec_register_all(); avcodec_register_all();
#if CONFIG_AVDEVICE #if CONFIG_AVDEVICE
......
...@@ -3050,6 +3050,7 @@ int main(int argc, char **argv) ...@@ -3050,6 +3050,7 @@ int main(int argc, char **argv)
int flags; int flags;
av_log_set_flags(AV_LOG_SKIP_REPEATED); av_log_set_flags(AV_LOG_SKIP_REPEATED);
parse_loglevel(argc, argv, options);
/* register all codecs, demux and protocols */ /* register all codecs, demux and protocols */
avcodec_register_all(); avcodec_register_all();
......
...@@ -399,6 +399,7 @@ int main(int argc, char **argv) ...@@ -399,6 +399,7 @@ int main(int argc, char **argv)
{ {
int ret; int ret;
parse_loglevel(argc, argv, options);
av_register_all(); av_register_all();
init_opts(); init_opts();
#if CONFIG_AVDEVICE #if CONFIG_AVDEVICE
......
...@@ -4668,6 +4668,7 @@ int main(int argc, char **argv) ...@@ -4668,6 +4668,7 @@ int main(int argc, char **argv)
{ {
struct sigaction sigact; struct sigaction sigact;
parse_loglevel(argc, argv, options);
av_register_all(); av_register_all();
show_banner(); show_banner();
......
...@@ -304,6 +304,41 @@ void parse_options(void *optctx, int argc, char **argv, const OptionDef *options ...@@ -304,6 +304,41 @@ void parse_options(void *optctx, int argc, char **argv, const OptionDef *options
} }
} }
/*
* Return index of option opt in argv or 0 if not found.
*/
static int locate_option(int argc, char **argv, const OptionDef *options, const char *optname)
{
const OptionDef *po;
int i;
for (i = 1; i < argc; i++) {
const char *cur_opt = argv[i];
if (*cur_opt++ != '-')
continue;
po = find_option(options, cur_opt);
if (!po->name && cur_opt[0] == 'n' && cur_opt[1] == 'o')
po = find_option(options, cur_opt + 2);
if ((!po->name && !strcmp(cur_opt, optname)) ||
(po->name && !strcmp(optname, po->name)))
return i;
if (!po || po->flags & HAS_ARG)
i++;
}
return 0;
}
void parse_loglevel(int argc, char **argv, const OptionDef *options)
{
int idx = locate_option(argc, argv, options, "loglevel");
if (idx && argv[idx + 1])
opt_loglevel("loglevel", argv[idx + 1]);
}
#define FLAGS (o->type == FF_OPT_TYPE_FLAGS) ? AV_DICT_APPEND : 0 #define FLAGS (o->type == FF_OPT_TYPE_FLAGS) ? AV_DICT_APPEND : 0
int opt_default(const char *opt, const char *arg) int opt_default(const char *opt, const char *arg)
{ {
......
...@@ -174,6 +174,11 @@ void parse_options(void *optctx, int argc, char **argv, const OptionDef *options ...@@ -174,6 +174,11 @@ void parse_options(void *optctx, int argc, char **argv, const OptionDef *options
*/ */
int parse_option(void *optctx, const char *opt, const char *arg, const OptionDef *options); int parse_option(void *optctx, const char *opt, const char *arg, const OptionDef *options);
/**
* Find the '-loglevel' option in the commandline args and apply it.
*/
void parse_loglevel(int argc, char **argv, const OptionDef *options);
/** /**
* Check if the given stream matches a stream specifier. * Check if the given stream matches a stream specifier.
* *
......
...@@ -4357,6 +4357,7 @@ int main(int argc, char **argv) ...@@ -4357,6 +4357,7 @@ int main(int argc, char **argv)
int64_t ti; int64_t ti;
av_log_set_flags(AV_LOG_SKIP_REPEATED); av_log_set_flags(AV_LOG_SKIP_REPEATED);
parse_loglevel(argc, argv, options);
avcodec_register_all(); avcodec_register_all();
#if CONFIG_AVDEVICE #if CONFIG_AVDEVICE
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment