[FFmpeg-devel] [PATCH 1/2] avformat/rtsp: If the rtcp port is specified in the sdp file, set rtcpport when creating the RTP stream

Kim Hwan akon47 at naver.com
Fri Aug 20 07:08:56 EEST 2021


Signed-off-by: Kim Hwan <akon47 at naver.com>
---
 libavformat/rtsp.c | 8 +++++++-
 libavformat/rtsp.h | 1 +
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index 9869e1b72e..9fa6861c2a 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -586,6 +586,10 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1,
                     av_strlcpy(rtsp_st->control_url, p,
                                sizeof(rtsp_st->control_url));
             }
+        } else if (av_strstart(p, "rtcp:", &p) && s->nb_streams > 0) {
+            get_word(buf1, sizeof(buf1), &p);
+            rtsp_st = rt->rtsp_streams[rt->nb_rtsp_streams - 1];
+            rtsp_st->rtcp_port = atoi(buf1);
         } else if (av_strstart(p, "rtpmap:", &p) && s->nb_streams > 0) {
             /* NOTE: rtpmap is only supported AFTER the 'm=' tag */
             get_word(buf1, sizeof(buf1), &p);
@@ -2422,8 +2426,10 @@ static int sdp_read_header(AVFormatContext *s)
             }
             ff_url_join(url, sizeof(url), "rtp", NULL,
                         namebuf, rtsp_st->sdp_port,
-                        "?localport=%d&ttl=%d&connect=%d&write_to_source=%d",
+                        "?localport=%d&ttl=%d&%srtcpport=%d&connect=%d&write_to_source=%d",
                         rtsp_st->sdp_port, rtsp_st->sdp_ttl,
+                        ff_is_multicast_address((struct sockaddr *)&rtsp_st->sdp_ip) ? "" : "local",
+                        rtsp_st->rtcp_port <= 0 ? (rtsp_st->sdp_port + 1) : rtsp_st->rtcp_port,
                         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 4ec974ed73..001ec3c962 100644
--- a/libavformat/rtsp.h
+++ b/libavformat/rtsp.h
@@ -457,6 +457,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) */
-- 
2.25.1



More information about the ffmpeg-devel mailing list