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 
45 };
46 
56 };
57 
65 };
66 
67 #define RTSP_DEFAULT_PORT 554
68 #define RTSP_MAX_TRANSPORTS 8
69 #define RTSP_TCP_MAX_PACKET_SIZE 1472
70 #define RTSP_DEFAULT_NB_AUDIO_CHANNELS 1
71 #define RTSP_DEFAULT_AUDIO_SAMPLERATE 44100
72 #define RTSP_RTP_PORT_MIN 5000
73 #define RTSP_RTP_PORT_MAX 10000
74 
82 typedef struct RTSPTransportField {
88 
92 
96 
100 
103  int ttl;
104 
110 
114 
118 typedef struct RTSPMessageHeader {
121 
126 
130 
134 
135  int seq;
139  char session_id[512];
140 
143  char location[4096];
144 
146  char real_challenge[64];
147 
155  char server[64];
156 
163  int timeout;
164 
168  int notice;
169 
173  char reason[256];
175 
186 };
187 
197 };
198 
204 typedef struct RTSPState {
205  const AVClass *class;
206  URLContext *rtsp_hd; /* RTSP TCP connection handle */
207 
210 
218 
225  int64_t seek_timestamp;
226 
227  int seq;
231  char session_id[512];
232 
236  int timeout;
237 
241  int64_t last_cmd_time;
242 
245 
249 
254 
256  char real_challenge[64];
257 
259  char auth[128];
260 
263 
265  char last_reply[2048]; /* XXX: allocate ? */
266 
270 
275 
279 
283 
287  char last_subscription[1024];
289 
294 
297  uint64_t asf_pb_pos;
299 
303  char control_uri[1024];
304 
308 
311 
312  /* Number of RTCP BYE packets the RTSP session has received.
313  * An EOF is propagated back if nb_byes == nb_streams.
314  * This is reset after a seek. */
315  int nb_byes;
316 
318  uint8_t* recvbuf;
319 
324 
328  uint64_t packets;
329 
333  struct pollfd *p;
334 
339 
344 
349 
352 
357 
362 } RTSPState;
363 
364 #define RTSP_FLAG_FILTER_SRC 0x1
374 typedef struct RTSPStream {
375  URLContext *rtp_handle;
376  void *transport_priv;
379  int stream_index;
380 
383  int interleaved_min, interleaved_max;
384 
385  char control_url[1024];
389  int sdp_port;
390  struct sockaddr_storage sdp_ip;
391  int sdp_ttl;
392  int sdp_payload_type;
398  RTPDynamicProtocolHandler *dynamic_handler;
399 
401  PayloadContext *dynamic_protocol_context;
404 
405 void ff_rtsp_parse_line(RTSPMessageHeader *reply, const char *buf,
406  RTSPState *rt, const char *method);
407 
413 int ff_rtsp_send_cmd_async(AVFormatContext *s, const char *method,
414  const char *url, const char *headers);
415 
433  const char *method, const char *url,
434  const char *headers,
435  RTSPMessageHeader *reply,
436  unsigned char **content_ptr,
437  const unsigned char *send_content,
438  int send_content_length);
439 
445 int ff_rtsp_send_cmd(AVFormatContext *s, const char *method,
446  const char *url, const char *headers,
447  RTSPMessageHeader *reply, unsigned char **content_ptr);
448 
473  unsigned char **content_ptr,
474  int return_on_interleaved_data, const char *method);
475 
480 
491 
498 
505 
511 
516 int ff_rtsp_setup_output_streams(AVFormatContext *s, const char *addr);
517 
523 int ff_sdp_parse(AVFormatContext *s, const char *content);
524 
529  uint8_t *buf, int buf_size);
530 
536 
542 int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port,
543  int lower_transport, const char *real_challenge);
544 
550 
551 extern const AVOption ff_rtsp_options[];
552 
553 #endif /* AVFORMAT_RTSP_H */
char auth[128]
plaintext authorization line (username:password)
Definition: rtsp.h:259
int interleaved_min
interleave ids, if TCP transport; each TCP/RTSP data packet starts with a '$', stream length and stre...
Definition: rtsp.h:87
void ff_rtsp_skip_packet(AVFormatContext *s)
Skip a RTP/TCP interleaved packet.
Realmedia Data Transport.
Definition: rtsp.h:54
RTSPLowerTransport
Network layer over which RTP/etc packet data will be transported.
Definition: rtsp.h:37
AVOption.
Definition: opt.h:244
char source[INET6_ADDRSTRLEN+1]
source IP address
Definition: rtsp.h:106
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:303
Windows Media server.
Definition: rtsp.h:195
struct pollfd * p
Polling array for udp.
Definition: rtsp.h:333
RTP/H264 specific private data.
Definition: rdt.c:83
AVOptions.
enum AVDiscard * real_setup
current stream setup.
Definition: rtsp.h:282
char location[4096]
the "Location:" field.
Definition: rtsp.h:143
enum AVDiscard * real_setup_cache
stream setup during the last frame read.
Definition: rtsp.h:278
struct RTSPTransportField RTSPTransportField
This describes a single item in the "Transport:" line of one stream as negotiated by the SETUP RTSP c...
UDP/unicast.
Definition: rtsp.h:38
int seq
sequence number
Definition: rtsp.h:135
initialized and sending/receiving data
Definition: rtsp.h:183
char real_challenge[64]
the "RealChallenge1:" field from the server
Definition: rtsp.h:256
RTSPClientState
Client state, i.e.
Definition: rtsp.h:181
HTTP Authentication state structure.
Definition: httpauth.h:52
char session_id[512]
copy of RTSPMessageHeader->session_id, i.e.
Definition: rtsp.h:231
int64_t seek_timestamp
the seek value requested when calling av_seek_frame().
Definition: rtsp.h:225
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:112
This describes the server response to each RTSP command.
Definition: rtsp.h:118
RTSPTransport
Packet profile of the data that we will be receiving.
Definition: rtsp.h:52
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:133
Format I/O context.
Definition: avformat.h:863
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:193
int get_parameter_supported
Whether the server supports the GET_PARAMETER method.
Definition: rtsp.h:338
Standards-compliant RTP.
Definition: rtsp.h:53
char session_id[512]
the "Session:" field.
Definition: rtsp.h:139
#define RTSP_MAX_TRANSPORTS
Definition: rtsp.h:68
int ttl
time-to-live value (required for multicast); the amount of HOPs that packets will be allowed to make ...
Definition: rtsp.h:103
void ff_rtsp_parse_line(RTSPMessageHeader *reply, const char *buf, RTSPState *rt, const char *method)
int rtp_muxer_flags
Option flags for the chained RTP muxer.
Definition: rtsp.h:348
int accept_dynamic_rate
Whether the server accepts the x-Dynamic-Rate header.
Definition: rtsp.h:351
URLContext * rtsp_hd_out
Additional output handle, used when input and output are done separately, eg for HTTP tunneling...
Definition: rtsp.h:307
Describe a single stream, as identified by a single m= line block in the SDP content.
Definition: rtsp.h:376
RTSPServerType
Identify particular servers that require special handling, such as standards-incompliant "Transport:"...
Definition: rtsp.h:192
enum RTSPStatusCode status_code
response code from server
Definition: rtsp.h:122
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:63
int nb_transports
number of items in the 'transports' variable below
Definition: rtsp.h:125
int notice
The "Notice" or "X-Notice" field value.
Definition: rtsp.h:168
int ff_sdp_parse(AVFormatContext *s, const char *content)
Parse an SDP description of streams by populating an RTSPState struct within the AVFormatContext; als...
Private data for the RTSP demuxer.
Definition: rtsp.h:204
int64_t last_cmd_time
timestamp of the last RTSP command that we sent to the RTSP server.
Definition: rtsp.h:241
const AVOption ff_rtsp_options[]
Definition: rtsp.c:74
int timeout
copy of RTSPMessageHeader->timeout, i.e.
Definition: rtsp.h:236
char reason[256]
The "reason" is meant to specify better the meaning of the error code returned.
Definition: rtsp.h:173
URLContext * rtsp_hd
Definition: rtsp.h:206
enum RTSPControlTransport control_transport
RTSP transport mode, such as plain or tunneled.
Definition: rtsp.h:310
AVDiscard
Definition: avcodec.h:522
struct RTSPStream ** rtsp_streams
streams in this session
Definition: rtsp.h:211
char server[64]
the "Server: field, which can be used to identify some special-case servers that are not 100% standar...
Definition: rtsp.h:155
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:297
int seq
RTSP command sequence number.
Definition: rtsp.h:227
uint8_t * recvbuf
Reusable buffer for receiving packets.
Definition: rtsp.h:318
AVFormatContext * asf_ctx
The following are used for RTP/ASF streams.
Definition: rtsp.h:293
int nb_rtsp_streams
number of items in the 'rtsp_streams' variable
Definition: rtsp.h:209
void * cur_transport_priv
RTSPStream->transport_priv of the last stream that we read a packet from.
Definition: rtsp.h:269
int content_length
length of the data following this header
Definition: rtsp.h:120
char last_subscription[1024]
the last value of the "SET_PARAMETER Subscribe:" RTSP command.
Definition: rtsp.h:287
int timeout
The "timeout" comes as part of the server response to the "SETUP" command, in the "Session: [;ti...
Definition: rtsp.h:163
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:82
RTSP over HTTP (tunneling)
Definition: rtsp.h:64
int nb_byes
Definition: rtsp.h:315
enum RTSPLowerTransport lower_transport
the negotiated network layer transport protocol; e.g.
Definition: rtsp.h:248
RTSPControlTransport
Transport mode for the RTSP data.
Definition: rtsp.h:62
void ff_rtsp_undo_setup(AVFormatContext *s)
Undo the effect of ff_rtsp_make_setup_request, close the transport_priv and rtp_handle fields...
Definition: rtsp.c:531
struct RTSPMessageHeader RTSPMessageHeader
This describes the server response to each RTSP command.
int media_type_mask
Mask of all requested media types.
Definition: rtsp.h:361
int server_port_max
Definition: rtsp.h:99
enum RTSPTransport transport
the negotiated data/packet transport protocol; e.g.
Definition: rtsp.h:244
Definition: url.h:42
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:356
int client_port_max
Definition: rtsp.h:95
Describe the class of an AVClass context structure.
Definition: log.h:33
struct RTSPState RTSPState
Private data for the RTSP demuxer.
char last_reply[2048]
The last reply of the server to a RTSP command.
Definition: rtsp.h:265
not initialized
Definition: rtsp.h:182
int64_t range_end
Definition: rtsp.h:129
enum RTSPTransport transport
data/packet transport protocol; e.g.
Definition: rtsp.h:109
char real_challenge[64]
the "RealChallenge1:" field from the server
Definition: rtsp.h:146
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:181
int interleaved_max
Definition: rtsp.h:87
enum RTSPServerType server_type
brand of server that we're talking to; e.g.
Definition: rtsp.h:253
RTSPStatusCode
RTSP handling.
Definition: rtspcodes.h:26
int64_t range_start
Time range of the streams that the server will stream.
Definition: rtsp.h:129
#define INET6_ADDRSTRLEN
Definition: network.h:157
enum RTSPClientState state
indicator of whether we are currently receiving data from the server.
Definition: rtsp.h:217
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:185
int need_subscription
The following are used for Real stream selection.
Definition: rtsp.h:274
initialized, but not receiving data
Definition: rtsp.h:184
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:565
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:262
struct RTSPStream RTSPStream
Describe a single stream, as identified by a single m= line block in the SDP content.
uint64_t packets
The number of returned packets.
Definition: rtsp.h:328
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:109
Realmedia-style server.
Definition: rtsp.h:194
int lower_transport_mask
A mask with all requested transport methods.
Definition: rtsp.h:323
struct sockaddr_storage destination
destination IP address
Definition: rtsp.h:105
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:99
void ff_rtsp_close_connections(AVFormatContext *s)
Close all connection handles within the RTSP (de)muxer.
int port_min
UDP multicast port range; the ports to which we should connect to receive multicast UDP data...
Definition: rtsp.h:91
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:95
int initial_pause
Do not begin to play the stream immediately.
Definition: rtsp.h:343