Mercurial > libavformat.hg
diff rtsp.c @ 5756:7c7fe75728dd libavformat
Use ff_url_join for assembling URLs, instead of snprintf
This ensures proper escaping of numerical IPv6 addresses.
The RTSP (de)muxer needs its own network initialization, since it isn't
a protocol and url_open hasn't been called yet.
author | mstorsjo |
---|---|
date | Fri, 05 Mar 2010 22:35:21 +0000 |
parents | 04b39763b51b |
children | a292ef47e2f9 |
line wrap: on
line diff
--- a/rtsp.c Fri Mar 05 22:31:45 2010 +0000 +++ b/rtsp.c Fri Mar 05 22:35:21 2010 +0000 @@ -1090,8 +1090,8 @@ /* first try in specified port range */ if (RTSP_RTP_PORT_MIN != 0) { while (j <= RTSP_RTP_PORT_MAX) { - snprintf(buf, sizeof(buf), "rtp://%s?localport=%d", - host, j); + 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 (url_open(&rtsp_st->rtp_handle, buf, URL_RDWR) == 0) @@ -1201,8 +1201,8 @@ char url[1024]; /* XXX: also use address if specified */ - snprintf(url, sizeof(url), "rtp://%s:%d", - host, reply->transports[0].server_port_min); + ff_url_join(url, sizeof(url), "rtp", NULL, host, + reply->transports[0].server_port_min, NULL); if (!(rt->server_type == RTSP_SERVER_WMS && i > 1) && rtp_set_remote_url(rtsp_st->rtp_handle, url) < 0) { err = AVERROR_INVALIDDATA; @@ -1230,8 +1230,8 @@ port = rtsp_st->sdp_port; ttl = rtsp_st->sdp_ttl; } - snprintf(url, sizeof(url), "rtp://%s:%d?ttl=%d", - inet_ntoa(in), port, ttl); + ff_url_join(url, sizeof(url), "rtp", NULL, inet_ntoa(in), + port, "?ttl=%d", ttl); if (url_open(&rtsp_st->rtp_handle, url, URL_RDWR) < 0) { err = AVERROR_INVALIDDATA; goto fail; @@ -1388,6 +1388,9 @@ RTSPMessageHeader reply1, *reply = &reply1; int lower_transport_mask = 0; char real_challenge[64]; + + if (!ff_network_init()) + return AVERROR(EIO); redirect: /* extract hostname and port */ url_split(NULL, 0, auth, sizeof(auth), @@ -1447,7 +1450,7 @@ } /* open the tcp connexion */ - snprintf(tcpname, sizeof(tcpname), "tcp://%s:%d", host, port); + ff_url_join(tcpname, sizeof(tcpname), "tcp", NULL, host, port, NULL); if (url_open(&rtsp_hd, tcpname, URL_RDWR) < 0) { err = AVERROR(EIO); goto fail; @@ -1531,6 +1534,7 @@ s->filename); goto redirect; } + ff_network_close(); return err; } #endif @@ -1886,6 +1890,7 @@ ff_rtsp_close_streams(s); url_close(rt->rtsp_hd); + ff_network_close(); return 0; } @@ -1933,6 +1938,9 @@ char *content; char url[1024]; + if (!ff_network_init()) + return AVERROR(EIO); + /* read the whole sdp file */ /* XXX: better loading */ content = av_malloc(SDP_MAX_SIZE); @@ -1950,11 +1958,10 @@ for (i = 0; i < rt->nb_rtsp_streams; i++) { rtsp_st = rt->rtsp_streams[i]; - snprintf(url, sizeof(url), "rtp://%s:%d?localport=%d&ttl=%d", - inet_ntoa(rtsp_st->sdp_ip), - rtsp_st->sdp_port, - rtsp_st->sdp_port, - rtsp_st->sdp_ttl); + ff_url_join(url, sizeof(url), "rtp", NULL, + inet_ntoa(rtsp_st->sdp_ip), rtsp_st->sdp_port, + "?localport=%d&ttl=%d", rtsp_st->sdp_port, + rtsp_st->sdp_ttl); if (url_open(&rtsp_st->rtp_handle, url, URL_RDWR) < 0) { err = AVERROR_INVALIDDATA; goto fail; @@ -1965,12 +1972,14 @@ return 0; fail: ff_rtsp_close_streams(s); + ff_network_close(); return err; } static int sdp_read_close(AVFormatContext *s) { ff_rtsp_close_streams(s); + ff_network_close(); return 0; }