From patchwork Sun Feb 2 03:48:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Li X-Patchwork-Id: 17658 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 C10FE44B3F8 for ; Sun, 2 Feb 2020 05:54:27 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A07126881EC; Sun, 2 Feb 2020 05:54:27 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f65.google.com (mail-pj1-f65.google.com [209.85.216.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 41C4D6881DE for ; Sun, 2 Feb 2020 05:54:21 +0200 (EET) Received: by mail-pj1-f65.google.com with SMTP id dw13so4741482pjb.4 for ; Sat, 01 Feb 2020 19:54:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=MWW57Y08oIxtAXzZa1rCjC7TY7JyWbyZBlvuuXu+XRw=; b=TwuKtTP/6hJWehrs9D0tPPMFzNBgk91i+tATuj3ySzi8LCM/CRbw2wehLK9etIthl1 WdI2jLZgMhxz7g9wQaPp/Prv2m5IVmd749ZcT3zNlYpw1yzHtWq1TbqXMzvQWHnVlaVk J9WhOBkdr/Ii7a5NwcrHeWZWuqjLr0AB1yYoh593qU4NMVw0G04SMVH5LLj0RYE+pnGI 65fGOqzHve99ngUwElhRttLS/Njlq4589CK6sAncofosDdOaNavXnrZwemp4PsTyVtgI b95GUMIYir6myzOSzGVxwBC4CY2l/7hCUyfI7obVydXStKSBMdeRKF3p4oHZFLuorJSj HJag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=MWW57Y08oIxtAXzZa1rCjC7TY7JyWbyZBlvuuXu+XRw=; b=KItd4HIs5vSxI+BSDtL5D/rAGN5otN2wUpgxzw6oGvFUTyOEAnN8UY7uDlzh0sCRBI pNC1W9f6QmdcyX6boSWVyou6fr800lWz/VkeM4GkO9EA+05nC9kWnEF8zSENnUFLvHHF wmDqZs6HT68OXU+AwU7fbopW0X93MEHUFVAhUpWQAU1wRK6NaGXBK/9ASLo2GdtKdScu A9M5AzbQDgTABd/Mqz0fu78n3014edGMVLfs+3KXoFvWMk5kQI1WCO8VzwSZ/95GWW8V gbthDuoghS5fyMAVpXOC0OykFvuToKcn27gQumjZWN5Q+wFd+PAzOuM6U9QKo3oBnP2o vurg== X-Gm-Message-State: APjAAAUc+rOcswuHZ3Yqu+eqVZ2X419e5mKbZ0oi9eZ5LM3yS6wAnE+T jfRtSzuAoe9kEj+6GmrMvRUyiyCo5I8= X-Google-Smtp-Source: APXvYqzYOI/wwoVB9+6dvobTptD0vOgAOjY1yjITH4mMelTDCA7o48aEbCxqrksRtJlRWj7uKtzgbg== X-Received: by 2002:a17:902:b490:: with SMTP id y16mr17664756plr.326.1580615317285; Sat, 01 Feb 2020 19:48:37 -0800 (PST) Received: from jun-ubuntu.corp.microsoft.com ([2001:4898:80e8:a:b84e:1130:45ef:eba1]) by smtp.googlemail.com with ESMTPSA id u3sm15255564pjv.32.2020.02.01.19.48.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Feb 2020 19:48:36 -0800 (PST) From: Jun Li To: ffmpeg-devel@ffmpeg.org Date: Sat, 1 Feb 2020 19:48:31 -0800 Message-Id: <20200202034831.26072-1-junli1026@gmail.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH v1] avformat/sdp, rtsp: add rtcp attribute to sdp file 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Fix #8479 1. write rtcpport to sdp file when rtpport is specified in url 2. apply rtcpport when sdp file contains rtcp attribute Signed-off-by: Jun Li --- libavformat/rtpproto.c | 11 +++++++++++ libavformat/rtpproto.h | 2 ++ libavformat/rtsp.c | 12 ++++++++++-- libavformat/rtsp.h | 1 + libavformat/sdp.c | 12 ++++++++++-- 5 files changed, 34 insertions(+), 4 deletions(-) diff --git a/libavformat/rtpproto.c b/libavformat/rtpproto.c index 1f0a82ac7e..81a39cc3de 100644 --- a/libavformat/rtpproto.c +++ b/libavformat/rtpproto.c @@ -524,6 +524,17 @@ int ff_rtp_get_local_rtp_port(URLContext *h) return ff_udp_get_local_port(s->rtp_hd); } +/** + * Return the remote rtcp port used by the RTP connection + * @param h media file context + * @return the remote port number + */ +int ff_rtp_get_remote_rtcp_port(URLContext *h) +{ + RTPContext *s = h->priv_data; + return s->rtcp_port; +} + /** * Return the local rtcp port used by the RTP connection * @param h media file context diff --git a/libavformat/rtpproto.h b/libavformat/rtpproto.h index 131aac5f3c..d42327ea5c 100644 --- a/libavformat/rtpproto.h +++ b/libavformat/rtpproto.h @@ -27,4 +27,6 @@ int ff_rtp_set_remote_url(URLContext *h, const char *uri); int ff_rtp_get_local_rtp_port(URLContext *h); +int ff_rtp_get_remote_rtcp_port(URLContext *h); + #endif /* AVFORMAT_RTPPROTO_H */ diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c index cd6fc32a29..c892f21142 100644 --- a/libavformat/rtsp.c +++ b/libavformat/rtsp.c @@ -577,6 +577,10 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1, if (s1->seen_fmtp) { parse_fmtp(s, rt, payload_type, s1->delayed_fmtp); } + } else if (av_strstart(p, "rtcp:", &p) && s->nb_streams > 0) { + rtsp_st = rt->rtsp_streams[rt->nb_rtsp_streams - 1]; + get_word(buf1, sizeof(buf1), &p); + rtsp_st->rtcp_port = strtol(buf1, NULL, 10); } else if (av_strstart(p, "fmtp:", &p) || av_strstart(p, "framesize:", &p)) { // let dynamic protocol handlers have a stab at the line. @@ -2367,6 +2371,7 @@ static int sdp_read_header(AVFormatContext *s) if (!(rt->rtsp_flags & RTSP_FLAG_CUSTOM_IO)) { AVDictionary *opts = map_to_opts(rt); + int rtcp_port = rtsp_st->rtcp_port; err = getnameinfo((struct sockaddr*) &rtsp_st->sdp_ip, sizeof(rtsp_st->sdp_ip), @@ -2377,10 +2382,13 @@ static int sdp_read_header(AVFormatContext *s) av_dict_free(&opts); goto fail; } + + if (rtcp_port <= 0) + rtcp_port = rtsp_st->sdp_port + 1; ff_url_join(url, sizeof(url), "rtp", NULL, namebuf, rtsp_st->sdp_port, - "?localport=%d&ttl=%d&connect=%d&write_to_source=%d", - rtsp_st->sdp_port, rtsp_st->sdp_ttl, + "?localport=%d&localrtcpport=%d&ttl=%d&connect=%d&write_to_source=%d", + rtsp_st->sdp_port, rtcp_port, rtsp_st->sdp_ttl, rt->rtsp_flags & RTSP_FLAG_FILTER_SRC ? 1 : 0, rt->rtsp_flags & RTSP_FLAG_RTCP_TO_SOURCE ? 1 : 0); diff --git a/libavformat/rtsp.h b/libavformat/rtsp.h index 54a9a30c16..15747fe6d1 100644 --- a/libavformat/rtsp.h +++ b/libavformat/rtsp.h @@ -448,6 +448,7 @@ typedef struct RTSPStream { /** The following are used only in SDP, not RTSP */ //@{ int sdp_port; /**< port (from SDP content) */ + int rtcp_port; /**< rtcp port (from SDP content) */ struct sockaddr_storage sdp_ip; /**< IP address (from SDP content) */ int nb_include_source_addrs; /**< Number of source-specific multicast include source IP addresses (from SDP content) */ struct RTSPSource **include_source_addrs; /**< Source-specific multicast include source IP addresses (from SDP content) */ diff --git a/libavformat/sdp.c b/libavformat/sdp.c index 34e9839b67..c3c2909090 100644 --- a/libavformat/sdp.c +++ b/libavformat/sdp.c @@ -26,11 +26,13 @@ #include "libavutil/opt.h" #include "libavcodec/xiph.h" #include "libavcodec/mpeg4audio.h" +#include "avio_internal.h" #include "avformat.h" #include "internal.h" #include "avc.h" #include "hevc.h" #include "rtp.h" +#include "rtpproto.h" #if CONFIG_NETWORK #include "network.h" #endif @@ -480,10 +482,16 @@ static char *latm_context2config(AVFormatContext *s, AVCodecParameters *par) return config; } -static char *sdp_write_media_attributes(char *buff, int size, AVStream *st, int payload_type, AVFormatContext *fmt) +static char *sdp_write_media_attributes(char *buff, int size, AVStream *st, int payload_type, AVFormatContext *fmt, int port) { char *config = NULL; AVCodecParameters *p = st->codecpar; + URLContext* url_ctx = ffio_geturlcontext(fmt->pb); + if (url_ctx) { + int rtcp_port = ff_rtp_get_remote_rtcp_port(url_ctx); + if (rtcp_port > 0 && rtcp_port != port+1) + av_strlcatf(buff, size, "a=rtcp:%d\r\n", rtcp_port); + } switch (p->codec_id) { case AV_CODEC_ID_DIRAC: @@ -766,7 +774,7 @@ void ff_sdp_write_media(char *buff, int size, AVStream *st, int idx, av_strlcatf(buff, size, "b=AS:%"PRId64"\r\n", p->bit_rate / 1000); } - sdp_write_media_attributes(buff, size, st, payload_type, fmt); + sdp_write_media_attributes(buff, size, st, payload_type, fmt, port); } int av_sdp_create(AVFormatContext *ac[], int n_files, char *buf, int size)