FFmpeg
Macros | Functions | Variables
rtpdec.c File Reference
#include "libavutil/mathematics.h"
#include "libavutil/avstring.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem.h"
#include "libavutil/time.h"
#include "libavcodec/bytestream.h"
#include "avformat.h"
#include "network.h"
#include "srtp.h"
#include "url.h"
#include "rtpdec.h"
#include "rtpdec_formats.h"
#include "internal.h"

Go to the source code of this file.

Macros

#define MIN_FEEDBACK_INTERVAL   200000 /* 200 ms in us */
 
#define RTP_SEQ_MOD   (1 << 16)
 

Functions

static const RTPDynamicProtocolHandlerrtp_handler_iterate (void **opaque)
 Iterate over all registered rtp dynamic protocol handlers. More...
 
const RTPDynamicProtocolHandlerff_rtp_handler_find_by_name (const char *name, enum AVMediaType codec_type)
 Find a registered rtp dynamic protocol handler with the specified name. More...
 
const RTPDynamicProtocolHandlerff_rtp_handler_find_by_id (int id, enum AVMediaType codec_type)
 Find a registered rtp dynamic protocol handler with a matching codec ID. More...
 
static int rtcp_parse_packet (RTPDemuxContext *s, const unsigned char *buf, int len)
 
static void rtp_init_statistics (RTPStatistics *s, uint16_t base_sequence)
 
static void rtp_init_sequence (RTPStatistics *s, uint16_t seq)
 
static int rtp_valid_packet_in_sequence (RTPStatistics *s, uint16_t seq)
 
static void rtcp_update_jitter (RTPStatistics *s, uint32_t sent_timestamp, uint32_t arrival_timestamp)
 
int ff_rtp_check_and_send_back_rr (RTPDemuxContext *s, URLContext *fd, AVIOContext *avio, int count)
 some rtp servers assume client is dead if they don't hear from them... More...
 
void ff_rtp_send_punch_packets (URLContext *rtp_handle)
 Send a dummy packet on both port pairs to set up the connection state in potential NAT routers, so that we're able to receive packets. More...
 
static int find_missing_packets (RTPDemuxContext *s, uint16_t *first_missing, uint16_t *missing_mask)
 
int ff_rtp_send_rtcp_feedback (RTPDemuxContext *s, URLContext *fd, AVIOContext *avio)
 
static int opus_write_extradata (AVCodecParameters *codecpar)
 
RTPDemuxContextff_rtp_parse_open (AVFormatContext *s1, AVStream *st, int payload_type, int queue_size)
 open a new RTP parse context for stream 'st'. More...
 
void ff_rtp_parse_set_dynamic_protocol (RTPDemuxContext *s, PayloadContext *ctx, const RTPDynamicProtocolHandler *handler)
 
void ff_rtp_parse_set_crypto (RTPDemuxContext *s, const char *suite, const char *params)
 
static int rtp_set_prft (RTPDemuxContext *s, AVPacket *pkt, uint32_t timestamp)
 
static void finalize_packet (RTPDemuxContext *s, AVPacket *pkt, uint32_t timestamp)
 This was the second switch in rtp_parse packet. More...
 
static int rtp_parse_packet_internal (RTPDemuxContext *s, AVPacket *pkt, const uint8_t *buf, int len)
 
void ff_rtp_reset_packet_queue (RTPDemuxContext *s)
 
static int enqueue_packet (RTPDemuxContext *s, uint8_t *buf, int len)
 
static int has_next_packet (RTPDemuxContext *s)
 
int64_t ff_rtp_queued_packet_time (RTPDemuxContext *s)
 
static int rtp_parse_queued_packet (RTPDemuxContext *s, AVPacket *pkt)
 
static int rtp_parse_one_packet (RTPDemuxContext *s, AVPacket *pkt, uint8_t **bufptr, int len)
 
int ff_rtp_parse_packet (RTPDemuxContext *s, AVPacket *pkt, uint8_t **bufptr, int len)
 Parse an RTP or RTCP packet directly sent as a buffer. More...
 
void ff_rtp_parse_close (RTPDemuxContext *s)
 
int ff_parse_fmtp (AVFormatContext *s, AVStream *stream, PayloadContext *data, const char *p, int(*parse_fmtp)(AVFormatContext *s, AVStream *stream, PayloadContext *data, const char *attr, const char *value))
 
int ff_rtp_finalize_packet (AVPacket *pkt, AVIOContext **dyn_buf, int stream_idx)
 Close the dynamic buffer and make a packet from it. More...
 

Variables

static const RTPDynamicProtocolHandler l24_dynamic_handler
 
