Libav
rtsp.h
Go to the documentation of this file.
1 /*
2  * RTSP definitions
3  * Copyright (c) 2002 Fabrice Bellard
4  *
5  * This file is part of Libav.
6  *
7  * Libav is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * Libav is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with Libav; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 #ifndef AVFORMAT_RTSP_H
22 #define AVFORMAT_RTSP_H
23 
24 #include <stdint.h>
25 #include "avformat.h"
26 #include "rtspcodes.h"
27 #include "rtpdec.h"
28 #include "network.h"
29 #include "httpauth.h"
30 
31 #include "libavutil/log.h"
32 #include "libavutil/opt.h"
33 
49 };
50 
61 };
62 
70 };
71 
72 #define RTSP_DEFAULT_PORT 554
73 #define RTSP_MAX_TRANSPORTS 8
74 #define RTSP_TCP_MAX_PACKET_SIZE 1472
75 #define RTSP_DEFAULT_NB_AUDIO_CHANNELS 1
76 #define RTSP_DEFAULT_AUDIO_SAMPLERATE 44100
77 #define RTSP_RTP_PORT_MIN 5000
78 #define RTSP_RTP_PORT_MAX 10000
79 
87 typedef struct RTSPTransportField {
93 
97 
101 
105 
108  int ttl;
109 
112 
118 
122 
126 typedef struct RTSPMessageHeader {
129 
134 
138 
142 
143  int seq;
147  char session_id[512];
148 
151  char location[4096];
152 
154  char real_challenge[64];
155 
163  char server[64];
164 
171  int timeout;
172 
176  int notice;
177 
181  char reason[256];
182 
186  char content_type[64];
188 
199 };
200 
210 };
211 
217 typedef struct RTSPState {
218  const AVClass *class;
219  URLContext *rtsp_hd; /* RTSP TCP connection handle */
220 
223 
231 
238  int64_t seek_timestamp;
239 
240  int seq;
244  char session_id[512];
245 
249  int timeout;
250 
254  int64_t last_cmd_time;
255 
258 
262 
267 
269  char real_challenge[64];
270 
272  char auth[128];
273 
276 
278  char last_reply[2048]; /* XXX: allocate ? */
279 
283 
288 
292 
296 
300  char last_subscription[1024];
302 
307 
310  uint64_t asf_pb_pos;
312 
316  char control_uri[1024];
317 
320  struct MpegTSContext *ts;
324 
328 
331 
332  /* Number of RTCP BYE packets the RTSP session has received.
333  * An EOF is propagated back if nb_byes == nb_streams.
334  * This is reset after a seek. */
335  int nb_byes;
336 
339 
344 
348  uint64_t packets;
349 
353  struct pollfd *p;
354 
359 
364 
369 
372 
377 
382 
387 
392 
397 } RTSPState;
398 
399 #define RTSP_FLAG_FILTER_SRC 0x1
402 #define RTSP_FLAG_LISTEN 0x2
403 #define RTSP_FLAG_CUSTOM_IO 0x4
404 #define RTSP_FLAG_RTCP_TO_SOURCE 0x8
407 typedef struct RTSPSource {
408  char addr[128];
409 } RTSPSource;
417 typedef struct RTSPStream {
419  void *transport_priv;
423 
427 
428  char control_url[1024];
432  int sdp_port;
433  struct sockaddr_storage sdp_ip;
438  int sdp_ttl;
446 
450 
452  int feedback;
453 
454  char crypto_suite[40];
455  char crypto_params[100];
456 } RTSPStream;
458 void ff_rtsp_parse_line(RTSPMessageHeader *reply, const char *buf,
459  RTSPState *rt, const char *method);
460 
466 int ff_rtsp_send_cmd_async(AVFormatContext *s, const char *method,
467  const char *url, const char *headers);
468 
486  const char *method, const char *url,
487  const char *headers,
488  RTSPMessageHeader *reply,
489  unsigned char **content_ptr,
490  const unsigned char *send_content,
491  int send_content_length);
492 
498 int ff_rtsp_send_cmd(AVFormatContext *s, const char *method,
499  const char *url, const char *headers,
500  RTSPMessageHeader *reply, unsigned char **content_ptr);
501 
526  unsigned char **content_ptr,
527  int return_on_interleaved_data, const char *method);
528 
533 
544 
551 
558 
564 
570 
576 
582 int ff_sdp_parse(AVFormatContext *s, const char *content);
583 
588  uint8_t *buf, int buf_size);
589 
594 
600 
606 int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port,
607  int lower_transport, const char *real_challenge);
608 
613 void ff_rtsp_undo_setup(AVFormatContext *s, int send_packets);
614 
619 
620 extern const AVOption ff_rtsp_options[];
621 
622 #endif /* AVFORMAT_RTSP_H */
char auth[128]
plaintext authorization line (username:password)
Definition: rtsp.h:272
int interleaved_min
interleave ids, if TCP transport; each TCP/RTSP data packet starts with a '$', stream length and stre...
Definition: rtsp.h:92
char crypto_suite[40]
Definition: rtsp.h:457
void ff_rtsp_skip_packet(AVFormatContext *s)
Skip a RTP/TCP interleaved packet.
int rtp_port_min
Minimum and maximum local UDP ports.
Definition: rtsp.h:386
Realmedia Data Transport.
Definition: rtsp.h:58
RTSPLowerTransport
Network layer over which RTP/etc packet data will be transported.
Definition: rtsp.h:37
int ff_rtsp_open_transport_ctx(AVFormatContext *s, RTSPStream *rtsp_st)
Open RTSP transport context.
Definition: rtsp.c:710
AVOption.
Definition: opt.h:233
char source[INET6_ADDRSTRLEN+1]
source IP address
Definition: rtsp.h:114
char content_type[64]
Content type header.
Definition: rtsp.h:186
char control_uri[1024]
some MS RTSP streams contain a URL in the SDP that we need to use for all subsequent RTSP requests...
Definition: rtsp.h:316
Windows Media server.
Definition: rtsp.h:208
struct pollfd * p
Polling array for udp.
Definition: rtsp.h:353
RTP/JPEG specific private data.
Definition: rdt.c:83
enum AVDiscard * real_setup
current stream setup.
Definition: rtsp.h:295
char location[4096]
the "Location:" field.
Definition: rtsp.h:151
enum AVDiscard * real_setup_cache
stream setup during the last frame read.
Definition: rtsp.h:291
int mode_record
transport set to record data
Definition: rtsp.h:111
UDP/unicast.
Definition: rtsp.h:38
int seq
sequence number
Definition: rtsp.h:143
initialized and sending/receiving data
Definition: rtsp.h:196
char real_challenge[64]
the "RealChallenge1:" field from the server
Definition: rtsp.h:269
int nb_include_source_addrs
Number of source-specific multicast include source IP addresses (from SDP content) ...
Definition: rtsp.h:437
RTSPClientState
Client state, i.e.
Definition: rtsp.h:194
HTTP Authentication state structure.
Definition: httpauth.h:55
char session_id[512]
copy of RTSPMessageHeader->session_id, i.e.
Definition: rtsp.h:244
int64_t seek_timestamp
the seek value requested when calling av_seek_frame().
Definition: rtsp.h:238
int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port, int lower_transport, const char *real_challenge)
Do the SETUP requests for each stream for the chosen lower transport mode.
enum RTSPLowerTransport lower_transport
network layer transport protocol; e.g.
Definition: rtsp.h:120
This describes the server response to each RTSP command.
Definition: rtsp.h:126
RTSPTransport
Packet profile of the data that we will be receiving.
Definition: rtsp.h:56
RTSPTransportField transports[RTSP_MAX_TRANSPORTS]
describes the complete "Transport:" line of the server in response to a SETUP RTSP command by the cli...
Definition: rtsp.h:141
Format I/O context.
Definition: avformat.h:871
int ff_rtsp_connect(AVFormatContext *s)
Connect to the RTSP server and set up the individual media streams.
Standards-compliant RTP-server.
Definition: rtsp.h:206
int reordering_queue_size
Size of RTP packet reordering queue.
Definition: rtsp.h:396
int recvbuf_len
Definition: rtsp.h:322
int get_parameter_supported
Whether the server supports the GET_PARAMETER method.
Definition: rtsp.h:358
Standards-compliant RTP.
Definition: rtsp.h:57
uint8_t
char session_id[512]
the "Session:" field.
Definition: rtsp.h:147
#define RTSP_MAX_TRANSPORTS
Definition: rtsp.h:73
int ttl
time-to-live value (required for multicast); the amount of HOPs that packets will be allowed to make ...
Definition: rtsp.h:108
AVOptions.
int feedback
Enable sending RTCP feedback messages according to RFC 4585.
Definition: rtsp.h:455
void ff_rtsp_parse_line(RTSPMessageHeader *reply, const char *buf, RTSPState *rt, const char *method)
int initial_timeout
Timeout to wait for incoming connections.
Definition: rtsp.h:391
int rtp_muxer_flags
Option flags for the chained RTP muxer.
Definition: rtsp.h:368
int accept_dynamic_rate
Whether the server accepts the x-Dynamic-Rate header.
Definition: rtsp.h:371
URLContext * rtsp_hd_out
Additional output handle, used when input and output are done separately, eg for HTTP tunneling...
Definition: rtsp.h:327
Describe a single stream, as identified by a single m= line block in the SDP content.
Definition: rtsp.h:420
Custom IO - not a public option for lower_transport_mask, but set in the SDP demuxer based on a flag...
Definition: rtsp.h:45
RTSPServerType
Identify particular servers that require special handling, such as standards-incompliant "Transport:"...
Definition: rtsp.h:205
enum RTSPStatusCode status_code
response code from server
Definition: rtsp.h:130
int ff_rtsp_parse_streaming_commands(AVFormatContext *s)
Parse RTSP commands (OPTIONS, PAUSE and TEARDOWN) during streaming in listen mode.
Definition: rtspdec.c:452
int ff_rtsp_send_cmd(AVFormatContext *s, const char *method, const char *url, const char *headers, RTSPMessageHeader *reply, unsigned char **content_ptr)
Send a command to the RTSP server and wait for the reply.
Normal RTSP.
Definition: rtsp.h:68
int nb_transports
number of items in the 'transports' variable below
Definition: rtsp.h:133
int notice
The "Notice" or "X-Notice" field value.
Definition: rtsp.h:176
int ff_sdp_parse(AVFormatContext *s, const char *content)
Parse an SDP description of streams by populating an RTSPState struct within the AVFormatContext; als...
struct RTSPSource ** exclude_source_addrs
Source-specific multicast exclude source IP addresses (from SDP content)
Definition: rtsp.h:440
Private data for the RTSP demuxer.
Definition: rtsp.h:217
int64_t last_cmd_time
timestamp of the last RTSP command that we sent to the RTSP server.
Definition: rtsp.h:254
const AVOption ff_rtsp_options[]
Definition: rtsp.c:78
int timeout
copy of RTSPMessageHeader->timeout, i.e.
Definition: rtsp.h:249
void ff_rtsp_undo_setup(AVFormatContext *s, int send_packets)
Undo the effect of ff_rtsp_make_setup_request, close the transport_priv and rtp_handle fields...
Definition: rtsp.c:641
char reason[256]
The "reason" is meant to specify better the meaning of the error code returned.
Definition: rtsp.h:181
URLContext * rtsp_hd
Definition: rtsp.h:219
enum RTSPControlTransport control_transport
RTSP transport mode, such as plain or tunneled.
Definition: rtsp.h:330
struct RTSPSource ** include_source_addrs
Source-specific multicast include source IP addresses (from SDP content)
Definition: rtsp.h:438
struct RTSPStream ** rtsp_streams
streams in this session
Definition: rtsp.h:224
char server[64]
the "Server: field, which can be used to identify some special-case servers that are not 100% standar...
Definition: rtsp.h:163
int stream_index
corresponding stream index, if any.
Definition: rtsp.h:425
uint64_t asf_pb_pos
cache for position of the asf demuxer, since we load a new data packet in the bytecontext for each in...
Definition: rtsp.h:310
int seq
RTSP command sequence number.
Definition: rtsp.h:240
uint8_t * recvbuf
Reusable buffer for receiving packets.
Definition: rtsp.h:338
AVFormatContext * asf_ctx
The following are used for RTP/ASF streams.
Definition: rtsp.h:306
int recvbuf_pos
Definition: rtsp.h:321
int nb_rtsp_streams
number of items in the 'rtsp_streams' variable
Definition: rtsp.h:222
void * cur_transport_priv
RTSPStream->transport_priv of the last stream that we read a packet from.
Definition: rtsp.h:282
int content_length
length of the data following this header
Definition: rtsp.h:128
char last_subscription[1024]
the last value of the "SET_PARAMETER Subscribe:" RTSP command.
Definition: rtsp.h:300
int timeout
The "timeout" comes as part of the server response to the "SETUP" command, in the "Session: <xyz>[;ti...
Definition: rtsp.h:171
HTTP tunneled - not a proper transport mode as such, only for use via AVOptions.
Definition: rtsp.h:42
This describes a single item in the "Transport:" line of one stream as negotiated by the SETUP RTSP c...
Definition: rtsp.h:87
RTSP over HTTP (tunneling)
Definition: rtsp.h:69
int ff_rtsp_tcp_write_packet(AVFormatContext *s, RTSPStream *rtsp_st)
Send buffered packets over TCP.
Definition: rtspenc.c:139
char crypto_params[100]
Definition: rtsp.h:458
int sdp_port
The following are used only in SDP, not RTSP.
Definition: rtsp.h:435
Raw data (over UDP)
Definition: rtsp.h:59
struct MpegTSContext * ts
The following are used for parsing raw mpegts in udp.
Definition: rtsp.h:320
int sdp_payload_type
payload type
Definition: rtsp.h:442
int nb_exclude_source_addrs
Number of source-specific multicast exclude source IP addresses (from SDP content) ...
Definition: rtsp.h:439
int nb_byes
Definition: rtsp.h:335
enum RTSPLowerTransport lower_transport
the negotiated network layer transport protocol; e.g.
Definition: rtsp.h:261
RTSPControlTransport
Transport mode for the RTSP data.
Definition: rtsp.h:67
char addr[128]
Source-specific multicast include source IP address (from SDP content)
Definition: rtsp.h:411
struct sockaddr_storage sdp_ip
IP address (from SDP content)
Definition: rtsp.h:436
int rtp_port_max
Definition: rtsp.h:386
int media_type_mask
Mask of all requested media types.
Definition: rtsp.h:381
int server_port_max
Definition: rtsp.h:104
enum RTSPTransport transport
the negotiated data/packet transport protocol; e.g.
Definition: rtsp.h:257
Definition: url.h:41
int ff_rtsp_setup_output_streams(AVFormatContext *s, const char *addr)
Announce the stream to the server and set up the RTSPStream child objects for each media stream...
Definition: rtspenc.c:46
int rtsp_flags
Various option flags for the RTSP muxer/demuxer.
Definition: rtsp.h:376
int client_port_max
Definition: rtsp.h:100
Describe the class of an AVClass context structure.
Definition: log.h:33
PayloadContext * dynamic_protocol_context
private data associated with the dynamic protocol
Definition: rtsp.h:451
char last_reply[2048]
The last reply of the server to a RTSP command.
Definition: rtsp.h:278
not initialized
Definition: rtsp.h:195
int64_t range_end
Definition: rtsp.h:137
enum RTSPTransport transport
data/packet transport protocol; e.g.
Definition: rtsp.h:117
char real_challenge[64]
the "RealChallenge1:" field from the server
Definition: rtsp.h:154
int ff_rtsp_tcp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st, uint8_t *buf, int buf_size)
Receive one RTP packet from an TCP interleaved RTSP stream.
Definition: rtspdec.c:714
int interleaved_max
Definition: rtsp.h:92
enum RTSPServerType server_type
brand of server that we're talking to; e.g.
Definition: rtsp.h:266
RTSPStatusCode
RTSP handling.
Definition: rtspcodes.h:26
int64_t range_start
Time range of the streams that the server will stream.
Definition: rtsp.h:137
#define INET6_ADDRSTRLEN
Definition: network.h:202
enum RTSPClientState state
indicator of whether we are currently receiving data from the server.
Definition: rtsp.h:230
int ff_rtsp_fetch_packet(AVFormatContext *s, AVPacket *pkt)
Receive one packet from the RTSPStreams set up in the AVFormatContext (which should contain a RTSPSta...
int ff_rtsp_send_cmd_with_content(AVFormatContext *s, const char *method, const char *url, const char *headers, RTSPMessageHeader *reply, unsigned char **content_ptr, const unsigned char *send_content, int send_content_length)
Send a command to the RTSP server and wait for the reply.
Main libavformat public API header.
initialized, requesting a seek
Definition: rtsp.h:198
int need_subscription
The following are used for Real stream selection.
Definition: rtsp.h:287
RTPDynamicProtocolHandler * dynamic_handler
The following are used for dynamic protocols (rtpdec_*.c/rdt.c)
Definition: rtsp.h:448
initialized, but not receiving data
Definition: rtsp.h:197
int ff_rtsp_read_reply(AVFormatContext *s, RTSPMessageHeader *reply, unsigned char **content_ptr, int return_on_interleaved_data, const char *method)
Read a RTSP message from the server, or prepare to read data packets if we're reading data interleave...
void ff_rtsp_close_streams(AVFormatContext *s)
Close and free all streams within the RTSP (de)muxer.
Definition: rtsp.c:677
int ff_rtsp_send_cmd_async(AVFormatContext *s, const char *method, const char *url, const char *headers)
Send a command to the RTSP server without waiting for the reply.
TCP; interleaved in RTSP.
Definition: rtsp.h:39
HTTPAuthState auth_state
authentication state
Definition: rtsp.h:275
char control_url[1024]
url for this stream (from SDP)
Definition: rtsp.h:431
uint64_t packets
The number of returned packets.
Definition: rtsp.h:348
int ff_rtsp_setup_input_streams(AVFormatContext *s, RTSPMessageHeader *reply)
Get the description of the stream and set up the RTSPStream child objects.
Definition: rtspdec.c:568
AVDiscard
Definition: avcodec.h:538
int sdp_ttl
IP Time-To-Live (from SDP content)
Definition: rtsp.h:441
Realmedia-style server.
Definition: rtsp.h:207
int lower_transport_mask
A mask with all requested transport methods.
Definition: rtsp.h:343
int interleaved_max
Definition: rtsp.h:429
struct sockaddr_storage destination
destination IP address
Definition: rtsp.h:113
int interleaved_min
interleave IDs; copies of RTSPTransportField->interleaved_min/max for the selected transport...
Definition: rtsp.h:429
This structure stores compressed data.
Definition: avcodec.h:950
int server_port_min
UDP unicast server port range; the ports to which we should connect to receive unicast UDP RTP/RTCP d...
Definition: rtsp.h:104
void ff_rtsp_close_connections(AVFormatContext *s)
Close all connection handles within the RTSP (de)muxer.
URLContext * rtp_handle
RTP stream handle (if UDP)
Definition: rtsp.h:421
int port_min
UDP multicast port range; the ports to which we should connect to receive multicast UDP data...
Definition: rtsp.h:96
void * transport_priv
RTP/RDT parse context if input, RTP AVFormatContext if output.
Definition: rtsp.h:422
int client_port_min
UDP client ports; these should be the local ports of the UDP RTP (and RTCP) sockets over which we rec...
Definition: rtsp.h:100
int initial_pause
Do not begin to play the stream immediately.
Definition: rtsp.h:363