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 10000
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 } RTSPMessageHeader;
00175
00181 enum RTSPClientState {
00182 RTSP_STATE_IDLE,
00183 RTSP_STATE_STREAMING,
00184 RTSP_STATE_PAUSED,
00185 RTSP_STATE_SEEKING,
00186 };
00187
00192 enum RTSPServerType {
00193 RTSP_SERVER_RTP,
00194 RTSP_SERVER_REAL,
00195 RTSP_SERVER_WMS,
00196 RTSP_SERVER_NB
00197 };
00198
00204 typedef struct RTSPState {
00205 const AVClass *class;
00206 URLContext *rtsp_hd;
00207
00209 int nb_rtsp_streams;
00210
00211 struct RTSPStream **rtsp_streams;
00217 enum RTSPClientState state;
00218
00225 int64_t seek_timestamp;
00226
00227 int seq;
00231 char session_id[512];
00232
00236 int timeout;
00237
00241 int64_t last_cmd_time;
00242
00244 enum RTSPTransport transport;
00245
00248 enum RTSPLowerTransport lower_transport;
00249
00253 enum RTSPServerType server_type;
00254
00256 char real_challenge[64];
00257
00259 char auth[128];
00260
00262 HTTPAuthState auth_state;
00263
00265 char last_reply[2048];
00266
00269 void *cur_transport_priv;
00270
00274 int need_subscription;
00275
00278 enum AVDiscard *real_setup_cache;
00279
00282 enum AVDiscard *real_setup;
00283
00287 char last_subscription[1024];
00289
00293 AVFormatContext *asf_ctx;
00294
00297 uint64_t asf_pb_pos;
00299
00303 char control_uri[1024];
00304
00307 URLContext *rtsp_hd_out;
00308
00310 enum RTSPControlTransport control_transport;
00311
00312
00313
00314
00315 int nb_byes;
00316
00318 uint8_t* recvbuf;
00319
00323 int lower_transport_mask;
00324
00328 uint64_t packets;
00329
00333 struct pollfd *p;
00334
00338 int get_parameter_supported;
00339
00343 int initial_pause;
00344
00348 int rtp_muxer_flags;
00349
00351 int accept_dynamic_rate;
00352
00356 int rtsp_flags;
00357
00361 int media_type_mask;
00362 } RTSPState;
00363
00364 #define RTSP_FLAG_FILTER_SRC 0x1
00374 typedef struct RTSPStream {
00375 URLContext *rtp_handle;
00376 void *transport_priv;
00379 int stream_index;
00380
00383 int interleaved_min, interleaved_max;
00384
00385 char control_url[1024];
00389 int sdp_port;
00390 struct sockaddr_storage sdp_ip;
00391 int sdp_ttl;
00392 int sdp_payload_type;
00394
00398 RTPDynamicProtocolHandler *dynamic_handler;
00399
00401 PayloadContext *dynamic_protocol_context;
00403 } RTSPStream;
00404
00405 void ff_rtsp_parse_line(RTSPMessageHeader *reply, const char *buf,
00406 RTSPState *rt, const char *method);
00407
00408 extern int rtsp_rtp_port_min;
00409 extern int rtsp_rtp_port_max;
00410
00416 int ff_rtsp_send_cmd_async(AVFormatContext *s, const char *method,
00417 const char *url, const char *headers);
00418
00435 int ff_rtsp_send_cmd_with_content(AVFormatContext *s,
00436 const char *method, const char *url,
00437 const char *headers,
00438 RTSPMessageHeader *reply,
00439 unsigned char **content_ptr,
00440 const unsigned char *send_content,
00441 int send_content_length);
00442
00448 int ff_rtsp_send_cmd(AVFormatContext *s, const char *method,
00449 const char *url, const char *headers,
00450 RTSPMessageHeader *reply, unsigned char **content_ptr);
00451
00475 int ff_rtsp_read_reply(AVFormatContext *s, RTSPMessageHeader *reply,
00476 unsigned char **content_ptr,
00477 int return_on_interleaved_data, const char *method);
00478
00482 void ff_rtsp_skip_packet(AVFormatContext *s);
00483
00493 int ff_rtsp_connect(AVFormatContext *s);
00494
00500 void ff_rtsp_close_streams(AVFormatContext *s);
00501
00507 void ff_rtsp_close_connections(AVFormatContext *s);
00508
00513 int ff_rtsp_setup_input_streams(AVFormatContext *s, RTSPMessageHeader *reply);
00514
00519 int ff_rtsp_setup_output_streams(AVFormatContext *s, const char *addr);
00520
00526 int ff_sdp_parse(AVFormatContext *s, const char *content);
00527
00531 int ff_rtsp_tcp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st,
00532 uint8_t *buf, int buf_size);
00533
00538 int ff_rtsp_fetch_packet(AVFormatContext *s, AVPacket *pkt);
00539
00545 int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port,
00546 int lower_transport, const char *real_challenge);
00547
00552 void ff_rtsp_undo_setup(AVFormatContext *s);
00553
00554 extern const AVOption ff_rtsp_options[];
00555
00556 #endif