From patchwork Wed Oct 14 14:34:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 22947 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 9C9BB44AB0D for ; Wed, 14 Oct 2020 17:35:30 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4949E68B9F5; Wed, 14 Oct 2020 17:35:30 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B45B468ADC1 for ; Wed, 14 Oct 2020 17:35:23 +0300 (EEST) Received: by mail-pg1-f175.google.com with SMTP id o3so2080405pgr.11 for ; Wed, 14 Oct 2020 07:35:23 -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:in-reply-to:references; bh=x1WA5lLsg7QMX4gdR68MyWGsOCCYOB96w57WpXTBpoU=; b=JTbRdgugS3pX44m+MQkEomQMD/H2PsqSdlaHgbGOuKnH+YVgY3PtM7Vy704befsb/8 Xadtw3ZuVz4GYxw3sNJRZ9MC7pImPqNvTx6j6rerOxttLoYg4cqgaBv7e6xZ5RKo6A9U h3Z4JnZO/wEAPEDG2KE27HidK9IqV0CfjJUVijlCYB+bP4pD3Oil8MzDFxjbZC/F28/o C9l0Oe/zagYUuLA7CwWKQdqJArmWKxrfxPPQUV01QAs/GA64f1voAjN6XLCeF5gQSUcd ZqO7uRWtY8G8+IdkWCxW0mFvtpXQfTuapSD59hOUPdfMuLXC3m8zvwvDPAdE96UaaiAJ AQwQ== 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:in-reply-to :references; bh=x1WA5lLsg7QMX4gdR68MyWGsOCCYOB96w57WpXTBpoU=; b=Jxknnid51Z8mut0ssw0QqhzuNR+8ZKPFue+mfcnynk1kmcsWpN5Gp+oHLsXlYBaFxp D+crb7mFo8L9bI8luVxiN4lTJBZ7vgKy2xuUIn6z+wn9U3M+6NpnHsexONNRU5Tc0geO Xpgdl1+siyidw/My1yklmo5TTvq4D9tQYKW/0YIa2OXH7R0lrsS87xuQ8G3AktZ65X3+ FQM/TPA8zMZ0mS4yZgAe1ZJsThHCdAO0m9ABhRhkzDPUQkZWBXIGxA/JhjdMuMpoiMYW oO/E22XlKWl/y7/Aqg3GTVVasAv8b1rqPs8hTAVKb2Qcls0Tgw/B99LoyosLuYULg3B3 Jc/A== X-Gm-Message-State: AOAM532oPiIDsldqzojG8T7VytWxb6sajoP1zhqj7+EuUPJA4rGn92Kc hpUVAsU9cC3DcI+5rfzk3FdgtX105h8= X-Google-Smtp-Source: ABdhPJxfe+4MvX9FdwmoLhUGjwo9sCRcWIJSF0w9FL0k3aXRZQaD1uK+4igY+FbXMY5EzIQHwQDOGg== X-Received: by 2002:a63:ff4e:: with SMTP id s14mr4020310pgk.137.1602686121384; Wed, 14 Oct 2020 07:35:21 -0700 (PDT) Received: from vpn2.localdomain ([161.117.202.209]) by smtp.gmail.com with ESMTPSA id o4sm3612035pjj.38.2020.10.14.07.35.20 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Oct 2020 07:35:20 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Wed, 14 Oct 2020 22:34:59 +0800 Message-Id: <1602686103-3427-2-git-send-email-lance.lmwang@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1602686103-3427-1-git-send-email-lance.lmwang@gmail.com> References: <1602686103-3427-1-git-send-email-lance.lmwang@gmail.com> Subject: [FFmpeg-devel] [PATCH 2/6] avformat/rtpproto: support for rtp read timeout 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: Limin Wang MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Limin Wang then we can set the rtp read timeout instead of infinite timeout. How to test(5s timeout): ./ffprobe -i rtp://192.168.1.67:1234?timeout=5000000 Signed-off-by: Limin Wang --- doc/protocols.texi | 3 +++ libavformat/rtpproto.c | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/doc/protocols.texi b/doc/protocols.texi index 7b3df96..b4efa14 100644 --- a/doc/protocols.texi +++ b/doc/protocols.texi @@ -990,6 +990,9 @@ set to 1) or to a default remote address (if set to 0). @item localport=@var{n} Set the local RTP port to @var{n}. +@item timeout=@var{n} +Set timeout (in microseconds) of socket I/O operations to @var{n}. + This is a deprecated option. Instead, @option{localrtpport} should be used. diff --git a/libavformat/rtpproto.c b/libavformat/rtpproto.c index 19e940d..7dd6042 100644 --- a/libavformat/rtpproto.c +++ b/libavformat/rtpproto.c @@ -60,6 +60,7 @@ typedef struct RTPContext { char *sources; char *block; char *fec_options_str; + int64_t rw_timeout; } RTPContext; #define OFFSET(x) offsetof(RTPContext, x) @@ -75,6 +76,7 @@ static const AVOption options[] = { { "write_to_source", "Send packets to the source address of the latest received packet", OFFSET(write_to_source), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, .flags = D|E }, { "pkt_size", "Maximum packet size", OFFSET(pkt_size), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E }, { "dscp", "DSCP class", OFFSET(dscp), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E }, + { "timeout", "set timeout (in microseconds) of socket I/O operations", OFFSET(rw_timeout), AV_OPT_TYPE_INT64, { .i64 = -1 }, -1, INT64_MAX, .flags = D|E }, { "sources", "Source list", OFFSET(sources), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = D|E }, { "block", "Block list", OFFSET(block), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = D|E }, { "fec", "FEC", OFFSET(fec_options_str), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = E }, @@ -265,6 +267,9 @@ static int rtp_open(URLContext *h, const char *uri, int flags) if (av_find_info_tag(buf, sizeof(buf), "dscp", p)) { s->dscp = strtol(buf, NULL, 10); } + if (av_find_info_tag(buf, sizeof(buf), "timeout", p)) { + s->rw_timeout = strtol(buf, NULL, 10); + } if (av_find_info_tag(buf, sizeof(buf), "sources", p)) { av_strlcpy(include_sources, buf, sizeof(include_sources)); ff_ip_parse_sources(h, buf, &s->filters); @@ -280,6 +285,8 @@ static int rtp_open(URLContext *h, const char *uri, int flags) block = s->block; } } + if (s->rw_timeout >= 0) + h->rw_timeout = s->rw_timeout; if (s->fec_options_str) { p = s->fec_options_str; @@ -375,9 +382,10 @@ static int rtp_read(URLContext *h, uint8_t *buf, int size) RTPContext *s = h->priv_data; int len, n, i; struct pollfd p[2] = {{s->rtp_fd, POLLIN, 0}, {s->rtcp_fd, POLLIN, 0}}; - int poll_delay = h->flags & AVIO_FLAG_NONBLOCK ? 0 : 100; + int poll_delay = h->flags & AVIO_FLAG_NONBLOCK ? 0 : POLLING_TIME; struct sockaddr_storage *addrs[2] = { &s->last_rtp_source, &s->last_rtcp_source }; socklen_t *addr_lens[2] = { &s->last_rtp_source_len, &s->last_rtcp_source_len }; + int runs = h->rw_timeout / 1000 / POLLING_TIME; for(;;) { if (ff_check_interrupt(&h->interrupt_callback)) @@ -401,6 +409,8 @@ static int rtp_read(URLContext *h, uint8_t *buf, int size) continue; return len; } + } else if (n == 0 && h->rw_timeout > 0 && --runs <= 0) { + return AVERROR(ETIMEDOUT); } else if (n < 0) { if (ff_neterrno() == AVERROR(EINTR)) continue;