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

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


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

diff --git a/libavformat/network.c b/libavformat/network.c
index 0f5a575f77..7a9a4be5bb 100644
--- a/libavformat/network.c
+++ b/libavformat/network.c
@@ -78,7 +78,10 @@ int ff_network_wait_fd(int fd, int write)
 int ff_network_wait_fd_timeout(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))
@@ -86,12 +89,8 @@ int ff_network_wait_fd_timeout(int fd, int write, int64_t timeout, AVIOInterrupt
         ret = ff_network_wait_fd(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