X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Frtsp.c;h=56e5de27f8d821e4dd06216769979996f9edca5c;hb=34aadeaa2c2ae2e84abde3cca0a8b1392b8294ac;hp=d32f49ed4c53b3204dfde94fbac9383e10c125e5;hpb=67f5650a78de2567c58dbd7545434cc6d3ef9b7e;p=ffmpeg diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c index d32f49ed4c5..56e5de27f8d 100644 --- a/libavformat/rtsp.c +++ b/libavformat/rtsp.c @@ -1103,7 +1103,7 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port, int lower_transport, const char *real_challenge) { RTSPState *rt = s->priv_data; - int rtx = 0, j, i, err, interleave = 0; + int rtx = 0, j, i, err, interleave = 0, port_off; RTSPStream *rtsp_st; RTSPMessageHeader reply1, *reply = &reply1; char cmd[2048]; @@ -1120,8 +1120,11 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port, /* for each stream, make the setup request */ /* XXX: we assume the same server is used for the control of each * RTSP stream */ + port_off = av_get_random_seed() % (RTSP_RTP_PORT_MAX - RTSP_RTP_PORT_MIN); + /* even random offset */ + port_off -= port_off & 0x01; - for (j = RTSP_RTP_PORT_MIN, i = 0; i < rt->nb_rtsp_streams; ++i) { + for (j = RTSP_RTP_PORT_MIN + port_off, i = 0; i < rt->nb_rtsp_streams; ++i) { char transport[2048]; /* @@ -1158,18 +1161,15 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int 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; - } + 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)) + goto rtp_opened; } - av_log(s, AV_LOG_ERROR, "Unable to open an input RTP port\n"); err = AVERROR(EIO); goto fail;