[FFmpeg-devel] [PATCH] rtp: Fix play multiple multicast streams with the same port

Zhao Zhili wantlamy at gmail.com
Thu Jan 7 10:44:03 CET 2016


We cannot play multiple multicast streams with the same port at the
same time. This is because both rtp and rtcp ports are opened in
read-write mode, so they will not bind to the multicast address. Try
to make rtp port as read-only by default to solve this bug.

Signed-off-by: Zhao Zhili <wantlamy at gmail.com>
---
 libavformat/rtpproto.c | 12 +++++++++---
 libavformat/rtsp.c     |  2 +-
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/libavformat/rtpproto.c b/libavformat/rtpproto.c
index e0aa23e..f334055 100644
--- a/libavformat/rtpproto.c
+++ b/libavformat/rtpproto.c
@@ -323,6 +323,7 @@ static int rtp_open(URLContext *h, const char *uri, int
flags)
     char path[1024];
     const char *p;
     int i, max_retry_count = 3;
+    int tmpflags;

     av_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &rtp_port,
                  path, sizeof(path), uri);
@@ -380,19 +381,24 @@ static int rtp_open(URLContext *h, const char *uri,
int flags)
         build_udp_url(s, buf, sizeof(buf),
                       hostname, rtp_port, s->local_rtpport,
                       sources, block);
-        if (ffurl_open(&s->rtp_hd, buf, flags, &h->interrupt_callback,
NULL) < 0)
+        if (s->local_rtpport > 0 && s->local_rtpport == s->local_rtcpport)
+            tmpflags = flags | AVIO_FLAG_WRITE;
+        else
+            tmpflags = flags;
+        if (ffurl_open(&s->rtp_hd, buf, tmpflags, &h->interrupt_callback,
NULL) < 0)
             goto fail;
         s->local_rtpport = ff_udp_get_local_port(s->rtp_hd);
         if(s->local_rtpport == 65535) {
             s->local_rtpport = -1;
             continue;
         }
+        tmpflags = flags | AVIO_FLAG_WRITE;
         if (s->local_rtcpport < 0) {
             s->local_rtcpport = s->local_rtpport + 1;
             build_udp_url(s, buf, sizeof(buf),
                           hostname, s->rtcp_port, s->local_rtcpport,
                           sources, block);
-            if (ffurl_open(&s->rtcp_hd, buf, flags,
&h->interrupt_callback, NULL) < 0) {
+            if (ffurl_open(&s->rtcp_hd, buf, tmpflags,
&h->interrupt_callback, NULL) < 0) {
                 s->local_rtpport = s->local_rtcpport = -1;
                 continue;
             }
@@ -401,7 +407,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);
-        if (ffurl_open(&s->rtcp_hd, buf, flags, &h->interrupt_callback,
NULL) < 0)
+        if (ffurl_open(&s->rtcp_hd, buf, tmpflags, &h->interrupt_callback,
NULL) < 0)
             goto fail;
         break;
     }
diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index 39539e9..8cae376 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -2316,7 +2316,7 @@ static int sdp_read_header(AVFormatContext *s)
             append_source_addrs(url, sizeof(url), "block",
                                 rtsp_st->nb_exclude_source_addrs,
                                 rtsp_st->exclude_source_addrs);
-            err = ffurl_open(&rtsp_st->rtp_handle, url,
AVIO_FLAG_READ_WRITE,
+            err = ffurl_open(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ,
                            &s->interrupt_callback, &opts);

             av_dict_free(&opts);
-- 
1.9.1


More information about the ffmpeg-devel mailing list