History

rtsp: Use a random offset for trying to open UDP ports for RTP

This avoids (for all practical cases) the issue of reusing the same UDP port as for an earlier connection. If the remote doesn't know the previous session was closed, he might keep on sending packets to that port. If we always start off trying to open the same UDP port, we might get those packets intermixed with the new ones. This is occasionally an issue when testing RTSP stuff with DSS, perhaps also with other servers.

Dmitry Volyntsev committed 14 years ago

Commit 58f09781 parent dbb06b81 file · +9 −2Browse files

Unified · Split

libavformat/rtsp.c+9−2
@@ -1105,7 +1105,7 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port, · 1104 unmodified lines
11051105 int lower_transport, const char *real_challenge)
11061106 {
11071107 RTSPState *rt = s->priv_data;
1108− int rtx = 0, j, i, err, interleave = 0;
1108+ int rtx = 0, j, i, err, interleave = 0, port_off;
11091109 RTSPStream *rtsp_st;
11101110 RTSPMessageHeader reply1, *reply = &reply1;
11111111 char cmd[2048];
@@ -1123,7 +1123,14 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port, · 11 unmodified lines
11231123 /* XXX: we assume the same server is used for the control of each
11241124 * RTSP stream */
11251125
1126− for (j = rt->rtp_port_min, i = 0; i < rt->nb_rtsp_streams; ++i) {
1126+ /* Choose a random starting offset within the first half of the
1127+ * port range, to allow for a number of ports to try even if the offset
1128+ * happens to be at the end of the random range. */
1129+ port_off = av_get_random_seed() % ((rt->rtp_port_max - rt->rtp_port_min)/2);
1130+ /* even random offset */
1131+ port_off -= port_off & 0x01;
1132+
1133+ for (j = rt->rtp_port_min + port_off, i = 0; i < rt->nb_rtsp_streams; ++i) {
11271134 char transport[2048];
11281135
11291136 /*

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t