FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
rtsp.h File Reference
#include <stdint.h>
#include "avformat.h"
#include "rtspcodes.h"
#include "rtpdec.h"
#include "network.h"
#include "httpauth.h"
#include "internal.h"
#include "os_support.h"
#include "libavutil/log.h"
#include "libavutil/opt.h"

Go to the source code of this file.

Data Structures

struct  RTSPTransportField
 This describes a single item in the "Transport:" line of one stream as negotiated by the SETUP RTSP command. More...
 
struct  RTSPMessageHeader
 This describes the server response to each RTSP command. More...
 
struct  RTSPState
 Private data for the RTSP demuxer. More...
 
struct  RTSPSource
 
struct  RTSPStream
 Describe a single stream, as identified by a single m= line block in the SDP content. More...
 

Macros

#define RTSP_DEFAULT_PORT   554
 
#define RTSPS_DEFAULT_PORT   322
 
#define RTSP_MAX_TRANSPORTS   8
 
#define RTSP_DEFAULT_AUDIO_SAMPLERATE   44100
 
#define RTSP_RTP_PORT_MIN   5000
 
#define RTSP_RTP_PORT_MAX   65000
 
#define SDP_MAX_SIZE   16384
 
#define RTSP_FLAG_FILTER_SRC   0x1
 Filter incoming UDP packets - receive packets only from the right source address and port. More...
 
#define RTSP_FLAG_LISTEN   0x2
 Wait for incoming connections. More...
 
#define RTSP_FLAG_CUSTOM_IO   0x4
 Do all IO via the AVIOContext. More...
 
#define RTSP_FLAG_RTCP_TO_SOURCE   0x8
 Send RTCP packets to the source address of received packets. More...
 
#define RTSP_FLAG_PREFER_TCP   0x10
 Try RTP via TCP first if possible. More...
 
#define RTSP_FLAG_SATIP_RAW   0x20
 Export SAT>IP stream as raw MPEG-TS. More...
 

Enumerations

enum  RTSPLowerTransport {
  RTSP_LOWER_TRANSPORT_UDP = 0, RTSP_LOWER_TRANSPORT_TCP = 1, RTSP_LOWER_TRANSPORT_UDP_MULTICAST = 2, RTSP_LOWER_TRANSPORT_NB,
  RTSP_LOWER_TRANSPORT_HTTP = 8, RTSP_LOWER_TRANSPORT_HTTPS, RTSP_LOWER_TRANSPORT_CUSTOM = 16
}
 Network layer over which RTP/etc packet data will be transported. More...
 
enum  RTSPTransport { RTSP_TRANSPORT_RTP, RTSP_TRANSPORT_RDT, RTSP_TRANSPORT_RAW, RTSP_TRANSPORT_NB }
 Packet profile of the data that we will be receiving. More...
 
enum  RTSPControlTransport { RTSP_MODE_PLAIN, RTSP_MODE_TUNNEL }
 Transport mode for the RTSP data. More...
 
enum  RTSPClientState { RTSP_STATE_IDLE, RTSP_STATE_STREAMING, RTSP_STATE_PAUSED, RTSP_STATE_SEEKING }
 Client state, i.e. More...
 
enum  RTSPServerType {
  RTSP_SERVER_RTP, RTSP_SERVER_REAL, RTSP_SERVER_WMS, RTSP_SERVER_SATIP,
  RTSP_SERVER_NB
}
 Identify particular servers that require special handling, such as standards-incompliant "Transport:" lines in the SETUP request. More...
 

Functions

void ff_rtsp_parse_line (AVFormatContext *s, RTSPMessageHeader *reply, const char *buf, RTSPState *rt, const char *method)
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
int ff_rtsp_skip_packet (AVFormatContext *s)
 Skip a RTP/TCP interleaved packet. More...
 
int ff_rtsp_connect (AVFormatContext *s)
 Connect to the RTSP server and set up the individual media streams. More...
 
void ff_rtsp_close_streams (AVFormatContext *s)
 Close and free all streams within the RTSP (de)muxer. More...
 
void ff_rtsp_close_connections (AVFormatContext *s)
 Close all connection handles within the RTSP (de)muxer. More...
 
int ff_rtsp_setup_input_streams (AVFormatContext *s, RTSPMessageHeader *reply)
 Get the description of the stream and set up the RTSPStream child objects. More...
 
int ff_rtsp_setup_output_streams (AVFormatContext *s, const char *addr)
 Announce the stream to the server and set up the RTSPStream child objects for each media stream. More...
 
int ff_rtsp_parse_streaming_commands (AVFormatContext *s)
 Parse RTSP commands (OPTIONS, PAUSE and TEARDOWN) during streaming in listen mode. More...
 
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. More...
 
int ff_rtsp_tcp_read_packet (AVFormatContext *s, RTSPStream **prtsp_st, uint8_t *buf, int buf_size)
 Receive one RTP packet from an TCP interleaved RTSP stream. More...
 
