From patchwork Sat Apr 10 06:31:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andriy Gelman X-Patchwork-Id: 26829 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 D04D444BA18 for ; Sat, 10 Apr 2021 10:01:52 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A555D680CDF; Sat, 10 Apr 2021 10:01:52 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f176.google.com (mail-qt1-f176.google.com [209.85.160.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 170A4680CDF for ; Sat, 10 Apr 2021 10:01:46 +0300 (EEST) Received: by mail-qt1-f176.google.com with SMTP id g14so1872230qtu.8 for ; Sat, 10 Apr 2021 00:01:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=E0uT36xKhB4kMfELjHBU0qU7rKXSk0ov8CLtZXnWnoI=; b=OUFayJzA7Bn/jlFjb0XDrDSjrp4Xfb86qyVTY/P65XOQaHmm4+173po0Xu/kGUp6y/ 1SBotyuHnScj0tN3hyvgr64A08++QVMQSqXAyO+fduPRlwKZl9jqEsYO30XN+uv9vAJT ieOoZYPrCCOBq5YWUscPn4Z+NcLGYxpi5Wx8FOtUOZpQ9mwOtH/P5txu8Aq+ZTORJlwc OHeIbuLjj8TiEk19rtq2mDAAi4r5rZHQvu7LR5Ill0aFigFl0CRxTNGDfWsQmFp6sefU vp5dskwSZKAytkKoaF4IgUHdvFBd8a/edGEXSy1qpgn08AHKjSyrmTdXIgxJjaoQgge2 WeMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=E0uT36xKhB4kMfELjHBU0qU7rKXSk0ov8CLtZXnWnoI=; b=cpaxnRqSYDap/pp27oViP2TUOMVlJdKOl9eZkIog/ssdunbW+PM76V+7t4b4MF5ktI QtygEmaZ+t8fS9JU5D3X1tE+Bf62F7OXgcFbtAEEiGoa6/0DxO1QDL1AaVS2ogzjrB3h yvHnrvKP+JjnFy2ZtnZ9Zadk2/INK0RL79auiH13s4WZwNxzUMBNiij3vlIhaNy49Xrr Zkogok3P5xlVofkyPUUQ6AY/2qcT/9wa2fF3zT8NkykSvD2uL05a+VafMMJdpvPJn3d7 UZk3lsn4ZxjIg76tJz524E7MPEY8cHKqkajSyRD6aqx8iYwIMghbSgreFUSHPikM0nrk nN1w== X-Gm-Message-State: AOAM533R/yMzGP6ZdMScZqpEXDvSa1qjV9IXoNeBdu/gFLhCZQz2afWy gNYKLnIeHiGUGlRNuFy3pXcrk0M4IhI= X-Google-Smtp-Source: ABdhPJwLDX86AxKffaMpX+MT2DZJLu38/IAAjK3QlomNfnw43+XSQOSqRNxNVVaDT39/u3xOnalhfA== X-Received: by 2002:a05:622a:446:: with SMTP id o6mr16053547qtx.257.1618036284533; Fri, 09 Apr 2021 23:31:24 -0700 (PDT) Received: from localhost.localdomain (c-73-149-98-40.hsd1.ma.comcast.net. [73.149.98.40]) by smtp.gmail.com with ESMTPSA id 84sm3564096qkg.8.2021.04.09.23.31.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Apr 2021 23:31:24 -0700 (PDT) From: Andriy Gelman X-Google-Original-From: Andriy Gelman To: ffmpeg-devel@ffmpeg.org Date: Sat, 10 Apr 2021 02:31:13 -0400 Message-Id: <20210410063113.18006-1-andriy.gelman@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2] avformat/rtsp: fix 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: Andriy Gelman Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Andriy Gelman 92c40ef882be115e72d2aa02f9032b7ce88f8537 added a listen_timeout option for sdp. This allowed a user to set variable timeout in sdp which was originally hard coded to 10 seconds. The commit used the initial_timeout variable to store the value. However, in rtsp this variable is also used to infer a "listen" mode. Thus, the timeout value could not be set when connecting to an rtsp server. The default value of -1 would also result in a 100ms total timeout. This was attempted to be fixed in c8101aabee654f6d147a4d89f77fa73e18908610, which changed the meaning of initial_timeout = -1 to be an infinite timeout in rtsp. However, it did not address the issue that the timeout could still not be set. Being able to set the timeout is useful because it allows to automatically reconfigure from a udp to tcp connection in the lower transport. In this commit, this is fixed by using the stimeout variable/option to set the timeout in rtsp. Signed-off-by: Andriy Gelman --- Resending this patch with a small change to docs. I removed TCP because -stimeout would also now apply to lower transport where it could be UDP. doc/protocols.texi | 2 +- libavformat/rtsp.c | 14 +++++++------- libavformat/rtsp.h | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/doc/protocols.texi b/doc/protocols.texi index d3f6cbefcf..8593e17d57 100644 --- a/doc/protocols.texi +++ b/doc/protocols.texi @@ -1174,7 +1174,7 @@ A value of -1 means infinite (default). This option implies the Set number of packets to buffer for handling of reordered packets. @item stimeout -Set socket TCP I/O timeout in microseconds. +Set socket I/O timeout in microseconds. @item user-agent Override User-Agent header. If not specified, it defaults to the diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c index 25bdf475b3..fff53b0a01 100644 --- a/libavformat/rtsp.c +++ b/libavformat/rtsp.c @@ -96,9 +96,9 @@ const AVOption ff_rtsp_options[] = { { "listen_timeout", "set maximum timeout (in seconds) to wait for incoming connections (-1 is infinite, imply flag listen)", OFFSET(initial_timeout), AV_OPT_TYPE_INT, {.i64 = -1}, INT_MIN, INT_MAX, DEC }, #if FF_API_OLD_RTSP_OPTIONS { "timeout", "set maximum timeout (in seconds) to wait for incoming connections (-1 is infinite, imply flag listen) (deprecated, use listen_timeout)", OFFSET(initial_timeout), AV_OPT_TYPE_INT, {.i64 = -1}, INT_MIN, INT_MAX, DEC|AV_OPT_FLAG_DEPRECATED }, - { "stimeout", "set timeout (in microseconds) of socket TCP I/O operations", OFFSET(stimeout), AV_OPT_TYPE_INT, {.i64 = 0}, INT_MIN, INT_MAX, DEC }, + { "stimeout", "set timeout (in microseconds) of socket I/O operations", OFFSET(stimeout), AV_OPT_TYPE_INT64, {.i64 = 0}, INT_MIN, INT64_MAX, DEC }, #else - { "timeout", "set timeout (in microseconds) of socket TCP I/O operations", OFFSET(stimeout), AV_OPT_TYPE_INT, {.i64 = 0}, INT_MIN, INT_MAX, DEC }, + { "timeout", "set timeout (in microseconds) of socket I/O operations", OFFSET(stimeout), AV_OPT_TYPE_INT64, {.i64 = 0}, INT_MIN, INT64_MAX, DEC }, #endif COMMON_OPTS(), { "user_agent", "override User-Agent header", OFFSET(user_agent), AV_OPT_TYPE_STRING, {.str = LIBAVFORMAT_IDENT}, 0, 0, DEC }, @@ -112,7 +112,7 @@ static const AVOption sdp_options[] = { RTSP_FLAG_OPTS("sdp_flags", "SDP flags"), { "custom_io", "use custom I/O", 0, AV_OPT_TYPE_CONST, {.i64 = RTSP_FLAG_CUSTOM_IO}, 0, 0, DEC, "rtsp_flags" }, { "rtcp_to_source", "send RTCP packets to the source address of received packets", 0, AV_OPT_TYPE_CONST, {.i64 = RTSP_FLAG_RTCP_TO_SOURCE}, 0, 0, DEC, "rtsp_flags" }, - { "listen_timeout", "set maximum timeout (in seconds) to wait for incoming connections", OFFSET(initial_timeout), AV_OPT_TYPE_INT, {.i64 = READ_PACKET_TIMEOUT_S}, INT_MIN, INT_MAX, DEC }, + { "listen_timeout", "set maximum timeout (in seconds) to wait for incoming connections", OFFSET(stimeout), AV_OPT_TYPE_DURATION, {.i64 = READ_PACKET_TIMEOUT_S*1000000}, INT_MIN, INT64_MAX, DEC }, RTSP_MEDIATYPE_OPTS("allowed_media_types", "set media types to accept from the server"), COMMON_OPTS(), { NULL }, @@ -120,7 +120,7 @@ static const AVOption sdp_options[] = { static const AVOption rtp_options[] = { RTSP_FLAG_OPTS("rtp_flags", "set RTP flags"), - { "listen_timeout", "set maximum timeout (in seconds) to wait for incoming connections", OFFSET(initial_timeout), AV_OPT_TYPE_INT, {.i64 = READ_PACKET_TIMEOUT_S}, INT_MIN, INT_MAX, DEC }, + { "listen_timeout", "set maximum timeout (in seconds) to wait for incoming connections", OFFSET(stimeout), AV_OPT_TYPE_DURATION, {.i64 = READ_PACKET_TIMEOUT_S*1000000}, INT_MIN, INT64_MAX, DEC }, RTSP_MEDIATYPE_OPTS("allowed_media_types", "set media types to accept from the server"), COMMON_OPTS(), { NULL }, @@ -1882,7 +1882,7 @@ redirect: /* open the tcp connection */ ff_url_join(tcpname, sizeof(tcpname), lower_rtsp_proto, NULL, host, port, - "?timeout=%d", rt->stimeout); + "?timeout=%"PRId64, rt->stimeout); if ((ret = ffurl_open_whitelist(&rt->rtsp_hd, tcpname, AVIO_FLAG_READ_WRITE, &s->interrupt_callback, NULL, s->protocol_whitelist, s->protocol_blacklist, NULL)) < 0) { err = ret; @@ -2035,7 +2035,7 @@ static int udp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st, int n, i, ret; struct pollfd *p = rt->p; int *fds = NULL, fdsnum, fdsidx; - int runs = rt->initial_timeout * 1000LL / POLLING_TIME; + int64_t runs = rt->stimeout / POLLING_TIME / 1000; if (!p) { p = rt->p = av_malloc_array(2 * rt->nb_rtsp_streams + 1, sizeof(*p)); @@ -2096,7 +2096,7 @@ static int udp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st, } } #endif - } else if (n == 0 && rt->initial_timeout > 0 && --runs <= 0) { + } else if (n == 0 && rt->stimeout > 0 && --runs <= 0) { return AVERROR(ETIMEDOUT); } else if (n < 0 && errno != EINTR) return AVERROR(errno); diff --git a/libavformat/rtsp.h b/libavformat/rtsp.h index 1310dd9c08..4ec974ed73 100644 --- a/libavformat/rtsp.h +++ b/libavformat/rtsp.h @@ -404,7 +404,7 @@ typedef struct RTSPState { /** * timeout of socket i/o operations. */ - int stimeout; + int64_t stimeout; /** * Size of RTP packet reordering queue.