diff mbox series

[FFmpeg-devel,v2,2/3] avformat/fifo: add a seperate function which sleeps any specified duration

Message ID 1588832225-63654-1-git-send-email-leozhang@qiyi.com
State New
Headers show
Series Patch set to delay output live stream
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

leozhang May 7, 2020, 6:17 a.m. UTC
Suggested-by: Nicolas George <george@nsup.org>
Reviewed-by:  Nicolas George <george@nsup.org>
Reviewed-by:  Marton Balint <cus@passwd.hu>
Reviewed-by:  Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: leozhang <leozhang@qiyi.com>
---
 libavformat/fifo.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/fifo.c b/libavformat/fifo.c
index 7acc420..b819aeb 100644
--- a/libavformat/fifo.c
+++ b/libavformat/fifo.c
@@ -123,6 +123,13 @@  typedef struct FifoMessage {
     AVPacket pkt;
 } FifoMessage;
 
+static void fifo_sleep(int64_t duration)
+{
+    for (; duration > 600000000; duration -= 600000000)
+        av_usleep(600000000);
+    av_usleep(duration);
+}
+
 static int fifo_thread_write_header(FifoThreadContext *ctx)
 {
     AVFormatContext *avf = ctx->avf;
@@ -214,9 +221,7 @@  static int fifo_thread_write_packet(FifoThreadContext *ctx, AVPacket *pkt)
 
         if (sleep > 0) {
             av_log(avf, AV_LOG_DEBUG, "sleeping %"PRIi64" us\n", sleep);
-            for (; sleep > 600000000; sleep -= 600000000)
-                av_usleep(600000000);
-            av_usleep(sleep);
+            fifo_sleep(sleep);
         }
     }