[FFmpeg-devel] [PATCH] RTP local udp port issue fix (ticket 916)

Dmitry Volyntsev xeioexception at gmail.com
Mon Jan 16 17:55:18 CET 2012


Abstract: Ffmpeg doen't check that udp port which it selects for
incoming rtp already receives packets

Detailed description, steps to reproduce and ffmpeg logs and wireshark
logs of the issue: https://ffmpeg.org/trac/ffmpeg/ticket/916

Description: RTSP session brakes some times and rstp server doesn't
receive any notification about it and still sends packet in rtp
session. new ffmpeg instance request the same port for incoming
streams and doesn't detect it, it receives two stream simultaneously
but tries constantly re-synchronize with two interleaved streams.

I've checked what other implementation of RTP/RTSP do in this case.
1) LIVE555 library (inside vlc media player)
2) gstreamer framework
Both of them just request no udp port from special range, but use port
which an OS provides.
It this case local udp ports grow sequentially and issue case doesn't
occur. The remote side after some period of time stops sending packets
to old ports.

proposed patch against latest-master:
diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index d32f49e..bf2be6a 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -1157,18 +1157,14 @@ int ff_rtsp_make_setup_request(AVFormatContext
*s, const char *host, i
                 goto have_port;
             }

-            /* first try in specified port range */
-            if (RTSP_RTP_PORT_MIN != 0) {
-                while (j <= RTSP_RTP_PORT_MAX) {
-                    ff_url_join(buf, sizeof(buf), "rtp", NULL, host, -1,
-                                "?localport=%d", j);
-                    /* we will use two ports per rtp stream (rtp and rtcp) */
-                    j += 2;
-                    if (ffurl_open(&rtsp_st->rtp_handle, buf,
AVIO_FLAG_READ_WRITE,
-                                   &s->interrupt_callback, NULL) == 0)
-                        goto rtp_opened;
-                }
-            }
+            /* OS will choose local port by itself */
+            ff_url_join(buf, sizeof(buf), "rtp", NULL, host, -1,
+                       "?localport=%d", 0);
+            /* we will use two ports per rtp stream (rtp and rtcp) */
+            j += 2;
+            if (ffurl_open(&rtsp_st->rtp_handle, buf, AVIO_FLAG_READ_WRITE,
+                       &s->interrupt_callback, NULL) == 0)
+               goto rtp_opened;

             av_log(s, AV_LOG_ERROR, "Unable to open an input RTP port\n");
             err = AVERROR(EIO);

-- 
Be happy,
Best regards,
Dmitry Volyntsev


More information about the ffmpeg-devel mailing list