[FFmpeg-cvslog] fftools/ffmpeg_filter: factorize allocating InputFilter

Anton Khirnov git at videolan.org
Tue May 2 12:31:13 EEST 2023


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Tue Apr 25 23:32:04 2023 +0200| [1dcae45ecbbc489d46695b41f92edf13efdca653] | committer: Anton Khirnov

fftools/ffmpeg_filter: factorize allocating InputFilter

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

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

diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 8246ffca77..a9242fcd11 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -203,6 +203,21 @@ static OutputFilter *ofilter_alloc(FilterGraph *fg)
     return ofilter;
 }
 
+static InputFilter *ifilter_alloc(FilterGraph *fg)
+{
+    InputFilter *ifilter;
+
+    ifilter         = ALLOC_ARRAY_ELEM(fg->inputs, fg->nb_inputs);
+    ifilter->graph  = fg;
+    ifilter->format = -1;
+
+    ifilter->frame_queue = av_fifo_alloc2(8, sizeof(AVFrame*), AV_FIFO_FLAG_AUTO_GROW);
+    if (!ifilter->frame_queue)
+        report_and_exit(AVERROR(ENOMEM));
+
+    return ifilter;
+}
+
 void fg_free(FilterGraph **pfg)
 {
     FilterGraph *fg = *pfg;
@@ -281,14 +296,8 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost)
 
     ost->filter = ofilter;
 
-    ifilter = ALLOC_ARRAY_ELEM(fg->inputs, fg->nb_inputs);
+    ifilter         = ifilter_alloc(fg);
     ifilter->ist    = ist;
-    ifilter->graph  = fg;
-    ifilter->format = -1;
-
-    ifilter->frame_queue = av_fifo_alloc2(8, sizeof(AVFrame*), AV_FIFO_FLAG_AUTO_GROW);
-    if (!ifilter->frame_queue)
-        report_and_exit(AVERROR(ENOMEM));
 
     ist_filter_add(ist, ifilter, 1);
 
@@ -379,17 +388,11 @@ static void init_input_filter(FilterGraph *fg, AVFilterInOut *in)
     }
     av_assert0(ist);
 
-    ifilter = ALLOC_ARRAY_ELEM(fg->inputs, fg->nb_inputs);
+    ifilter = ifilter_alloc(fg);
     ifilter->ist    = ist;
-    ifilter->graph  = fg;
-    ifilter->format = -1;
     ifilter->type   = ist->st->codecpar->codec_type;
     ifilter->name   = describe_filter_link(fg, in, 1);
 
-    ifilter->frame_queue = av_fifo_alloc2(8, sizeof(AVFrame*), AV_FIFO_FLAG_AUTO_GROW);
-    if (!ifilter->frame_queue)
-        report_and_exit(AVERROR(ENOMEM));
-
     ist_filter_add(ist, ifilter, 0);
 }
 



More information about the ffmpeg-cvslog mailing list