[FFmpeg-cvslog] avformat/rtpproto: when local rtp port and local rtcp port are not specified, try to make two successive ports and retry 3 times when failed

lemonlinger@gmail.com git at videolan.org
Fri Oct 25 22:54:14 CEST 2013


ffmpeg | branch: master | lemonlinger at gmail.com <lemonlinger at gmail.com> | Sun Oct 20 16:53:09 2013 +0800| [2cf94485de9aa0e8f4552fd9477e0d4bc5cb84bc] | committer: Michael Niedermayer

avformat/rtpproto: when local rtp port and local rtcp port are not specified, try to make two successive ports and retry 3 times when failed

some video players on Android will not send udp hole punching messages if the rtcp port and rtp port are not two successive integers.
So, if the video player is behind NAT, it could not receive and rtp messages via udp

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2cf94485de9aa0e8f4552fd9477e0d4bc5cb84bc
---

 libavformat/rtpproto.c |   43 ++++++++++++++++++++++++++++++-------------
 1 file changed, 30 insertions(+), 13 deletions(-)

diff --git a/libavformat/rtpproto.c b/libavformat/rtpproto.c
index bf9c60d..a8cbd97 100644
--- a/libavformat/rtpproto.c
+++ b/libavformat/rtpproto.c
@@ -281,6 +281,7 @@ static int rtp_open(URLContext *h, const char *uri, int flags)
     char buf[1024];
     char path[1024];
     const char *p;
+    int i, max_retry_count = 3;
 
     av_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &rtp_port,
                  path, sizeof(path), uri);
@@ -328,19 +329,35 @@ static int rtp_open(URLContext *h, const char *uri, int flags)
         }
     }
 
-    build_udp_url(buf, sizeof(buf),
-                  hostname, rtp_port, local_rtp_port, ttl, max_packet_size,
-                  connect, include_sources, exclude_sources);
-    if (ffurl_open(&s->rtp_hd, buf, flags, &h->interrupt_callback, NULL) < 0)
-        goto fail;
-    if (local_rtp_port>=0 && local_rtcp_port<0)
-        local_rtcp_port = ff_udp_get_local_port(s->rtp_hd) + 1;
-
-    build_udp_url(buf, sizeof(buf),
-                  hostname, rtcp_port, local_rtcp_port, ttl, max_packet_size,
-                  connect, include_sources, exclude_sources);
-    if (ffurl_open(&s->rtcp_hd, buf, flags, &h->interrupt_callback, NULL) < 0)
-        goto fail;
+    for (i = 0;i < max_retry_count;i++) {
+        build_udp_url(buf, sizeof(buf),
+                      hostname, rtp_port, local_rtp_port, ttl, max_packet_size,
+                      connect, include_sources, exclude_sources);
+        if (ffurl_open(&s->rtp_hd, buf, flags, &h->interrupt_callback, NULL) < 0)
+            goto fail;
+        local_rtp_port = ff_udp_get_local_port(s->rtp_hd);
+        if(local_rtp_port == 65535) {
+            local_rtp_port = -1;
+            continue;
+        }
+        if (local_rtcp_port<0) {
+            local_rtcp_port = local_rtp_port + 1;
+            build_udp_url(buf, sizeof(buf),
+                          hostname, rtcp_port, local_rtcp_port, ttl, max_packet_size,
+                          connect, include_sources, exclude_sources);
+            if (ffurl_open(&s->rtcp_hd, buf, flags, &h->interrupt_callback, NULL) < 0) {
+                local_rtp_port = local_rtcp_port = -1;
+                continue;
+            }
+            break;
+        }
+        build_udp_url(buf, sizeof(buf),
+                      hostname, rtcp_port, local_rtcp_port, ttl, max_packet_size,
+                      connect, include_sources, exclude_sources);
+        if (ffurl_open(&s->rtcp_hd, buf, flags, &h->interrupt_callback, NULL) < 0)
+            goto fail;
+        break;
+    }
 
     /* just to ease handle access. XXX: need to suppress direct handle
        access */



More information about the ffmpeg-cvslog mailing list