[FFmpeg-devel] [PATCH 2/2] lavf/libsrt: deduplicate libsrt_network_wait_fd_timeout
"zhilizhao(赵志立)"
quinkblack at foxmail.com
Mon Feb 8 05:13:28 EET 2021
> On Feb 8, 2021, at 2:36 AM, Marton Balint <cus at passwd.hu> wrote:
>
>
>
> On Mon, 8 Feb 2021, Zhao Zhili wrote:
>
>> ---
>> libavformat/libsrt.c | 45 +++++++++++++++++---------------------------
>> 1 file changed, 17 insertions(+), 28 deletions(-)
>
> Hmm, it seems my latest srt patches conflics with this a bit, and you will have to somewhat rebase this, sorry. On the bright side, now only eid is passed to libsrt_network_wait_fd, so maybe you can pass eid instead of fd, especially since it is not always the context->eid that is used for wait.
Thanks for review. Rebase is done:
https://patchwork.ffmpeg.org/project/ffmpeg/patch/tencent_FF259AEF9F5AAB614E6C70EF2D7A9A684008@qq.com/
libsrt_network_wait_fd_timeout is implemented on top of ff_network_wait_fd_timeout
to keep minimum code changes. libsrt_network_wait_fd_timeout can be removed if
add a NetworkWaitFdCB field to SRTContext but more code need to be changed.
What do you think?
>
> Regards,
> Marton
>
>>
>> diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c
>> index f73e7dbfa5..67e42bacc6 100644
>> --- a/libavformat/libsrt.c
>> +++ b/libavformat/libsrt.c
>> @@ -164,12 +164,14 @@ static int libsrt_socket_nonblock(int socket, int enable)
>> return srt_setsockopt(socket, 0, SRTO_RCVSYN, &blocking, sizeof(blocking));
>> }
>> -static int libsrt_network_wait_fd(URLContext *h, int eid, int fd, int write)
>> +static int libsrt_network_wait_fd(int fd, int write, void *ctx)
>> {
>> int ret, len = 1, errlen = 1;
>> int modes = SRT_EPOLL_ERR | (write ? SRT_EPOLL_OUT : SRT_EPOLL_IN);
>> SRTSOCKET ready[1];
>> SRTSOCKET error[1];
>> + URLContext *h = ctx;
>> + int eid = ((SRTContext*)h->priv_data)->eid;
>>
>> if (srt_epoll_add_usock(eid, fd, &modes) < 0)
>> return libsrt_neterrno(h);
>> @@ -191,29 +193,16 @@ static int libsrt_network_wait_fd(URLContext *h, int eid, int fd, 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 fd, int write, int64_t timeout, AVIOInterruptCB *int_cb)
>> +static int libsrt_network_wait_fd_timeout(URLContext *h, int fd, int write, int64_t timeout)
>> {
>> - 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, 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);
>> - }
>> - }
>> + struct NetworkWaitFdCB wait_cb = {
>> + .wait_fd = libsrt_network_wait_fd,
>> + .opaque = h
>> + };
>> + return ff_network_wait_fd_timeout(fd, 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)
>> +static int libsrt_listen(int fd, const struct sockaddr *addr, socklen_t addrlen, URLContext *h, int64_t timeout)
>> {
>> int ret;
>> int reuse = 1;
>> @@ -228,7 +217,7 @@ static int libsrt_listen(int eid, int fd, const struct sockaddr *addr, socklen_t
>> if (ret)
>> return libsrt_neterrno(h);
>> - ret = libsrt_network_wait_fd_timeout(h, eid, fd, 1, timeout, &h->interrupt_callback);
>> + ret = libsrt_network_wait_fd_timeout(h, fd, 1, timeout);
>> if (ret < 0)
>> return ret;
>> @@ -241,7 +230,7 @@ static int libsrt_listen(int eid, int fd, const struct sockaddr *addr, socklen_t
>> return ret;
>> }
>> -static int libsrt_listen_connect(int eid, int fd, const struct sockaddr *addr, socklen_t addrlen, int64_t timeout, URLContext *h, int will_try_next)
>> +static int libsrt_listen_connect(int fd, const struct sockaddr *addr, socklen_t addrlen, int64_t timeout, URLContext *h, int will_try_next)
>> {
>> int ret;
>> @@ -249,7 +238,7 @@ static int libsrt_listen_connect(int eid, int fd, const struct sockaddr *addr, s
>> if (ret < 0)
>> return libsrt_neterrno(h);
>> - ret = libsrt_network_wait_fd_timeout(h, eid, fd, 1, timeout, &h->interrupt_callback);
>> + ret = libsrt_network_wait_fd_timeout(h, fd, 1, timeout);
>> if (ret < 0) {
>> if (will_try_next) {
>> av_log(h, AV_LOG_WARNING,
>> @@ -438,7 +427,7 @@ static int libsrt_setup(URLContext *h, const char *uri, int flags)
>>
>> if (s->mode == SRT_MODE_LISTENER) {
>> // multi-client
>> - if ((ret = libsrt_listen(s->eid, fd, cur_ai->ai_addr, cur_ai->ai_addrlen, h, s->listen_timeout)) < 0)
>> + if ((ret = libsrt_listen(fd, cur_ai->ai_addr, cur_ai->ai_addrlen, h, s->listen_timeout)) < 0)
>> goto fail1;
>> listen_fd = fd;
>> fd = ret;
>> @@ -449,7 +438,7 @@ static int libsrt_setup(URLContext *h, const char *uri, int flags)
>> goto fail1;
>> }
>> - if ((ret = libsrt_listen_connect(s->eid, fd, cur_ai->ai_addr, cur_ai->ai_addrlen,
>> + if ((ret = libsrt_listen_connect(fd, cur_ai->ai_addr, cur_ai->ai_addrlen,
>> open_timeout, h, !!cur_ai->ai_next)) < 0) {
>> if (ret == AVERROR_EXIT)
>> goto fail1;
>> @@ -652,7 +641,7 @@ static int libsrt_read(URLContext *h, uint8_t *buf, int size)
>> int ret;
>>
>> if (!(h->flags & AVIO_FLAG_NONBLOCK)) {
>> - ret = libsrt_network_wait_fd_timeout(h, s->eid, s->fd, 0, h->rw_timeout, &h->interrupt_callback);
>> + ret = libsrt_network_wait_fd_timeout(h, s->fd, 0, h->rw_timeout);
>> if (ret)
>> return ret;
>> }
>> @@ -671,7 +660,7 @@ static int libsrt_write(URLContext *h, const uint8_t *buf, int size)
>> int ret;
>>
>> if (!(h->flags & AVIO_FLAG_NONBLOCK)) {
>> - ret = libsrt_network_wait_fd_timeout(h, s->eid, s->fd, 1, h->rw_timeout, &h->interrupt_callback);
>> + ret = libsrt_network_wait_fd_timeout(h, s->fd, 1, h->rw_timeout);
>> if (ret)
>> return ret;
>> }
>> --
>> 2.27.0
>>
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel at ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".
More information about the ffmpeg-devel
mailing list