[FFmpeg-devel] [PATCH v3 3/3] fftools/cmdutils: replace loglevel option parsing with av_log_set_opts

Tobias Rapp t.rapp at noa-archive.com
Wed Mar 28 18:03:40 EEST 2018


Signed-off-by: Tobias Rapp <t.rapp at noa-archive.com>
---
 fftools/cmdutils.c | 48 +++++++-----------------------------------------
 1 file changed, 7 insertions(+), 41 deletions(-)

diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index c0ddf0b..2a0a995 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -870,51 +870,17 @@ int opt_cpuflags(void *optctx, const char *opt, const char *arg)
 
 int opt_loglevel(void *optctx, const char *opt, const char *arg)
 {
-    const struct { const char *name; int level; } log_levels[] = {
-        { "quiet"  , AV_LOG_QUIET   },
-        { "panic"  , AV_LOG_PANIC   },
-        { "fatal"  , AV_LOG_FATAL   },
-        { "error"  , AV_LOG_ERROR   },
-        { "warning", AV_LOG_WARNING },
-        { "info"   , AV_LOG_INFO    },
-        { "verbose", AV_LOG_VERBOSE },
-        { "debug"  , AV_LOG_DEBUG   },
-        { "trace"  , AV_LOG_TRACE   },
-    };
-    char *tail;
-    int level;
-    int flags;
-    int i;
-
-    flags = av_log_get_flags();
-    tail = strstr(arg, "repeat");
-    if (tail)
-        flags &= ~AV_LOG_SKIP_REPEATED;
-    else
-        flags |= AV_LOG_SKIP_REPEATED;
-
-    av_log_set_flags(flags);
-    if (tail == arg)
-        arg += 6 + (arg[6]=='+');
-    if(tail && !*arg)
-        return 0;
-
-    for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++) {
-        if (!strcmp(log_levels[i].name, arg)) {
-            av_log_set_level(log_levels[i].level);
-            return 0;
-        }
-    }
+    int ret;
 
-    level = strtol(arg, &tail, 10);
-    if (*tail) {
+    ret = av_log_set_opts(arg);
+    if (ret < 0) {
         av_log(NULL, AV_LOG_FATAL, "Invalid loglevel \"%s\". "
-               "Possible levels are numbers or:\n", arg);
-        for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++)
-            av_log(NULL, AV_LOG_FATAL, "\"%s\"\n", log_levels[i].name);
+               "Possible levels are numbers or:\n"
+               "\"quiet\", \"panic\", \"fatal\", \"error\", \"warning\", "
+               "\"info\", \"verbose\", \"debug\", \"trace\"\n"
+               "optionally prefixed by \"repeat\" or \"level\" flags\n", arg);
         exit_program(1);
     }
-    av_log_set_level(level);
     return 0;
 }
 
-- 
2.7.4




More information about the ffmpeg-devel mailing list