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

leozhang leozhang at qiyi.com
Thu May 7 09:17:05 EEST 2020


Suggested-by: Nicolas George <george at nsup.org>
Reviewed-by:  Nicolas George <george at nsup.org>
Reviewed-by:  Marton Balint <cus at passwd.hu>
Reviewed-by:  Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
Signed-off-by: leozhang <leozhang at qiyi.com>
---
 libavformat/fifo.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

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);
         }
     }
 
-- 
1.8.3.1



More information about the ffmpeg-devel mailing list