diff mbox series

[FFmpeg-devel,13/13] fftools/ffmpeg_filter: remove remaining OutputStream usage in init_simple_filtergraph()

Message ID 20240924071000.11428-13-anton@khirnov.net
State New
Headers show
Series [FFmpeg-devel,01/13] doc/ffmpeg; improve wording in the description section | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 fail Make fate failed
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Anton Khirnov Sept. 24, 2024, 7:09 a.m. UTC
With this, nothing in ffmpeg_filter acesses OutputStream anymore, thus
there are no more direct ties between filtering and muxing.

Rename init_simple_filtergraph() to fg_create_simple() for consistency.
---
 fftools/ffmpeg.h          |  9 +++++----
 fftools/ffmpeg_filter.c   | 22 +++++++++++-----------
 fftools/ffmpeg_mux_init.c |  7 +++++--
 3 files changed, 21 insertions(+), 17 deletions(-)
diff mbox series

Patch

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index d20034efb0..b5c95439e5 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -755,10 +755,11 @@  int find_codec(void *logctx, const char *name,
 int parse_and_set_vsync(const char *arg, int *vsync_var, int file_idx, int st_idx, int is_global);
 
 int filtergraph_is_simple(const FilterGraph *fg);
-int init_simple_filtergraph(InputStream *ist, OutputStream *ost,
-                            char *graph_desc,
-                            Scheduler *sch, unsigned sch_idx_enc,
-                            const OutputFilterOptions *opts);
+int fg_create_simple(FilterGraph **pfg,
+                     InputStream *ist,
+                     char *graph_desc,
+                     Scheduler *sch, unsigned sched_idx_enc,
+                     const OutputFilterOptions *opts);
 int fg_finalise_bindings(void);
 
 /**
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 7faa666d2d..c36a3ad00a 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -1180,25 +1180,27 @@  fail:
     return 0;
 }
 
-int init_simple_filtergraph(InputStream *ist, OutputStream *ost,
-                            char *graph_desc,
-                            Scheduler *sch, unsigned sched_idx_enc,
-                            const OutputFilterOptions *opts)
+int fg_create_simple(FilterGraph **pfg,
+                     InputStream *ist,
+                     char *graph_desc,
+                     Scheduler *sch, unsigned sched_idx_enc,
+                     const OutputFilterOptions *opts)
 {
+    const enum AVMediaType type = ist->par->codec_type;
     FilterGraph *fg;
     FilterGraphPriv *fgp;
     int ret;
 
-    ret = fg_create(&ost->fg_simple, graph_desc, sch);
+    ret = fg_create(pfg, graph_desc, sch);
     if (ret < 0)
         return ret;
-    fg  = ost->fg_simple;
+    fg  = *pfg;
     fgp = fgp_from_fg(fg);
 
     fgp->is_simple = 1;
 
     snprintf(fgp->log_name, sizeof(fgp->log_name), "%cf%s",
-             av_get_media_type_string(ost->type)[0], opts->name);
+             av_get_media_type_string(type)[0], opts->name);
 
     if (fg->nb_inputs != 1 || fg->nb_outputs != 1) {
         av_log(fg, AV_LOG_ERROR, "Simple filtergraph '%s' was expected "
@@ -1208,16 +1210,14 @@  int init_simple_filtergraph(InputStream *ist, OutputStream *ost,
                graph_desc, fg->nb_inputs, fg->nb_outputs);
         return AVERROR(EINVAL);
     }
-    if (fg->outputs[0]->type != ost->type) {
+    if (fg->outputs[0]->type != type) {
         av_log(fg, AV_LOG_ERROR, "Filtergraph has a %s output, cannot connect "
                "it to %s output stream\n",
                av_get_media_type_string(fg->outputs[0]->type),
-               av_get_media_type_string(ost->type));
+               av_get_media_type_string(type));
         return AVERROR(EINVAL);
     }
 
-    ost->filter = fg->outputs[0];
-
     ret = ifilter_bind_ist(fg->inputs[0], ist, opts->vs);
     if (ret < 0)
         return ret;
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 53a17c33a6..ec9f328e90 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -1010,8 +1010,11 @@  ost_bind_filter(const Muxer *mux, MuxStream *ms, OutputFilter *ofilter,
         ost->filter = ofilter;
         ret = ofilter_bind_enc(ofilter, ms->sch_idx_enc, &opts);
     } else {
-        ret = init_simple_filtergraph(ost->ist, ost, filters,
-                                      mux->sch, ms->sch_idx_enc, &opts);
+        ret = fg_create_simple(&ost->fg_simple, ost->ist, filters,
+                               mux->sch, ms->sch_idx_enc, &opts);
+        if (ret >= 0)
+            ost->filter = ost->fg_simple->outputs[0];
+
     }
     av_freep(&opts.nb_threads);
     if (ret < 0)