From patchwork Tue Feb 4 00:34:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Li X-Patchwork-Id: 17685 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 EE75E446CBB for ; Tue, 4 Feb 2020 02:56:23 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D2938689C61; Tue, 4 Feb 2020 02:56:23 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-oi1-f196.google.com (mail-oi1-f196.google.com [209.85.167.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A76B8680B6D for ; Tue, 4 Feb 2020 02:56:17 +0200 (EET) Received: by mail-oi1-f196.google.com with SMTP id d62so16699974oia.11 for ; Mon, 03 Feb 2020 16:56:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=TrjFjzrvKoWsAUOD+/FUUaDqfW+xXtMwWY+mph10db8=; b=FNlr/JAGE/1J78B8vifgsCLUOzxZ4lYudp0mWHL3EUDbYtIn65ChW2Oi0IIya0Obql nSK7Rnlig7YESjWt3ZXR/2ZLrzIEuCvIrPYLcXCAyzbPi30nFUrhs8qcbhZx4TzXlhe4 0AypqpLLEUPekSjhyYzrC/c7u7C4WKAmnbAxWjUJSNA9SmampQ17SXdQRUmgRUdfPtSG wdnY5tARol94c5MlD6YYG0QZ5fDRGjxXLrNUKmknoUHraOG8UsDyZJ+36BIQp0MlbSOQ MbOeiYy1Oi/2EOSZFt/6KaynkosDWM0BU0ZZhBf5IIIgnJnlSkgzVpkcYfepngoht4ig ztfw== 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:in-reply-to :references; bh=TrjFjzrvKoWsAUOD+/FUUaDqfW+xXtMwWY+mph10db8=; b=le7v6eQvysf4x1ClQXpCIrho3tNvZphVOBPykY72M7E73qi9VXXxIgr4JbJTcBDUED 8qq74Hul3bxu9uekkUnmt8b8KHfWK3Hx7pY0jLHYEADi7OJNUlC6peFwmLMA1thZuRk5 4DmhaLgBqhwYAKVXpFH6/24N+d4AB6SxRY7Jd12z896Ff2upVQln6dOk5vXsfH2wqV7D GLKOypMblGfRwYzYaQmh9vQiZ89H3M1I4gXiVIL+PsYq0rumaLmM/HytCbGt2mSaB+No P09XpNeZ6oM5F3zavIFfkurSP+DG7sW/02Hor7LpuJ2MsTeyAuesur3qdO2Or+a4Qzon aU3g== X-Gm-Message-State: APjAAAUkZlvBg9sdOsWF+ay/FD0p4vwy4RBkRD92OfcX4Lr8jjF37MG3 6Pm14vElOKHWH0JZY9DN+4KuOKVzKFQ= X-Google-Smtp-Source: APXvYqzSNN/HzlwTWK5rippLvXom1bNspGRXhdFszZn9wGauMjwvDcxqFq4ioYKvPT8tebEDnlYIWQ== X-Received: by 2002:a17:90a:cb0f:: with SMTP id z15mr2295250pjt.67.1580776455010; Mon, 03 Feb 2020 16:34:15 -0800 (PST) Received: from jun-ubuntu.corp.microsoft.com ([2001:4898:80e8:9:1545:8b7b:2e03:1631]) by smtp.googlemail.com with ESMTPSA id 196sm22096067pfy.86.2020.02.03.16.34.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2020 16:34:14 -0800 (PST) From: Jun Li To: ffmpeg-devel@ffmpeg.org Date: Mon, 3 Feb 2020 16:34:07 -0800 Message-Id: <20200204003407.3545-2-junli1026@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200204003407.3545-1-junli1026@gmail.com> References: <20200204003407.3545-1-junli1026@gmail.com> Subject: [FFmpeg-devel] [PATCH v1 2/2] avformat/rtpproto, sdp: write rtcp port 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 #8474 Write rtcp port attribute to sdp file when necessary. Signed-off-by: Jun Li --- libavformat/rtpproto.c | 11 +++++++++++ libavformat/rtpproto.h | 2 ++ libavformat/sdp.c | 12 ++++++++++-- 3 files changed, 23 insertions(+), 2 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/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)