FFmpeg
Macros | Functions | Variables
rtsp.c File Reference
#include "config_components.h"
#include "libavutil/avassert.h"
#include "libavutil/base64.h"
#include "libavutil/bprint.h"
#include "libavutil/avstring.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mathematics.h"
#include "libavutil/mem.h"
#include "libavutil/parseutils.h"
#include "libavutil/random_seed.h"
#include "libavutil/dict.h"
#include "libavutil/opt.h"
#include "libavutil/time.h"
#include "libavcodec/codec_desc.h"
#include "avformat.h"
#include "avio_internal.h"
#include "demux.h"
#include "internal.h"
#include "network.h"
#include "os_support.h"
#include "http.h"
#include "rtsp.h"
#include "rtpdec.h"
#include "rtpproto.h"
#include "rdt.h"
#include "rtpdec_formats.h"
#include "rtpenc_chain.h"
#include "url.h"
#include "rtpenc.h"
#include "mpegts.h"
#include "version.h"

Go to the source code of this file.

Macros

#define READ_PACKET_TIMEOUT_S   10
 
#define RECVBUF_SIZE   10 * RTP_MAX_PACKET_LENGTH
 
#define DEFAULT_REORDERING_DELAY   100000
 
#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)
 
#define COMMON_OPTS()
 

Functions

static AVDictionarymap_to_opts (RTSPState *rt)
 
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. More...
 
static int get_sockaddr (AVFormatContext *s, const char *buf, struct sockaddr_storage *sock)
 
void ff_rtsp_undo_setup (AVFormatContext *s, int send_packets)
 Undo the effect of ff_rtsp_make_setup_request, close the transport_priv and rtp_handle fields. More...
 
void ff_rtsp_close_streams (AVFormatContext *s)
 Close and free all streams within the RTSP (de)muxer. More...
 
int ff_rtsp_open_transport_ctx (AVFormatContext *s, RTSPStream *rtsp_st)
 Open RTSP transport context. More...
 

Variables

const AVOption ff_rtsp_options []
 
static const AVOption sdp_options []
 
static const AVOption rtp_options []
 

Macro Definition Documentation

◆ READ_PACKET_TIMEOUT_S

#define READ_PACKET_TIMEOUT_S   10

Definition at line 61 of file rtsp.c.

◆ RECVBUF_SIZE

#define RECVBUF_SIZE   10 * RTP_MAX_PACKET_LENGTH

Definition at line 62 of file rtsp.c.

◆ DEFAULT_REORDERING_DELAY

#define DEFAULT_REORDERING_DELAY   100000

Definition at line 63 of file rtsp.c.

◆ OFFSET

#define OFFSET (   x)    offsetof(RTSPState, x)

Definition at line 65 of file rtsp.c.

◆ DEC

#define DEC   AV_OPT_FLAG_DECODING_PARAM

Definition at line 66 of file rtsp.c.

◆ ENC

#define ENC   AV_OPT_FLAG_ENCODING_PARAM

Definition at line 67 of file rtsp.c.

◆ RTSP_FLAG_OPTS

#define RTSP_FLAG_OPTS (   name,
  longname 
)
Value:
{ name, longname, OFFSET(rtsp_flags), AV_OPT_TYPE_FLAGS, {.i64 = 0}, INT_MIN, INT_MAX, DEC, .unit = "rtsp_flags" }, \
{ "filter_src", "only receive packets from the negotiated peer IP", 0, AV_OPT_TYPE_CONST, {.i64 = RTSP_FLAG_FILTER_SRC}, 0, 0, DEC, .unit = "rtsp_flags" }

Definition at line 69 of file rtsp.c.

◆ RTSP_MEDIATYPE_OPTS

#define RTSP_MEDIATYPE_OPTS (   name,
  longname 
)
Value:
{ name, longname, OFFSET(media_type_mask), AV_OPT_TYPE_FLAGS, { .i64 = (1 << (AVMEDIA_TYPE_SUBTITLE+1)) - 1 }, INT_MIN, INT_MAX, DEC, .unit = "allowed_media_types" }, \
{ "video", "Video", 0, AV_OPT_TYPE_CONST, {.i64 = 1 << AVMEDIA_TYPE_VIDEO}, 0, 0, DEC, .unit = "allowed_media_types" }, \
{ "audio", "Audio", 0, AV_OPT_TYPE_CONST, {.i64 = 1 << AVMEDIA_TYPE_AUDIO}, 0, 0, DEC, .unit = "allowed_media_types" }, \
{ "data", "Data", 0, AV_OPT_TYPE_CONST, {.i64 = 1 << AVMEDIA_TYPE_DATA}, 0, 0, DEC, .unit = "allowed_media_types" }, \
{ "subtitle", "Subtitle", 0, AV_OPT_TYPE_CONST, {.i64 = 1 << AVMEDIA_TYPE_SUBTITLE}, 0, 0, DEC, .unit = "allowed_media_types" }