int ff_rtsp_tcp_write_packet (AVFormatContext *s, RTSPStream *rtsp_st)
 Send buffered packets over TCP. More...
 
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). More...
 
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. More...
 
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...
 
int ff_rtsp_open_transport_ctx (AVFormatContext *s, RTSPStream *rtsp_st)
 Open RTSP transport context. More...
 

Variables

const AVOption ff_rtsp_options []
 

Macro Definition Documentation

◆ RTSP_DEFAULT_PORT

#define RTSP_DEFAULT_PORT   554

Definition at line 75 of file rtsp.h.

◆ RTSPS_DEFAULT_PORT

#define RTSPS_DEFAULT_PORT   322

Definition at line 76 of file rtsp.h.

◆ RTSP_MAX_TRANSPORTS

#define RTSP_MAX_TRANSPORTS   8

Definition at line 77 of file rtsp.h.

◆ RTSP_DEFAULT_AUDIO_SAMPLERATE

#define RTSP_DEFAULT_AUDIO_SAMPLERATE   44100

Definition at line 78 of file rtsp.h.

◆ RTSP_RTP_PORT_MIN

#define RTSP_RTP_PORT_MIN   5000

Definition at line 79 of file rtsp.h.

◆ RTSP_RTP_PORT_MAX

#define RTSP_RTP_PORT_MAX   65000

Definition at line 80 of file rtsp.h.

◆ SDP_MAX_SIZE

#define SDP_MAX_SIZE   16384

Definition at line 81 of file rtsp.h.

◆ RTSP_FLAG_FILTER_SRC

#define RTSP_FLAG_FILTER_SRC   0x1

Filter incoming UDP packets - receive packets only from the right source address and port.

Definition at line 424 of file rtsp.h.

◆ RTSP_FLAG_LISTEN

#define RTSP_FLAG_LISTEN   0x2

Wait for incoming connections.

Definition at line 427 of file rtsp.h.

◆ RTSP_FLAG_CUSTOM_IO

#define RTSP_FLAG_CUSTOM_IO   0x4

Do all IO via the AVIOContext.

Definition at line 428 of file rtsp.h.

◆ RTSP_FLAG_RTCP_TO_SOURCE

#define RTSP_FLAG_RTCP_TO_SOURCE   0x8

Send RTCP packets to the source address of received packets.

Definition at line 429 of file rtsp.h.

◆ RTSP_FLAG_PREFER_TCP

#define RTSP_FLAG_PREFER_TCP   0x10

Try RTP via TCP first if possible.

Definition at line 431 of file rtsp.h.

◆ RTSP_FLAG_SATIP_RAW

#define RTSP_FLAG_SATIP_RAW   0x20

Export SAT>IP stream as raw MPEG-TS.

Definition at line 432 of file rtsp.h.

Enumeration Type Documentation

◆ RTSPLowerTransport

Network layer over which RTP/etc packet data will be transported.

Enumerator
RTSP_LOWER_TRANSPORT_UDP 

UDP/unicast.

RTSP_LOWER_TRANSPORT_TCP 

TCP; interleaved in RTSP.

RTSP_LOWER_TRANSPORT_UDP_MULTICAST 

UDP/multicast.

RTSP_LOWER_TRANSPORT_NB 
RTSP_LOWER_TRANSPORT_HTTP 

HTTP tunneled - not a proper transport mode as such, only for use via AVOptions.

RTSP_LOWER_TRANSPORT_HTTPS 

HTTPS tunneled.

RTSP_LOWER_TRANSPORT_CUSTOM 

Custom IO - not a public option for lower_transport_mask, but set in the SDP demuxer based on a flag.

Definition at line 39 of file rtsp.h.

◆ RTSPTransport

Packet profile of the data that we will be receiving.

Real servers commonly send RDT (although they can sometimes send RTP as well), whereas most others will send RTP.

Enumerator
RTSP_TRANSPORT_RTP 

Standards-compliant RTP.

RTSP_TRANSPORT_RDT 

Realmedia Data Transport.

RTSP_TRANSPORT_RAW 

Raw data (over UDP)

RTSP_TRANSPORT_NB 

Definition at line 59 of file rtsp.h.

◆ RTSPControlTransport

Transport mode for the RTSP data.

This may be plain, or tunneled, which is done over HTTP.

Enumerator
RTSP_MODE_PLAIN 

Normal RTSP.

RTSP_MODE_TUNNEL 

RTSP over HTTP (tunneling)

Definition at line 70 of file rtsp.h.

◆ RTSPClientState

Client state, i.e.

whether we are currently receiving data (PLAYING) or setup-but-not-receiving (PAUSED). State can be changed in applications by calling av_read_play/pause().

Enumerator
RTSP_STATE_IDLE 

not initialized

RTSP_STATE_STREAMING 

initialized and sending/receiving data

RTSP_STATE_PAUSED 

initialized, but not receiving data

RTSP_STATE_SEEKING 

initialized, requesting a seek

