Fork me on GitHub
Loading...
Searching...
No Matches
Macros | Functions
rtp.c File Reference

RTP processing. More...

#include <string.h>
#include "rtp.h"
#include "rtpsrtp.h"
#include "debug.h"
#include "utils.h"
Include dependency graph for rtp.c:

Macros

#define OPUS_PT   111
 
#define MULTIOPUS_PT   OPUS_PT
 
#define OPUSRED_PT   120
 
#define ISAC32_PT   104
 
#define ISAC16_PT   103
 
#define PCMU_PT   0
 
#define PCMA_PT   8
 
#define G722_PT   9
 
#define VP8_PT   96
 
#define VP9_PT   101
 
#define H264_PT   107
 
#define AV1_PT   98
 
#define H265_PT   100
 

Functions

gboolean janus_is_rtp (char *buf, guint len)
 Helper method to demultiplex RTP from other protocols.
 
char * janus_rtp_payload (char *buf, int len, int *plen)
 Helper to quickly access the RTP payload, skipping header and extensions.
 
int janus_rtp_header_extension_get_id (const char *sdp, const char *extension)
 Ugly and dirty helper to quickly get the id associated with an RTP extension (extmap) in an SDP.
 
const char * janus_rtp_header_extension_get_from_id (const char *sdp, int id)
 Ugly and dirty helper to quickly get the RTP extension namespace associated with an id (extmap) in an SDP.
 
