diff mbox series

[FFmpeg-devel,v2,2/2] lavf/libsrt: deduplicate libsrt_network_wait_fd_timeout

Message ID tencent_FF259AEF9F5AAB614E6C70EF2D7A9A684008@qq.com
State New
Headers show
Series [FFmpeg-devel,v2,1/2] lavf/network: add wait fd callback to ff_network_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. 8, 2021, 3:04 a.m. UTC
---
v2: code rebase 
 libavformat/libsrt.c | 27 +++++++--------------------
 1 file changed, 7 insertions(+), 20 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c
index 233e9096fa..95a20b2308 100644
--- a/libavformat/libsrt.c
+++ b/libavformat/libsrt.c
@@ -176,7 +176,7 @@  static int libsrt_epoll_create(URLContext *h, int fd, int write)
     return eid;
 }
 
-static int libsrt_network_wait_fd(URLContext *h, int eid, int write)
+static int libsrt_network_wait_fd(int eid, int write, void *h)
 {
     int ret, len = 1, errlen = 1;
     SRTSOCKET ready[1];
@@ -198,26 +198,13 @@  static int libsrt_network_wait_fd(URLContext *h, int eid, int write)
     return ret;
 }
 
-/* TODO de-duplicate code from ff_network_wait_fd_timeout() */
-
-static int libsrt_network_wait_fd_timeout(URLContext *h, int eid, int write, int64_t timeout, AVIOInterruptCB *int_cb)
+static inline int libsrt_network_wait_fd_timeout(URLContext *h, int eid, int write, int64_t timeout, AVIOInterruptCB *int_cb)
 {
-    int ret;
-    int64_t wait_start = 0;
-
-    while (1) {
-        if (ff_check_interrupt(int_cb))
-            return AVERROR_EXIT;
-        ret = libsrt_network_wait_fd(h, eid, 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);
-        }
-    }
+    NetworkWaitFdCB wait_cb = {
+        .wait_fd = libsrt_network_wait_fd,
+        .opaque = h
+    };
+    return ff_network_wait_fd_timeout(eid, write, timeout, &h->interrupt_callback, &wait_cb);
 }
 
 static int libsrt_listen(int eid, int fd, const struct sockaddr *addr, socklen_t addrlen, URLContext *h, int64_t timeout)