diff mbox series

[FFmpeg-devel,27/31] fftools/ffmpeg_filter: only store complex filtergraphs in global array

Message ID 20240405161212.26167-27-anton@khirnov.net
State Accepted
Commit 243a51490a85923c29ea9c276786e7b7d29cff0d
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
Store simple filtergraphs in the stream they feed. Keeping the two
separate will be useful in following commits.
---
 fftools/ffmpeg.c        |  5 +++++
 fftools/ffmpeg.h        |  3 +++
 fftools/ffmpeg_filter.c | 16 +++++++++++++---
 fftools/ffmpeg_mux.c    |  1 +
 4 files changed, 22 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 0ee76d69b5..1f50ed6805 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -787,6 +787,11 @@  static int check_keyboard_interaction(int64_t cur_time)
             (n = sscanf(buf, "%63[^ ] %lf %255[^ ] %255[^\n]", target, &time, command, arg)) >= 3) {
             av_log(NULL, AV_LOG_DEBUG, "Processing command target:%s time:%f command:%s arg:%s",
                    target, time, command, arg);
+            for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) {
+                if (ost->fg_simple)
+                    fg_send_command(ost->fg_simple, time, target, command, arg,
+                                    key == 'C');
+            }
             for (i = 0; i < nb_filtergraphs; i++)
                 fg_send_command(filtergraphs[i], time, target, command, arg,
                                 key == 'C');
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 6446a141b5..882d241bdb 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -582,6 +582,8 @@  typedef struct OutputStream {
     char *logfile_prefix;
     FILE *logfile;
 
+    // simple filtergraph feeding this stream, if any
+    FilterGraph  *fg_simple;
     OutputFilter *filter;
 
     AVDictionary *encoder_opts;
@@ -653,6 +655,7 @@  extern int        nb_input_files;
 extern OutputFile   **output_files;
 extern int         nb_output_files;
 
+// complex filtergraphs
 extern FilterGraph **filtergraphs;
 extern int        nb_filtergraphs;
 
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 3988cf5fc2..388c8919fd 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -1009,16 +1009,25 @@  int fg_create(FilterGraph **pfg, char *graph_desc, Scheduler *sch)
     AVFilterGraph *graph;
     int ret = 0;
 
-    fgp = allocate_array_elem(&filtergraphs, sizeof(*fgp), &nb_filtergraphs);
+    fgp = av_mallocz(sizeof(*fgp));
     if (!fgp)
         return AVERROR(ENOMEM);
     fg = &fgp->fg;
 
-    if (pfg)
+    if (pfg) {
         *pfg = fg;
+        fg->index = -1;
+    } else {
+        ret = av_dynarray_add_nofree(&filtergraphs, &nb_filtergraphs, fgp);
+        if (ret < 0) {
+            av_freep(&fgp);
+            return ret;
+        }
+
+        fg->index = nb_filtergraphs - 1;
+    }
 
     fg->class       = &fg_class;
-    fg->index      = nb_filtergraphs - 1;
     fgp->graph_desc = graph_desc;
     fgp->disable_conversions = !auto_conversion_filters;
     fgp->sch                 = sch;
@@ -1135,6 +1144,7 @@  int init_simple_filtergraph(InputStream *ist, OutputStream *ost,
     ret = fg_create(&fg, graph_desc, sch);
     if (ret < 0)
         return ret;
+    ost->fg_simple = fg;
     fgp = fgp_from_fg(fg);
 
     fgp->is_simple = 1;
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 2b7a733501..a1583edd61 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -797,6 +797,7 @@  static void ost_free(OutputStream **post)
     ms = ms_from_ost(ost);
 
     enc_free(&ost->enc);
+    fg_free(&ost->fg_simple);
 
     if (ost->logfile) {
         if (fclose(ost->logfile))