#include "libavutil/base64.h"
#include "libavutil/avstring.h"
#include "libavutil/intreadwrite.h"
#include "avformat.h"
#include <sys/time.h>
#include <sys/select.h>
#include <strings.h>
#include "internal.h"
#include "network.h"
#include "os_support.h"
#include "rtsp.h"
#include "rtpdec.h"
#include "rdt.h"
#include "rtpdec_asf.h"
Go to the source code of this file.
Data Structures | |
struct | AttrNameMap |
struct | SDPParseState |
Defines | |
#define | SELECT_TIMEOUT_MS 100 |
#define | READ_PACKET_TIMEOUT_S 10 |
#define | MAX_TIMEOUTS READ_PACKET_TIMEOUT_S * 1000 / SELECT_TIMEOUT_MS |
#define | SPACE_CHARS " \t\r\n" |
#define | redir_isspace(c) memchr(SPACE_CHARS, c, 4) |
#define | ATTR_NAME_TYPE_INT 0 |
#define | ATTR_NAME_TYPE_STR 1 |
#define | SDP_MAX_SIZE 8192 |
Functions | |
static void | skip_spaces (const char **pp) |
static void | get_word_until_chars (char *buf, int buf_size, const char *sep, const char **pp) |
static void | get_word_sep (char *buf, int buf_size, const char *sep, const char **pp) |
static void | get_word (char *buf, int buf_size, const char **pp) |
static int | sdp_parse_rtpmap (AVFormatContext *s, AVCodecContext *codec, RTSPStream *rtsp_st, int payload_type, const char *p) |
static int | hex_to_data (uint8_t *data, const char *p) |
static void | sdp_parse_fmtp_config (AVCodecContext *codec, void *ctx, char *attr, char *value) |
int | ff_rtsp_next_attr_and_value (const char **p, char *attr, int attr_size, char *value, int value_size) |
from rtsp.c, but used by rtp dynamic protocol handlers. | |
static void | sdp_parse_fmtp (AVStream *st, const char *p) |
static void | rtsp_parse_range_npt (const char *p, int64_t *start, int64_t *end) |
Parse a string p in the form of Range:npt=xx-xx, and determine the start and end time. | |
static void | sdp_parse_line (AVFormatContext *s, SDPParseState *s1, int letter, const char *buf) |
static int | sdp_parse (AVFormatContext *s, const char *content) |
void | ff_rtsp_close_streams (AVFormatContext *s) |
Close and free all streams within the RTSP (de)muxer. | |
static void * | rtsp_rtp_mux_open (AVFormatContext *s, AVStream *st, URLContext *handle) |
static int | rtsp_open_transport_ctx (AVFormatContext *s, RTSPStream *rtsp_st) |
static int | rtsp_probe (AVProbeData *p) |
static void | rtsp_parse_range (int *min_ptr, int *max_ptr, const char **pp) |
static void | rtsp_parse_transport (RTSPMessageHeader *reply, const char *p) |
void | ff_rtsp_parse_line (RTSPMessageHeader *reply, const char *buf, HTTPAuthState *auth_state) |
void | ff_rtsp_skip_packet (AVFormatContext *s) |
Skip a RTP/TCP interleaved packet. | |
int | ff_rtsp_read_reply (AVFormatContext *s, RTSPMessageHeader *reply, unsigned char **content_ptr, int return_on_interleaved_data) |
Read a RTSP message from the server, or prepare to read data packets if we're reading data interleaved over the TCP/RTSP connection as well. | |
void | ff_rtsp_send_cmd_with_content_async (AVFormatContext *s, const char *method, const char *url, const char *headers, const unsigned char *send_content, int send_content_length) |
Send a command to the RTSP server without waiting for the reply. | |
void | ff_rtsp_send_cmd_async (AVFormatContext *s, const char *method, const char *url, const char *headers) |
Send a command to the RTSP server without waiting for the reply. | |
void | ff_rtsp_send_cmd (AVFormatContext *s, const char *method, const char *url, const char *headers, RTSPMessageHeader *reply, unsigned char **content_ptr) |
Send a command to the RTSP server and wait for the reply. | |
void | ff_rtsp_send_cmd_with_content (AVFormatContext *s, const char *method, const char *url, const char *header, RTSPMessageHeader *reply, unsigned char **content_ptr, const unsigned char *send_content, int send_content_length) |
Send a command to the RTSP server and wait for the reply. | |
static int | make_setup_request (AVFormatContext *s, const char *host, int port, int lower_transport, const char *real_challenge) |
static int | rtsp_read_play (AVFormatContext *s) |
static int | rtsp_setup_input_streams (AVFormatContext *s, RTSPMessageHeader *reply) |
static int | rtsp_setup_output_streams (AVFormatContext *s, const char *addr) |
int | ff_rtsp_connect (AVFormatContext *s) |
Connect to the RTSP server and set up the individual media streams. | |
static int | rtsp_read_header (AVFormatContext *s, AVFormatParameters *ap) |
static int | udp_read_packet (AVFormatContext *s, RTSPStream **prtsp_st, uint8_t *buf, int buf_size) |
static int | tcp_read_packet (AVFormatContext *s, RTSPStream **prtsp_st, uint8_t *buf, int buf_size) |
static int | rtsp_fetch_packet (AVFormatContext *s, AVPacket *pkt) |
static int | rtsp_read_packet (AVFormatContext *s, AVPacket *pkt) |
static int | rtsp_read_pause (AVFormatContext *s) |
static int | rtsp_read_seek (AVFormatContext *s, int stream_index, int64_t timestamp, int flags) |
static int | rtsp_read_close (AVFormatContext *s) |
static int | sdp_probe (AVProbeData *p1) |
static int | sdp_read_header (AVFormatContext *s, AVFormatParameters *ap) |
static int | sdp_read_close (AVFormatContext *s) |
Variables | |
int | rtsp_default_protocols = (1 << RTSP_LOWER_TRANSPORT_UDP) |
static const AttrNameMap | attr_names [] |
AVInputFormat | rtsp_demuxer |
AVInputFormat | sdp_demuxer |
#define ATTR_NAME_TYPE_INT 0 |
#define ATTR_NAME_TYPE_STR 1 |
#define MAX_TIMEOUTS READ_PACKET_TIMEOUT_S * 1000 / SELECT_TIMEOUT_MS |
#define redir_isspace | ( | c | ) | memchr(SPACE_CHARS, c, 4) |
#define SDP_MAX_SIZE 8192 |
#define SELECT_TIMEOUT_MS 100 |
#define SPACE_CHARS " \t\r\n" |
void ff_rtsp_close_streams | ( | AVFormatContext * | s | ) |
Close and free all streams within the RTSP (de)muxer.
s | RTSP (de)muxer context |
Definition at line 576 of file rtsp.c.
Referenced by ff_rtsp_connect(), rtsp_read_close(), rtsp_read_header(), rtsp_write_close(), rtsp_write_header(), sdp_read_close(), and sdp_read_header().
int ff_rtsp_connect | ( | AVFormatContext * | s | ) |
Connect to the RTSP server and set up the individual media streams.
This can be used for both muxers and demuxers.
s | RTSP (de)muxer context |
The following entries are required for proper streaming from a Realmedia server. They are interdependent in some way although we currently don't quite understand how. Values were copied from mplayer SVN r23589.
CompanyID | is a 16-byte ID in base64 | |
ClientChallenge | is a 16-byte ID in hex |
Definition at line 1438 of file rtsp.c.
Referenced by rtsp_read_header(), and rtsp_write_header().
int ff_rtsp_next_attr_and_value | ( | const char ** | p, | |
char * | attr, | |||
int | attr_size, | |||
char * | value, | |||
int | value_size | |||
) |
from rtsp.c, but used by rtp dynamic protocol handlers.
Definition at line 254 of file rtsp.c.
Referenced by amr_parse_sdp_line(), parse_h264_sdp_line(), sdp_parse_fmtp(), and xiph_parse_sdp_line().
void ff_rtsp_parse_line | ( | RTSPMessageHeader * | reply, | |
const char * | buf, | |||
HTTPAuthState * | auth_state | |||
) |
Definition at line 843 of file rtsp.c.
Referenced by ff_rtsp_read_reply(), and rtsp_parse_request().
int ff_rtsp_read_reply | ( | AVFormatContext * | s, | |
RTSPMessageHeader * | reply, | |||
unsigned char ** | content_ptr, | |||
int | return_on_interleaved_data | |||
) |
Read a RTSP message from the server, or prepare to read data packets if we're reading data interleaved over the TCP/RTSP connection as well.
s | RTSP (de)muxer context | |
reply | pointer where the RTSP message header will be stored | |
content_ptr | pointer where the RTSP message body, if any, will be stored (length is in reply) | |
return_on_interleaved_data | whether the function may return if we encounter a data marker ('$'), which precedes data packets over interleaved TCP/RTSP connections. If this is set, this function will return 1 after encountering a '$'. If it is not set, the function will skip any data packets (if they are encountered), until a reply has been fully parsed. If no more data is available without parsing a reply, it will return an error. |
Definition at line 912 of file rtsp.c.
Referenced by ff_rtsp_send_cmd_with_content(), rtsp_write_packet(), tcp_read_packet(), and udp_read_packet().
void ff_rtsp_send_cmd | ( | AVFormatContext * | s, | |
const char * | method, | |||
const char * | url, | |||
const char * | headers, | |||
RTSPMessageHeader * | reply, | |||
unsigned char ** | content_ptr | |||
) |
Send a command to the RTSP server and wait for the reply.
Definition at line 1047 of file rtsp.c.
Referenced by ff_rtsp_connect(), make_setup_request(), rtsp_read_packet(), rtsp_read_pause(), rtsp_read_play(), rtsp_setup_input_streams(), and rtsp_write_record().
void ff_rtsp_send_cmd_async | ( | AVFormatContext * | s, | |
const char * | method, | |||
const char * | url, | |||
const char * | headers | |||
) |
Send a command to the RTSP server without waiting for the reply.
Definition at line 1041 of file rtsp.c.
Referenced by rtsp_read_close(), rtsp_read_packet(), and rtsp_write_close().
void ff_rtsp_send_cmd_with_content | ( | AVFormatContext * | s, | |
const char * | method, | |||
const char * | url, | |||
const char * | headers, | |||
RTSPMessageHeader * | reply, | |||
unsigned char ** | content_ptr, | |||
const unsigned char * | send_content, | |||
int | send_content_length | |||
) |
Send a command to the RTSP server and wait for the reply.
s | RTSP (de)muxer context | |
method | the method for the request | |
url | the target url for the request | |
headers | extra header lines to include in the request | |
reply | pointer where the RTSP message header will be stored | |
content_ptr | pointer where the RTSP message body, if any, will be stored (length is in reply) | |
send_content | if non-null, the data to send as request body content | |
send_content_length | the length of the send_content data, or 0 if send_content is null |
Definition at line 1055 of file rtsp.c.
Referenced by ff_rtsp_send_cmd(), and rtsp_setup_output_streams().
void ff_rtsp_send_cmd_with_content_async | ( | AVFormatContext * | s, | |
const char * | method, | |||
const char * | url, | |||
const char * | headers, | |||
const unsigned char * | send_content, | |||
int | send_content_length | |||
) |
Send a command to the RTSP server without waiting for the reply.
s | RTSP (de)muxer context | |
method | the method for the request | |
url | the target url for the request | |
headers | extra header lines to include in the request | |
send_content | if non-null, the data to send as request body content | |
send_content_length | the length of the send_content data, or 0 if send_content is null |
Definition at line 1004 of file rtsp.c.
Referenced by ff_rtsp_send_cmd_async(), and ff_rtsp_send_cmd_with_content().
void ff_rtsp_skip_packet | ( | AVFormatContext * | s | ) |
Skip a RTP/TCP interleaved packet.
Definition at line 887 of file rtsp.c.
Referenced by ff_rtsp_read_reply(), and rtsp_write_packet().
static void get_word | ( | char * | buf, | |
int | buf_size, | |||
const char ** | pp | |||
) | [static] |
static void get_word_sep | ( | char * | buf, | |
int | buf_size, | |||
const char * | sep, | |||
const char ** | pp | |||
) | [static] |
Definition at line 86 of file rtsp.c.
Referenced by ff_rtsp_next_attr_and_value(), ff_rtsp_parse_line(), rtsp_parse_range_npt(), rtsp_parse_transport(), sdp_parse_line(), and sdp_parse_rtpmap().
static void get_word_until_chars | ( | char * | buf, | |
int | buf_size, | |||
const char * | sep, | |||
const char ** | pp | |||
) | [static] |
static int hex_to_data | ( | uint8_t * | data, | |
const char * | p | |||
) | [static] |
static int make_setup_request | ( | AVFormatContext * | s, | |
const char * | host, | |||
int | port, | |||
int | lower_transport, | |||
const char * | real_challenge | |||
) | [static] |
WMS serves all UDP data over a single connection, the RTX, which isn't necessarily the first in the SDP but has to be the first to be set up, else the second/third SETUP will fail with a 461.
For WMS streams, the application streams are only used for UDP. When trying to set it up for TCP streams, the server will return an error. Therefore, we skip those streams.
Definition at line 1081 of file rtsp.c.
Referenced by ff_rtsp_connect().
static int rtsp_fetch_packet | ( | AVFormatContext * | s, | |
AVPacket * | pkt | |||
) | [static] |
static int rtsp_open_transport_ctx | ( | AVFormatContext * | s, | |
RTSPStream * | rtsp_st | |||
) | [static] |
static void rtsp_parse_range | ( | int * | min_ptr, | |
int * | max_ptr, | |||
const char ** | pp | |||
) | [static] |
static void rtsp_parse_range_npt | ( | const char * | p, | |
int64_t * | start, | |||
int64_t * | end | |||
) | [static] |
Parse a string p in the form of Range:npt=xx-xx, and determine the start and end time.
Used for seeking in the rtp stream.
Definition at line 307 of file rtsp.c.
Referenced by ff_rtsp_parse_line(), and sdp_parse_line().
static void rtsp_parse_transport | ( | RTSPMessageHeader * | reply, | |
const char * | p | |||
) | [static] |
static int rtsp_probe | ( | AVProbeData * | p | ) | [static] |
static int rtsp_read_close | ( | AVFormatContext * | s | ) | [static] |
static int rtsp_read_header | ( | AVFormatContext * | s, | |
AVFormatParameters * | ap | |||
) | [static] |
static int rtsp_read_packet | ( | AVFormatContext * | s, | |
AVPacket * | pkt | |||
) | [static] |
static int rtsp_read_pause | ( | AVFormatContext * | s | ) | [static] |
static int rtsp_read_play | ( | AVFormatContext * | s | ) | [static] |
Definition at line 1313 of file rtsp.c.
Referenced by rtsp_read_header(), rtsp_read_packet(), and rtsp_read_seek().
static int rtsp_read_seek | ( | AVFormatContext * | s, | |
int | stream_index, | |||
int64_t | timestamp, | |||
int | flags | |||
) | [static] |
static void* rtsp_rtp_mux_open | ( | AVFormatContext * | s, | |
AVStream * | st, | |||
URLContext * | handle | |||
) | [static] |
static int rtsp_setup_input_streams | ( | AVFormatContext * | s, | |
RTSPMessageHeader * | reply | |||
) | [static] |
The Require: attribute is needed for proper streaming from Realmedia servers.
Definition at line 1338 of file rtsp.c.
Referenced by ff_rtsp_connect().
static int rtsp_setup_output_streams | ( | AVFormatContext * | s, | |
const char * | addr | |||
) | [static] |
static int sdp_parse | ( | AVFormatContext * | s, | |
const char * | content | |||
) | [static] |
Definition at line 532 of file rtsp.c.
Referenced by rtsp_setup_input_streams(), and sdp_read_header().
static void sdp_parse_fmtp | ( | AVStream * | st, | |
const char * | p | |||
) | [static] |
static void sdp_parse_fmtp_config | ( | AVCodecContext * | codec, | |
void * | ctx, | |||
char * | attr, | |||
char * | value | |||
) | [static] |
static void sdp_parse_line | ( | AVFormatContext * | s, | |
SDPParseState * | s1, | |||
int | letter, | |||
const char * | buf | |||
) | [static] |
static int sdp_parse_rtpmap | ( | AVFormatContext * | s, | |
AVCodecContext * | codec, | |||
RTSPStream * | rtsp_st, | |||
int | payload_type, | |||
const char * | p | |||
) | [static] |
static int sdp_probe | ( | AVProbeData * | p1 | ) | [static] |
static int sdp_read_close | ( | AVFormatContext * | s | ) | [static] |
static int sdp_read_header | ( | AVFormatContext * | s, | |
AVFormatParameters * | ap | |||
) | [static] |
static int tcp_read_packet | ( | AVFormatContext * | s, | |
RTSPStream ** | prtsp_st, | |||
uint8_t * | buf, | |||
int | buf_size | |||
) | [static] |
static int udp_read_packet | ( | AVFormatContext * | s, | |
RTSPStream ** | prtsp_st, | |||
uint8_t * | buf, | |||
int | buf_size | |||
) | [static] |
const AttrNameMap attr_names[] [static] |
Initial value:
{ { "SizeLength", ATTR_NAME_TYPE_INT, offsetof(RTPPayloadData, sizelength) }, { "IndexLength", ATTR_NAME_TYPE_INT, offsetof(RTPPayloadData, indexlength) }, { "IndexDeltaLength", ATTR_NAME_TYPE_INT, offsetof(RTPPayloadData, indexdeltalength) }, { "profile-level-id", ATTR_NAME_TYPE_INT, offsetof(RTPPayloadData, profile_level_id) }, { "StreamType", ATTR_NAME_TYPE_INT, offsetof(RTPPayloadData, streamtype) }, { "mode", ATTR_NAME_TYPE_STR, offsetof(RTPPayloadData, mode) }, { NULL, -1, -1 }, }
int rtsp_default_protocols = (1 << RTSP_LOWER_TRANSPORT_UDP) |
Initial value:
{ "rtsp", NULL_IF_CONFIG_SMALL("RTSP input format"), sizeof(RTSPState), rtsp_probe, rtsp_read_header, rtsp_read_packet, rtsp_read_close, rtsp_read_seek, .flags = AVFMT_NOFILE, .read_play = rtsp_read_play, .read_pause = rtsp_read_pause, }
Initial value:
{ "sdp", NULL_IF_CONFIG_SMALL("SDP"), sizeof(RTSPState), sdp_probe, sdp_read_header, rtsp_fetch_packet, sdp_read_close, }