diff mbox series

[FFmpeg-devel,06/24] fftools/ffmpeg_filter: decouple allocating InputFilter and binding it to InputStream

Message ID 20230528091416.17927-6-anton@khirnov.net
State Accepted
Commit 00183880aa065e97a3ec37524c802b562f83876d
Headers show
Series [FFmpeg-devel,01/24] fftools/ffmpeg_mux_init: merge ost_add_from_filter() to ost_add() | expand

Checks

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

Commit Message

Anton Khirnov May 28, 2023, 9:13 a.m. UTC
Will be useful in future commits.
---
 fftools/ffmpeg_filter.c | 31 ++++++++++++++++++++++---------
 1 file changed, 22 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 323e63b829..a8c4ef321f 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -258,7 +258,24 @@  static OutputFilter *ofilter_alloc(FilterGraph *fg)
     return ofilter;
 }
 
-static InputFilter *ifilter_alloc(FilterGraph *fg, InputStream *ist)
+static int ifilter_bind_ist(InputFilter *ifilter, InputStream *ist)
+{
+    InputFilterPriv *ifp = ifp_from_ifilter(ifilter);
+    int ret;
+
+    ret = ist_filter_add(ist, ifilter, filtergraph_is_simple(ifilter->graph));
+    if (ret < 0)
+        return ret;
+
+    ifp->ist             = ist;
+    ifp->type_src        = ist->st->codecpar->codec_type;
+    ifp->type            = ifp->type_src == AVMEDIA_TYPE_SUBTITLE ?
+                           AVMEDIA_TYPE_VIDEO : ifp->type_src;
+
+    return 0;
+}
+
+static InputFilter *ifilter_alloc(FilterGraph *fg)
 {
     InputFilterPriv *ifp = allocate_array_elem(&fg->inputs, sizeof(*ifp),
                                                &fg->nb_inputs);
@@ -272,10 +289,6 @@  static InputFilter *ifilter_alloc(FilterGraph *fg, InputStream *ist)
 
     ifp->format          = -1;
     ifp->fallback.format = -1;
-    ifp->ist             = ist;
-    ifp->type_src        = ist->st->codecpar->codec_type;
-    ifp->type            = ifp->type_src == AVMEDIA_TYPE_SUBTITLE ?
-                           AVMEDIA_TYPE_VIDEO : ifp->type_src;
 
     ifp->frame_queue = av_fifo_alloc2(8, sizeof(AVFrame*), AV_FIFO_FLAG_AUTO_GROW);
     if (!ifp->frame_queue)
@@ -373,9 +386,9 @@  int init_simple_filtergraph(InputStream *ist, OutputStream *ost,
 
     ost->filter = ofilter;
 
-    ifilter = ifilter_alloc(fg, ist);
+    ifilter = ifilter_alloc(fg);
 
-    ret = ist_filter_add(ist, ifilter, 1);
+    ret = ifilter_bind_ist(ifilter, ist);
     if (ret < 0)
         return ret;
 
@@ -455,10 +468,10 @@  static void init_input_filter(FilterGraph *fg, AVFilterInOut *in)
     }
     av_assert0(ist);
 
-    ifilter         = ifilter_alloc(fg, ist);
+    ifilter         = ifilter_alloc(fg);
     ifilter->name   = describe_filter_link(fg, in, 1);
 
-    ret = ist_filter_add(ist, ifilter, 0);
+    ret = ifilter_bind_ist(ifilter, ist);
     if (ret < 0) {
         av_log(NULL, AV_LOG_ERROR,
                "Error binding an input stream to complex filtergraph input %s.\n",