int janus_rtp_header_extension_parse_audio_level (char *buf, int len, int id, gboolean *vad, int *level)
 Helper to parse a ssrc-audio-level RTP extension (https://tools.ietf.org/html/rfc6464)
 
int janus_rtp_header_extension_parse_video_orientation (char *buf, int len, int id, gboolean *c, gboolean *f, gboolean *r1, gboolean *r0)
 Helper to parse a video-orientation RTP extension (http://www.3gpp.org/ftp/Specs/html-info/26114.htm)
 
int janus_rtp_header_extension_parse_playout_delay (char *buf, int len, int id, uint16_t *min_delay, uint16_t *max_delay)
 Helper to parse a playout-delay RTP extension (https://webrtc.org/experiments/rtp-hdrext/playout-delay)
 
int janus_rtp_header_extension_parse_mid (char *buf, int len, int id, char *sdes_item, int sdes_len)
 Helper to parse a sdes-mid RTP extension (https://tools.ietf.org/html/draft-ietf-mmusic-sdp-bundle-negotiation-54)
 
int janus_rtp_header_extension_parse_rid (char *buf, int len, int id, char *sdes_item, int sdes_len)
 Helper to parse a rtp-stream-id RTP extension (https://tools.ietf.org/html/draft-ietf-avtext-rid-09)
 
int janus_rtp_header_extension_parse_dependency_desc (char *buf, int len, int id, uint8_t *dd_item, int *dd_len)
 Helper to parse a dependency descriptor RTP extension (https://aomediacodec.github.io/av1-rtp-spec/#dependency-descriptor-rtp-header-extension)
 
int janus_rtp_header_extension_parse_abs_sent_time (char *buf, int len, int id, uint32_t *abs_ts)
 Helper to parse an abs-send-time RTP extension (http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time)
 
int janus_rtp_header_extension_set_abs_send_time (char *buf, int len, int id, uint32_t abs_ts)
 Helper to set an abs-send-time RTP extension (http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time)
 
int janus_rtp_header_extension_parse_transport_wide_cc (char *buf, int len, int id, uint16_t *transSeqNum)
 Helper to parse a transport wide sequence number (https://tools.ietf.org/html/draft-holmer-rmcat-transport-wide-cc-extensions-01)
 
int janus_rtp_header_extension_set_transport_wide_cc (char *buf, int len, int id, uint16_t transSeqNum)
 Helper to set a transport wide sequence number (https://tools.ietf.org/html/draft-holmer-rmcat-transport-wide-cc-extensions-01)
 
int janus_rtp_header_extension_replace_id (char *buf, int len, int id, int new_id)
 Helper to replace the ID of an RTP extension with a different one (e.g., to turn a repaired-rtp-stream-id into a rtp-stream-id after a successful rtx)
 
void janus_rtp_switching_context_reset (janus_rtp_switching_context *context)
 Set (or reset) the context fields to their default values.
 
int janus_rtp_skew_compensate_audio (janus_rtp_header *header, janus_rtp_switching_context *context, gint64 now)
 Use the context info to compensate for audio source skew, if needed.
 
int janus_rtp_skew_compensate_video (janus_rtp_header *header, janus_rtp_switching_context *context, gint64 now)
 Use the context info to compensate for video source skew, if needed.
 
void janus_rtp_header_update (janus_rtp_header *header, janus_rtp_switching_context *context, gboolean video, int step)
 Use the context info to update the RTP header of a packet, if needed.
 
const char * janus_srtp_error_str (int error)
 Helper method to get a string representation of a libsrtp error code.
 
const char * janus_audiocodec_name (janus_audiocodec acodec)
 
janus_audiocodec janus_audiocodec_from_name (const char *name)
 
int janus_audiocodec_pt (janus_audiocodec acodec)
 
const char * janus_videocodec_name (janus_videocodec vcodec)
 
janus_videocodec janus_videocodec_from_name (const char *name)
 
int janus_videocodec_pt (janus_videocodec vcodec)
 
void janus_rtp_simulcasting_context_reset (janus_rtp_simulcasting_context *context)
 Set (or reset) the context fields to their default values.
 
void janus_rtp_simulcasting_prepare (json_t *simulcast, int *rid_ext_id, uint32_t *ssrcs, char **rids)
 Helper method to prepare the simulcasting info (rids and/or SSRCs) from the simulcast object the core passes to plugins for new PeerConnections.
 
gboolean janus_rtp_simulcasting_context_process_rtp (janus_rtp_simulcasting_context *context, char *buf, int len, uint32_t *ssrcs, char **rids, janus_videocodec vcodec, janus_rtp_switching_context *sc)
 Process an RTP packet, and decide whether this should be relayed or not, updating the context accordingly.
 
void janus_av1_svc_context_reset (janus_av1_svc_context *context)
 Set (or reset) the context fields to their default values.
 
gboolean janus_av1_svc_context_process_dd (janus_av1_svc_context *context, uint8_t *dd, int dd_len, uint8_t *template_id)
 Process a Dependency Descriptor payload, updating the SVC context accordingly.
 

Detailed Description

RTP processing.

Author
Lorenzo Miniero loren.nosp@m.zo@m.nosp@m.eetec.nosp@m.ho.c.nosp@m.om

Implementation of the RTP header. Since the server does not much more than relaying frames around, the only thing we're interested in is the RTP header and how to get its payload, and parsing extensions.

Protocols

Macro Definition Documentation

◆ AV1_PT

#define AV1_PT   98

◆ G722_PT

#define G722_PT   9

◆ H264_PT

#define H264_PT   107

◆ H265_PT

#define H265_PT   100

◆ ISAC16_PT

#define ISAC16_PT   103

◆ ISAC32_PT

#define ISAC32_PT   104

◆ MULTIOPUS_PT

#define MULTIOPUS_PT   OPUS_PT

◆ OPUS_PT

#define OPUS_PT   111

◆ OPUSRED_PT

#define OPUSRED_PT   120

◆ PCMA_PT

#define PCMA_PT   8

◆ PCMU_PT

#define PCMU_PT   0

◆ VP8_PT

#define VP8_PT   96

◆ VP9_PT

#define VP9_PT   101

Function Documentation

◆ janus_audiocodec_from_name()

janus_audiocodec janus_audiocodec_from_name ( const char *  name)

◆ janus_audiocodec_name()

const char * janus_audiocodec_name ( janus_audiocodec  acodec)

◆ janus_audiocodec_pt()

int janus_audiocodec_pt ( janus_audiocodec  acodec)

◆ janus_av1_svc_context_process_dd()

gboolean janus_av1_svc_context_process_dd ( janus_av1_svc_context context,
uint8_t *  dd,
int  dd_len,
uint8_t *  template_id 
)

Process a Dependency Descriptor payload, updating the SVC context accordingly.

Note
At the moment, this code is quite naive, as it mostly looks at the target spatial/temporal layers, and the one written in the Dependency Descriptor data. In the future, this should become more sophisticated, and use additional information like dependency chains and stuff like that
Parameters
[in]contextThe av1svc context to use
[in]ddPointer to the Dependency Descriptor data
[in]dd_lenThe length of the Dependendy Descriptor data
[out]template_idPointer to the ID of the template referenced in this packet
Returns
TRUE if the packet is valid, FALSE if it should be dropped instead

◆ janus_av1_svc_context_reset()

void janus_av1_svc_context_reset ( janus_av1_svc_context context)

Set (or reset) the context fields to their default values.

Parameters
[in]contextThe context to (re)set

◆ janus_is_rtp()

gboolean janus_is_rtp ( char *  buf,
guint  len 
)

Helper method to demultiplex RTP from other protocols.

Parameters
[in]bufBuffer to inspect
[in]lenLength of the buffer to inspect

◆ janus_rtp_header_extension_get_from_id()

const char * janus_rtp_header_extension_get_from_id ( const char *  sdp,
int  id 
)

Ugly and dirty helper to quickly get the RTP extension namespace associated with an id (extmap) in an SDP.

Note
This only looks for the extensions we know about, those defined in rtp.h
Parameters
sdpThe SDP to parse
idThe extension id to look for
Returns
The extension namespace, if found, NULL otherwise

◆ janus_rtp_header_extension_get_id()

int janus_rtp_header_extension_get_id ( const char *  sdp,
const char *  extension 
)

Ugly and dirty helper to quickly get the id associated with an RTP extension (extmap) in an SDP.

Parameters
sdpThe SDP to parse
extensionThe extension namespace to look for
Returns
The extension id, if found, -1 otherwise

◆ janus_rtp_header_extension_parse_abs_sent_time()

int janus_rtp_header_extension_parse_abs_sent_time ( char *  buf,
int  len,
int  id,
uint32_t *  abs_ts 
)

Helper to parse an abs-send-time RTP extension (http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time)

Parameters
[in]bufThe packet data
[in]lenThe packet data length in bytes
[in]idThe extension ID to look for
[out]abs_tsVariable where the parsed abs-send-time value will be stored
Returns
0 if found, -1 otherwise

◆ janus_rtp_header_extension_parse_audio_level()

int janus_rtp_header_extension_parse_audio_level ( char *  buf,
int  len,
int  id,
gboolean *  vad,
int *  level 
)

Helper to parse a ssrc-audio-level RTP extension (https://tools.ietf.org/html/rfc6464)

Note
Browsers apparently always set the VAD to 1, so it's unreliable and should be ignored: only use this method if you're interested in the audio-level value itself.
Parameters
[in]bufThe packet data
[in]lenThe packet data length in bytes
[in]idThe extension ID to look for
[out]vadWhether the encoder thinks there's voice activity
[out]levelThe level value in dBov (0=max, 127=min)
Returns
0 if found, -1 otherwise

◆ janus_rtp_header_extension_parse_dependency_desc()

int janus_rtp_header_extension_parse_dependency_desc ( char *  buf,
int  len,
int  id,
uint8_t *  dd_item,
int *  dd_len 
)

Helper to parse a dependency descriptor RTP extension (https://aomediacodec.github.io/av1-rtp-spec/#dependency-descriptor-rtp-header-extension)

Parameters
[in]bufThe packet data
[in]lenThe packet data length in bytes
[in]idThe extension ID to look for
[out]dd_itemBuffer where the dependency descriptor will be written
[out]dd_lenSize of the input/output buffer, will be updated with the size of the data
Returns
0 if found, -1 otherwise

◆ janus_rtp_header_extension_parse_mid()

int janus_rtp_header_extension_parse_mid ( char *  buf,
int  len,
int  id,
char *  sdes_item,
int  sdes_len 
)

Helper to parse a sdes-mid RTP extension (https://tools.ietf.org/html/draft-ietf-mmusic-sdp-bundle-negotiation-54)

Parameters
[in]bufThe packet data
[in]lenThe packet data length in bytes
[in]idThe extension ID to look for
[out]sdes_itemBuffer where the RTP stream ID will be written
[in]sdes_lenSize of the input/output buffer
Returns
0 if found, -1 otherwise

◆ janus_rtp_header_extension_parse_playout_delay()

int janus_rtp_header_extension_parse_playout_delay ( char *  buf,
int  len,
int  id,
uint16_t *  min_delay,
uint16_t *  max_delay 
)

Helper to parse a playout-delay RTP extension (https://webrtc.org/experiments/rtp-hdrext/playout-delay)

Parameters
[in]bufThe packet data
[in]lenThe packet data length in bytes
[in]idThe extension ID to look for
[out]min_delayThe minimum delay value
[out]max_delayThe maximum delay value
Returns
0 if found, -1 otherwise

◆ janus_rtp_header_extension_parse_rid()

int janus_rtp_header_extension_parse_rid ( char *  buf,
int  len,
int  id,
char *  sdes_item,
int  sdes_len 
)

Helper to parse a rtp-stream-id RTP extension (https://tools.ietf.org/html/draft-ietf-avtext-rid-09)

Parameters
[in]bufThe packet data
[in]lenThe packet data length in bytes
[in]idThe extension ID to look for
[out]sdes_itemBuffer where the RTP stream ID will be written
[in]sdes_lenSize of the input/output buffer
Returns
0 if found, -1 otherwise

◆ janus_rtp_header_extension_parse_transport_wide_cc()

int janus_rtp_header_extension_parse_transport_wide_cc ( char *  buf,
int  len,
int  id,
uint16_t *  transSeqNum 
)

Helper to parse a transport wide sequence number (https://tools.ietf.org/html/draft-holmer-rmcat-transport-wide-cc-extensions-01)

Parameters
[in]bufThe packet data
[in]lenThe packet data length in bytes
[in]idThe extension ID to look for
[out]transSeqNumVariable to read the transport wide sequence number in
Returns
0 if found, -1 otherwise

◆ janus_rtp_header_extension_parse_video_orientation()

int janus_rtp_header_extension_parse_video_orientation ( char *  buf,
int  len,
int  id,
gboolean *  c,
gboolean *  f,
gboolean *  r1,
gboolean *  r0 
)

Helper to parse a video-orientation RTP extension (http://www.3gpp.org/ftp/Specs/html-info/26114.htm)

Parameters
[in]bufThe packet data
[in]lenThe packet data length in bytes
[in]idThe extension ID to look for
[out]cThe value of the Camera (C) bit
[out]fThe value of the Flip (F) bit
[out]r1The value of the first Rotation (R1) bit
[out]r0The value of the second Rotation (R0) bit
Returns
0 if found, -1 otherwise

◆ janus_rtp_header_extension_replace_id()

int janus_rtp_header_extension_replace_id ( char *  buf,
int  len,
int  id,
int  new_id 
)

Helper to replace the ID of an RTP extension with a different one (e.g., to turn a repaired-rtp-stream-id into a rtp-stream-id after a successful rtx)

Parameters
[in]bufThe packet data
[in]lenThe packet data length in bytes
[in]idThe extension ID to look for and replace
[in]new_idThe new value for the extension ID
Returns
0 if found, a negative integer otherwise

◆ janus_rtp_header_extension_set_abs_send_time()

int janus_rtp_header_extension_set_abs_send_time ( char *  buf,
int  len,
int  id,
uint32_t  abs_ts 
)

Helper to set an abs-send-time RTP extension (http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time)

Parameters
[in]bufThe packet data
[in]lenThe packet data length in bytes
[in]idThe extension ID to look for
[out]abs_tsAbsolute Send Time value to set
Returns
0 if found, -1 otherwise

◆ janus_rtp_header_extension_set_transport_wide_cc()

int janus_rtp_header_extension_set_transport_wide_cc ( char *  buf,
int  len,
int  id,
uint16_t  transSeqNum 
)

Helper to set a transport wide sequence number (https://tools.ietf.org/html/draft-holmer-rmcat-transport-wide-cc-extensions-01)

Parameters
[in]bufThe packet data
[in]lenThe packet data length in bytes
[in]idThe extension ID to look for
[out]transSeqNumTransport wide sequence number to set
Returns
0 if found, -1 otherwise

◆ janus_rtp_header_update()

void janus_rtp_header_update ( janus_rtp_header header,
janus_rtp_switching_context context,
gboolean  video,
int  step 
)

Use the context info to update the RTP header of a packet, if needed.

Parameters
[in]headerThe RTP header to update
[in]contextThe context to use as a reference
[in]videoWhether this is an audio or a video packet
[in]stepdeprecated The expected timestamp step

◆ janus_rtp_payload()

char * janus_rtp_payload ( char *  buf,
int  len,
int *  plen 
)

Helper to quickly access the RTP payload, skipping header and extensions.

Parameters
[in]bufThe packet data
[in]lenThe packet data length in bytes
[out]plenThe payload data length in bytes
Returns
A pointer to where the payload data starts, or NULL otherwise; plen is also set accordingly

◆ janus_rtp_simulcasting_context_process_rtp()

gboolean janus_rtp_simulcasting_context_process_rtp ( janus_rtp_simulcasting_context context,
char *  buf,
int  len,
uint32_t *  ssrcs,
char **  rids,
janus_videocodec  vcodec,
janus_rtp_switching_context sc 
)

Process an RTP packet, and decide whether this should be relayed or not, updating the context accordingly.

Note
Calling this method resets the changed_substream , changed_temporal and need_pli properties, and updates them according to the decisions made after processing the packet
Parameters
[in]contextThe simulcasting context to use
[in]bufThe RTP packet to process
[in]lenThe length of the RTP packet (header, extension and payload)
[in]ssrcsThe simulcast SSRCs to refer to (may be updated if rids are involved)
[in]ridsThe simulcast rids to refer to, if any
[in]vcodecVideo codec of the RTP payload
[in]scRTP switching context to refer to, if any (only needed for VP8 and dropping temporal layers)
Returns
TRUE if the packet should be relayed, FALSE if it should be dropped instead

◆ janus_rtp_simulcasting_context_reset()

void janus_rtp_simulcasting_context_reset ( janus_rtp_simulcasting_context context)

Set (or reset) the context fields to their default values.

Parameters
[in]contextThe context to (re)set

◆ janus_rtp_simulcasting_prepare()

void janus_rtp_simulcasting_prepare ( json_t simulcast,
int *  rid_ext_id,
uint32_t *  ssrcs,
char **  rids 
)

Helper method to prepare the simulcasting info (rids and/or SSRCs) from the simulcast object the core passes to plugins for new PeerConnections.

Parameters
[in]simulcastJSON object containing SSRCs and rids
[in]rid_ext_idThe rid RTP extension ID to set, if any
[in]ssrcsThe list of simulcast SSRCs to update, if any
[in]ridsThe list of rids to update, if any (items will be allocated)

◆ janus_rtp_skew_compensate_audio()

int janus_rtp_skew_compensate_audio ( janus_rtp_header header,
janus_rtp_switching_context context,
gint64  now 
)

Use the context info to compensate for audio source skew, if needed.

Parameters
[in]headerThe RTP header to update
[in]contextThe context to use as a reference
[in]nowThe packet arrival monotonic time
Returns
0 if no compensation is needed, -N if a N packets drop must be performed, N if a N sequence numbers jump has been performed

◆ janus_rtp_skew_compensate_video()

int janus_rtp_skew_compensate_video ( janus_rtp_header header,
janus_rtp_switching_context context,
gint64  now 
)

Use the context info to compensate for video source skew, if needed.

Parameters
[in]headerThe RTP header to update
[in]contextThe context to use as a reference
[in]nowThe packet arrival monotonic time
Returns
0 if no compensation is needed, -N if a N packets drop must be performed, N if a N sequence numbers jump has been performed

◆ janus_rtp_switching_context_reset()

void janus_rtp_switching_context_reset ( janus_rtp_switching_context context)

Set (or reset) the context fields to their default values.

Parameters
[in]contextThe context to (re)set

◆ janus_srtp_error_str()

const char * janus_srtp_error_str ( int  error)

Helper method to get a string representation of a libsrtp error code.

Parameters
[in]errorThe libsrtp error code
Returns
A string representation of the error code

◆ janus_videocodec_from_name()

janus_videocodec janus_videocodec_from_name ( const char *  name)

◆ janus_videocodec_name()

const char * janus_videocodec_name ( janus_videocodec  vcodec)

◆ janus_videocodec_pt()

int janus_videocodec_pt ( janus_videocodec  vcodec)