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
1105 int lower_transport, const char *real_challenge)1105 int lower_transport, const char *real_challenge)
1106{1106{
1107 RTSPState *rt = s->priv_data;1107 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;
1109 RTSPStream *rtsp_st;1109 RTSPStream *rtsp_st;
1110 RTSPMessageHeader reply1, *reply = &reply1;1110 RTSPMessageHeader reply1, *reply = &reply1;
1111 char cmd[2048];1111 char cmd[2048];
@@ -1123,7 +1123,14 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port, · 11 unmodified lines
1123 /* XXX: we assume the same server is used for the control of each1123 /* XXX: we assume the same server is used for the control of each
1124 * RTSP stream */1124 * RTSP stream */
1125 1125
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) {
1127 char transport[2048];1134 char transport[2048];
1128 1135
1129 /*1136 /*

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