From patchwork Sun May 30 20:24:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andriy Gelman X-Patchwork-Id: 27989 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:b214:0:0:0:0:0 with SMTP id b20csp2328829iof; Sun, 30 May 2021 13:45:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxu+4A0lBLo+q6BrIGPshexynD4FK9dUho6iSkab+xUanaXOBSGk0q9/ADOKDmHz2yJTMVi X-Received: by 2002:a05:6402:3585:: with SMTP id y5mr22053022edc.121.1622407558664; Sun, 30 May 2021 13:45:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622407558; cv=none; d=google.com; s=arc-20160816; b=IIu8wL4UqC/pNW8rSig3ZZASeSxLJEfWqRBDbzFDz2cskg1R74DZdtzqEOuxdk/iO3 ryDMbA2Cun+t+36xG8/VdN6XPFIi1IZq9Y1tHSE3c7Pyl0Bqof1w+Oi8N/NZ3yhX1i/+ R+0MsGQqM/LKzFfs+uV+WgbLW53bL8Y5NBAt2cfL1Z5aB+/GjO8K2XCUEfmpNf+hw9y6 ANlVx2g6FIh+ZsmWXY4AWNNghM0F+qqf2lXiJQ5fjgKy4M0w5UZaYxb58tG6JCeZegR3 7tH6jcHJf/V7QpADVvW/Ni81AwwRERISkuPoBWdLZi3wfWIvr5aoJzUMblzH7/TRzy+v BXdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=NFitcUmKBAuz0DLI18TD1JfCX4UkGMHp7od+VNeIrjI=; b=FuQSeAxz7oW8m1AvOujcrlfuZlDkfbMMH/QCzwQSh/IWIyjZ/ZmHrOT2HQKzo52RUO fP3SX2pBKmvlmHb6zAWlYnhdNkpHHAGjMtSScq3B0Oe63NuTjjjeDmHpt7SS8I2q3VmV S+1C30IrollBAWAL7zACu3vZ8iLVj5Z3xVw5xm1cLpE0Mw++4KNwCYOLn/ZBKJ6sKO2y MTLmdIdKvFcG7h+21j6qff6V0Vjnb3NKZNPJwGb8hRieWLHrl4i8/tAStQgNzUFxOndt wxW5OdterFLgDLlMQ/oU+32G/2lmncjOCioZeF3Zf4Pi4v6MjUDGYRMU5QA8pX5GSp5U zN+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b="mpy/yQtI"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id s2si10551459edt.551.2021.05.30.13.45.57; Sun, 30 May 2021 13:45:58 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b="mpy/yQtI"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CCE586806F5; Sun, 30 May 2021 23:45:53 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0149A6806F5 for ; Sun, 30 May 2021 23:45:46 +0300 (EEST) Received: by mail-qk1-f180.google.com with SMTP id h20so9505807qko.11 for ; Sun, 30 May 2021 13:45: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=zNmBBnzcSHYeSv210CVI0waB1rl/9YTysi7M2R2iypM=; b=mpy/yQtID8n0uuNuXeJ/Gyp1AQj63QdVP2f49aN0ml/jt6uFKg2iCsJTmro9YM1QZF HWK6mlRAjmPp12QvzU6Qjig3makpwsyu1nVIy/9374cwEkx9qhPExnxuHgK5EMWxe7GL t4+vtlMDU/hOw6J2khYVvMTJkwXLLGJAK6fAtEUHVPR79xFDkel6oQRY9eb70jKns/Gn CEwq3/XKk6EDzn3yJ4K3jSGil85y5Fd3VhxxnKi3CzaTLN3x0lO8HdNijpjCy4dfyY0Z tZFtEtgmLQBgPzozN4m7PGHBcutj04aBcKeCK0VJsWr5RBvZ2o9xpxxulN0B66+NF5gN t44w== 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=zNmBBnzcSHYeSv210CVI0waB1rl/9YTysi7M2R2iypM=; b=RGaWdGMpvQyMZfVolbhOsyAK7DXm7ltRQgKaKiZ0EmlMQeHo/m/WFhplgg3bloF9uy fv7mXPWgkVZatmVujVRE2okGzxYJyyTpicg+gDa3AhAN/KSSAu76NEGSNToeHUfckKR5 CQUz/fjRwHjOaMsXU4Bi5vZkx78zG52PsVTlZbmm10jtp0aqifKqPNoHB/sfBAkImCQX bCgOmcME9gvJg1MNHWPGnKnaGp+/nwRhpNMbkXXll0PNw1n6IyLrW5nocfrElA1V6ffI +Ck7twNBCGFJ84CjiYi7NUVMbHo0OqZLzItyF2BKDB2+kr3qwUQzfoIYrF9ocXT219Oy o3Ag== X-Gm-Message-State: AOAM533sfhTfIre839xlSlMrp8HvQrsRNFWgPDnh9dU0yy2cdSKbaW3T yUpZFlY3jQ+8oDPe4jQp3eI71tLj8hk= X-Received: by 2002:a37:46cd:: with SMTP id t196mr13748068qka.305.1622406262009; Sun, 30 May 2021 13:24:22 -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 20sm7930751qks.64.2021.05.30.13.24.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 May 2021 13:24:21 -0700 (PDT) From: Andriy Gelman X-Google-Original-From: Andriy Gelman To: ffmpeg-devel@ffmpeg.org Date: Sun, 30 May 2021 16:24:10 -0400 Message-Id: <20210530202410.202575-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.29 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" X-TUID: GaSUwhn3ZJRa 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 --- Patch didn't apply cleanly anymore. Rebased to master libavformat/rtsp.c | 12 ++++++------ libavformat/rtsp.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c index 9f509a229f..d4ab8f28bf 100644 --- a/libavformat/rtsp.c +++ b/libavformat/rtsp.c @@ -94,7 +94,7 @@ const AVOption ff_rtsp_options[] = { { "min_port", "set minimum local UDP port", OFFSET(rtp_port_min), AV_OPT_TYPE_INT, {.i64 = RTSP_RTP_PORT_MIN}, 0, 65535, DEC|ENC }, { "max_port", "set maximum local UDP port", OFFSET(rtp_port_max), AV_OPT_TYPE_INT, {.i64 = RTSP_RTP_PORT_MAX}, 0, 65535, DEC|ENC }, { "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 }, - { "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 }, COMMON_OPTS(), { "user_agent", "override User-Agent header", OFFSET(user_agent), AV_OPT_TYPE_STRING, {.str = LIBAVFORMAT_IDENT}, 0, 0, DEC }, { NULL }, @@ -104,7 +104,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 }, @@ -112,7 +112,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 }, @@ -1874,7 +1874,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; @@ -2027,7 +2027,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)); @@ -2088,7 +2088,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.