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
00036 enum RTSPLowerTransport {
00037 RTSP_LOWER_TRANSPORT_UDP = 0,
00038 RTSP_LOWER_TRANSPORT_TCP = 1,
00039 RTSP_LOWER_TRANSPORT_UDP_MULTICAST = 2,
00040 RTSP_LOWER_TRANSPORT_NB
00041 };
00042
00048 enum RTSPTransport {
00049 RTSP_TRANSPORT_RTP,
00050 RTSP_TRANSPORT_RDT,
00051 RTSP_TRANSPORT_NB
00052 };
00053
00058 enum RTSPControlTransport {
00059 RTSP_MODE_PLAIN,
00060 RTSP_MODE_TUNNEL
00061 };
00062
00063 #define RTSP_DEFAULT_PORT 554
00064 #define RTSP_MAX_TRANSPORTS 8
00065 #define RTSP_TCP_MAX_PACKET_SIZE 1472
00066 #define RTSP_DEFAULT_NB_AUDIO_CHANNELS 1
00067 #define RTSP_DEFAULT_AUDIO_SAMPLERATE 44100
00068 #define RTSP_RTP_PORT_MIN 5000
00069 #define RTSP_RTP_PORT_MAX 10000
00070
00078 typedef struct RTSPTransportField {
00083 int interleaved_min, interleaved_max;
00084
00087 int port_min, port_max;
00088
00091 int client_port_min, client_port_max;
00092
00095 int server_port_min, server_port_max;
00096
00099 int ttl;
00100
00101 struct sockaddr_storage destination;
00102 char source[INET6_ADDRSTRLEN + 1];
00105 enum RTSPTransport transport;
00106
00108 enum RTSPLowerTransport lower_transport;
00109 } RTSPTransportField;
00110
00114 typedef struct RTSPMessageHeader {
00116 int content_length;
00117
00118 enum RTSPStatusCode status_code;
00121 int nb_transports;
00122
00125 int64_t range_start, range_end;
00126
00129 RTSPTransportField transports[RTSP_MAX_TRANSPORTS];
00130
00131 int seq;
00135 char session_id[512];
00136
00139 char location[4096];
00140
00142 char real_challenge[64];
00143
00151 char server[64];
00152
00159 int timeout;
00160
00164 int notice;
00165
00169 char reason[256];
00170 } RTSPMessageHeader;
00171
00177 enum RTSPClientState {
00178 RTSP_STATE_IDLE,
00179 RTSP_STATE_STREAMING,
00180 RTSP_STATE_PAUSED,
00181 RTSP_STATE_SEEKING,
00182 };
00183
00188 enum RTSPServerType {
00189 RTSP_SERVER_RTP,
00190 RTSP_SERVER_REAL,
00191 RTSP_SERVER_WMS,
00192 RTSP_SERVER_NB
00193 };
00194
00200 typedef struct RTSPState {
00201 const AVClass *class;
00202 URLContext *rtsp_hd;
00203
00205 int nb_rtsp_streams;
00206
00207 struct RTSPStream **rtsp_streams;
00213 enum RTSPClientState state;
00214
00221 int64_t seek_timestamp;
00222
00223
00224
00225
00226 int seq;
00230 char session_id[512];
00231
00235 int timeout;
00236
00240 int64_t last_cmd_time;
00241
00243 enum RTSPTransport transport;
00244
00247 enum RTSPLowerTransport lower_transport;
00248
00252 enum RTSPServerType server_type;
00253
00255 char real_challenge[64];
00256
00258 char auth[128];
00259
00261 HTTPAuthState auth_state;
00262
00264 char last_reply[2048];
00265
00268 void *cur_transport_priv;
00269
00273 int need_subscription;
00274
00277 enum AVDiscard *real_setup_cache;
00278
00281 enum AVDiscard *real_setup;
00282
00286 char last_subscription[1024];
00288
00292 AVFormatContext *asf_ctx;
00293
00296 uint64_t asf_pb_pos;
00298
00302 char control_uri[1024];
00303
00306 URLContext *rtsp_hd_out;
00307
00309 enum RTSPControlTransport control_transport;
00310
00311
00312
00313
00314 int nb_byes;
00315
00317 uint8_t* recvbuf;
00318
00321 int filter_source;
00322
00326 int lower_transport_mask;
00327
00331 uint64_t packets;
00332
00336 struct pollfd *p;
00337
00341 int get_parameter_supported;
00342
00346 int initial_pause;
00347
00351 int rtp_muxer_flags;
00352 } RTSPState;
00353
00360 typedef struct RTSPStream {
00361 URLContext *rtp_handle;
00362 void *transport_priv;
00365 int stream_index;
00366
00369 int interleaved_min, interleaved_max;
00370
00371 char control_url[1024];
00375 int sdp_port;
00376 struct sockaddr_storage sdp_ip;
00377 int sdp_ttl;
00378 int sdp_payload_type;
00380
00384 RTPDynamicProtocolHandler *dynamic_handler;
00385
00387 PayloadContext *dynamic_protocol_context;
00389 } RTSPStream;
00390
00391 void ff_rtsp_parse_line(RTSPMessageHeader *reply, const char *buf,
00392 RTSPState *rt, const char *method);
00393
00394 extern int rtsp_rtp_port_min;
00395 extern int rtsp_rtp_port_max;
00396
00402 int ff_rtsp_send_cmd_async(AVFormatContext *s, const char *method,
00403 const char *url, const char *headers);
00404
00421 int ff_rtsp_send_cmd_with_content(AVFormatContext *s,
00422 const char *method, const char *url,
00423 const char *headers,
00424 RTSPMessageHeader *reply,
00425 unsigned char **content_ptr,
00426 const unsigned char *send_content,
00427 int send_content_length);
00428
00434 int ff_rtsp_send_cmd(AVFormatContext *s, const char *method,
00435 const char *url, const char *headers,
00436 RTSPMessageHeader *reply, unsigned char **content_ptr);
00437
00461 int ff_rtsp_read_reply(AVFormatContext *s, RTSPMessageHeader *reply,
00462 unsigned char **content_ptr,
00463 int return_on_interleaved_data, const char *method);
00464
00468 void ff_rtsp_skip_packet(AVFormatContext *s);
00469
00479 int ff_rtsp_connect(AVFormatContext *s);
00480
00486 void ff_rtsp_close_streams(AVFormatContext *s);
00487
00493 void ff_rtsp_close_connections(AVFormatContext *rt);
00494
00499 int ff_rtsp_setup_input_streams(AVFormatContext *s, RTSPMessageHeader *reply);
00500
00505 int ff_rtsp_setup_output_streams(AVFormatContext *s, const char *addr);
00506
00512 int ff_sdp_parse(AVFormatContext *s, const char *content);
00513
00517 int ff_rtsp_tcp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st,
00518 uint8_t *buf, int buf_size);
00519
00524 int ff_rtsp_fetch_packet(AVFormatContext *s, AVPacket *pkt);
00525
00531 int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port,
00532 int lower_transport, const char *real_challenge);
00533
00538 void ff_rtsp_undo_setup(AVFormatContext *s);
00539
00540 #endif