Definition at line 202 of file rtsp.h.

◆ RTSPServerType

Identify particular servers that require special handling, such as standards-incompliant "Transport:" lines in the SETUP request.

Enumerator
RTSP_SERVER_RTP 

Standards-compliant RTP-server.

RTSP_SERVER_REAL 

Realmedia-style server.

RTSP_SERVER_WMS 

Windows Media server.

RTSP_SERVER_SATIP 

SAT>IP server.

RTSP_SERVER_NB 

Definition at line 213 of file rtsp.h.

Function Documentation

◆ ff_rtsp_parse_line()

void ff_rtsp_parse_line ( AVFormatContext s,
RTSPMessageHeader reply,
const char *  buf,
RTSPState rt,
const char *  method 
)

Referenced by rtsp_read_request().

◆ ff_rtsp_send_cmd_async()

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.

See also
rtsp_send_cmd_with_content_async

Referenced by rtsp_read_close(), rtsp_read_packet(), and rtsp_write_close().

◆ ff_rtsp_send_cmd_with_content()

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.

Parameters
sRTSP (de)muxer context
methodthe method for the request
urlthe target url for the request
headersextra header lines to include in the request
replypointer where the RTSP message header will be stored
content_ptrpointer where the RTSP message body, if any, will be stored (length is in reply)
send_contentif non-null, the data to send as request body content
send_content_lengththe length of the send_content data, or 0 if send_content is null
Returns
zero if success, nonzero otherwise

Referenced by ff_rtsp_setup_output_streams().

◆ ff_rtsp_send_cmd()

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.

See also
rtsp_send_cmd_with_content

Referenced by ff_rtsp_setup_input_streams(), rtsp_read_packet(), rtsp_read_pause(), rtsp_read_play(), and rtsp_write_record().

◆ ff_rtsp_read_reply()

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.

Parameters
sRTSP (de)muxer context
replypointer where the RTSP message header will be stored
content_ptrpointer where the RTSP message body, if any, will be stored (length is in reply)
return_on_interleaved_datawhether 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.
methodthe RTSP method this is a reply to. This affects how some response headers are acted upon. May be NULL.
Returns
1 if a data packets is ready to be received, -1 on error, and 0 on success.

Referenced by ff_rtsp_tcp_read_packet(), and rtsp_write_packet().

◆ ff_rtsp_skip_packet()

int ff_rtsp_skip_packet ( AVFormatContext s)

Skip a RTP/TCP interleaved packet.

Returns
0 on success, < 0 on failure.

Referenced by rtsp_write_packet().

◆ ff_rtsp_connect()

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.

Parameters
sRTSP (de)muxer context
Returns
0 on success, < 0 on error. Cleans up all allocations done within the function on error.

Referenced by rtsp_read_header(), and rtsp_write_header().

◆ 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_close_connections()

void ff_rtsp_close_connections ( AVFormatContext s)

Close all connection handles within the RTSP (de)muxer.

Parameters
sRTSP (de)muxer context

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

◆ ff_rtsp_setup_input_streams()

int ff_rtsp_setup_input_streams ( AVFormatContext s,
RTSPMessageHeader reply 
)

Get the description of the stream and set up the RTSPStream child objects.

The Require: attribute is needed for proper streaming from Realmedia servers.

Definition at line 614 of file rtspdec.c.

◆ ff_rtsp_setup_output_streams()

int ff_rtsp_setup_output_streams ( AVFormatContext s,
const char *  addr 
)

Announce the stream to the server and set up the RTSPStream child objects for each media stream.

Definition at line 47 of file rtspenc.c.

◆ ff_rtsp_parse_streaming_commands()

int ff_rtsp_parse_streaming_commands ( AVFormatContext s)

Parse RTSP commands (OPTIONS, PAUSE and TEARDOWN) during streaming in listen mode.

Definition at line 485 of file rtspdec.c.

◆ ff_sdp_parse()

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.

Referenced by ff_rtsp_setup_input_streams(), and rtsp_read_announce().

◆ ff_rtsp_tcp_read_packet()

int ff_rtsp_tcp_read_packet ( AVFormatContext s,
RTSPStream **  prtsp_st,
uint8_t *  buf,
int  buf_size 
)

Receive one RTP packet from an TCP interleaved RTSP stream.

Definition at line 785 of file rtspdec.c.

◆ ff_rtsp_tcp_write_packet()

int ff_rtsp_tcp_write_packet ( AVFormatContext s,
RTSPStream rtsp_st 
)

Send buffered packets over TCP.

Definition at line 143 of file rtspenc.c.

Referenced by ff_rtsp_undo_setup(), and rtsp_write_packet().

◆ ff_rtsp_fetch_packet()

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).

Referenced by rtsp_read_packet().

◆ ff_rtsp_make_setup_request()

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.

Returns
0 on success, <0 on error, 1 if protocol is unavailable

Referenced by resetup_tcp().

◆ 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_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[]

Definition at line 86 of file rtsp.c.