00001 /* 00002 * RTSP definitions 00003 * Copyright (c) 2002 Fabrice Bellard 00004 * 00005 * This file is part of FFmpeg. 00006 * 00007 * FFmpeg is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * FFmpeg is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with FFmpeg; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 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 } 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; /* RTSP TCP connection handle */ 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]; /* XXX: allocate ? */ 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 /* Number of RTCP BYE packets the RTSP session has received. 00313 * An EOF is propagated back if nb_byes == nb_streams. 00314 * This is reset after a seek. */ 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 00366 int rtp_port_min, rtp_port_max; 00367 } RTSPState; 00368 00369 #define RTSP_FLAG_FILTER_SRC 0x1 00379 typedef struct RTSPStream { 00380 URLContext *rtp_handle; 00381 void *transport_priv; 00384 int stream_index; 00385 00388 int interleaved_min, interleaved_max; 00389 00390 char control_url[1024]; 00394 int sdp_port; 00395 struct sockaddr_storage sdp_ip; 00396 int sdp_ttl; 00397 int sdp_payload_type; 00399 00403 RTPDynamicProtocolHandler *dynamic_handler; 00404 00406 PayloadContext *dynamic_protocol_context; 00408 } RTSPStream; 00409 00410 void ff_rtsp_parse_line(RTSPMessageHeader *reply, const char *buf, 00411 RTSPState *rt, const char *method); 00412 00418 int ff_rtsp_send_cmd_async(AVFormatContext *s, const char *method, 00419 const char *url, const char *headers); 00420 00437 int ff_rtsp_send_cmd_with_content(AVFormatContext *s, 00438 const char *method, const char *url, 00439 const char *headers, 00440 RTSPMessageHeader *reply, 00441 unsigned char **content_ptr, 00442 const unsigned char *send_content, 00443 int send_content_length); 00444 00450 int ff_rtsp_send_cmd(AVFormatContext *s, const char *method, 00451 const char *url, const char *headers, 00452 RTSPMessageHeader *reply, unsigned char **content_ptr); 00453 00477 int ff_rtsp_read_reply(AVFormatContext *s, RTSPMessageHeader *reply, 00478 unsigned char **content_ptr, 00479 int return_on_interleaved_data, const char *method); 00480 00484 void ff_rtsp_skip_packet(AVFormatContext *s); 00485 00495 int ff_rtsp_connect(AVFormatContext *s); 00496 00502 void ff_rtsp_close_streams(AVFormatContext *s); 00503 00509 void ff_rtsp_close_connections(AVFormatContext *s); 00510 00515 int ff_rtsp_setup_input_streams(AVFormatContext *s, RTSPMessageHeader *reply); 00516 00521 int ff_rtsp_setup_output_streams(AVFormatContext *s, const char *addr); 00522 00528 int ff_sdp_parse(AVFormatContext *s, const char *content); 00529 00533 int ff_rtsp_tcp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st, 00534 uint8_t *buf, int buf_size); 00535 00540 int ff_rtsp_fetch_packet(AVFormatContext *s, AVPacket *pkt); 00541 00547 int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port, 00548 int lower_transport, const char *real_challenge); 00549 00554 void ff_rtsp_undo_setup(AVFormatContext *s); 00555 00556 extern const AVOption ff_rtsp_options[]; 00557 00558 #endif /* AVFORMAT_RTSP_H */