[FFmpeg-cvslog] fftools/cmdutils: add support for level flag in loglevel option parser

Tobias Rapp git at videolan.org
Tue Apr 3 11:18:42 EEST 2018


ffmpeg | branch: master | Tobias Rapp <t.rapp at noa-archive.com> | Tue Apr  3 08:54:10 2018 +0200| [4b736bc921ed96ad6d312ce0cbe0de29b9e3fe81] | committer: Tobias Rapp

fftools/cmdutils: add support for level flag in loglevel option parser

Allows to manage the AV_LOG_PRINT_LEVEL flag as a prefix to the loglevel
option value, similar to the existing AV_LOG_SKIP_REPEATE flag. Adds
support for setting flags relative to the existing value by using a +/-
prefix.

Previous version reviewed-by: Michael Niedermayer <michael at niedermayer.cc>
Signed-off-by: Tobias Rapp <t.rapp at noa-archive.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=4b736bc921ed96ad6d312ce0cbe0de29b9e3fe81
---

 fftools/cmdutils.c | 65 +++++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 47 insertions(+), 18 deletions(-)

diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 1001f36299..8ffc9d240b 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -881,28 +881,54 @@ int opt_loglevel(void *optctx, const char *opt, const char *arg)
         { "debug"  , AV_LOG_DEBUG   },
         { "trace"  , AV_LOG_TRACE   },
     };
+    const char *token;
     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;
+    int flags = av_log_get_flags();
+    int level = av_log_get_level();
+    int cmd, i = 0;
+
+    av_assert0(arg);
+    while (*arg) {
+        token = arg;
+        if (*token == '+' || *token == '-') {
+            cmd = *token++;
+        } else {
+            cmd = 0;
+        }
+        if (!i && !cmd) {
+            flags = 0;  /* missing relative prefix, build absolute value */
+        }
+        if (!strncmp(token, "repeat", 6)) {
+            if (cmd == '-') {
+                flags |= AV_LOG_SKIP_REPEATED;
+            } else {
+                flags &= ~AV_LOG_SKIP_REPEATED;
+            }
+            arg = token + 6;
+        } else if (!strncmp(token, "level", 5)) {
+            if (cmd == '-') {
+                flags &= ~AV_LOG_PRINT_LEVEL;
+            } else {
+                flags |= AV_LOG_PRINT_LEVEL;
+            }
+            arg = token + 5;
+        } else {
+            break;
+        }
+        i++;
+    }
+    if (!*arg) {
+        goto end;
+    } else if (*arg == '+') {
+        arg++;
+    } else if (!i) {
+        flags = av_log_get_flags();  /* level value without prefix, reset flags */
+    }
 
     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;
+            level = log_levels[i].level;
+            goto end;
         }
     }
 
@@ -914,6 +940,9 @@ int opt_loglevel(void *optctx, const char *opt, const char *arg)
             av_log(NULL, AV_LOG_FATAL, "\"%s\"\n", log_levels[i].name);
         exit_program(1);
     }
+
+end:
+    av_log_set_flags(flags);
     av_log_set_level(level);
     return 0;
 }



More information about the ffmpeg-cvslog mailing list