FFmpeg
rtsp.h
1 /*
2  * RTSP definitions
3  * Copyright (c) 2002 Fabrice Bellard
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg 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  * FFmpeg 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 FFmpeg; 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 
37 enum RTSPLowerTransport {
38  RTSP_LOWER_TRANSPORT_UDP = 0,
39  RTSP_LOWER_TRANSPORT_TCP = 1,
40  RTSP_LOWER_TRANSPORT_UDP_MULTICAST = 2,
41  RTSP_LOWER_TRANSPORT_NB,
42  RTSP_LOWER_TRANSPORT_HTTP = 8,
45  RTSP_LOWER_TRANSPORT_CUSTOM = 16,
49 };
50 
56 enum RTSPTransport {
57  RTSP_TRANSPORT_RTP,
58  RTSP_TRANSPORT_RDT,
59  RTSP_TRANSPORT_RAW,
60  RTSP_TRANSPORT_NB
61 };
62 
67 enum RTSPControlTransport {
68  RTSP_MODE_PLAIN,
69  RTSP_MODE_TUNNEL
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 65000
80 
88 typedef struct RTSPTransportField {
93  int interleaved_min, interleaved_max;
94 
97  int port_min, port_max;
98 
101  int client_port_min, client_port_max;
102 
105  int server_port_min, server_port_max;
106 
109  int ttl;
110 
113 
115  char source[INET6_ADDRSTRLEN + 1];
118  enum RTSPTransport transport;
119 
121  enum RTSPLowerTransport lower_transport;
123 
127 typedef struct RTSPMessageHeader {
130 
131  enum RTSPStatusCode status_code;
135 
138  int64_t range_start, range_end;
139 
142  RTSPTransportField transports[RTSP_MAX_TRANSPORTS];
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 
195 enum RTSPClientState {
196  RTSP_STATE_IDLE,
197  RTSP_STATE_STREAMING,
198  RTSP_STATE_PAUSED,
199  RTSP_STATE_SEEKING,
200 };
201 
206 enum RTSPServerType {
207  RTSP_SERVER_RTP,
208  RTSP_SERVER_REAL,
209  RTSP_SERVER_WMS,
210  RTSP_SERVER_NB
211 };
212 
218 typedef struct RTSPState {
219  const AVClass *class;
220  URLContext *rtsp_hd; /* RTSP TCP connection handle */
221 
224 
231  enum RTSPClientState state;
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 
258  enum RTSPTransport transport;
259 
262  enum RTSPLowerTransport lower_transport;
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;
322  int recvbuf_pos;
323  int recvbuf_len;
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 
339  uint8_t* recvbuf;
340 
345 
349  uint64_t packets;
350 
354  struct pollfd *p;
355  int max_p;
356 
361 
366 
371 
374 
379 
384 
388  int rtp_port_min, rtp_port_max;
389 
394 
398  int stimeout;
399 
404 
408  char *user_agent;
409 
410  char default_lang[4];
411  int buffer_size;
412 } RTSPState;
413 
414 #define RTSP_FLAG_FILTER_SRC 0x1
417 #define RTSP_FLAG_LISTEN 0x2
418 #define RTSP_FLAG_CUSTOM_IO 0x4
419 #define RTSP_FLAG_RTCP_TO_SOURCE 0x8
421 #define RTSP_FLAG_PREFER_TCP 0x10
423 typedef struct RTSPSource {
424  char addr[128];
425 } RTSPSource;
433 typedef struct RTSPStream {
434  URLContext *rtp_handle;
435  void *transport_priv;
438  int stream_index;
439 
442  int interleaved_min, interleaved_max;
443 
444  char control_url[1024];
448  int sdp_port;
449  struct sockaddr_storage sdp_ip;
450  int nb_include_source_addrs;
451  struct RTSPSource **include_source_addrs;
452  int nb_exclude_source_addrs;
453  struct RTSPSource **exclude_source_addrs;
454  int sdp_ttl;
455  int sdp_payload_type;
461  const RTPDynamicProtocolHandler *dynamic_handler;
462 
464  PayloadContext *dynamic_protocol_context;
466 
468  int feedback;
469 
471  uint32_t ssrc;
472 
473  char crypto_suite[40];
474  char crypto_params[100];
475 } RTSPStream;
476 
477 void ff_rtsp_parse_line(AVFormatContext *s,
478  RTSPMessageHeader *reply, const char *buf,
479  RTSPState *rt, const char *method);
480 
486 int ff_rtsp_send_cmd_async(AVFormatContext *s, const char *method,
487  const char *url, const char *headers);
488 
505 int ff_rtsp_send_cmd_with_content(AVFormatContext *s,
506  const char *method, const char *url,
507  const char *headers,
508  RTSPMessageHeader *reply,
509  unsigned char **content_ptr,
510  const unsigned char *send_content,
511  int send_content_length);
512 
518 int ff_rtsp_send_cmd(AVFormatContext *s, const char *method,
519  const char *url, const char *headers,
520  RTSPMessageHeader *reply, unsigned char **content_ptr);
521 
545 int ff_rtsp_read_reply(AVFormatContext *s, RTSPMessageHeader *reply,
546  unsigned char **content_ptr,
547  int return_on_interleaved_data, const char *method);
548 
552 void ff_rtsp_skip_packet(AVFormatContext *s);
553 
563 int ff_rtsp_connect(AVFormatContext *s);
564 
570 void ff_rtsp_close_streams(AVFormatContext *s);
571 
577 void ff_rtsp_close_connections(AVFormatContext *s);
578 
583 int ff_rtsp_setup_input_streams(AVFormatContext *s, RTSPMessageHeader *reply);
584 
589 int ff_rtsp_setup_output_streams(AVFormatContext *s, const char *addr);
590 
595 int ff_rtsp_parse_streaming_commands(AVFormatContext *s);
596 
602 int ff_sdp_parse(AVFormatContext *s, const char *content);
603 
607 int ff_rtsp_tcp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st,
608  uint8_t *buf, int buf_size);
609 
613 int ff_rtsp_tcp_write_packet(AVFormatContext *s, RTSPStream *rtsp_st);
614 
619 int ff_rtsp_fetch_packet(AVFormatContext *s, AVPacket *pkt);
620 
626 int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port,
627  int lower_transport, const char *real_challenge);
628 
633 void ff_rtsp_undo_setup(AVFormatContext *s, int send_packets);
634 
638 int ff_rtsp_open_transport_ctx(AVFormatContext *s, RTSPStream *rtsp_st);
639 
640 extern const AVOption ff_rtsp_options[];
641 
642 #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
int rtp_port_min
Minimum and maximum local UDP ports.
Definition: rtsp.h:388
Definition: mpegts.c:111
Definition: rtsp.h:426
AVOption.
Definition: opt.h:246
char source[INET6_ADDRSTRLEN+1]
source IP address
Definition: rtsp.h:115
struct pollfd * p
Polling array for udp.
Definition: rtsp.h:354
RTP/JPEG specific private data.
Definition: rdt.c:83
Definition: rtpdec.h:115
enum AVDiscard * real_setup
current stream setup.
Definition: rtsp.h:296
char * user_agent
User-Agent string.
Definition: rtsp.h:408
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
int seq
sequence number
Definition: rtsp.h:144
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
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
Format I/O context.
Definition: avformat.h:1342
int reordering_queue_size
Size of RTP packet reordering queue.
Definition: rtsp.h:403
int get_parameter_supported
Whether the server supports the GET_PARAMETER method.
Definition: rtsp.h:360
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:393
int rtp_muxer_flags
Option flags for the chained RTP muxer.
Definition: rtsp.h:370
int accept_dynamic_rate
Whether the server accepts the x-Dynamic-Rate header.
Definition: rtsp.h:373
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:436
int nb_transports
number of items in the &#39;transports&#39; variable below
Definition: rtsp.h:134
int notice
The "Notice" or "X-Notice" field value.
Definition: rtsp.h:177
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
int timeout
copy of RTSPMessageHeader->timeout, i.e.
Definition: rtsp.h:250
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 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
This describes a single item in the "Transport:" line of one stream as negotiated by the SETUP RTSP c...
Definition: rtsp.h:88
struct MpegTSContext * ts
The following are used for parsing raw mpegts in udp.
Definition: rtsp.h:321
Definition: network.h:108
char addr[128]
Source-specific multicast include source IP address (from SDP content)
Definition: rtsp.h:427
int media_type_mask
Mask of all requested media types.
Definition: rtsp.h:383
Definition: url.h:38
int rtsp_flags
Various option flags for the RTSP muxer/demuxer.
Definition: rtsp.h:378
Describe the class of an AVClass context structure.
Definition: log.h:67
enum RTSPTransport transport
data/packet transport protocol; e.g.
Definition: rtsp.h:118
int64_t range_start
Time range of the streams that the server will stream.
Definition: rtsp.h:138
Main libavformat public API header.
int need_subscription
The following are used for Real stream selection.
Definition: rtsp.h:288
int stimeout
timeout of socket i/o operations.
Definition: rtsp.h:398
HTTPAuthState auth_state
authentication state
Definition: rtsp.h:276
uint64_t packets
The number of returned packets.
Definition: rtsp.h:349
AVDiscard
Definition: avcodec.h:785
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:1407
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
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:365