[FFmpeg-devel] [PATCH 2/4] lavfi/framesync: reorder functions to avoid a forward declaration

Anton Khirnov anton at khirnov.net
Fri Jan 27 15:16:37 EET 2023


---
 libavfilter/framesync.c | 144 ++++++++++++++++++++--------------------
 1 file changed, 71 insertions(+), 73 deletions(-)

diff --git a/libavfilter/framesync.c b/libavfilter/framesync.c
index 153db4fa21..fdcc3b57c8 100644
--- a/libavfilter/framesync.c
+++ b/libavfilter/framesync.c
@@ -73,8 +73,6 @@ enum {
     STATE_EOF,
 };
 
-static int consume_from_fifos(FFFrameSync *fs);
-
 void ff_framesync_preinit(FFFrameSync *fs)
 {
     if (fs->class)
@@ -181,6 +179,77 @@ int ff_framesync_configure(FFFrameSync *fs)
     return 0;
 }
 
+static void framesync_inject_frame(FFFrameSync *fs, unsigned in, AVFrame *frame)
+{
+    int64_t pts;
+
+    av_assert0(!fs->in[in].have_next);
+    av_assert0(frame);
+    pts = av_rescale_q(frame->pts, fs->in[in].time_base, fs->time_base);
+    frame->pts = pts;
+    fs->in[in].frame_next = frame;
+    fs->in[in].pts_next   = pts;
+    fs->in[in].have_next  = 1;
+}
+
+static int64_t framesync_pts_extrapolate(FFFrameSync *fs, unsigned in,
+                                         int64_t pts)
+{
+    /* Possible enhancement: use the link's frame rate */
+    return pts + 1;
+}
+
+static void framesync_inject_status(FFFrameSync *fs, unsigned in, int status, int64_t pts)
+{
+    av_assert0(!fs->in[in].have_next);
+    pts = fs->in[in].state != STATE_RUN || fs->in[in].after == EXT_INFINITY
+        ? INT64_MAX : framesync_pts_extrapolate(fs, in, fs->in[in].pts);
+    fs->in[in].sync = 0;
+    framesync_sync_level_update(fs);
+    fs->in[in].frame_next = NULL;
+    fs->in[in].pts_next   = pts;
+    fs->in[in].have_next  = 1;
+}
+
+static int consume_from_fifos(FFFrameSync *fs)
+{
+    AVFilterContext *ctx = fs->parent;
+    AVFrame *frame = NULL;
+    int64_t pts;
+    unsigned i, nb_active, nb_miss;
+    int ret, status;
+
+    nb_active = nb_miss = 0;
+    for (i = 0; i < fs->nb_in; i++) {
+        if (fs->in[i].have_next || fs->in[i].state == STATE_EOF)
+            continue;
+        nb_active++;
+        ret = ff_inlink_consume_frame(ctx->inputs[i], &frame);
+        if (ret < 0)
+            return ret;
+        if (ret) {
+            av_assert0(frame);
+            framesync_inject_frame(fs, i, frame);
+        } else {
+            ret = ff_inlink_acknowledge_status(ctx->inputs[i], &status, &pts);
+            if (ret > 0) {
+                framesync_inject_status(fs, i, status, pts);
+            } else if (!ret) {
+                nb_miss++;
+            }
+        }
+    }
+    if (nb_miss) {
+        if (nb_miss == nb_active && !ff_outlink_frame_wanted(ctx->outputs[0]))
+            return FFERROR_NOT_READY;
+        for (i = 0; i < fs->nb_in; i++)
+            if (!fs->in[i].have_next && fs->in[i].state != STATE_EOF)
+                ff_inlink_request_frame(ctx->inputs[i]);
+        return 0;
+    }
+    return 1;
+}
+
 static int framesync_advance(FFFrameSync *fs)
 {
     unsigned i;
@@ -231,38 +300,6 @@ static int framesync_advance(FFFrameSync *fs)
     return 0;
 }
 
-static int64_t framesync_pts_extrapolate(FFFrameSync *fs, unsigned in,
-                                         int64_t pts)
-{
-    /* Possible enhancement: use the link's frame rate */
-    return pts + 1;
-}
-
-static void framesync_inject_frame(FFFrameSync *fs, unsigned in, AVFrame *frame)
-{
-    int64_t pts;
-
-    av_assert0(!fs->in[in].have_next);
-    av_assert0(frame);
-    pts = av_rescale_q(frame->pts, fs->in[in].time_base, fs->time_base);
-    frame->pts = pts;
-    fs->in[in].frame_next = frame;
-    fs->in[in].pts_next   = pts;
-    fs->in[in].have_next  = 1;
-}
-
-static void framesync_inject_status(FFFrameSync *fs, unsigned in, int status, int64_t pts)
-{
-    av_assert0(!fs->in[in].have_next);
-    pts = fs->in[in].state != STATE_RUN || fs->in[in].after == EXT_INFINITY
-        ? INT64_MAX : framesync_pts_extrapolate(fs, in, fs->in[in].pts);
-    fs->in[in].sync = 0;
-    framesync_sync_level_update(fs);
-    fs->in[in].frame_next = NULL;
-    fs->in[in].pts_next   = pts;
-    fs->in[in].have_next  = 1;
-}
-
 int ff_framesync_get_frame(FFFrameSync *fs, unsigned in, AVFrame **rframe,
                             unsigned get)
 {
@@ -312,45 +349,6 @@ void ff_framesync_uninit(FFFrameSync *fs)
     av_freep(&fs->in);
 }
 
-static int consume_from_fifos(FFFrameSync *fs)
-{
-    AVFilterContext *ctx = fs->parent;
-    AVFrame *frame = NULL;
-    int64_t pts;
-    unsigned i, nb_active, nb_miss;
-    int ret, status;
-
-    nb_active = nb_miss = 0;
-    for (i = 0; i < fs->nb_in; i++) {
-        if (fs->in[i].have_next || fs->in[i].state == STATE_EOF)
-            continue;
-        nb_active++;
-        ret = ff_inlink_consume_frame(ctx->inputs[i], &frame);
-        if (ret < 0)
-            return ret;
-        if (ret) {
-            av_assert0(frame);
-            framesync_inject_frame(fs, i, frame);
-        } else {
-            ret = ff_inlink_acknowledge_status(ctx->inputs[i], &status, &pts);
-            if (ret > 0) {
-                framesync_inject_status(fs, i, status, pts);
-            } else if (!ret) {
-                nb_miss++;
-            }
-        }
-    }
-    if (nb_miss) {
-        if (nb_miss == nb_active && !ff_outlink_frame_wanted(ctx->outputs[0]))
-            return FFERROR_NOT_READY;
-        for (i = 0; i < fs->nb_in; i++)
-            if (!fs->in[i].have_next && fs->in[i].state != STATE_EOF)
-                ff_inlink_request_frame(ctx->inputs[i]);
-        return 0;
-    }
-    return 1;
-}
-
 int ff_framesync_activate(FFFrameSync *fs)
 {
     int ret;
-- 
2.35.1



More information about the ffmpeg-devel mailing list