static const RTPDynamicProtocolHandler gsm_dynamic_handler
 
static const RTPDynamicProtocolHandler realmedia_mp3_dynamic_handler
 
static const RTPDynamicProtocolHandler speex_dynamic_handler
 
static const RTPDynamicProtocolHandler opus_dynamic_handler
 
static const RTPDynamicProtocolHandler t140_dynamic_handler
 
const RTPDynamicProtocolHandler ff_rdt_video_handler
 
const RTPDynamicProtocolHandler ff_rdt_audio_handler
 
const RTPDynamicProtocolHandler ff_rdt_live_video_handler
 
const RTPDynamicProtocolHandler ff_rdt_live_audio_handler
 
static const RTPDynamicProtocolHandler *const rtp_dynamic_protocol_handler_list []
 

Macro Definition Documentation

◆ MIN_FEEDBACK_INTERVAL

#define MIN_FEEDBACK_INTERVAL   200000 /* 200 ms in us */

Definition at line 38 of file rtpdec.c.

◆ RTP_SEQ_MOD

#define RTP_SEQ_MOD   (1 << 16)

Definition at line 221 of file rtpdec.c.

Function Documentation

◆ rtp_handler_iterate()

static const RTPDynamicProtocolHandler* rtp_handler_iterate ( void **  opaque)
static

Iterate over all registered rtp dynamic protocol handlers.

Parameters
opaquea pointer where libavformat will store the iteration state. Must point to NULL to start the iteration.
Returns
the next registered rtp dynamic protocol handler or NULL when the iteration is finished

Definition at line 148 of file rtpdec.c.

Referenced by ff_rtp_handler_find_by_id(), and ff_rtp_handler_find_by_name().

◆ ff_rtp_handler_find_by_name()

const RTPDynamicProtocolHandler* ff_rtp_handler_find_by_name ( const char *  name,
enum AVMediaType  codec_type 
)

Find a registered rtp dynamic protocol handler with the specified name.

Parameters
namename of the requested rtp dynamic protocol handler
Returns
A rtp dynamic protocol handler if one was found, NULL otherwise.

Definition at line 159 of file rtpdec.c.

◆ ff_rtp_handler_find_by_id()

const RTPDynamicProtocolHandler* ff_rtp_handler_find_by_id ( int  id,
enum AVMediaType  codec_type 
)

Find a registered rtp dynamic protocol handler with a matching codec ID.

Parameters
idAVCodecID of the requested rtp dynamic protocol handler.
Returns
A rtp dynamic protocol handler if one was found, NULL otherwise.

Definition at line 173 of file rtpdec.c.

◆ rtcp_parse_packet()

static int rtcp_parse_packet ( RTPDemuxContext s,
const unsigned char *  buf,
int  len 
)
static

Definition at line 186 of file rtpdec.c.

Referenced by rtp_parse_one_packet().

◆ rtp_init_statistics()

static void rtp_init_statistics ( RTPStatistics s,
uint16_t  base_sequence 
)
static

Definition at line 223 of file rtpdec.c.

Referenced by ff_rtp_parse_open().

◆ rtp_init_sequence()

static void rtp_init_sequence ( RTPStatistics s,
uint16_t  seq 
)
static

Definition at line 234 of file rtpdec.c.

Referenced by rtp_valid_packet_in_sequence().

◆ rtp_valid_packet_in_sequence()

static int rtp_valid_packet_in_sequence ( RTPStatistics s,
uint16_t  seq 
)
static

Definition at line 248 of file rtpdec.c.

Referenced by rtp_parse_packet_internal().

◆ rtcp_update_jitter()

static void rtcp_update_jitter ( RTPStatistics s,
uint32_t  sent_timestamp,
uint32_t  arrival_timestamp 
)
static

Definition at line 294 of file rtpdec.c.

Referenced by rtp_parse_one_packet().

◆ ff_rtp_check_and_send_back_rr()

int ff_rtp_check_and_send_back_rr ( RTPDemuxContext s,
URLContext fd,
AVIOContext avio,
int  count 
)

some rtp servers assume client is dead if they don't hear from them...

