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 RTSPS_DEFAULT_PORT 322
74 #define RTSP_MAX_TRANSPORTS 8
75 #define RTSP_TCP_MAX_PACKET_SIZE 1472
76 #define RTSP_DEFAULT_NB_AUDIO_CHANNELS 1
77 #define RTSP_DEFAULT_AUDIO_SAMPLERATE 44100
78 #define RTSP_RTP_PORT_MIN 5000
79 #define RTSP_RTP_PORT_MAX 10000
80 
88 typedef struct RTSPTransportField {
94 
98 
102 
106 
109  int ttl;
110 
113 
119 
123 
127 typedef struct RTSPMessageHeader {
130 
131  enum RTSPStatusCode status_code;
135 
138  int64_t range_start, range_end;
139 
143 
144  int seq;
148  char session_id[512];
149 
152  char location[4096];
153 
155  char real_challenge[64];
156 
164  char server[64];
165 
172  int timeout;
173 
177  int notice;
178 
182  char reason[256];
183 
187  char content_type[64];
189 
200 };
201 
211 };
212 
218 typedef struct RTSPState {
219  const AVClass *class;
220  URLContext *rtsp_hd; /* RTSP TCP connection handle */
221 
224 
232 
239  int64_t seek_timestamp;
240 
241  int seq;
245  char session_id[512];
246 
250  int timeout;
251 
255  int64_t last_cmd_time;
256 
259 
263 
267  enum RTSPServerType server_type;
268 
270  char real_challenge[64];
271 
273  char auth[128];
274 
277 
279  char last_reply[2048]; /* XXX: allocate ? */
280 
284 
289 
293 
297 
301  char last_subscription[1024];
303 
308 
311  uint64_t asf_pb_pos;
313 
317  char control_uri[1024];
318 
321  struct MpegTSContext *ts;
325 
329 
331  enum RTSPControlTransport control_transport;
332 
333  /* Number of RTCP BYE packets the RTSP session has received.
334  * An EOF is propagated back if nb_byes == nb_streams.
335  * This is reset after a seek. */
336  int nb_byes;
337 
340 
345 
349  uint64_t packets;
350 
354  struct pollfd *p;
355 
360 
365 
370 
373 
378 
383 
387  int rtp_port_min, rtp_port_max;
388 
393 
398 
399  char default_lang[4];
401 
403 } RTSPState;
404 
405 #define RTSP_FLAG_FILTER_SRC 0x1
408 #define RTSP_FLAG_LISTEN 0x2
409 #define RTSP_FLAG_CUSTOM_IO 0x4
410 #define RTSP_FLAG_RTCP_TO_SOURCE 0x8
413 typedef struct RTSPSource {
414  char addr[128];
415 } RTSPSource;
423 typedef struct RTSPStream {
424  URLContext *rtp_handle;
425  void *transport_priv;
428  int stream_index;
429 
433 
434  char control_url[1024];
438  int sdp_port;
439  struct sockaddr_storage sdp_ip;
440  int nb_include_source_addrs;
441  struct RTSPSource **include_source_addrs;
442  int nb_exclude_source_addrs;
443  struct RTSPSource **exclude_source_addrs;
444  int sdp_ttl;
445  int sdp_payload_type;
451  RTPDynamicProtocolHandler *dynamic_handler;
452 
454  PayloadContext *dynamic_protocol_context;
456 
458  int feedback;
459 
461  uint32_t ssrc;
462 
463  char crypto_suite[40];
464  char crypto_params[100];
465 } RTSPStream;
468  RTSPMessageHeader *reply, const char *buf,
469  RTSPState *rt, const char *method);
470 
476 int ff_rtsp_send_cmd_async(AVFormatContext *s, const char *method,
477  const char *url, const char *headers);
478 
496  const char *method, const char *url,
497  const char *headers,
498  RTSPMessageHeader *reply,
499  unsigned char **content_ptr,
500  const unsigned char *send_content,
501  int send_content_length);
502 
508 int ff_rtsp_send_cmd(AVFormatContext *s, const char *method,
509  const char *url, const char *headers,
510  RTSPMessageHeader *reply, unsigned char **content_ptr);
511 
536  unsigned char **content_ptr,
537  int return_on_interleaved_data, const char *method);
538 
543 
554 
561 
568 
574 
580 
586 
592 int ff_sdp_parse(AVFormatContext *s, const char *content);
593 
598  uint8_t *buf, int buf_size);
599 
604 
610 
616 int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port,
617  int lower_transport, const char *real_challenge);
618 
623 void ff_rtsp_undo_setup(AVFormatContext *s, int send_packets);
624 
629 
630 extern const AVOption ff_rtsp_options[];
631 
632 #endif /* AVFORMAT_RTSP_H */
int interleaved_min
interleave ids, if TCP transport; each TCP/RTSP data packet starts with a &#39;$&#39;, stream length and stre...
Definition: rtsp.h:93
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:387
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:789
AVOption.
Definition: opt.h:234
char source[INET6_ADDRSTRLEN+1]
source IP address
Definition: rtsp.h:115
Windows Media server.
Definition: rtsp.h:209
struct pollfd * p
Polling array for udp.
Definition: rtsp.h:354
RTP/JPEG specific private data.
Definition: rdt.c:83
enum AVDiscard * real_setup
current stream setup.
Definition: rtsp.h:296
enum AVDiscard * real_setup_cache
stream setup during the last frame read.
Definition: rtsp.h:292
int mode_record
transport set to record data
Definition: rtsp.h:112
UDP/unicast.
Definition: rtsp.h:38
int seq
sequence number
Definition: rtsp.h:144
initialized and sending/receiving data
Definition: rtsp.h:197
RTSPClientState
Client state, i.e.
Definition: rtsp.h:195
HTTP Authentication state structure.
Definition: httpauth.h:55
int64_t seek_timestamp
the seek value requested when calling av_seek_frame().
Definition: rtsp.h:239
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:121
This describes the server response to each RTSP command.
Definition: rtsp.h:127
RTSPTransport
Packet profile of the data that we will be receiving.
Definition: rtsp.h:56
Format I/O context.
Definition: avformat.h:940
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:207
int reordering_queue_size
Size of RTP packet reordering queue.
Definition: rtsp.h:397
int recvbuf_len
Definition: rtsp.h:323
int get_parameter_supported
Whether the server supports the GET_PARAMETER method.
Definition: rtsp.h:359
Standards-compliant RTP.
Definition: rtsp.h:57
uint8_t
#define RTSP_MAX_TRANSPORTS
Definition: rtsp.h:74
int ttl
time-to-live value (required for multicast); the amount of HOPs that packets will be allowed to make ...
Definition: rtsp.h:109
AVOptions.
int initial_timeout
Timeout to wait for incoming connections.
Definition: rtsp.h:392
int rtp_muxer_flags
Option flags for the chained RTP muxer.
Definition: rtsp.h:369
int accept_dynamic_rate
Whether the server accepts the x-Dynamic-Rate header.
Definition: rtsp.h:372
URLContext * rtsp_hd_out
Additional output handle, used when input and output are done separately, eg for HTTP tunneling...
Definition: rtsp.h:328
Describe a single stream, as identified by a single m= line block in the SDP content.
Definition: rtsp.h:426
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:206
int ff_rtsp_parse_streaming_commands(AVFormatContext *s)
Parse RTSP commands (OPTIONS, PAUSE and TEARDOWN) during streaming in listen mode.
Definition: rtspdec.c:462
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 &#39;transports&#39; variable below
Definition: rtsp.h:134
void ff_rtsp_parse_line(AVFormatContext *s, RTSPMessageHeader *reply, const char *buf, RTSPState *rt, const char *method)
int notice
The "Notice" or "X-Notice" field value.
Definition: rtsp.h:177
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:218
int64_t last_cmd_time
timestamp of the last RTSP command that we sent to the RTSP server.
Definition: rtsp.h:255
const AVOption ff_rtsp_options[]
Definition: rtsp.c:80
int timeout
copy of RTSPMessageHeader->timeout, i.e.
Definition: rtsp.h:250
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:718
URLContext * rtsp_hd
Definition: rtsp.h:220
struct RTSPStream ** rtsp_streams
streams in this session
Definition: rtsp.h:225
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:311
int seq
RTSP command sequence number.
Definition: rtsp.h:241
uint8_t * recvbuf
Reusable buffer for receiving packets.
Definition: rtsp.h:339
AVFormatContext * asf_ctx
The following are used for RTP/ASF streams.
Definition: rtsp.h:307
int recvbuf_pos
Definition: rtsp.h:322
int nb_rtsp_streams
number of items in the &#39;rtsp_streams&#39; variable
Definition: rtsp.h:223
void * cur_transport_priv
RTSPStream->transport_priv of the last stream that we read a packet from.
Definition: rtsp.h:283
int content_length
length of the data following this header
Definition: rtsp.h:129
int timeout
The "timeout" comes as part of the server response to the "SETUP" command, in the "Session: <xyz>[;ti...
Definition: rtsp.h:172
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:88
RTSP over HTTP (tunneling)
Definition: rtsp.h:69
const URLProtocol ** protocols
Definition: rtsp.h:402
int ff_rtsp_tcp_write_packet(AVFormatContext *s, RTSPStream *rtsp_st)
Send buffered packets over TCP.
Definition: rtspenc.c:139
Raw data (over UDP)
Definition: rtsp.h:59
struct MpegTSContext * ts
The following are used for parsing raw mpegts in udp.
Definition: rtsp.h:321
int nb_byes
Definition: rtsp.h:336
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:417
int media_type_mask
Mask of all requested media types.
Definition: rtsp.h:382
int server_port_max
Definition: rtsp.h:105
Definition: url.h:38
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:377
int client_port_max
Definition: rtsp.h:101
Describe the class of an AVClass context structure.
Definition: log.h:34
not initialized
Definition: rtsp.h:196
enum RTSPTransport transport
data/packet transport protocol; e.g.
Definition: rtsp.h:118
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:754
int buffer_size
Definition: rtsp.h:400
int interleaved_max
Definition: rtsp.h:93
RTSPStatusCode
RTSP handling.
Definition: rtspcodes.h:26
int64_t range_start
Time range of the streams that the server will stream.
Definition: rtsp.h:138
#define INET6_ADDRSTRLEN
Definition: network.h:206
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.
static struct @174 state
initialized, requesting a seek
Definition: rtsp.h:199
int need_subscription
The following are used for Real stream selection.
Definition: rtsp.h:288
initialized, but not receiving data
Definition: rtsp.h:198
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&#39;re reading data interleave...
void ff_rtsp_close_streams(AVFormatContext *s)
Close and free all streams within the RTSP (de)muxer.
Definition: rtsp.c:752
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:276
uint64_t packets
The number of returned packets.
Definition: rtsp.h:349
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:590
AVDiscard
Definition: avcodec.h:681
Realmedia-style server.
Definition: rtsp.h:208
int lower_transport_mask
A mask with all requested transport methods.
Definition: rtsp.h:344
struct sockaddr_storage destination
destination IP address
Definition: rtsp.h:114
This structure stores compressed data.
Definition: avcodec.h:1323
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:105
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:97
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:101
int initial_pause
Do not begin to play the stream immediately.
Definition: rtsp.h:364