[FFmpeg-cvslog] fftools/ffmpeg_filter: factor processing a single frame out of reap_filters()

Anton Khirnov git at videolan.org
Wed Aug 30 13:00:23 EEST 2023


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Sun Jul 23 10:19:08 2023 +0200| [d9c862b57f078852eb8f5604784e2b2e69096926] | committer: Anton Khirnov

fftools/ffmpeg_filter: factor processing a single frame out of reap_filters()

This is easier to read.

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

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

diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 177a6f7e5c..5f4a7bfcc6 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -1741,25 +1741,14 @@ int filtergraph_is_simple(const FilterGraph *fg)
     return fgp->is_simple;
 }
 
-int reap_filters(FilterGraph *fg, int flush)
+static int fg_output_step(OutputFilterPriv *ofp, int flush)
 {
-    FilterGraphPriv    *fgp = fgp_from_fg(fg);
+    FilterGraphPriv    *fgp = fgp_from_fg(ofp->ofilter.graph);
+    OutputStream       *ost = ofp->ofilter.ost;
     AVFrame *filtered_frame = fgp->frame;
-
-    if (!fg->graph)
-        return 0;
-
-    /* Reap all buffers present in the buffer sinks */
-    for (int i = 0; i < fg->nb_outputs; i++) {
-        OutputFilter   *ofilter = fg->outputs[i];
-        OutputStream       *ost = ofilter->ost;
-        OutputFilterPriv   *ofp = ofp_from_ofilter(ofilter);
         AVFilterContext *filter = ofp->filter;
-
-        int ret = 0;
-
-        while (1) {
             FrameData *fd;
+    int ret;
 
             ret = av_buffersink_get_frame_flags(filter, filtered_frame,
                                                AV_BUFFERSINK_FLAG_NO_REQUEST);
@@ -1774,11 +1763,11 @@ int reap_filters(FilterGraph *fg, int flush)
                         return ret;
                 }
 
-                break;
+                return 1;
             }
             if (ost->finished) {
                 av_frame_unref(filtered_frame);
-                continue;
+                return 0;
             }
 
             if (filtered_frame->pts != AV_NOPTS_VALUE) {
@@ -1817,6 +1806,24 @@ int reap_filters(FilterGraph *fg, int flush)
                 return ret;
 
             ofp->got_frame = 1;
+
+    return 0;
+}
+
+int reap_filters(FilterGraph *fg, int flush)
+{
+    if (!fg->graph)
+        return 0;
+
+    /* Reap all buffers present in the buffer sinks */
+    for (int i = 0; i < fg->nb_outputs; i++) {
+        OutputFilterPriv *ofp = ofp_from_ofilter(fg->outputs[i]);
+        int ret = 0;
+
+        while (!ret) {
+            ret = fg_output_step(ofp, flush);
+            if (ret < 0)
+                return ret;
         }
     }
 



More information about the ffmpeg-cvslog mailing list