diff mbox series

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

Message ID tencent_9870222D699AE140BB9A3D9FA8ABE74E3008@qq.com
State New
Headers show
Series [FFmpeg-devel,1/2] avformat/network: fix timeout inaccurate in wait_fd_timeout
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Zhao Zhili Feb. 7, 2021, 1:18 p.m. UTC
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(-)

Comments

Nicolas George Feb. 7, 2021, 1:26 p.m. UTC | #1
Zhao Zhili (12021-02-07):
> 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(-)

I see two patches with exactly identical code, except for a single
function name.

Please try to merge it to avoid duplication.

Regards,
diff mbox series

Patch

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