00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef AVFORMAT_RTSP_H
00022 #define AVFORMAT_RTSP_H
00023
00024 #include <stdint.h>
00025 #include "avformat.h"
00026 #include "rtspcodes.h"
00027 #include "rtpdec.h"
00028 #include "network.h"
00029 #include "httpauth.h"
00030
00031 #include "libavutil/log.h"
00032 #include "libavutil/opt.h"
00033
00037 enum RTSPLowerTransport {
00038 RTSP_LOWER_TRANSPORT_UDP = 0,
00039 RTSP_LOWER_TRANSPORT_TCP = 1,
00040 RTSP_LOWER_TRANSPORT_UDP_MULTICAST = 2,
00041 RTSP_LOWER_TRANSPORT_NB,
00042 RTSP_LOWER_TRANSPORT_HTTP = 8,
00045 };
00046
00052 enum RTSPTransport {
00053 RTSP_TRANSPORT_RTP,
00054 RTSP_TRANSPORT_RDT,
00055 RTSP_TRANSPORT_RAW,
00056 RTSP_TRANSPORT_NB
00057 };
00058
00063 enum RTSPControlTransport {
00064 RTSP_MODE_PLAIN,
00065 RTSP_MODE_TUNNEL
00066 };
00067
00068 #define RTSP_DEFAULT_PORT 554
00069 #define RTSP_MAX_TRANSPORTS 8
00070 #define RTSP_TCP_MAX_PACKET_SIZE 1472
00071 #define RTSP_DEFAULT_NB_AUDIO_CHANNELS 1
00072 #define RTSP_DEFAULT_AUDIO_SAMPLERATE 44100
00073 #define RTSP_RTP_PORT_MIN 5000
00074 #define RTSP_RTP_PORT_MAX 65000
00075
00083 typedef struct RTSPTransportField {
00088 int interleaved_min, interleaved_max;
00089
00092 int port_min, port_max;
00093
00096 int client_port_min, client_port_max;
00097
00100 int server_port_min, server_port_max;
00101
00104 int ttl;
00105
00107 int mode_record;
00108
00109 struct sockaddr_storage destination;
00110 char source[INET6_ADDRSTRLEN + 1];
00113 enum RTSPTransport transport;
00114
00116 enum RTSPLowerTransport lower_transport;
00117 } RTSPTransportField;
00118
00122 typedef struct RTSPMessageHeader {
00124 int content_length;
00125
00126 enum RTSPStatusCode status_code;
00129 int nb_transports;
00130
00133 int64_t range_start, range_end;
00134
00137 RTSPTransportField transports[RTSP_MAX_TRANSPORTS];
00138
00139 int seq;
00143 char session_id[512];
00144
00147 char location[4096];
00148
00150 char real_challenge[64];
00151
00159 char server[64];
00160
00167 int timeout;
00168
00172 int notice;
00173
00177 char reason[256];
00178
00182 char content_type[64];
00183 } RTSPMessageHeader;
00184
00190 enum RTSPClientState {
00191 RTSP_STATE_IDLE,
00192 RTSP_STATE_STREAMING,
00193 RTSP_STATE_PAUSED,
00194 RTSP_STATE_SEEKING,
00195 };
00196
00201 enum RTSPServerType {
00202 RTSP_SERVER_RTP,
00203 RTSP_SERVER_REAL,
00204 RTSP_SERVER_WMS,
00205 RTSP_SERVER_NB
00206 };
00207
00213 typedef struct RTSPState {
00214 const AVClass *class;
00215 URLContext *rtsp_hd;
00216
00218 int nb_rtsp_streams;
00219
00220 struct RTSPStream **rtsp_streams;
00226 enum RTSPClientState state;
00227
00234 int64_t seek_timestamp;
00235
00236 int seq;
00240 char session_id[512];
00241
00245 int timeout;
00246
00250 int64_t last_cmd_time;
00251
00253 enum RTSPTransport transport;
00254
00257 enum RTSPLowerTransport lower_transport;
00258
00262 enum RTSPServerType server_type;
00263
00265 char real_challenge[64];
00266
00268 char auth[128];
00269
00271 HTTPAuthState auth_state;
00272
00274 char last_reply[2048];
00275
00278 void *cur_transport_priv;
00279
00283 int need_subscription;
00284
00287 enum AVDiscard *real_setup_cache;
00288
00291 enum AVDiscard *real_setup;
00292
00296 char last_subscription[1024];
00298
00302 AVFormatContext *asf_ctx;
00303
00306 uint64_t asf_pb_pos;
00308
00312 char control_uri[1024];
00313
00316 struct MpegTSContext *ts;
00317 int recvbuf_pos;
00318 int recvbuf_len;
00320
00323 URLContext *rtsp_hd_out;
00324
00326 enum RTSPControlTransport control_transport;
00327
00328
00329
00330
00331 int nb_byes;
00332
00334 uint8_t* recvbuf;
00335
00339 int lower_transport_mask;
00340
00344 uint64_t packets;
00345
00349 struct pollfd *p;
00350
00354 int get_parameter_supported;
00355
00359 int initial_pause;
00360
00364 int rtp_muxer_flags;
00365
00367 int accept_dynamic_rate;
00368
00372 int rtsp_flags;
00373
00377 int media_type_mask;
00378
00382 int rtp_port_min, rtp_port_max;
00383
00387 int initial_timeout;
00388 } RTSPState;
00389
00390 #define RTSP_FLAG_FILTER_SRC 0x1
00393 #define RTSP_FLAG_LISTEN 0x2
00401 typedef struct RTSPStream {
00402 URLContext *rtp_handle;
00403 void *transport_priv;
00406 int stream_index;
00407
00410 int interleaved_min, interleaved_max;
00411
00412 char control_url[1024];
00416 int sdp_port;
00417 struct sockaddr_storage sdp_ip;
00418 int sdp_ttl;
00419 int sdp_payload_type;
00421
00425 RTPDynamicProtocolHandler *dynamic_handler;
00426
00428 PayloadContext *dynamic_protocol_context;
00430 } RTSPStream;
00431
00432 void ff_rtsp_parse_line(RTSPMessageHeader *reply, const char *buf,
00433 RTSPState *rt, const char *method);
00434
00440 int ff_rtsp_send_cmd_async(AVFormatContext *s, const char *method,
00441 const char *url, const char *headers);
00442
00459 int ff_rtsp_send_cmd_with_content(AVFormatContext *s,
00460 const char *method, const char *url,
00461 const char *headers,
00462 RTSPMessageHeader *reply,
00463 unsigned char **content_ptr,
00464 const unsigned char *send_content,
00465 int send_content_length);
00466
00472 int ff_rtsp_send_cmd(AVFormatContext *s, const char *method,
00473 const char *url, const char *headers,
00474 RTSPMessageHeader *reply, unsigned char **content_ptr);
00475
00499 int ff_rtsp_read_reply(AVFormatContext *s, RTSPMessageHeader *reply,
00500 unsigned char **content_ptr,
00501 int return_on_interleaved_data, const char *method);
00502
00506 void ff_rtsp_skip_packet(AVFormatContext *s);
00507
00517 int ff_rtsp_connect(AVFormatContext *s);
00518
00524 void ff_rtsp_close_streams(AVFormatContext *s);
00525
00531 void ff_rtsp_close_connections(AVFormatContext *s);
00532
00537 int ff_rtsp_setup_input_streams(AVFormatContext *s, RTSPMessageHeader *reply);
00538
00543 int ff_rtsp_setup_output_streams(AVFormatContext *s, const char *addr);
00544
00549 int ff_rtsp_parse_streaming_commands(AVFormatContext *s);
00550
00556 int ff_sdp_parse(AVFormatContext *s, const char *content);
00557
00561 int ff_rtsp_tcp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st,
00562 uint8_t *buf, int buf_size);
00563
00568 int ff_rtsp_fetch_packet(AVFormatContext *s, AVPacket *pkt);
00569
00575 int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port,
00576 int lower_transport, const char *real_challenge);
00577
00582 void ff_rtsp_undo_setup(AVFormatContext *s);
00583
00587 int ff_rtsp_open_transport_ctx(AVFormatContext *s, RTSPStream *rtsp_st);
00588
00589 extern const AVOption ff_rtsp_options[];
00590
00591 #endif