[FFmpeg-cvslog] fftools/ffmpeg_filter: decouple allocating InputFilter and binding it to InputStream

Anton Khirnov git at videolan.org
Wed May 31 17:25:48 EEST 2023


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Sun May 21 21:11:09 2023 +0200| [00183880aa065e97a3ec37524c802b562f83876d] | committer: Anton Khirnov

fftools/ffmpeg_filter: decouple allocating InputFilter and binding it to InputStream

Will be useful in future commits.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=00183880aa065e97a3ec37524c802b562f83876d
---

 fftools/ffmpeg_filter.c | 31 ++++++++++++++++++++++---------
 1 file changed, 22 insertions(+), 9 deletions(-)

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",



More information about the ffmpeg-cvslog mailing list