Definition at line 73 of file rtsp.c.

◆ COMMON_OPTS

#define COMMON_OPTS ( )
Value:
{ "reorder_queue_size", "set number of packets to buffer for handling of reordered packets", OFFSET(reordering_queue_size), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, DEC }, \
{ "buffer_size", "Underlying protocol send/receive buffer size", OFFSET(buffer_size), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, DEC|ENC }, \
{ "pkt_size", "Underlying protocol send packet size", OFFSET(pkt_size), AV_OPT_TYPE_INT, { .i64 = 1472 }, -1, INT_MAX, ENC } \

Definition at line 80 of file rtsp.c.

Function Documentation

◆ map_to_opts()

static AVDictionary* map_to_opts ( RTSPState rt)
static

Definition at line 130 of file rtsp.c.

◆ get_word_until_chars()

static void get_word_until_chars ( char *  buf,
int  buf_size,
const char *  sep,
const char **  pp 
)
static

Definition at line 142 of file rtsp.c.

Referenced by get_word(), and get_word_sep().

◆ get_word_sep()

static void get_word_sep ( char *  buf,
int  buf_size,
const char *  sep,
const char **  pp 
)
static

Definition at line 161 of file rtsp.c.

Referenced by rtsp_parse_range_npt().

◆ get_word()

static void get_word ( char *  buf,
int  buf_size,
const char **  pp 
)
static

Definition at line 168 of file rtsp.c.

◆ rtsp_parse_range_npt()

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 177 of file rtsp.c.

◆ get_sockaddr()

static int get_sockaddr ( AVFormatContext s,
const char *  buf,
struct sockaddr_storage sock 
)
static

Definition at line 199 of file rtsp.c.

◆ ff_rtsp_undo_setup()

void ff_rtsp_undo_setup ( AVFormatContext s,
int  send_packets 
)

Undo the effect of ff_rtsp_make_setup_request, close the transport_priv and rtp_handle fields.

Definition at line 760 of file rtsp.c.

Referenced by ff_rtsp_close_streams(), resetup_tcp(), and rtsp_write_close().

◆ ff_rtsp_close_streams()

void ff_rtsp_close_streams ( AVFormatContext s)

Close and free all streams within the RTSP (de)muxer.

Parameters
sRTSP (de)muxer context

Definition at line 792 of file rtsp.c.

Referenced by rtsp_listen(), rtsp_read_close(), rtsp_write_close(), and rtsp_write_header().

◆ ff_rtsp_open_transport_ctx()

int ff_rtsp_open_transport_ctx ( AVFormatContext s,
RTSPStream rtsp_st 
)

Open RTSP transport context.

Definition at line 828 of file rtsp.c.

Referenced by rtsp_read_setup().

Variable Documentation

◆ ff_rtsp_options

