diff mbox series

[FFmpeg-devel,12/18] fftools/ffmpeg_filter: factor processing a single frame out of reap_filters()

Message ID 20230826151144.24858-12-anton@khirnov.net
State Accepted
Commit d9c862b57f078852eb8f5604784e2b2e69096926
Headers show
Series [FFmpeg-devel,01/18] fftools/ffmpeg: stop explicitly closing output streams on input EOF | 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 Aug. 26, 2023, 3:11 p.m. UTC
This is easier to read.
---
 fftools/ffmpeg_filter.c | 41 ++++++++++++++++++++++++-----------------
 1 file changed, 24 insertions(+), 17 deletions(-)
diff mbox series

Patch

diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 74b57191d1..5bf2431fb9 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) {
@@ -1823,6 +1812,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;
         }
     }