#include "libavutil/base64.h"
#include "libavutil/avstring.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/parseutils.h"
#include "libavutil/random_seed.h"
#include "libavutil/dict.h"
#include "avformat.h"
#include "avio_internal.h"
#include <sys/time.h>
#include <poll.h>
#include <strings.h>
#include "internal.h"
#include "network.h"
#include "os_support.h"
#include "http.h"
#include "rtsp.h"
#include "rtpdec.h"
#include "rdt.h"
#include "rtpdec_formats.h"
#include "rtpenc_chain.h"
#include "url.h"
Go to the source code of this file.
Data Structures | |
struct | SDPParseState |
Defines | |
#define | POLL_TIMEOUT_MS 100 |
#define | READ_PACKET_TIMEOUT_S 10 |
#define | MAX_TIMEOUTS READ_PACKET_TIMEOUT_S * 1000 / POLL_TIMEOUT_MS |
#define | SDP_MAX_SIZE 16384 |
#define | RECVBUF_SIZE 10 * RTP_MAX_PACKET_LENGTH |
Typedefs | |
typedef struct SDPParseState | SDPParseState |
Functions | |
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 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 int | get_sockaddr (const char *buf, struct sockaddr_storage *sock) |
static void | init_rtp_handler (RTPDynamicProtocolHandler *handler, RTSPStream *rtsp_st, AVCodecContext *codec) |
static int | sdp_parse_rtpmap (AVFormatContext *s, AVStream *st, RTSPStream *rtsp_st, int payload_type, const char *p) |
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_line (AVFormatContext *s, SDPParseState *s1, int letter, const char *buf) |
int | ff_sdp_parse (AVFormatContext *s, const char *content) |
Parse an SDP description of streams by populating an RTSPState struct within the AVFormatContext; also allocate the RTP streams and the pollfd array used for UDP streams. | |
void | ff_rtsp_undo_setup (AVFormatContext *s) |
Undo the effect of ff_rtsp_make_setup_request, close the transport_priv and rtp_handle fields. | |
void | ff_rtsp_close_streams (AVFormatContext *s) |
Close and free all streams within the RTSP (de)muxer. | |
static int | rtsp_open_transport_ctx (AVFormatContext *s, RTSPStream *rtsp_st) |
static void | rtsp_parse_range (int *min_ptr, int *max_ptr, const char **pp) |
static void | rtsp_parse_transport (RTSPMessageHeader *reply, const char *p) |
static void | handle_rtp_info (RTSPState *rt, const char *url, uint32_t seq, uint32_t rtptime) |
static void | rtsp_parse_rtp_info (RTSPState *rt, const char *p) |
void | ff_rtsp_parse_line (RTSPMessageHeader *reply, const char *buf, RTSPState *rt, const char *method) |
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, const char *method) |
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. | |
static int | 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. | |
int | 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. | |
int | 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. | |
int | 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. | |
int | ff_rtsp_make_setup_request (AVFormatContext *s, const char *host, int port, int lower_transport, const char *real_challenge) |
Do the SETUP requests for each stream for the chosen lower transport mode. | |
void | ff_rtsp_close_connections (AVFormatContext *s) |
Close all connection handles within the RTSP (de)muxer. | |
int | ff_rtsp_connect (AVFormatContext *s) |
Connect to the RTSP server and set up the individual media streams. | |
static int | udp_read_packet (AVFormatContext *s, RTSPStream **prtsp_st, uint8_t *buf, int buf_size, int64_t wait_end) |
int | ff_rtsp_fetch_packet (AVFormatContext *s, AVPacket *pkt) |
Receive one packet from the RTSPStreams set up in the AVFormatContext (which should contain a RTSPState struct as priv_data). | |
static int | sdp_probe (AVProbeData *p1) |
static int | sdp_read_header (AVFormatContext *s, AVFormatParameters *ap) |
static int | sdp_read_close (AVFormatContext *s) |
static int | rtp_probe (AVProbeData *p) |
static int | rtp_read_header (AVFormatContext *s, AVFormatParameters *ap) |
Variables | |
AVInputFormat | ff_sdp_demuxer |
AVInputFormat | ff_rtp_demuxer |
#define MAX_TIMEOUTS READ_PACKET_TIMEOUT_S * 1000 / POLL_TIMEOUT_MS |
Definition at line 54 of file rtsp.c.
Referenced by udp_read_packet().
#define POLL_TIMEOUT_MS 100 |
Definition at line 52 of file rtsp.c.
Referenced by udp_read_packet().
#define RECVBUF_SIZE 10 * RTP_MAX_PACKET_LENGTH |
Definition at line 56 of file rtsp.c.
Referenced by ff_rtsp_fetch_packet().
#define SDP_MAX_SIZE 16384 |
Definition at line 55 of file rtsp.c.
Referenced by sdp_read_header().
typedef struct SDPParseState SDPParseState |
void ff_rtsp_close_connections | ( | AVFormatContext * | rt | ) |
Close all connection handles within the RTSP (de)muxer.
rt | RTSP (de)muxer context |
Definition at line 1291 of file rtsp.c.
Referenced by ff_rtsp_connect(), rtsp_read_close(), rtsp_read_header(), rtsp_write_close(), and rtsp_write_header().
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 513 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 |
Definition at line 1299 of file rtsp.c.
Referenced by rtsp_read_header(), and rtsp_write_header().
int ff_rtsp_fetch_packet | ( | AVFormatContext * | s, | |
AVPacket * | pkt | |||
) |
Receive one packet from the RTSPStreams set up in the AVFormatContext (which should contain a RTSPState struct as priv_data).
Definition at line 1619 of file rtsp.c.
Referenced by rtsp_read_packet().
int ff_rtsp_make_setup_request | ( | AVFormatContext * | s, | |
const char * | host, | |||
int | port, | |||
int | lower_transport, | |||
const char * | real_challenge | |||
) |
Do the SETUP requests for each stream for the chosen lower transport mode.
Definition at line 1048 of file rtsp.c.
Referenced by ff_rtsp_connect(), and resetup_tcp().
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 217 of file rtsp.c.
Referenced by ff_parse_fmtp().
void ff_rtsp_parse_line | ( | RTSPMessageHeader * | reply, | |
const char * | buf, | |||
RTSPState * | rt, | |||
const char * | method | |||
) |
Definition at line 758 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, | |||
const char * | method | |||
) |
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. | |
method | the RTSP method this is a reply to. This affects how some response headers are acted upon. May be NULL. |
Definition at line 839 of file rtsp.c.
Referenced by ff_rtsp_send_cmd_with_content(), ff_rtsp_tcp_read_packet(), rtsp_write_packet(), and udp_read_packet().
int 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 1003 of file rtsp.c.
Referenced by ff_rtsp_connect(), ff_rtsp_make_setup_request(), ff_rtsp_setup_input_streams(), rtsp_read_packet(), rtsp_read_pause(), rtsp_read_play(), and rtsp_write_record().
int 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 997 of file rtsp.c.
Referenced by rtsp_read_close(), rtsp_read_packet(), and rtsp_write_close().
int 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 1011 of file rtsp.c.
Referenced by ff_rtsp_send_cmd(), and ff_rtsp_setup_output_streams().
static int 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 | |||
) | [static] |
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 943 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 814 of file rtsp.c.
Referenced by ff_rtsp_read_reply(), and rtsp_write_packet().
void ff_rtsp_undo_setup | ( | AVFormatContext * | s | ) |
Undo the effect of ff_rtsp_make_setup_request, close the transport_priv and rtp_handle fields.
Definition at line 479 of file rtsp.c.
Referenced by ff_rtsp_close_streams(), ff_rtsp_make_setup_request(), and resetup_tcp().
int ff_sdp_parse | ( | AVFormatContext * | s, | |
const char * | content | |||
) |
Parse an SDP description of streams by populating an RTSPState struct within the AVFormatContext; also allocate the RTP streams and the pollfd array used for UDP streams.
Definition at line 431 of file rtsp.c.
Referenced by ff_rtsp_setup_input_streams(), and sdp_read_header().
static int get_sockaddr | ( | const char * | buf, | |
struct sockaddr_storage * | sock | |||
) | [static] |
Definition at line 115 of file rtsp.c.
Referenced by rtsp_parse_transport(), and sdp_parse_line().
static void get_word | ( | char * | buf, | |
int | buf_size, | |||
const char ** | pp | |||
) | [static] |
Definition at line 84 of file rtsp.c.
Referenced by ff_rtsp_read_reply(), and sdp_parse_line().
static void get_word_sep | ( | char * | buf, | |
int | buf_size, | |||
const char * | sep, | |||
const char ** | pp | |||
) | [static] |
Definition at line 77 of file rtsp.c.
Referenced by ff_rtsp_next_attr_and_value(), ff_rtsp_parse_line(), rtsp_parse_range_npt(), rtsp_parse_rtp_info(), 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] |
Definition at line 58 of file rtsp.c.
Referenced by get_word(), and get_word_sep().
static void handle_rtp_info | ( | RTSPState * | rt, | |
const char * | url, | |||
uint32_t | seq, | |||
uint32_t | rtptime | |||
) | [static] |
Definition at line 703 of file rtsp.c.
Referenced by rtsp_parse_rtp_info().
static void init_rtp_handler | ( | RTPDynamicProtocolHandler * | handler, | |
RTSPStream * | rtsp_st, | |||
AVCodecContext * | codec | |||
) | [static] |
Definition at line 128 of file rtsp.c.
Referenced by sdp_parse_line(), and sdp_parse_rtpmap().
static int rtp_probe | ( | AVProbeData * | p | ) | [static] |
static int rtp_read_header | ( | AVFormatContext * | s, | |
AVFormatParameters * | ap | |||
) | [static] |
static int rtsp_open_transport_ctx | ( | AVFormatContext * | s, | |
RTSPStream * | rtsp_st | |||
) | [static] |
Definition at line 538 of file rtsp.c.
Referenced by ff_rtsp_make_setup_request(), and sdp_read_header().
static void rtsp_parse_range | ( | int * | min_ptr, | |
int * | max_ptr, | |||
const char ** | pp | |||
) | [static] |
Definition at line 579 of file rtsp.c.
Referenced by rtsp_parse_transport().
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 93 of file rtsp.c.
Referenced by ff_rtsp_parse_line(), and sdp_parse_line().
static void rtsp_parse_rtp_info | ( | RTSPState * | rt, | |
const char * | p | |||
) | [static] |
Definition at line 723 of file rtsp.c.
Referenced by ff_rtsp_parse_line().
static void rtsp_parse_transport | ( | RTSPMessageHeader * | reply, | |
const char * | p | |||
) | [static] |
Definition at line 600 of file rtsp.c.
Referenced by ff_rtsp_parse_line().
static void sdp_parse_line | ( | AVFormatContext * | s, | |
SDPParseState * | s1, | |||
int | letter, | |||
const char * | buf | |||
) | [static] |
Definition at line 240 of file rtsp.c.
Referenced by ff_sdp_parse().
static int sdp_parse_rtpmap | ( | AVFormatContext * | s, | |
AVStream * | st, | |||
RTSPStream * | rtsp_st, | |||
int | payload_type, | |||
const char * | p | |||
) | [static] |
Definition at line 140 of file rtsp.c.
Referenced by sdp_parse_line().
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] |
Definition at line 1772 of file rtsp.c.
Referenced by rtp_read_header().
static int udp_read_packet | ( | AVFormatContext * | s, | |
RTSPStream ** | prtsp_st, | |||
uint8_t * | buf, | |||
int | buf_size, | |||
int64_t | wait_end | |||
) | [static] |
Definition at line 1552 of file rtsp.c.
Referenced by ff_rtsp_fetch_packet().
{ "rtp", NULL_IF_CONFIG_SMALL("RTP input format"), sizeof(RTSPState), rtp_probe, rtp_read_header, ff_rtsp_fetch_packet, sdp_read_close, .flags = AVFMT_NOFILE, }
{ "sdp", NULL_IF_CONFIG_SMALL("SDP"), sizeof(RTSPState), sdp_probe, sdp_read_header, ff_rtsp_fetch_packet, sdp_read_close, }