const AVOption ff_rtsp_options[]
Initial value:
= {
{ "initial_pause", "do not start playing the stream immediately", OFFSET(initial_pause), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DEC },
FF_RTP_FLAG_OPTS(RTSPState, rtp_muxer_flags),
{ "rtsp_transport", "set RTSP transport protocols", OFFSET(lower_transport_mask), AV_OPT_TYPE_FLAGS, {.i64 = 0}, INT_MIN, INT_MAX, DEC|ENC, .unit = "rtsp_transport" },
{ "udp", "UDP", 0, AV_OPT_TYPE_CONST, {.i64 = 1 << RTSP_LOWER_TRANSPORT_UDP}, 0, 0, DEC|ENC, .unit = "rtsp_transport" },
{ "tcp", "TCP", 0, AV_OPT_TYPE_CONST, {.i64 = 1 << RTSP_LOWER_TRANSPORT_TCP}, 0, 0, DEC|ENC, .unit = "rtsp_transport" },
{ "udp_multicast", "UDP multicast", 0, AV_OPT_TYPE_CONST, {.i64 = 1 << RTSP_LOWER_TRANSPORT_UDP_MULTICAST}, 0, 0, DEC, .unit = "rtsp_transport" },
{ "http", "HTTP tunneling", 0, AV_OPT_TYPE_CONST, {.i64 = (1 << RTSP_LOWER_TRANSPORT_HTTP)}, 0, 0, DEC, .unit = "rtsp_transport" },
{ "https", "HTTPS tunneling", 0, AV_OPT_TYPE_CONST, {.i64 = (1 << RTSP_LOWER_TRANSPORT_HTTPS )}, 0, 0, DEC, .unit = "rtsp_transport" },
RTSP_FLAG_OPTS("rtsp_flags", "set RTSP flags"),
{ "listen", "wait for incoming connections", 0, AV_OPT_TYPE_CONST, {.i64 = RTSP_FLAG_LISTEN}, 0, 0, DEC, .unit = "rtsp_flags" },
{ "prefer_tcp", "try RTP via TCP first, if available", 0, AV_OPT_TYPE_CONST, {.i64 = RTSP_FLAG_PREFER_TCP}, 0, 0, DEC|ENC, .unit = "rtsp_flags" },
{ "satip_raw", "export raw MPEG-TS stream instead of demuxing", 0, AV_OPT_TYPE_CONST, {.i64 = RTSP_FLAG_SATIP_RAW}, 0, 0, DEC, .unit = "rtsp_flags" },
RTSP_MEDIATYPE_OPTS("allowed_media_types", "set media types to accept from the server"),
{ "min_port", "set minimum local UDP port", OFFSET(rtp_port_min), AV_OPT_TYPE_INT, {.i64 = RTSP_RTP_PORT_MIN}, 0, 65535, DEC|ENC },
{ "max_port", "set maximum local UDP port", OFFSET(rtp_port_max), AV_OPT_TYPE_INT, {.i64 = RTSP_RTP_PORT_MAX}, 0, 65535, DEC|ENC },
{ "listen_timeout", "set maximum timeout (in seconds) to wait for incoming connections (-1 is infinite, imply flag listen)", OFFSET(initial_timeout), AV_OPT_TYPE_INT, {.i64 = -1}, INT_MIN, INT_MAX, DEC },
{ "timeout", "set timeout (in microseconds) of socket I/O operations", OFFSET(stimeout), AV_OPT_TYPE_INT64, {.i64 = 0}, INT_MIN, INT64_MAX, DEC },
{ "user_agent", "override User-Agent header", OFFSET(user_agent), AV_OPT_TYPE_STRING, {.str = LIBAVFORMAT_IDENT}, 0, 0, DEC },
{ NULL },
}

Definition at line 86 of file rtsp.c.

◆ sdp_options

