From patchwork Thu Feb 13 23:16:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 17777 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 1F4A144B50B for ; Fri, 14 Feb 2020 01:16:41 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0A3CD68AD85; Fri, 14 Feb 2020 01:16:41 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9DCD668A636 for ; Fri, 14 Feb 2020 01:16:34 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id CFBE5E3B01; Fri, 14 Feb 2020 00:16:33 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id S8PftDL_HAVE; Fri, 14 Feb 2020 00:16:32 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id BDB09E101C; Fri, 14 Feb 2020 00:16:31 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Fri, 14 Feb 2020 00:16:22 +0100 Message-Id: <20200213231624.28373-1-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 Subject: [FFmpeg-devel] [PATCH 1/3] avformat/libsrt: fix timeout unit confusion between milisec and microsec X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Marton Balint --- libavformat/libsrt.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c index d7faa603f5..1d748f0e81 100644 --- a/libavformat/libsrt.c +++ b/libavformat/libsrt.c @@ -210,7 +210,7 @@ static int libsrt_network_wait_fd_timeout(URLContext *h, int eid, int fd, int wr } } -static int libsrt_listen(int eid, int fd, const struct sockaddr *addr, socklen_t addrlen, URLContext *h, int timeout) +static int libsrt_listen(int eid, int fd, const struct sockaddr *addr, socklen_t addrlen, URLContext *h, int64_t timeout) { int ret; int reuse = 1; @@ -243,7 +243,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, int timeout, URLContext *h, int will_try_next) +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) { int ret; @@ -447,7 +447,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, open_timeout / 1000)) < 0) + if ((ret = libsrt_listen(s->eid, fd, cur_ai->ai_addr, cur_ai->ai_addrlen, h, open_timeout)) < 0) goto fail1; fd = ret; } else { @@ -458,7 +458,7 @@ static int libsrt_setup(URLContext *h, const char *uri, int flags) } if ((ret = libsrt_listen_connect(s->eid, fd, cur_ai->ai_addr, cur_ai->ai_addrlen, - open_timeout / 1000, h, !!cur_ai->ai_next)) < 0) { + open_timeout, h, !!cur_ai->ai_next)) < 0) { if (ret == AVERROR_EXIT) goto fail1; else From patchwork Thu Feb 13 23:16:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 17778 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 16E7544B50B for ; Fri, 14 Feb 2020 01:16:46 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F0A8568AF22; Fri, 14 Feb 2020 01:16:45 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 75AEB68AD48 for ; Fri, 14 Feb 2020 01:16:39 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 60EF3E3E26; Fri, 14 Feb 2020 00:16:39 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DP-cVg_7S1ZC; Fri, 14 Feb 2020 00:16:37 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 3AA50E101C; Fri, 14 Feb 2020 00:16:37 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Fri, 14 Feb 2020 00:16:23 +0100 Message-Id: <20200213231624.28373-2-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200213231624.28373-1-cus@passwd.hu> References: <20200213231624.28373-1-cus@passwd.hu> Subject: [FFmpeg-devel] [PATCH 2/3] avformat/libsrt: fix name of timeout option X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" rw_timeout is the generic URLcontext option, not the protocol specific timeout option, also ?rw_timeout never worked because ?timeout was parsed instead. Signed-off-by: Marton Balint --- doc/protocols.texi | 2 +- libavformat/libsrt.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/protocols.texi b/doc/protocols.texi index 5e8c97d164..57814c7831 100644 --- a/doc/protocols.texi +++ b/doc/protocols.texi @@ -1347,7 +1347,7 @@ Set UDP receive buffer size, expressed in bytes. @item send_buffer_size=@var{bytes} Set UDP send buffer size, expressed in bytes. -@item rw_timeout +@item timeout Set raise error timeout for read/write optations. This option is only relevant in read mode: diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c index 1d748f0e81..378acb045a 100644 --- a/libavformat/libsrt.c +++ b/libavformat/libsrt.c @@ -96,7 +96,7 @@ typedef struct SRTContext { #define E AV_OPT_FLAG_ENCODING_PARAM #define OFFSET(x) offsetof(SRTContext, x) static const AVOption libsrt_options[] = { - { "rw_timeout", "Timeout of socket I/O operations", OFFSET(rw_timeout), AV_OPT_TYPE_INT64, { .i64 = -1 }, -1, INT64_MAX, .flags = D|E }, + { "timeout", "Timeout of socket I/O operations", OFFSET(rw_timeout), AV_OPT_TYPE_INT64, { .i64 = -1 }, -1, INT64_MAX, .flags = D|E }, { "listen_timeout", "Connection awaiting timeout", OFFSET(listen_timeout), AV_OPT_TYPE_INT64, { .i64 = -1 }, -1, INT64_MAX, .flags = D|E }, { "send_buffer_size", "Socket send buffer size (in bytes)", OFFSET(send_buffer_size), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E }, { "recv_buffer_size", "Socket receive buffer size (in bytes)", OFFSET(recv_buffer_size), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E }, From patchwork Thu Feb 13 23:16:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 17779 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 0713D44B50B for ; Fri, 14 Feb 2020 01:16:48 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E33FB68AF70; Fri, 14 Feb 2020 01:16:47 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 52C7F68AF63 for ; Fri, 14 Feb 2020 01:16:41 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 3AF2DE3B01; Fri, 14 Feb 2020 00:16:41 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vddDzDegY_R0; Fri, 14 Feb 2020 00:16:39 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id CE610E101C; Fri, 14 Feb 2020 00:16:39 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Fri, 14 Feb 2020 00:16:24 +0100 Message-Id: <20200213231624.28373-3-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200213231624.28373-1-cus@passwd.hu> References: <20200213231624.28373-1-cus@passwd.hu> Subject: [FFmpeg-devel] [PATCH 3/3] avformat/libsrt: fix checking connection result in non-blocking mode X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" After f8990c5f414d4575415e2a3981c3b142222ca3d4 we properly set non-blocking mode which makes the connect() call return always 0 even if no connection can be established. Fix this by always doing a poll after calling connect(). Also there was some leftover copy paste code which checks for various errors which are simply not possible with SRT. Signed-off-by: Marton Balint --- libavformat/libsrt.c | 41 +++++++++++++---------------------------- 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c index 378acb045a..1ab6c1ddb3 100644 --- a/libavformat/libsrt.c +++ b/libavformat/libsrt.c @@ -250,34 +250,19 @@ static int libsrt_listen_connect(int eid, int fd, const struct sockaddr *addr, s if (libsrt_socket_nonblock(fd, 1) < 0) av_log(h, AV_LOG_DEBUG, "ff_socket_nonblock failed\n"); - while ((ret = srt_connect(fd, addr, addrlen))) { - ret = libsrt_neterrno(h); - switch (ret) { - case AVERROR(EINTR): - if (ff_check_interrupt(&h->interrupt_callback)) - return AVERROR_EXIT; - continue; - case AVERROR(EINPROGRESS): - case AVERROR(EAGAIN): - ret = libsrt_network_wait_fd_timeout(h, eid, fd, 1, timeout, &h->interrupt_callback); - if (ret < 0) - return ret; - ret = srt_getlasterror(NULL); - srt_clearlasterror(); - if (ret != 0) { - char buf[128]; - ret = AVERROR(ret); - av_strerror(ret, buf, sizeof(buf)); - if (will_try_next) - av_log(h, AV_LOG_WARNING, - "Connection to %s failed (%s), trying next address\n", - h->filename, buf); - else - av_log(h, AV_LOG_ERROR, "Connection to %s failed: %s\n", - h->filename, buf); - } - default: - return ret; + ret = srt_connect(fd, addr, addrlen); + if (ret < 0) + return libsrt_neterrno(h); + + ret = libsrt_network_wait_fd_timeout(h, eid, fd, 1, timeout, &h->interrupt_callback); + if (ret < 0) { + if (will_try_next) { + av_log(h, AV_LOG_WARNING, + "Connection to %s failed (%s), trying next address\n", + h->filename, av_err2str(ret)); + } else { + av_log(h, AV_LOG_ERROR, "Connection to %s failed: %s\n", + h->filename, av_err2str(ret)); } } return ret;