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_NB
00056 };
00057
00062 enum RTSPControlTransport {
00063 RTSP_MODE_PLAIN,
00064 RTSP_MODE_TUNNEL
00065 };
00066
00067 #define RTSP_DEFAULT_PORT 554
00068 #define RTSP_MAX_TRANSPORTS 8
00069 #define RTSP_TCP_MAX_PACKET_SIZE 1472
00070 #define RTSP_DEFAULT_NB_AUDIO_CHANNELS 1
00071 #define RTSP_DEFAULT_AUDIO_SAMPLERATE 44100
00072 #define RTSP_RTP_PORT_MIN 5000
00073 #define RTSP_RTP_PORT_MAX 65000
00074
00082 typedef struct RTSPTransportField {
00087 int interleaved_min, interleaved_max;
00088
00091 int port_min, port_max;
00092
00095 int client_port_min, client_port_max;
00096
00099 int server_port_min, server_port_max;
00100
00103 int ttl;
00104
00105 struct sockaddr_storage destination;
00106 char source[INET6_ADDRSTRLEN + 1];
00109 enum RTSPTransport transport;
00110
00112 enum RTSPLowerTransport lower_transport;
00113 } RTSPTransportField;
00114
00118 typedef struct RTSPMessageHeader {
00120 int content_length;
00121
00122 enum RTSPStatusCode status_code;
00125 int nb_transports;
00126
00129 int64_t range_start, range_end;
00130
00133 RTSPTransportField transports[RTSP_MAX_TRANSPORTS];
00134
00135 int seq;
00139 char session_id[512];
00140
00143 char location[4096];
00144
00146 char real_challenge[64];
00147
00155 char server[64];
00156
00163 int timeout;
00164
00168 int notice;
00169
00173 char reason[256];
00174
00178 char content_type[64];
00179 } RTSPMessageHeader;
00180
00186 enum RTSPClientState {
00187 RTSP_STATE_IDLE,
00188 RTSP_STATE_STREAMING,
00189 RTSP_STATE_PAUSED,
00190 RTSP_STATE_SEEKING,
00191 };
00192
00197 enum RTSPServerType {
00198 RTSP_SERVER_RTP,
00199 RTSP_SERVER_REAL,
00200 RTSP_SERVER_WMS,
00201 RTSP_SERVER_NB
00202 };
00203
00209 typedef struct RTSPState {
00210 const AVClass *class;
00211 URLContext *rtsp_hd;
00212
00214 int nb_rtsp_streams;
00215
00216 struct RTSPStream **rtsp_streams;
00222 enum RTSPClientState state;
00223
00230 int64_t seek_timestamp;
00231
00232 int seq;
00236 char session_id[512];
00237
00241 int timeout;
00242
00246 int64_t last_cmd_time;
00247
00249 enum RTSPTransport transport;
00250
00253 enum RTSPLowerTransport lower_transport;
00254
00258 enum RTSPServerType server_type;
00259
00261 char real_challenge[64];
00262
00264 char auth[128];
00265
00267 HTTPAuthState auth_state;
00268
00270 char last_reply[2048];
00271
00274 void *cur_transport_priv;
00275
00279 int need_subscription;
00280
00283 enum AVDiscard *real_setup_cache;
00284
00287 enum AVDiscard *real_setup;
00288
00292 char last_subscription[1024];
00294
00298 AVFormatContext *asf_ctx;
00299
00302 uint64_t asf_pb_pos;
00304
00308 char control_uri[1024];
00309
00312 URLContext *rtsp_hd_out;
00313
00315 enum RTSPControlTransport control_transport;
00316
00317
00318
00319
00320 int nb_byes;
00321
00323 uint8_t* recvbuf;
00324
00328 int lower_transport_mask;
00329
00333 uint64_t packets;
00334
00338 struct pollfd *p;
00339
00343 int get_parameter_supported;
00344
00348 int initial_pause;
00349
00353 int rtp_muxer_flags;
00354
00356 int accept_dynamic_rate;
00357
00361 int rtsp_flags;
00362
00366 int media_type_mask;
00367
00371 int rtp_port_min, rtp_port_max;
00372 } RTSPState;
00373
00374 #define RTSP_FLAG_FILTER_SRC 0x1
00384 typedef struct RTSPStream {
00385 URLContext *rtp_handle;
00386 void *transport_priv;
00389 int stream_index;
00390
00393 int interleaved_min, interleaved_max;
00394
00395 char control_url[1024];
00399 int sdp_port;
00400 struct sockaddr_storage sdp_ip;
00401 int sdp_ttl;
00402 int sdp_payload_type;
00404
00408 RTPDynamicProtocolHandler *dynamic_handler;
00409
00411 PayloadContext *dynamic_protocol_context;
00413 } RTSPStream;
00414
00415 void ff_rtsp_parse_line(RTSPMessageHeader *reply, const char *buf,
00416 RTSPState *rt, const char *method);
00417
00423 int ff_rtsp_send_cmd_async(AVFormatContext *s, const char *method,
00424 const char *url, const char *headers);
00425
00442 int ff_rtsp_send_cmd_with_content(AVFormatContext *s,
00443 const char *method, const char *url,
00444 const char *headers,
00445 RTSPMessageHeader *reply,
00446 unsigned char **content_ptr,
00447 const unsigned char *send_content,
00448 int send_content_length);
00449
00455 int ff_rtsp_send_cmd(AVFormatContext *s, const char *method,
00456 const char *url, const char *headers,
00457 RTSPMessageHeader *reply, unsigned char **content_ptr);
00458
00482 int ff_rtsp_read_reply(AVFormatContext *s, RTSPMessageHeader *reply,
00483 unsigned char **content_ptr,
00484 int return_on_interleaved_data, const char *method);
00485
00489 void ff_rtsp_skip_packet(AVFormatContext *s);
00490
00500 int ff_rtsp_connect(AVFormatContext *s);
00501
00507 void ff_rtsp_close_streams(AVFormatContext *s);
00508
00514 void ff_rtsp_close_connections(AVFormatContext *s);
00515
00520 int ff_rtsp_setup_input_streams(AVFormatContext *s, RTSPMessageHeader *reply);
00521
00526 int ff_rtsp_setup_output_streams(AVFormatContext *s, const char *addr);
00527
00533 int ff_sdp_parse(AVFormatContext *s, const char *content);
00534
00538 int ff_rtsp_tcp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st,
00539 uint8_t *buf, int buf_size);
00540
00545 int ff_rtsp_fetch_packet(AVFormatContext *s, AVPacket *pkt);
00546
00552 int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port,
00553 int lower_transport, const char *real_challenge);
00554
00559 void ff_rtsp_undo_setup(AVFormatContext *s);
00560
00561 extern const AVOption ff_rtsp_options[];
00562
00563 #endif