RTP processing (headers) More...
#include <arpa/inet.h>
#include <endian.h>
#include <inttypes.h>
#include <string.h>
#include <glib.h>
#include <jansson.h>
Go to the source code of this file.
Data Structures | |
struct | rtp_header |
RTP Header (http://tools.ietf.org/html/rfc3550#section-5.1) More... | |
struct | janus_rtp_packet |
RTP packet. More... | |
struct | janus_rtp_header_extension |
RTP extension. More... | |
struct | janus_rtp_switching_context |
RTP context, in order to make sure SSRC changes result in coherent seq/ts increases. More... | |
struct | janus_rtp_simulcasting_context |
Helper struct for processing and tracking simulcast streams. More... | |
Macros | |
#define | RTP_HEADER_SIZE 12 |
#define | JANUS_RTP_EXTMAP_AUDIO_LEVEL "urn:ietf:params:rtp-hdrext:ssrc-audio-level" |
a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level More... | |
#define | JANUS_RTP_EXTMAP_TOFFSET "urn:ietf:params:rtp-hdrext:toffset" |
a=extmap:2 urn:ietf:params:rtp-hdrext:toffset More... | |
#define | JANUS_RTP_EXTMAP_ABS_SEND_TIME "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time" |
a=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time More... | |
#define | JANUS_RTP_EXTMAP_VIDEO_ORIENTATION "urn:3gpp:video-orientation" |
a=extmap:4 urn:3gpp:video-orientation More... | |
#define | JANUS_RTP_EXTMAP_TRANSPORT_WIDE_CC "http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01" |
a=extmap:5 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01 More... | |
#define | JANUS_RTP_EXTMAP_PLAYOUT_DELAY "http://www.webrtc.org/experiments/rtp-hdrext/playout-delay" |
a=extmap:6 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay More... | |
#define | JANUS_RTP_EXTMAP_MID "urn:ietf:params:rtp-hdrext:sdes:mid" |
a=extmap:3 urn:ietf:params:rtp-hdrext:sdes:mid More... | |
#define | JANUS_RTP_EXTMAP_RID "urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id" |
a=extmap:4 urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id More... | |
#define | JANUS_RTP_EXTMAP_REPAIRED_RID "urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id" |
a=extmap:5 urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id More... | |
#define | JANUS_RTP_EXTMAP_FRAME_MARKING "http://tools.ietf.org/html/draft-ietf-avtext-framemarking-07" |
a=extmap:8 http://tools.ietf.org/html/draft-ietf-avtext-framemarking-07 More... | |
#define | JANUS_RTP_EXTMAP_ENCRYPTED "urn:ietf:params:rtp-hdrext:encrypt" |
#define | RTP_AUDIO_SKEW_TH_MS 120 |
#define | RTP_VIDEO_SKEW_TH_MS 120 |
#define | SKEW_DETECTION_WAIT_TIME_SECS 10 |
Typedefs | |
typedef struct rtp_header | rtp_header |
RTP Header (http://tools.ietf.org/html/rfc3550#section-5.1) More... | |
typedef rtp_header | janus_rtp_header |
typedef struct janus_rtp_packet | janus_rtp_packet |
RTP packet. More... | |
typedef struct janus_rtp_header_extension | janus_rtp_header_extension |
RTP extension. More... | |
typedef enum janus_audiocodec | janus_audiocodec |
typedef enum janus_videocodec | janus_videocodec |
typedef struct janus_rtp_switching_context | janus_rtp_switching_context |
RTP context, in order to make sure SSRC changes result in coherent seq/ts increases. More... | |
typedef struct janus_rtp_simulcasting_context | janus_rtp_simulcasting_context |
Helper struct for processing and tracking simulcast streams. More... | |
Functions | |
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) |
gboolean | janus_is_rtp (char *buf, guint len) |
Helper method to demultiplex RTP from other protocols. More... | |
char * | janus_rtp_payload (char *buf, int len, int *plen) |
Helper to quickly access the RTP payload, skipping header and extensions. More... | |
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. More... | |
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. More... | |
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) More... | |
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) More... | |
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) More... | |
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) More... | |
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) More... | |
int | janus_rtp_header_extension_parse_framemarking (char *buf, int len, int id, janus_videocodec codec, uint8_t *tid) |
Helper to parse a frame-marking RTP extension (http://tools.ietf.org/html/draft-ietf-avtext-framemarking-07) More... | |
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) More... | |
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) More... | |
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) More... | |
void | janus_rtp_switching_context_reset (janus_rtp_switching_context *context) |
Set (or reset) the context fields to their default values. More... | |
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. More... | |
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. More... | |
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. More... | |
void | janus_rtp_simulcasting_context_reset (janus_rtp_simulcasting_context *context) |
Set (or reset) the context fields to their default values. More... | |
void | janus_rtp_simulcasting_prepare (json_t *simulcast, int *rid_ext_id, int *framemarking_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. More... | |
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. More... | |
RTP processing (headers)
#define JANUS_RTP_EXTMAP_ABS_SEND_TIME "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time" |
#define JANUS_RTP_EXTMAP_AUDIO_LEVEL "urn:ietf:params:rtp-hdrext:ssrc-audio-level" |
a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level
#define JANUS_RTP_EXTMAP_ENCRYPTED "urn:ietf:params:rtp-hdrext:encrypt" |
#define JANUS_RTP_EXTMAP_FRAME_MARKING "http://tools.ietf.org/html/draft-ietf-avtext-framemarking-07" |
#define JANUS_RTP_EXTMAP_MID "urn:ietf:params:rtp-hdrext:sdes:mid" |
a=extmap:3 urn:ietf:params:rtp-hdrext:sdes:mid
#define JANUS_RTP_EXTMAP_PLAYOUT_DELAY "http://www.webrtc.org/experiments/rtp-hdrext/playout-delay" |
#define JANUS_RTP_EXTMAP_REPAIRED_RID "urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id" |
a=extmap:5 urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id
#define JANUS_RTP_EXTMAP_RID "urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id" |
a=extmap:4 urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id
#define JANUS_RTP_EXTMAP_TOFFSET "urn:ietf:params:rtp-hdrext:toffset" |
a=extmap:2 urn:ietf:params:rtp-hdrext:toffset
#define JANUS_RTP_EXTMAP_TRANSPORT_WIDE_CC "http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01" |
#define JANUS_RTP_EXTMAP_VIDEO_ORIENTATION "urn:3gpp:video-orientation" |
a=extmap:4 urn:3gpp:video-orientation
#define RTP_AUDIO_SKEW_TH_MS 120 |
#define RTP_HEADER_SIZE 12 |
#define RTP_VIDEO_SKEW_TH_MS 120 |
#define SKEW_DETECTION_WAIT_TIME_SECS 10 |
typedef enum janus_audiocodec janus_audiocodec |
typedef rtp_header janus_rtp_header |
typedef struct janus_rtp_header_extension janus_rtp_header_extension |
RTP extension.
typedef struct janus_rtp_packet janus_rtp_packet |
RTP packet.
typedef struct janus_rtp_simulcasting_context janus_rtp_simulcasting_context |
Helper struct for processing and tracking simulcast streams.
typedef struct janus_rtp_switching_context janus_rtp_switching_context |
RTP context, in order to make sure SSRC changes result in coherent seq/ts increases.
typedef enum janus_videocodec janus_videocodec |
typedef struct rtp_header rtp_header |
RTP Header (http://tools.ietf.org/html/rfc3550#section-5.1)
enum janus_audiocodec |
enum janus_videocodec |
janus_audiocodec janus_audiocodec_from_name | ( | const char * | name | ) |
const char* janus_audiocodec_name | ( | janus_audiocodec | acodec | ) |
int janus_audiocodec_pt | ( | janus_audiocodec | acodec | ) |
gboolean janus_is_rtp | ( | char * | buf, |
guint | len | ||
) |
Helper method to demultiplex RTP from other protocols.
[in] | buf | Buffer to inspect |
[in] | len | Length of the buffer to inspect |
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.
sdp | The SDP to parse |
id | The extension id to look for |
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.
sdp | The SDP to parse |
extension | The extension namespace to look for |
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)
[in] | buf | The packet data |
[in] | len | The packet data length in bytes |
[in] | id | The extension ID to look for |
[out] | vad | Whether the encoder thinks there's voice activity |
[out] | level | The level value in dBov (0=max, 127=min) |
int janus_rtp_header_extension_parse_framemarking | ( | char * | buf, |
int | len, | ||
int | id, | ||
janus_videocodec | codec, | ||
uint8_t * | tid | ||
) |
Helper to parse a frame-marking RTP extension (http://tools.ietf.org/html/draft-ietf-avtext-framemarking-07)
[in] | buf | The packet data |
[in] | len | The packet data length in bytes |
[in] | id | The extension ID to look for |
[in] | codec | The video codec (as a janus_videocodec instance) the extension refers to |
[out] | tid | Temporal layer ID of the frame |
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)
[in] | buf | The packet data |
[in] | len | The packet data length in bytes |
[in] | id | The extension ID to look for |
[out] | sdes_item | Buffer where the RTP stream ID will be written |
[in] | sdes_len | Size of the input/output buffer |
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)
[in] | buf | The packet data |
[in] | len | The packet data length in bytes |
[in] | id | The extension ID to look for |
[out] | min_delay | The minimum delay value |
[out] | max_delay | The maximum delay value |
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)
[in] | buf | The packet data |
[in] | len | The packet data length in bytes |
[in] | id | The extension ID to look for |
[out] | sdes_item | Buffer where the RTP stream ID will be written |
[in] | sdes_len | Size of the input/output buffer |
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)
[in] | buf | The packet data |
[in] | len | The packet data length in bytes |
[in] | id | The extension ID to look for |
[out] | transSeqNum | Variable to read the transport wide sequence number in |
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)
[in] | buf | The packet data |
[in] | len | The packet data length in bytes |
[in] | id | The extension ID to look for |
[out] | c | The value of the Camera (C) bit |
[out] | f | The value of the Flip (F) bit |
[out] | r1 | The value of the first Rotation (R1) bit |
[out] | r0 | The value of the second Rotation (R0) bit |
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)
[in] | buf | The packet data |
[in] | len | The packet data length in bytes |
[in] | id | The extension ID to look for and replace |
[in] | new_id | The new value for the extension ID |
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)
[in] | buf | The packet data |
[in] | len | The packet data length in bytes |
[in] | id | The extension ID to look for |
[out] | transSeqNum | Transport wide sequence number to set |
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.
[in] | header | The RTP header to update |
[in] | context | The context to use as a reference |
[in] | video | Whether this is an audio or a video packet |
[in] | step | deprecated The expected timestamp step |
char* janus_rtp_payload | ( | char * | buf, |
int | len, | ||
int * | plen | ||
) |
Helper to quickly access the RTP payload, skipping header and extensions.
[in] | buf | The packet data |
[in] | len | The packet data length in bytes |
[out] | plen | The payload data length in bytes |
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.
changed_substream
, changed_temporal
and need_pli
properties, and updates them according to the decisions made after processinf the packet [in] | context | The simulcasting context to use |
[in] | buf | The RTP packet to process |
[in] | len | The length of the RTP packet (header, extension and payload) |
[in] | ssrcs | The simulcast SSRCs to refer to (may be updated if rids are involved) |
[in] | rids | The simulcast rids to refer to, if any |
[in] | vcodec | Video codec of the RTP payload |
[in] | sc | RTP switching context to refer to, if any (only needed for VP8 and dropping temporal layers) |
void janus_rtp_simulcasting_context_reset | ( | janus_rtp_simulcasting_context * | context | ) |
Set (or reset) the context fields to their default values.
[in] | context | The context to (re)set |
void janus_rtp_simulcasting_prepare | ( | json_t * | simulcast, |
int * | rid_ext_id, | ||
int * | framemarking_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.
[in] | simulcast | JSON object containing SSRCs and rids |
[in] | rid_ext_id | The rid RTP extension ID to set, if any |
[in] | framemarking_ext_id | The frame marking RTP extension ID to set, if any |
[in] | ssrcs | The list of simulcast SSRCs to update, if any |
[in] | rids | The list of rids to update, if any (items will be allocated) |
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.
[in] | header | The RTP header to update |
[in] | context | The context to use as a reference |
[in] | now | The packet arrival monotonic time |
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.
[in] | header | The RTP header to update |
[in] | context | The context to use as a reference |
[in] | now | The packet arrival monotonic time |
void janus_rtp_switching_context_reset | ( | janus_rtp_switching_context * | context | ) |
Set (or reset) the context fields to their default values.
[in] | context | The context to (re)set |
janus_videocodec janus_videocodec_from_name | ( | const char * | name | ) |
const char* janus_videocodec_name | ( | janus_videocodec | vcodec | ) |
int janus_videocodec_pt | ( | janus_videocodec | vcodec | ) |