const AVOption sdp_options[]
static
Initial value:
= {
RTSP_FLAG_OPTS("sdp_flags", "SDP flags"),
{ "custom_io", "use custom I/O", 0, AV_OPT_TYPE_CONST, {.i64 = RTSP_FLAG_CUSTOM_IO}, 0, 0, DEC, .unit = "rtsp_flags" },
{ "rtcp_to_source", "send RTCP packets to the source address of received packets", 0, AV_OPT_TYPE_CONST, {.i64 = RTSP_FLAG_RTCP_TO_SOURCE}, 0, 0, DEC, .unit = "rtsp_flags" },
{ "listen_timeout", "set maximum timeout (in seconds) to wait for incoming connections", OFFSET(stimeout), AV_OPT_TYPE_DURATION, {.i64 = READ_PACKET_TIMEOUT_S*1000000}, INT_MIN, INT64_MAX, DEC },
{ "localaddr", "local address", OFFSET(localaddr),AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
RTSP_MEDIATYPE_OPTS("allowed_media_types", "set media types to accept from the server"),
{ NULL },
}

Definition at line 109 of file rtsp.c.

◆ rtp_options

const AVOption rtp_options[]
static
Initial value:
= {
RTSP_FLAG_OPTS("rtp_flags", "set RTP flags"),
{ "listen_timeout", "set maximum timeout (in seconds) to wait for incoming connections", OFFSET(stimeout), AV_OPT_TYPE_DURATION, {.i64 = READ_PACKET_TIMEOUT_S*1000000}, INT_MIN, INT64_MAX, DEC },
{ "localaddr", "local address", OFFSET(localaddr),AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
RTSP_MEDIATYPE_OPTS("allowed_media_types", "set media types to accept from the server"),
{ NULL },
}

Definition at line 120 of file rtsp.c.

AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:204
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
LIBAVFORMAT_IDENT
#define LIBAVFORMAT_IDENT
Definition: version.h:45
RTSP_RTP_PORT_MIN
#define RTSP_RTP_PORT_MIN
Definition: rtsp.h:79
AV_OPT_TYPE_DURATION
@ AV_OPT_TYPE_DURATION
Underlying C type is int64_t.
Definition: opt.h:319
ENC
#define ENC
Definition: rtsp.c:67
FF_RTP_FLAG_OPTS
#define FF_RTP_FLAG_OPTS(ctx, fieldname)
Definition: rtpenc.h:74
RTSP_FLAG_SATIP_RAW
#define RTSP_FLAG_SATIP_RAW
Export SAT>IP stream as raw MPEG-TS.
Definition: rtsp.h:432
OFFSET
#define OFFSET(x)
Definition: rtsp.c:65
RTSP_LOWER_TRANSPORT_HTTPS
@ RTSP_LOWER_TRANSPORT_HTTPS
HTTPS tunneled.
Definition: rtsp.h:47
RTSP_FLAG_LISTEN
#define RTSP_FLAG_LISTEN
Wait for incoming connections.
Definition: rtsp.h:427
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AV_OPT_TYPE_INT64
@ AV_OPT_TYPE_INT64
Underlying C type is int64_t.
Definition: opt.h:263
AVMEDIA_TYPE_DATA
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
Definition: avutil.h:203
RTSP_FLAG_OPTS
#define RTSP_FLAG_OPTS(name, longname)
Definition: rtsp.c:69
RTSP_MEDIATYPE_OPTS
#define RTSP_MEDIATYPE_OPTS(name, longname)
Definition: rtsp.c:73
NULL
#define NULL
Definition: coverity.c:32
DEC
#define DEC
Definition: rtsp.c:66
RTSP_FLAG_PREFER_TCP
#define RTSP_FLAG_PREFER_TCP
Try RTP via TCP first if possible.
Definition: rtsp.h:431
RTSPState
Private data for the RTSP demuxer.
Definition: rtsp.h:226
COMMON_OPTS
#define COMMON_OPTS()
Definition: rtsp.c:80
READ_PACKET_TIMEOUT_S
#define READ_PACKET_TIMEOUT_S
Definition: rtsp.c:61
RTSP_LOWER_TRANSPORT_TCP
@ RTSP_LOWER_TRANSPORT_TCP
TCP; interleaved in RTSP.
Definition: rtsp.h:41
RTSP_FLAG_CUSTOM_IO
#define RTSP_FLAG_CUSTOM_IO
Do all IO via the AVIOContext.
Definition: rtsp.h:428
RTSP_LOWER_TRANSPORT_UDP_MULTICAST
@ RTSP_LOWER_TRANSPORT_UDP_MULTICAST
UDP/multicast.
Definition: rtsp.h:42
RTSP_LOWER_TRANSPORT_HTTP
@ RTSP_LOWER_TRANSPORT_HTTP
HTTP tunneled - not a proper transport mode as such, only for use via AVOptions.
Definition: rtsp.h:44
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
RTSP_RTP_PORT_MAX
#define RTSP_RTP_PORT_MAX
Definition: rtsp.h:80
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition: opt.h:327
AV_OPT_TYPE_FLAGS
@ AV_OPT_TYPE_FLAGS
Underlying C type is unsigned int.
Definition: opt.h:255
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition: opt.h:276
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299
RTSP_FLAG_FILTER_SRC
#define RTSP_FLAG_FILTER_SRC
Filter incoming UDP packets - receive packets only from the right source address and port.
Definition: rtsp.h:424
RTSP_LOWER_TRANSPORT_UDP
@ RTSP_LOWER_TRANSPORT_UDP
UDP/unicast.
Definition: rtsp.h:40
RTSP_FLAG_RTCP_TO_SOURCE
#define RTSP_FLAG_RTCP_TO_SOURCE
Send RTCP packets to the source address of received packets.
Definition: rtsp.h:429