diff mbox series

[FFmpeg-devel,28/31] fftools/ffmpeg_filter: change processing order in fg_finalise_bindings()

Message ID 20240405161212.26167-28-anton@khirnov.net
State Accepted
Commit 3d01996b242ee588bcb27d61d6351439b8849260
Headers show
Series [FFmpeg-devel,01/31] lavfi/vf_scale: fix AVOption flags for "size"/"s" | expand

Checks

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

Commit Message

Anton Khirnov April 5, 2024, 4:12 p.m. UTC
First bind all inputs in all filtergraphs, only then check that all
outputs are bound.

Needed by the following commit.
---
 fftools/ffmpeg.h        |  2 +-
 fftools/ffmpeg_filter.c | 33 ++++++++++++++++++++++++++-------
 fftools/ffmpeg_opt.c    | 10 ++++------
 3 files changed, 31 insertions(+), 14 deletions(-)
diff mbox series

Patch

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 882d241bdb..885a7c0c10 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -724,7 +724,7 @@  int init_simple_filtergraph(InputStream *ist, OutputStream *ost,
                             char *graph_desc,
                             Scheduler *sch, unsigned sch_idx_enc,
                             const OutputFilterOptions *opts);
-int fg_finalise_bindings(FilterGraph *fg);
+int fg_finalise_bindings(void);
 
 /**
  * Get our axiliary frame data attached to the frame, allocating it
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 388c8919fd..1e14962f41 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -1272,7 +1272,7 @@  static int fg_complex_bind_input(FilterGraph *fg, InputFilter *ifilter)
     return 0;
 }
 
-int fg_finalise_bindings(FilterGraph *fg)
+static int bind_inputs(FilterGraph *fg)
 {
     // bind filtergraph inputs to input streams
     for (int i = 0; i < fg->nb_inputs; i++) {
@@ -1287,14 +1287,33 @@  int fg_finalise_bindings(FilterGraph *fg)
             return ret;
     }
 
-    for (int i = 0; i < fg->nb_outputs; i++) {
-        OutputFilter *output = fg->outputs[i];
-        if (!output->bound) {
-            av_log(filtergraphs[i], AV_LOG_FATAL,
-                   "Filter %s has an unconnected output\n", output->name);
-            return AVERROR(EINVAL);
+    return 0;
+}
+
+int fg_finalise_bindings(void)
+{
+    int ret;
+
+    for (int i = 0; i < nb_filtergraphs; i++) {
+        ret = bind_inputs(filtergraphs[i]);
+        if (ret < 0)
+            return ret;
+    }
+
+    // check that all outputs were bound
+    for (int i = 0; i < nb_filtergraphs; i++) {
+        FilterGraph *fg = filtergraphs[i];
+
+        for (int j = 0; j < fg->nb_outputs; j++) {
+            OutputFilter *output = fg->outputs[j];
+            if (!output->bound) {
+                av_log(filtergraphs[j], AV_LOG_FATAL,
+                       "Filter %s has an unconnected output\n", output->name);
+                return AVERROR(EINVAL);
+            }
         }
     }
+
     return 0;
 }
 
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index f764da1ed4..6526e8e3e8 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -1264,12 +1264,10 @@  int ffmpeg_parse_options(int argc, char **argv, Scheduler *sch)
     }
 
     // bind unbound filtegraph inputs/outputs and check consistency
-    for (int i = 0; i < nb_filtergraphs; i++) {
-        ret = fg_finalise_bindings(filtergraphs[i]);
-        if (ret < 0) {
-            errmsg = "binding filtergraph inputs/outputs";
-            goto fail;
-        }
+    ret = fg_finalise_bindings();
+    if (ret < 0) {
+        errmsg = "binding filtergraph inputs/outputs";
+        goto fail;
     }
 
     correct_input_start_times();