so we send a Receiver Report to the provided URLContext or AVIOContext (we don't have access to the rtcp handle from here)

Definition at line 312 of file rtpdec.c.

◆ ff_rtp_send_punch_packets()

void ff_rtp_send_punch_packets ( URLContext rtp_handle)

Send a dummy packet on both port pairs to set up the connection state in potential NAT routers, so that we're able to receive packets.

Note, this only works if the NAT router doesn't remap ports. This isn't a standardized procedure, but it works in many cases in practice.

The same routine is used with RDT too, even if RDT doesn't use normal RTP packets otherwise.

Definition at line 415 of file rtpdec.c.

Referenced by rtsp_read_play().

◆ find_missing_packets()

static int find_missing_packets ( RTPDemuxContext s,
uint16_t *  first_missing,
uint16_t *  missing_mask 
)
static

Definition at line 439 of file rtpdec.c.

Referenced by ff_rtp_send_rtcp_feedback().

◆ ff_rtp_send_rtcp_feedback()

int ff_rtp_send_rtcp_feedback ( RTPDemuxContext s,
URLContext fd,
AVIOContext avio 
)

Definition at line 469 of file rtpdec.c.

◆ opus_write_extradata()

static int opus_write_extradata ( AVCodecParameters codecpar)
static

Definition at line 533 of file rtpdec.c.

Referenced by ff_rtp_parse_open().

◆ ff_rtp_parse_open()

RTPDemuxContext* ff_rtp_parse_open ( AVFormatContext s1,
AVStream st,
int  payload_type,
int  queue_size 
)

open a new RTP parse context for stream 'st'.

'st' can be NULL for MPEG-2 TS streams.

Definition at line 574 of file rtpdec.c.

Referenced by ff_rtsp_open_transport_ctx().

◆ ff_rtp_parse_set_dynamic_protocol()

void ff_rtp_parse_set_dynamic_protocol ( RTPDemuxContext s,
PayloadContext ctx,
const RTPDynamicProtocolHandler handler 
)

Definition at line 621 of file rtpdec.c.

Referenced by ff_rtsp_open_transport_ctx().

◆ ff_rtp_parse_set_crypto()

void ff_rtp_parse_set_crypto ( RTPDemuxContext s,
const char *  suite,
const char *  params 
)

Definition at line 628 of file rtpdec.c.

Referenced by ff_rtsp_open_transport_ctx().

◆ rtp_set_prft()

static int rtp_set_prft ( RTPDemuxContext s,
AVPacket pkt,
uint32_t  timestamp 
)
static

Definition at line 635 of file rtpdec.c.

Referenced by finalize_packet().

◆ finalize_packet()

static void finalize_packet ( RTPDemuxContext s,
AVPacket pkt,
uint32_t  timestamp 
)
static

This was the second switch in rtp_parse packet.

Normalizes time, if required, sets stream_index, etc.

Definition at line 657 of file rtpdec.c.

Referenced by rtp_parse_one_packet(), and rtp_parse_packet_internal().

◆ rtp_parse_packet_internal()

static int rtp_parse_packet_internal ( RTPDemuxContext s,
AVPacket pkt,
const uint8_t *  buf,
int  len 
)
static

Definition at line 698 of file rtpdec.c.

Referenced by rtp_parse_one_packet(), and rtp_parse_queued_packet().

◆ ff_rtp_reset_packet_queue()

void ff_rtp_reset_packet_queue ( RTPDemuxContext s)

Definition at line 781 of file rtpdec.c.

Referenced by ff_rtp_parse_close(), and rtsp_read_play().

◆ enqueue_packet()

static int enqueue_packet ( RTPDemuxContext s,
uint8_t *  buf,
int  len 
)
static

Definition at line 794 of file rtpdec.c.

Referenced by rtp_parse_one_packet().

◆ has_next_packet()

static int has_next_packet ( RTPDemuxContext s)
static

Definition at line 821 of file rtpdec.c.

Referenced by ff_rtp_parse_packet(), and rtp_parse_queued_packet().

◆ ff_rtp_queued_packet_time()

int64_t ff_rtp_queued_packet_time ( RTPDemuxContext s)

Definition at line 826 of file rtpdec.c.

◆ rtp_parse_queued_packet()

static int rtp_parse_queued_packet ( RTPDemuxContext s,
AVPacket pkt 
)
static

Definition at line 831 of file rtpdec.c.

Referenced by ff_rtp_parse_packet(), and rtp_parse_one_packet().

◆ rtp_parse_one_packet()

static int rtp_parse_one_packet ( RTPDemuxContext s,
AVPacket pkt,
uint8_t **  bufptr,
int  len 
)
static

Definition at line 858 of file rtpdec.c.

Referenced by ff_rtp_parse_packet().

◆ ff_rtp_parse_packet()

int ff_rtp_parse_packet ( RTPDemuxContext s,
AVPacket pkt,
uint8_t **  bufptr,
int  len 
)

Parse an RTP or RTCP packet directly sent as a buffer.

Parameters
sRTP parse context.
pktreturned packet
bufptrpointer to the input buffer or NULL to read the next packets
lenbuffer len
Returns
0 if a packet is returned, 1 if a packet is returned and more can follow (use buf as NULL to read the next). -1 if no packet (error or no more packet).

Definition at line 945 of file rtpdec.c.

◆ ff_rtp_parse_close()

void ff_rtp_parse_close ( RTPDemuxContext s)

Definition at line 958 of file rtpdec.c.

Referenced by ff_rtsp_undo_setup(), and rtsp_read_setup().

◆ ff_parse_fmtp()

int ff_parse_fmtp ( AVFormatContext s,
AVStream stream,
PayloadContext data,
const char *  p,
int(*)(AVFormatContext *s, AVStream *stream, PayloadContext *data, const char *attr, const char *value parse_fmtp 
)

◆ ff_rtp_finalize_packet()

int ff_rtp_finalize_packet ( AVPacket pkt,
AVIOContext **  dyn_buf,
int  stream_idx 
)

Variable Documentation

◆ l24_dynamic_handler

const RTPDynamicProtocolHandler l24_dynamic_handler
static
Initial value:
= {
.enc_name = "L24",
.codec_type = AVMEDIA_TYPE_AUDIO,
.codec_id = AV_CODEC_ID_PCM_S24BE,
}

Definition at line 40 of file rtpdec.c.

◆ gsm_dynamic_handler

const RTPDynamicProtocolHandler gsm_dynamic_handler
static
Initial value:
= {
.enc_name = "GSM",
.codec_type = AVMEDIA_TYPE_AUDIO,
.codec_id = AV_CODEC_ID_GSM,
}

Definition at line 46 of file rtpdec.c.

◆ realmedia_mp3_dynamic_handler

const RTPDynamicProtocolHandler realmedia_mp3_dynamic_handler
static
Initial value:
= {
.enc_name = "X-MP3-draft-00",
.codec_type = AVMEDIA_TYPE_AUDIO,
.codec_id = AV_CODEC_ID_MP3ADU,
}

Definition at line 52 of file rtpdec.c.

◆ speex_dynamic_handler

const RTPDynamicProtocolHandler speex_dynamic_handler
static
Initial value:
= {
.enc_name = "speex",
.codec_type = AVMEDIA_TYPE_AUDIO,
.codec_id = AV_CODEC_ID_SPEEX,
}

Definition at line 58 of file rtpdec.c.

◆ opus_dynamic_handler

const RTPDynamicProtocolHandler opus_dynamic_handler
static
Initial value:
= {
.enc_name = "opus",
.codec_type = AVMEDIA_TYPE_AUDIO,
.codec_id = AV_CODEC_ID_OPUS,
}

Definition at line 64 of file rtpdec.c.

◆ t140_dynamic_handler

const RTPDynamicProtocolHandler t140_dynamic_handler
static
Initial value:
= {
.enc_name = "t140",
.codec_type = AVMEDIA_TYPE_SUBTITLE,
.codec_id = AV_CODEC_ID_TEXT,
}

Definition at line 70 of file rtpdec.c.

◆ ff_rdt_video_handler

const RTPDynamicProtocolHandler ff_rdt_video_handler

◆ ff_rdt_audio_handler

const RTPDynamicProtocolHandler ff_rdt_audio_handler

◆ ff_rdt_live_video_handler

const RTPDynamicProtocolHandler ff_rdt_live_video_handler

◆ ff_rdt_live_audio_handler

const RTPDynamicProtocolHandler ff_rdt_live_audio_handler

◆ rtp_dynamic_protocol_handler_list

const RTPDynamicProtocolHandler* const rtp_dynamic_protocol_handler_list[]
static

Definition at line 81 of file rtpdec.c.

Referenced by rtp_handler_iterate().

AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:204
AV_CODEC_ID_MP3ADU
@ AV_CODEC_ID_MP3ADU
Definition: codec_id.h:459
AV_CODEC_ID_SPEEX
@ AV_CODEC_ID_SPEEX
Definition: codec_id.h:481
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AV_CODEC_ID_GSM
@ AV_CODEC_ID_GSM
as in Berlin toast format
Definition: codec_id.h:464
AV_CODEC_ID_OPUS
@ AV_CODEC_ID_OPUS
Definition: codec_id.h:506
AV_CODEC_ID_TEXT
@ AV_CODEC_ID_TEXT
raw UTF-8 text
Definition: codec_id.h:558
AV_CODEC_ID_PCM_S24BE
@ AV_CODEC_ID_PCM_S24BE
Definition: codec_id.h:347