[FFmpeg-devel] [PATCH 2/2] avformat/libsrt: fix timeout inaccurate in wait_fd_timeout

Zhao Zhili quinkblack at foxmail.com
Sun Feb 7 15:18:50 EET 2021


The wait_start was about POLLING_TIME larger which leads to timeout
100ms late than the option setting.
---
 libavformat/libsrt.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c
index d3c661d9d8..d08634b71a 100644
--- a/libavformat/libsrt.c
+++ b/libavformat/libsrt.c
@@ -196,7 +196,10 @@ static int libsrt_network_wait_fd(URLContext *h, int eid, int fd, int write)
 static int libsrt_network_wait_fd_timeout(URLContext *h, int eid, int fd, int write, int64_t timeout, AVIOInterruptCB *int_cb)
 {
     int ret;
-    int64_t wait_start = 0;
+    int64_t wait_start;
+
+    if (timeout > 0)
+        wait_start = av_gettime_relative();
 
     while (1) {
         if (ff_check_interrupt(int_cb))
@@ -204,12 +207,8 @@ static int libsrt_network_wait_fd_timeout(URLContext *h, int eid, int fd, int wr
         ret = libsrt_network_wait_fd(h, eid, fd, write);
         if (ret != AVERROR(EAGAIN))
             return ret;
-        if (timeout > 0) {
-            if (!wait_start)
-                wait_start = av_gettime_relative();
-            else if (av_gettime_relative() - wait_start > timeout)
-                return AVERROR(ETIMEDOUT);
-        }
+        if (timeout > 0 && (av_gettime_relative() - wait_start > timeout))
+            return AVERROR(ETIMEDOUT);
     }
 }
 
-- 
2.28.0



More information about the ffmpeg-devel mailing list