#include "libavutil/base64.h"#include "libavutil/avstring.h"#include "libavutil/intreadwrite.h"#include "libavutil/mathematics.h"#include "libavutil/parseutils.h"#include "libavutil/random_seed.h"#include "libavutil/dict.h"#include "libavutil/opt.h"#include "avformat.h"#include "avio_internal.h"#include <sys/time.h>#include <poll.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"#include "rtpenc.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 |
| #define | OFFSET(x) offsetof(RTSPState, x) |
| #define | DEC AV_OPT_FLAG_DECODING_PARAM |
| #define | ENC AV_OPT_FLAG_ENCODING_PARAM |
| #define | RTSP_FLAG_OPTS(name, longname) |
| #define | RTSP_MEDIATYPE_OPTS(name, longname) |
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 | |
| const AVOption | ff_rtsp_options [] |
| static const AVOption | sdp_options [] |
| static const AVOption | rtp_options [] |
| static const AVClass | sdp_demuxer_class |
| AVInputFormat | ff_sdp_demuxer |
| static const AVClass | rtp_demuxer_class |
| AVInputFormat | ff_rtp_demuxer |
| #define MAX_TIMEOUTS READ_PACKET_TIMEOUT_S * 1000 / POLL_TIMEOUT_MS |
Definition at line 56 of file rtsp.c.
Referenced by udp_read_packet().
| #define POLL_TIMEOUT_MS 100 |
Definition at line 54 of file rtsp.c.
Referenced by udp_read_packet().
| #define RECVBUF_SIZE 10 * RTP_MAX_PACKET_LENGTH |
Definition at line 58 of file rtsp.c.
Referenced by ff_rtsp_fetch_packet().
| #define RTSP_FLAG_OPTS | ( | name, | ||
| longname | ||||
| ) |
{ name, longname, OFFSET(rtsp_flags), AV_OPT_TYPE_FLAGS, {0}, INT_MIN, INT_MAX, DEC, "rtsp_flags" }, \
{ "filter_src", "Only receive packets from the negotiated peer IP", 0, AV_OPT_TYPE_CONST, {RTSP_FLAG_FILTER_SRC}, 0, 0, DEC, "rtsp_flags" }
| #define RTSP_MEDIATYPE_OPTS | ( | name, | ||
| longname | ||||
| ) |
{ name, longname, OFFSET(media_type_mask), AV_OPT_TYPE_FLAGS, { (1 << (AVMEDIA_TYPE_DATA+1)) - 1 }, INT_MIN, INT_MAX, DEC, "allowed_media_types" }, \
{ "video", "Video", 0, AV_OPT_TYPE_CONST, {1 << AVMEDIA_TYPE_VIDEO}, 0, 0, DEC, "allowed_media_types" }, \
{ "audio", "Audio", 0, AV_OPT_TYPE_CONST, {1 << AVMEDIA_TYPE_AUDIO}, 0, 0, DEC, "allowed_media_types" }, \
{ "data", "Data", 0, AV_OPT_TYPE_CONST, {1 << AVMEDIA_TYPE_DATA}, 0, 0, DEC, "allowed_media_types" }
| #define SDP_MAX_SIZE 16384 |
Definition at line 57 of file rtsp.c.
Referenced by sdp_read_header().
| typedef struct SDPParseState SDPParseState |
| void ff_rtsp_close_connections | ( | AVFormatContext * | s | ) |
Close all connection handles within the RTSP (de)muxer.
| s | RTSP (de)muxer context |
Definition at line 1341 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 565 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 1349 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 1689 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 1102 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 263 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 809 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 893 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 1057 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 1051 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 1065 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 997 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 868 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 531 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 483 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 155 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 124 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 117 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 98 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 754 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 168 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 589 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 630 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 133 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 774 of file rtsp.c.
Referenced by ff_rtsp_parse_line().
| static void rtsp_parse_transport | ( | RTSPMessageHeader * | reply, | |
| const char * | p | |||
| ) | [static] |
Definition at line 651 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 286 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 183 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 1842 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 1622 of file rtsp.c.
Referenced by ff_rtsp_fetch_packet().
{
.name = "rtp",
.long_name = NULL_IF_CONFIG_SMALL("RTP input format"),
.priv_data_size = sizeof(RTSPState),
.read_probe = rtp_probe,
.read_header = rtp_read_header,
.read_packet = ff_rtsp_fetch_packet,
.read_close = sdp_read_close,
.flags = AVFMT_NOFILE,
.priv_class = &rtp_demuxer_class
}
| const AVOption ff_rtsp_options[] |
{
{ "initial_pause", "Don't start playing the stream immediately", OFFSET(initial_pause), AV_OPT_TYPE_INT, {0}, 0, 1, DEC },
FF_RTP_FLAG_OPTS(RTSPState, rtp_muxer_flags),
{ "rtsp_transport", "RTSP transport protocols", OFFSET(lower_transport_mask), AV_OPT_TYPE_FLAGS, {0}, INT_MIN, INT_MAX, DEC|ENC, "rtsp_transport" },
{ "udp", "UDP", 0, AV_OPT_TYPE_CONST, {1 << RTSP_LOWER_TRANSPORT_UDP}, 0, 0, DEC|ENC, "rtsp_transport" },
{ "tcp", "TCP", 0, AV_OPT_TYPE_CONST, {1 << RTSP_LOWER_TRANSPORT_TCP}, 0, 0, DEC|ENC, "rtsp_transport" },
{ "udp_multicast", "UDP multicast", 0, AV_OPT_TYPE_CONST, {1 << RTSP_LOWER_TRANSPORT_UDP_MULTICAST}, 0, 0, DEC, "rtsp_transport" },
{ "http", "HTTP tunneling", 0, AV_OPT_TYPE_CONST, {(1 << RTSP_LOWER_TRANSPORT_HTTP)}, 0, 0, DEC, "rtsp_transport" },
RTSP_FLAG_OPTS("rtsp_flags", "RTSP flags"),
RTSP_MEDIATYPE_OPTS("allowed_media_types", "Media types to accept from the server"),
{ NULL },
}
{
.name = "sdp",
.long_name = NULL_IF_CONFIG_SMALL("SDP"),
.priv_data_size = sizeof(RTSPState),
.read_probe = sdp_probe,
.read_header = sdp_read_header,
.read_packet = ff_rtsp_fetch_packet,
.read_close = sdp_read_close,
.priv_class = &sdp_demuxer_class
}
const AVClass rtp_demuxer_class [static] |
{
.class_name = "RTP demuxer",
.item_name = av_default_item_name,
.option = rtp_options,
.version = LIBAVUTIL_VERSION_INT,
}
const AVOption rtp_options[] [static] |
{
RTSP_FLAG_OPTS("rtp_flags", "RTP flags"),
{ NULL },
}
const AVClass sdp_demuxer_class [static] |
{
.class_name = "SDP demuxer",
.item_name = av_default_item_name,
.option = sdp_options,
.version = LIBAVUTIL_VERSION_INT,
}
const AVOption sdp_options[] [static] |
{
RTSP_FLAG_OPTS("sdp_flags", "SDP flags"),
RTSP_MEDIATYPE_OPTS("allowed_media_types", "Media types to accept from the server"),
{ NULL },
}