* RTSP/SDP client
* Copyright (c) 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
{ "http", "HTTP tunneling", 0, AV_OPT_TYPE_CONST, {(1 << RTSP_LOWER_TRANSPORT_HTTP)}, 0, 0, DEC, "rtsp_transport" },
RTSP_FLAG_OPTS("rtsp_flags", "RTSP flags"),
RTSP_MEDIATYPE_OPTS("allowed_media_types", "Media types to accept from the server"),
+ { "min_port", "Minimum local UDP port", OFFSET(rtp_port_min), AV_OPT_TYPE_INT, {RTSP_RTP_PORT_MIN}, 0, 65535, DEC|ENC },
+ { "max_port", "Maximum local UDP port", OFFSET(rtp_port_max), AV_OPT_TYPE_INT, {RTSP_RTP_PORT_MAX}, 0, 65535, DEC|ENC },
{ NULL },
};
int lower_transport, const char *real_challenge)
{
RTSPState *rt = s->priv_data;
- int rtx, 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];
/* default timeout: 1 minute */
rt->timeout = 60;
- /* for each stream, make the setup request */
- /* XXX: we assume the same server is used for the control of each
- * RTSP stream */
+ /* Choose a random starting offset within the first half of the
+ * port range, to allow for a number of ports to try even if the offset
+ * happens to be at the end of the random range. */
+ port_off = av_get_random_seed() % ((rt->rtp_port_max - rt->rtp_port_min)/2);
+ /* even random offset */
+ port_off -= port_off & 0x01;
- for (j = RTSP_RTP_PORT_MIN, i = 0; i < rt->nb_rtsp_streams; ++i) {
+ for (j = rt->rtp_port_min + port_off, i = 0; i < rt->nb_rtsp_streams; ++i) {
char transport[2048];
/*
}
/* 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 <= rt->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;
{
RTSPState *rt = s->priv_data;
char host[1024], path[1024], tcpname[1024], cmd[2048], auth[128];
- char *option_list, *option, *filename;
int port, err, tcp_fd;
RTSPMessageHeader reply1 = {0}, *reply = &reply1;
int lower_transport_mask = 0;
struct sockaddr_storage peer;
socklen_t peer_len = sizeof(peer);
+ if (rt->rtp_port_max < rt->rtp_port_min) {
+ av_log(s, AV_LOG_ERROR, "Invalid UDP port range, max port %d less "
+ "than min port %d\n", rt->rtp_port_max,
+ rt->rtp_port_min);
+ return AVERROR(EINVAL);
+ }
+
if (!ff_network_init())
return AVERROR(EIO);
if (port < 0)
port = RTSP_DEFAULT_PORT;
-#if FF_API_RTSP_URL_OPTIONS
- /* search for options */
- option_list = strrchr(path, '?');
- if (option_list) {
- /* Strip out the RTSP specific options, write out the rest of
- * the options back into the same string. */
- filename = option_list;
- while (option_list) {
- int handled = 1;
- /* move the option pointer */
- option = ++option_list;
- option_list = strchr(option_list, '&');
- if (option_list)
- *option_list = 0;
-
- /* handle the options */
- if (!strcmp(option, "udp")) {
- lower_transport_mask |= (1<< RTSP_LOWER_TRANSPORT_UDP);
- } else if (!strcmp(option, "multicast")) {
- lower_transport_mask |= (1<< RTSP_LOWER_TRANSPORT_UDP_MULTICAST);
- } else if (!strcmp(option, "tcp")) {
- lower_transport_mask |= (1<< RTSP_LOWER_TRANSPORT_TCP);
- } else if(!strcmp(option, "http")) {
- lower_transport_mask |= (1<< RTSP_LOWER_TRANSPORT_TCP);
- rt->control_transport = RTSP_MODE_TUNNEL;
- } else if (!strcmp(option, "filter_src")) {
- rt->rtsp_flags |= RTSP_FLAG_FILTER_SRC;
- } else {
- /* Write options back into the buffer, using memmove instead
- * of strcpy since the strings may overlap. */
- int len = strlen(option);
- memmove(++filename, option, len);
- filename += len;
- if (option_list) *filename = '&';
- handled = 0;
- }
- if (handled)
- av_log(s, AV_LOG_WARNING, "Options passed via URL are "
- "deprecated, use -rtsp_transport "
- "and -rtsp_flags instead.\n");
- }
- *filename = 0;
- }
-#endif
-
if (!lower_transport_mask)
lower_transport_mask = (1 << RTSP_LOWER_TRANSPORT_NB) - 1;
return 0;
}
-static int sdp_read_header(AVFormatContext *s, AVFormatParameters *ap)
+static int sdp_read_header(AVFormatContext *s)
{
RTSPState *rt = s->priv_data;
RTSPStream *rtsp_st;
return 0;
}
-static int rtp_read_header(AVFormatContext *s,
- AVFormatParameters *ap)
+static int rtp_read_header(AVFormatContext *s)
{
uint8_t recvbuf[1500];
char host[500], sdp[500];
continue;
}
+ if (RTP_PT_IS_RTCP(recvbuf[1]))
+ continue;
+
payload_type = recvbuf[1] & 0x7f;
break;
}
rt->media_type_mask = (1 << (AVMEDIA_TYPE_DATA+1)) - 1;
- ret = sdp_read_header(s, ap);
+ ret = sdp_read_header(s);
s->pb = NULL;
return ret;
.priv_class = &rtp_demuxer_class
};
#endif /* CONFIG_RTP_DEMUXER */
-