55
57
#define SDP_MAX_SIZE 16384
56
58
#define RECVBUF_SIZE 10 * RTP_MAX_PACKET_LENGTH
60
#define OFFSET(x) offsetof(RTSPState, x)
61
#define DEC AV_OPT_FLAG_DECODING_PARAM
62
#define ENC AV_OPT_FLAG_ENCODING_PARAM
64
#define RTSP_FLAG_OPTS(name, longname) \
65
{ name, longname, OFFSET(rtsp_flags), AV_OPT_TYPE_FLAGS, {0}, INT_MIN, INT_MAX, DEC, "rtsp_flags" }, \
66
{ "filter_src", "Only receive packets from the negotiated peer IP", 0, AV_OPT_TYPE_CONST, {RTSP_FLAG_FILTER_SRC}, 0, 0, DEC, "rtsp_flags" }
68
#define RTSP_MEDIATYPE_OPTS(name, longname) \
69
{ name, longname, OFFSET(media_type_mask), AV_OPT_TYPE_FLAGS, { (1 << (AVMEDIA_TYPE_DATA+1)) - 1 }, INT_MIN, INT_MAX, DEC, "allowed_media_types" }, \
70
{ "video", "Video", 0, AV_OPT_TYPE_CONST, {1 << AVMEDIA_TYPE_VIDEO}, 0, 0, DEC, "allowed_media_types" }, \
71
{ "audio", "Audio", 0, AV_OPT_TYPE_CONST, {1 << AVMEDIA_TYPE_AUDIO}, 0, 0, DEC, "allowed_media_types" }, \
72
{ "data", "Data", 0, AV_OPT_TYPE_CONST, {1 << AVMEDIA_TYPE_DATA}, 0, 0, DEC, "allowed_media_types" }
74
const AVOption ff_rtsp_options[] = {
75
{ "initial_pause", "Don't start playing the stream immediately", OFFSET(initial_pause), AV_OPT_TYPE_INT, {0}, 0, 1, DEC },
76
FF_RTP_FLAG_OPTS(RTSPState, rtp_muxer_flags),
77
{ "rtsp_transport", "RTSP transport protocols", OFFSET(lower_transport_mask), AV_OPT_TYPE_FLAGS, {0}, INT_MIN, INT_MAX, DEC|ENC, "rtsp_transport" }, \
78
{ "udp", "UDP", 0, AV_OPT_TYPE_CONST, {1 << RTSP_LOWER_TRANSPORT_UDP}, 0, 0, DEC|ENC, "rtsp_transport" }, \
79
{ "tcp", "TCP", 0, AV_OPT_TYPE_CONST, {1 << RTSP_LOWER_TRANSPORT_TCP}, 0, 0, DEC|ENC, "rtsp_transport" }, \
80
{ "udp_multicast", "UDP multicast", 0, AV_OPT_TYPE_CONST, {1 << RTSP_LOWER_TRANSPORT_UDP_MULTICAST}, 0, 0, DEC, "rtsp_transport" },
81
{ "http", "HTTP tunneling", 0, AV_OPT_TYPE_CONST, {(1 << RTSP_LOWER_TRANSPORT_HTTP)}, 0, 0, DEC, "rtsp_transport" },
82
RTSP_FLAG_OPTS("rtsp_flags", "RTSP flags"),
83
RTSP_MEDIATYPE_OPTS("allowed_media_types", "Media types to accept from the server"),
87
static const AVOption sdp_options[] = {
88
RTSP_FLAG_OPTS("sdp_flags", "SDP flags"),
89
RTSP_MEDIATYPE_OPTS("allowed_media_types", "Media types to accept from the server"),
93
static const AVOption rtp_options[] = {
94
RTSP_FLAG_OPTS("rtp_flags", "RTP flags"),
58
98
static void get_word_until_chars(char *buf, int buf_size,
59
99
const char *sep, const char **pp)
336
385
ff_rtp_get_codec_info(st->codec, rtsp_st->sdp_payload_type);
337
386
if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO &&
338
387
st->codec->sample_rate > 0)
339
av_set_pts_info(st, 32, 1, st->codec->sample_rate);
388
avpriv_set_pts_info(st, 32, 1, st->codec->sample_rate);
340
389
/* Even static payload types may need a custom depacketizer */
341
390
handler = ff_rtp_handler_find_by_id(
342
391
rtsp_st->sdp_payload_type, st->codec->codec_type);
343
392
init_rtp_handler(handler, rtsp_st, st->codec);
393
if (handler && handler->init)
394
handler->init(s, st->index,
395
rtsp_st->dynamic_protocol_context);
346
398
/* put a default control url */
633
679
th->transport = RTSP_TRANSPORT_RTP;
634
} else if (!strcasecmp (transport_protocol, "x-pn-tng") ||
635
!strcasecmp (transport_protocol, "x-real-rdt")) {
680
} else if (!av_strcasecmp (transport_protocol, "x-pn-tng") ||
681
!av_strcasecmp (transport_protocol, "x-real-rdt")) {
636
682
/* x-pn-tng/<protocol> */
637
683
get_word_sep(lower_transport, sizeof(lower_transport), "/;,", &p);
638
684
profile[0] = '\0';
639
685
th->transport = RTSP_TRANSPORT_RDT;
641
if (!strcasecmp(lower_transport, "TCP"))
687
if (!av_strcasecmp(lower_transport, "TCP"))
642
688
th->lower_transport = RTSP_LOWER_TRANSPORT_TCP;
644
690
th->lower_transport = RTSP_LOWER_TRANSPORT_UDP;
1118
1164
"?localport=%d", j);
1119
1165
/* we will use two ports per rtp stream (rtp and rtcp) */
1121
if (ffurl_open(&rtsp_st->rtp_handle, buf, AVIO_FLAG_READ_WRITE) == 0)
1167
if (ffurl_open(&rtsp_st->rtp_handle, buf, AVIO_FLAG_READ_WRITE,
1168
&s->interrupt_callback, NULL) == 0)
1122
1169
goto rtp_opened;
1127
/* then try on any port */
1128
if (ffurl_open(&rtsp_st->rtp_handle, "rtp://", AVIO_FLAG_READ) < 0) {
1129
err = AVERROR_INVALIDDATA;
1133
1173
av_log(s, AV_LOG_ERROR, "Unable to open an input RTP port\n");
1134
1174
err = AVERROR(EIO);
1139
port = rtp_get_local_rtp_port(rtsp_st->rtp_handle);
1178
port = ff_rtp_get_local_rtp_port(rtsp_st->rtp_handle);
1141
1180
snprintf(transport, sizeof(transport) - 1,
1142
1181
"%s/UDP;", trans_pref);
1319
1361
if (!ff_network_init())
1320
1362
return AVERROR(EIO);
1364
rt->control_transport = RTSP_MODE_PLAIN;
1365
if (rt->lower_transport_mask & (1 << RTSP_LOWER_TRANSPORT_HTTP)) {
1366
rt->lower_transport_mask = 1 << RTSP_LOWER_TRANSPORT_TCP;
1367
rt->control_transport = RTSP_MODE_TUNNEL;
1369
/* Only pass through valid flags from here */
1370
rt->lower_transport_mask &= (1 << RTSP_LOWER_TRANSPORT_NB) - 1;
1322
rt->control_transport = RTSP_MODE_PLAIN;
1373
lower_transport_mask = rt->lower_transport_mask;
1323
1374
/* extract hostname and port */
1324
1375
av_url_split(NULL, 0, auth, sizeof(auth),
1325
1376
host, sizeof(host), &port, path, sizeof(path), s->filename);
1455
1516
ff_http_init_auth_state(rt->rtsp_hd_out, rt->rtsp_hd);
1457
1518
/* complete the connection */
1458
if (ffurl_connect(rt->rtsp_hd_out)) {
1519
if (ffurl_connect(rt->rtsp_hd_out, NULL)) {
1459
1520
err = AVERROR(EIO);
1463
1524
/* open the tcp connection */
1464
1525
ff_url_join(tcpname, sizeof(tcpname), "tcp", NULL, host, port, NULL);
1465
if (ffurl_open(&rt->rtsp_hd, tcpname, AVIO_FLAG_READ_WRITE) < 0) {
1526
if (ffurl_open(&rt->rtsp_hd, tcpname, AVIO_FLAG_READ_WRITE,
1527
&s->interrupt_callback, NULL) < 0) {
1466
1528
err = AVERROR(EIO);
1687
1749
case RTSP_LOWER_TRANSPORT_UDP_MULTICAST:
1688
1750
len = udp_read_packet(s, &rtsp_st, rt->recvbuf, RECVBUF_SIZE, wait_end);
1689
1751
if (len > 0 && rtsp_st->transport_priv && rt->transport == RTSP_TRANSPORT_RTP)
1690
rtp_check_and_send_back_rr(rtsp_st->transport_priv, len);
1752
ff_rtp_check_and_send_back_rr(rtsp_st->transport_priv, len);
1693
1755
if (len == AVERROR(EAGAIN) && first_queue_st &&
1694
1756
rt->transport == RTSP_TRANSPORT_RTP) {
1695
1757
rtsp_st = first_queue_st;
1696
ret = rtp_parse_packet(rtsp_st->transport_priv, pkt, NULL, 0);
1758
ret = ff_rtp_parse_packet(rtsp_st->transport_priv, pkt, NULL, 0);
1807
1869
namebuf, sizeof(namebuf), NULL, 0, NI_NUMERICHOST);
1808
1870
ff_url_join(url, sizeof(url), "rtp", NULL,
1809
1871
namebuf, rtsp_st->sdp_port,
1810
"?localport=%d&ttl=%d", rtsp_st->sdp_port,
1812
if (ffurl_open(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE) < 0) {
1872
"?localport=%d&ttl=%d&connect=%d", rtsp_st->sdp_port,
1874
rt->rtsp_flags & RTSP_FLAG_FILTER_SRC ? 1 : 0);
1875
if (ffurl_open(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE,
1876
&s->interrupt_callback, NULL) < 0) {
1813
1877
err = AVERROR_INVALIDDATA;
1897
static const AVClass sdp_demuxer_class = {
1898
.class_name = "SDP demuxer",
1899
.item_name = av_default_item_name,
1900
.option = sdp_options,
1901
.version = LIBAVUTIL_VERSION_INT,
1833
1904
AVInputFormat ff_sdp_demuxer = {
1835
NULL_IF_CONFIG_SMALL("SDP"),
1839
ff_rtsp_fetch_packet,
1906
.long_name = NULL_IF_CONFIG_SMALL("SDP"),
1907
.priv_data_size = sizeof(RTSPState),
1908
.read_probe = sdp_probe,
1909
.read_header = sdp_read_header,
1910
.read_packet = ff_rtsp_fetch_packet,
1911
.read_close = sdp_read_close,
1912
.priv_class = &sdp_demuxer_class
1842
1914
#endif /* CONFIG_SDP_DEMUXER */
2013
static const AVClass rtp_demuxer_class = {
2014
.class_name = "RTP demuxer",
2015
.item_name = av_default_item_name,
2016
.option = rtp_options,
2017
.version = LIBAVUTIL_VERSION_INT,
1937
2020
AVInputFormat ff_rtp_demuxer = {
1939
NULL_IF_CONFIG_SMALL("RTP input format"),
1943
ff_rtsp_fetch_packet,
2022
.long_name = NULL_IF_CONFIG_SMALL("RTP input format"),
2023
.priv_data_size = sizeof(RTSPState),
2024
.read_probe = rtp_probe,
2025
.read_header = rtp_read_header,
2026
.read_packet = ff_rtsp_fetch_packet,
2027
.read_close = sdp_read_close,
1945
2028
.flags = AVFMT_NOFILE,
2029
.priv_class = &rtp_demuxer_class
1947
2031
#endif /* CONFIG_RTP_DEMUXER */