[FFmpeg-devel] [PATCH v2 2/2] lavf/libsrt: deduplicate libsrt_network_wait_fd_timeout
Zhao Zhili
quinkblack at foxmail.com
Mon Feb 8 05:04:16 EET 2021
---
v2: code rebase
libavformat/libsrt.c | 27 +++++++--------------------
1 file changed, 7 insertions(+), 20 deletions(-)
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)
--
2.28.0
More information about the ffmpeg-devel
mailing list