From patchwork Tue Jul 3 09:16:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: leozhang X-Patchwork-Id: 9591 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:104:0:0:0:0:0 with SMTP id c4-v6csp894068jad; Tue, 3 Jul 2018 02:22:49 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdsGLENr8K/PmnI+VARvWHOmLBQEy9Q62JraFsuiZ1wPLowxHYykwMdeV0g8cPQabqQgyA8 X-Received: by 2002:a1c:6a1a:: with SMTP id f26-v6mr1392451wmc.1.1530609769104; Tue, 03 Jul 2018 02:22:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530609769; cv=none; d=google.com; s=arc-20160816; b=bPpBt3v+2p+PGhxtVYzPT8MjSqvv1nbguOPS1E2cUgGB7PM/dy6Z/Jj5jJXTx6rehU T3TkjP/YjTM6rT0D8v+p77lKt7sod7dZIkdgI2+OdY6rDGeqsL0/N+m7VNmdpSCWuBi/ ZbTmrOjHYy02kDrNgo26keUnIKjoERI764UNfyQRFQgso6Xg7qcYgvPpCV4piCBrZj5M 6qlcUCW9fcgNmDg4NdRYVHGS/4DpXZYLwFFy83cSpD6Moz834UaBYwx9KTDGQfOmw4O+ Uu0TKx4nZPSrFYCWpV9bnBU9EkQWmHrEc3U2gVqX/fMmEy37OIWH8rvLO7+h+0XAzoFX +BWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=ywwwUoHUKFzyTzZHA1F23jd1MLlOgzsJ9GShNNzS9Y8=; b=DQznC5pa+ozCt4A7b+Av5jnEIUb2AoSYIao6Ku4Z+VHCLQPp9qiIE89NtOqWpO/d/h yzFbhARF26IQs8geuNHjCuDADHvb7xsFoYKnXI3ichQDHFrX+tIZu1UflGds37unDXlA x7/WrpEiH635dHNqwoVvVK5RSxWUabHBNUHKbsPrVsFGUleV8ZGau3wIBNl7PFLlKEG7 ofcdiOJiK4wCwNGK6OB5m9V0Q78uUgRAc1M7TG9fI1LOGJIFxUT+n0aeYl8a4KtVNC+v cYkf948XDwlMcpeSv5FvwG6iIw5XnQipbCpNC2QEAeKXMHM0YeTSZ/+f4Nmx2b7rswQk EdQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=nHE6UxBO; 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 a84-v6si674272wme.146.2018.07.03.02.22.48; Tue, 03 Jul 2018 02:22:49 -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=nHE6UxBO; 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 6092B689732; Tue, 3 Jul 2018 12:22:42 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf0-f172.google.com (mail-pf0-f172.google.com [209.85.192.172]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 283D7680AF8 for ; Tue, 3 Jul 2018 12:22:35 +0300 (EEST) Received: by mail-pf0-f172.google.com with SMTP id s21-v6so723366pfm.6 for ; Tue, 03 Jul 2018 02:22:39 -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; bh=n0i9fHaqp2ur5XbnDaL9QHaQjxi+v4uXXlrMsVtDbcg=; b=nHE6UxBO9gnvWA+R80D06GmJWhP4hNIpldMWi55Mys5ojjAbpZMO9SBlBF+ADEOi3+ ssGE0y5yx+6MOHgo4fyDW07oejoO3MztyUMVHO9kUfLPr0PDoSGNcK1bKIpMXfLwXWA7 oiwEbR3GGbUFoNeXwIndeumAhUvWs5XVFCmOPOWbYu+ElSm2YkRvjDGU2El77ePiYSgd yB5pAVusG2fP3u/Uwc4EHuRIkjVrQvwei/mpYNPPj2HApw3P10K4+xgT5cMjJRXbIhKG Gv0PD0janBNLPP91JOHTsgVfM0xMJoe9SKoIGBZOrf51V1aiGqMNkFbDERycH2M7bULx P2Jg== 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; bh=n0i9fHaqp2ur5XbnDaL9QHaQjxi+v4uXXlrMsVtDbcg=; b=eDGTNJclP4+xLIsJ20oI2EscSBMPkKn5xkBG8f7Z4dB+/jYDDITV98RHYS3TB3aKu0 gOuQ+tsJBpBjam8aeaMI44NIzHxqV4ZbgpvkpInXdEZqBlh2J49LKH1g4uf1zC4Zl3MM O86aEfTIV7K1TO0s1/r+/+7uO3uLTmE3mI7C/NAJd9BXR6enUgw0A0902SpcyD2PfTS+ imvOAsoI4rULNzeOeVhMkxNdqMPFw75pMfCzvd+yoogy/SaTH3fmHYRTu3CIy+5vGmHR tt3FY62sTxQNMOwfrpIPPKv1NFRSWVPYtgJidLdABYs+KocATOLWxw3Qdr+lTr9TPrru 9TCQ== X-Gm-Message-State: APt69E1pK557kmf0XgiKrdEcr9POOg3ezxXkx/KwZYRuRmbG9PSdwt6P DP5ki+nkn2ojzr8Qj5csVHYSWQ== X-Received: by 2002:a62:5d83:: with SMTP id n3-v6mr28980937pfj.68.1530609399692; Tue, 03 Jul 2018 02:16:39 -0700 (PDT) Received: from localhost.localdomain ([223.26.73.150]) by smtp.gmail.com with ESMTPSA id d9-v6sm1455019pge.68.2018.07.03.02.16.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Jul 2018 02:16:39 -0700 (PDT) From: UsingtcNower To: ffmpeg-devel@ffmpeg.org Date: Tue, 3 Jul 2018 17:16:27 +0800 Message-Id: <1530609387-38382-1-git-send-email-nowerzt@gmail.com> X-Mailer: git-send-email 1.8.3.1 Subject: [FFmpeg-devel] [PATCH] libavformat/rtpproto, libavformat/rtsp: receive multicast rtp input 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: UsingtcNower MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: UsingtcNower --- libavformat/rtpproto.c | 20 +++++++++++++++----- libavformat/rtsp.c | 16 +++++++++++++++- libavformat/rtsp.h | 5 +++++ 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/libavformat/rtpproto.c b/libavformat/rtpproto.c index c01d9ce..6bb0324 100644 --- a/libavformat/rtpproto.c +++ b/libavformat/rtpproto.c @@ -59,6 +59,7 @@ typedef struct RTPContext { char *sources; char *block; char *fec_options_str; + char *localaddr; } RTPContext; #define OFFSET(x) offsetof(RTPContext, x) @@ -77,6 +78,7 @@ static const AVOption options[] = { { "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 }, + { "localaddr", "Local address", OFFSET(localaddr), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = D|E }, { NULL } }; @@ -230,7 +232,8 @@ static void build_udp_url(RTPContext *s, const char *hostname, int port, int local_port, const char *include_sources, - const char *exclude_sources) + const char *exclude_sources, + const char *localaddr) { ff_url_join(buf, buf_size, "udp", NULL, hostname, port, NULL); if (local_port >= 0) @@ -250,6 +253,8 @@ static void build_udp_url(RTPContext *s, url_add_option(buf, buf_size, "sources=%s", include_sources); if (exclude_sources && exclude_sources[0]) url_add_option(buf, buf_size, "block=%s", exclude_sources); + if (localaddr && localaddr[0]) + url_add_option(buf, buf_size, "localaddr=%s", localaddr); } static void rtp_parse_addr_list(URLContext *h, char *buf, @@ -320,7 +325,7 @@ static int rtp_open(URLContext *h, const char *uri, int flags) RTPContext *s = h->priv_data; AVDictionary *fec_opts = NULL; int rtp_port; - char hostname[256], include_sources[1024] = "", exclude_sources[1024] = ""; + char hostname[256], include_sources[1024] = "", exclude_sources[1024] = "", localaddr[1024] = ""; char *sources = include_sources, *block = exclude_sources; char *fec_protocol = NULL; char buf[1024]; @@ -379,7 +384,12 @@ static int rtp_open(URLContext *h, const char *uri, int flags) rtp_parse_addr_list(h, s->block, &s->ssm_exclude_addrs, &s->nb_ssm_exclude_addrs); block = s->block; } + if (av_find_info_tag(buf, sizeof(buf), "localaddr", p)) { + av_strlcpy(localaddr, buf, sizeof(localaddr)); + } } + if(!localaddr[0] && s->localaddr) + av_strlcpy(localaddr, s->localaddr, sizeof(localaddr)); if (s->fec_options_str) { p = s->fec_options_str; @@ -409,7 +419,7 @@ static int rtp_open(URLContext *h, const char *uri, int flags) for (i = 0; i < max_retry_count; i++) { build_udp_url(s, buf, sizeof(buf), hostname, rtp_port, s->local_rtpport, - sources, block); + sources, block, localaddr); if (ffurl_open_whitelist(&s->rtp_hd, buf, flags, &h->interrupt_callback, NULL, h->protocol_whitelist, h->protocol_blacklist, h) < 0) goto fail; @@ -423,7 +433,7 @@ static int rtp_open(URLContext *h, const char *uri, int flags) s->local_rtcpport = s->local_rtpport + 1; build_udp_url(s, buf, sizeof(buf), hostname, s->rtcp_port, s->local_rtcpport, - sources, block); + sources, block, localaddr); if (ffurl_open_whitelist(&s->rtcp_hd, buf, rtcpflags, &h->interrupt_callback, NULL, h->protocol_whitelist, h->protocol_blacklist, h) < 0) { @@ -434,7 +444,7 @@ static int rtp_open(URLContext *h, const char *uri, int flags) } build_udp_url(s, buf, sizeof(buf), hostname, s->rtcp_port, s->local_rtcpport, - sources, block); + sources, block, localaddr); if (ffurl_open_whitelist(&s->rtcp_hd, buf, rtcpflags, &h->interrupt_callback, NULL, h->protocol_whitelist, h->protocol_blacklist, h) < 0) goto fail; diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c index ceb770a..e18efbf 100644 --- a/libavformat/rtsp.c +++ b/libavformat/rtsp.c @@ -120,6 +120,7 @@ static const AVOption sdp_options[] = { static const AVOption rtp_options[] = { RTSP_FLAG_OPTS("rtp_flags", "set RTP flags"), COMMON_OPTS(), + { "localaddr", "Local address", OFFSET(localaddr), AV_OPT_TYPE_STRING, {.str = NULL}, .flags = DEC|ENC}, { NULL }, }; @@ -2314,6 +2315,8 @@ static int sdp_read_header(AVFormatContext *s) int size, i, err; char *content; char url[1024]; + char buf[1024]; + const char *p; if (!ff_network_init()) return AVERROR(EIO); @@ -2363,6 +2366,14 @@ static int sdp_read_header(AVFormatContext *s) rt->rtsp_flags & RTSP_FLAG_FILTER_SRC ? 1 : 0, rt->rtsp_flags & RTSP_FLAG_RTCP_TO_SOURCE ? 1 : 0); + p = strchr(s->url, '?'); + if(p && av_find_info_tag(buf, sizeof(buf), "localaddr", p)) { + av_strlcat(url, "&localaddr=", sizeof(url)); + av_strlcat(url, buf, sizeof(url)); + } else if(rt->localaddr) { + av_strlcat(url, "&localaddr=", sizeof(url)); + av_strlcat(url, rt->localaddr, sizeof(url)); + } append_source_addrs(url, sizeof(url), "sources", rtsp_st->nb_include_source_addrs, rtsp_st->include_source_addrs); @@ -2435,12 +2446,15 @@ static int rtp_read_header(AVFormatContext *s) AVIOContext pb; socklen_t addrlen = sizeof(addr); RTSPState *rt = s->priv_data; + AVDictionary *opts = NULL; if (!ff_network_init()) return AVERROR(EIO); + av_dict_set(&opts, "localaddr", rt->localaddr, 0); ret = ffurl_open_whitelist(&in, s->url, AVIO_FLAG_READ, - &s->interrupt_callback, NULL, s->protocol_whitelist, s->protocol_blacklist, NULL); + &s->interrupt_callback, &opts, s->protocol_whitelist, s->protocol_blacklist, NULL); + av_dict_free(&opts); if (ret) goto fail; diff --git a/libavformat/rtsp.h b/libavformat/rtsp.h index 9a7f366..6a32788 100644 --- a/libavformat/rtsp.h +++ b/libavformat/rtsp.h @@ -409,6 +409,11 @@ typedef struct RTSPState { char default_lang[4]; int buffer_size; + + /** + * Multicast local address + */ + char *localaddr; } RTSPState; #define RTSP_FLAG_FILTER_SRC 0x1 /**< Filter incoming UDP packets -