diff mbox series

[FFmpeg-devel,1/5] fftools/ffmpeg: split loop for parsing and validation of -stats_* specifiers

Message ID 20231211150725.46473-2-thilo.borgmann@mail.de
State New
Headers show
Series avfilter: Add fsync filter | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Thilo Borgmann Dec. 11, 2023, 3:07 p.m. UTC
---
 fftools/ffmpeg_mux_init.c | 40 ++++++++++++++++++++++++++-------------
 1 file changed, 27 insertions(+), 13 deletions(-)
diff mbox series

Patch

diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 63a25a350f..6c473a8f09 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -365,6 +365,26 @@  static int enc_stats_init(OutputStream *ost, EncStats *es, int pre,
 
         c = &es->components[es->nb_components - 1];
 
+        for (size_t i = 0; i < FF_ARRAY_ELEMS(fmt_specs); i++) {
+            if (!strcmp(val, fmt_specs[i].str)) {
+                c->type = fmt_specs[i].type;
+                c->str  = val;
+                c->str_len = val_len;
+                break;
+            }
+        }
+
+        if (!c->type) {
+            av_log(NULL, AV_LOG_ERROR, "Invalid format directive: %s\n", val);
+            ret = AVERROR(EINVAL);
+            goto fail;
+        }
+    }
+
+    for (int j = 0; j < es->nb_components; j++) {
+        EncStatsComponent *c = &es->components[j];
+        char *val = c->str;
+
         for (size_t i = 0; i < FF_ARRAY_ELEMS(fmt_specs); i++) {
             if (!strcmp(val, fmt_specs[i].str)) {
                 if ((pre && fmt_specs[i].post_only) || (!pre && fmt_specs[i].pre_only)) {
@@ -375,8 +395,6 @@  static int enc_stats_init(OutputStream *ost, EncStats *es, int pre,
                     goto fail;
                 }
 
-                c->type = fmt_specs[i].type;
-
                 if (fmt_specs[i].need_input_data && !ost->ist) {
                     av_log(ost, AV_LOG_WARNING,
                            "Format directive '%s' is unavailable, because "
@@ -387,20 +405,16 @@  static int enc_stats_init(OutputStream *ost, EncStats *es, int pre,
                 break;
             }
         }
-
-        if (!c->type) {
-            av_log(NULL, AV_LOG_ERROR, "Invalid format directive: %s\n", val);
-            ret = AVERROR(EINVAL);
-            goto fail;
-        }
-
-fail:
-        av_freep(&val);
-        if (ret < 0)
-            return ret;
     }
 
     ret = enc_stats_get_file(&es->io, path);
+fail:
+    for (int j = 0; j < es->nb_components; j++) {
+        EncStatsComponent *c = &es->components[j];
+        if (c->type != ENC_STATS_LITERAL) {
+            av_freep(&c->str);
+        }
+    }
     if (ret < 0)
         return ret;