diff mbox series

[FFmpeg-devel,14/22] lavfi/vf_libplacebo: only drain actually used PTS

Message ID 20230616092959.5247-14-ffmpeg@haasn.xyz
State New
Headers show
Series [FFmpeg-devel,01/22] lavfi/vf_libplacebo: drop redundant case | 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

Niklas Haas June 16, 2023, 9:29 a.m. UTC
From: Niklas Haas <git@haasn.dev>

When combining multiple inputs, the output PTS may be less than the PTS
of the input. In this case, the current's code assumption of always
draining one value from the FIFO is incorrect. Replace by a smarter
function which drains only those PTS values that were actually consumed.
---
 libavfilter/vf_libplacebo.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index 5903bd5a01..896bdb4eb8 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -969,6 +969,13 @@  static int handle_input(AVFilterContext *ctx, LibplaceboInput *input)
     return 0;
 }
 
+static void drain_input_pts(LibplaceboInput *in, int64_t until)
+{
+    int64_t pts;
+    while (av_fifo_peek(in->out_pts, &pts, 1, 0) >= 0 && pts <= until)
+        av_fifo_drain2(in->out_pts, 1);
+}
+
 static int libplacebo_activate(AVFilterContext *ctx)
 {
     int ret, retry = 0;
@@ -1021,8 +1028,7 @@  static int libplacebo_activate(AVFilterContext *ctx)
             ff_inlink_request_frame(in->link);
             return 0;
         case PL_QUEUE_OK:
-            if (!s->fps.num)
-                av_fifo_drain2(in->out_pts, 1);
+            drain_input_pts(in, out_pts);
             return output_frame(ctx, out_pts);
         case PL_QUEUE_ERR:
             return AVERROR_EXTERNAL;