RTCP processing. More...
#include <math.h>
#include <stdlib.h>
#include <sys/time.h>
#include "debug.h"
#include "rtp.h"
#include "rtcp.h"
#include "utils.h"
Macros | |
#define | LINK_QUALITY_FILTER_K 3.0 |
Typedefs | |
typedef enum janus_rtp_packet_status | janus_rtp_packet_status |
Enumerations | |
enum | janus_rtp_packet_status { janus_rtp_packet_status_notreceived = 0 , janus_rtp_packet_status_smalldelta = 1 , janus_rtp_packet_status_largeornegativedelta = 2 , janus_rtp_packet_status_reserved = 3 } |
Functions | |
gboolean | janus_is_rtcp (char *buf, guint len) |
Helper method to demultiplex RTCP from other protocols. | |
int | janus_rtcp_parse (janus_rtcp_context *ctx, char *packet, int len) |
Method to parse/validate an RTCP message. | |
guint32 | janus_rtcp_get_sender_ssrc (char *packet, int len) |
Method to quickly retrieve the sender SSRC (needed for demuxing RTCP in BUNDLE) | |
guint32 | janus_rtcp_get_receiver_ssrc (char *packet, int len) |
Method to quickly retrieve the received SSRC (needed for demuxing RTCP in BUNDLE) | |
void | janus_rtcp_swap_report_blocks (char *packet, int len, uint32_t rtx_ssrc) |
Method to swap Report Blocks and move media RB in first position in case rtx SSRC comes first. | |
gboolean | janus_rtcp_check_len (janus_rtcp_header *rtcp, int len) |
Method to check that a RTCP packet size is at least the minimum necessary (8 bytes) and to validate the length field against the actual size. | |
gboolean | janus_rtcp_check_sr (janus_rtcp_header *rtcp, int len) |
Method to check if a RTCP packet could contain a Sender Report. | |
gboolean | janus_rtcp_check_rr (janus_rtcp_header *rtcp, int len) |
Method to check if a RTCP packet could contain a Receiver Report. | |
gboolean | janus_rtcp_check_fci (janus_rtcp_header *rtcp, int len, int sizeof_fci) |
Method to check if a RTCP packet could contain a Feedback Message with a defined FCI size. | |
gboolean | janus_rtcp_check_remb (janus_rtcp_header *rtcp, int len) |
Method to check if a RTCP packet could contain an AFB REMB Message. | |
int | janus_rtcp_fix_ssrc (janus_rtcp_context *ctx, char *packet, int len, int fixssrc, uint32_t newssrcl, uint32_t newssrcr) |
Method to fix an RTCP message (http://tools.ietf.org/html/draft-ietf-straw-b2bua-rtcp-00) | |
char * | janus_rtcp_filter (char *packet, int len, int *newlen) |
Method to filter an outgoing RTCP message (http://tools.ietf.org/html/draft-ietf-straw-b2bua-rtcp-00) | |
int | janus_rtcp_process_incoming_rtp (janus_rtcp_context *ctx, char *packet, int len, gboolean rfc4588_pkt, gboolean rfc4588_enabled, gboolean retransmissions_disabled, GHashTable *clock_rates) |
Method to quickly process the header of an incoming RTP packet to update the associated RTCP context. | |
uint32_t | janus_rtcp_context_get_rtt (janus_rtcp_context *ctx) |
Method to retrieve the estimated round-trip time from an existing RTCP context. | |
uint32_t | janus_rtcp_context_get_in_link_quality (janus_rtcp_context *ctx) |
Method to retrieve inbound link quality from an existing RTCP context. | |
uint32_t | janus_rtcp_context_get_in_media_link_quality (janus_rtcp_context *ctx) |
Method to retrieve inbound media link quality from an existing RTCP context. | |
uint32_t | janus_rtcp_context_get_out_link_quality (janus_rtcp_context *ctx) |
Method to retrieve outbound link quality from an existing RTCP context. | |
uint32_t | janus_rtcp_context_get_out_media_link_quality (janus_rtcp_context *ctx) |
Method to retrieve outbound media link quality from an existing RTCP context. | |
int32_t | janus_rtcp_context_get_lost_all (janus_rtcp_context *ctx, gboolean remote) |
Method to retrieve the total number of lost packets from an existing RTCP context. | |
uint32_t | janus_rtcp_context_get_jitter (janus_rtcp_context *ctx, gboolean remote) |
Method to retrieve the jitter from an existing RTCP context. | |
int | janus_rtcp_report_block (janus_rtcp_context *ctx, janus_report_block *rb) |
Method to fill in a Report Block in a Receiver Report. | |
int | janus_rtcp_fix_report_data (char *packet, int len, uint32_t base_ts, uint32_t base_ts_prev, uint32_t ssrc_peer, uint32_t ssrc_local, uint32_t ssrc_expected, gboolean video) |
Method to fix incoming RTCP SR and RR data. | |
gboolean | janus_rtcp_has_bye (char *packet, int len) |
Method to check whether an RTCP message contains a BYE message. | |
gboolean | janus_rtcp_has_fir (char *packet, int len) |
Method to check whether an RTCP message contains a FIR request. | |
gboolean | janus_rtcp_has_pli (char *packet, int len) |
Method to check whether an RTCP message contains a PLI request. | |
GSList * | janus_rtcp_get_nacks (char *packet, int len) |
Method to parse an RTCP NACK message. | |
int | janus_rtcp_remove_nacks (char *packet, int len) |
Method to remove an RTCP NACK message. | |
uint32_t | janus_rtcp_get_remb (char *packet, int len) |
Inspect an existing RTCP REMB message to retrieve the reported bitrate. | |
int | janus_rtcp_cap_remb (char *packet, int len, uint32_t bitrate) |
Method to modify an existing RTCP REMB message to cap the reported bitrate. | |
int | janus_rtcp_sdes_cname (char *packet, int len, const char *cname, int cnamelen) |
Method to generate a new RTCP SDES message. | |
int | janus_rtcp_remb (char *packet, int len, uint32_t bitrate) |
Method to generate a new RTCP REMB message to cap the reported bitrate. | |
int | janus_rtcp_remb_ssrcs (char *packet, int len, uint32_t bitrate, uint8_t numssrc) |
Method to generate a new RTCP REMB message to cap the reported bitrate, but for more SSRCs. | |
int | janus_rtcp_fir (char *packet, int len, int *seqnr) |
Method to generate a new RTCP FIR message to request a key frame. | |
int | janus_rtcp_pli (char *packet, int len) |
Method to generate a new RTCP PLI message to request a key frame. | |
int | janus_rtcp_nacks (char *packet, int len, GSList *nacks) |
Method to generate a new RTCP NACK message to report lost packets. | |
int | janus_rtcp_transport_wide_cc_feedback (char *packet, size_t size, guint32 ssrc, guint32 media, guint8 feedback_packet_count, GQueue *transport_wide_cc_stats) |
Method to generate a new RTCP transport wide message to report reception stats. | |
RTCP processing.
Implementation (based on the oRTP structures) of the RTCP messages. RTCP messages coming through the server are parsed and, if needed (according to http://tools.ietf.org/html/draft-ietf-straw-b2bua-rtcp-00), fixed before they are sent to the peers (e.g., to fix SSRCs that may have been changed by the server). Methods to generate FIR messages and generate/cap REMB messages are provided as well.
#define LINK_QUALITY_FILTER_K 3.0 |
typedef enum janus_rtp_packet_status janus_rtp_packet_status |
gboolean janus_is_rtcp | ( | char * | buf, |
guint | len ) |
Helper method to demultiplex RTCP from other protocols.
[in] | buf | Buffer to inspect |
[in] | len | Length of the buffer to inspect |
int janus_rtcp_cap_remb | ( | char * | packet, |
int | len, | ||
uint32_t | bitrate ) |
Method to modify an existing RTCP REMB message to cap the reported bitrate.
[in] | packet | The message data |
[in] | len | The message data length in bytes |
[in] | bitrate | The new bitrate to report (e.g., 128000) |
gboolean janus_rtcp_check_fci | ( | janus_rtcp_header * | rtcp, |
int | len, | ||
int | sizeof_fci ) |
Method to check if a RTCP packet could contain a Feedback Message with a defined FCI size.
[in] | rtcp | The RTCP message |
[in] | len | The message data length in bytes |
[in] | sizeof_fci | The size of a FCI entry |
gboolean janus_rtcp_check_len | ( | janus_rtcp_header * | rtcp, |
int | len ) |
Method to check that a RTCP packet size is at least the minimum necessary (8 bytes) and to validate the length field against the actual size.
[in] | rtcp | The RTCP message |
[in] | len | The message data length in bytes |
gboolean janus_rtcp_check_remb | ( | janus_rtcp_header * | rtcp, |
int | len ) |
Method to check if a RTCP packet could contain an AFB REMB Message.
[in] | rtcp | The RTCP message |
[in] | len | The message data length in bytes |
gboolean janus_rtcp_check_rr | ( | janus_rtcp_header * | rtcp, |
int | len ) |
Method to check if a RTCP packet could contain a Receiver Report.
[in] | rtcp | The RTCP message |
[in] | len | The message data length in bytes |
gboolean janus_rtcp_check_sr | ( | janus_rtcp_header * | rtcp, |
int | len ) |
Method to check if a RTCP packet could contain a Sender Report.
[in] | rtcp | The RTCP message |
[in] | len | The message data length in bytes |
uint32_t janus_rtcp_context_get_in_link_quality | ( | janus_rtcp_context * | ctx | ) |
Method to retrieve inbound link quality from an existing RTCP context.
[in] | ctx | The RTCP context to query |
uint32_t janus_rtcp_context_get_in_media_link_quality | ( | janus_rtcp_context * | ctx | ) |
Method to retrieve inbound media link quality from an existing RTCP context.
[in] | ctx | The RTCP context to query |
uint32_t janus_rtcp_context_get_jitter | ( | janus_rtcp_context * | ctx, |
gboolean | remote ) |
Method to retrieve the jitter from an existing RTCP context.
[in] | ctx | The RTCP context to query |
[in] | remote | Whether we're querying the remote (provided by peer) or local (computed by Janus) info |
int32_t janus_rtcp_context_get_lost_all | ( | janus_rtcp_context * | ctx, |
gboolean | remote ) |
Method to retrieve the total number of lost packets from an existing RTCP context.
[in] | ctx | The RTCP context to query |
[in] | remote | Whether we're querying the remote (provided by peer) or local (computed by Janus) info |
uint32_t janus_rtcp_context_get_out_link_quality | ( | janus_rtcp_context * | ctx | ) |
Method to retrieve outbound link quality from an existing RTCP context.
[in] | ctx | The RTCP context to query |
uint32_t janus_rtcp_context_get_out_media_link_quality | ( | janus_rtcp_context * | ctx | ) |
Method to retrieve outbound media link quality from an existing RTCP context.
[in] | ctx | The RTCP context to query |
uint32_t janus_rtcp_context_get_rtt | ( | janus_rtcp_context * | ctx | ) |
Method to retrieve the estimated round-trip time from an existing RTCP context.
[in] | ctx | The RTCP context to query |
char * janus_rtcp_filter | ( | char * | packet, |
int | len, | ||
int * | newlen ) |
Method to filter an outgoing RTCP message (http://tools.ietf.org/html/draft-ietf-straw-b2bua-rtcp-00)
[in] | packet | The message data |
[in] | len | The message data length in bytes |
[in,out] | newlen | The data length of the filtered RTCP message |
int janus_rtcp_fir | ( | char * | packet, |
int | len, | ||
int * | seqnr ) |
Method to generate a new RTCP FIR message to request a key frame.
[in] | packet | The buffer data (MUST be at least 20 chars) |
[in] | len | The message data length in bytes (MUST be 20) |
[in,out] | seqnr | The current FIR sequence number (will be incremented by the method) |
int janus_rtcp_fix_report_data | ( | char * | packet, |
int | len, | ||
uint32_t | base_ts, | ||
uint32_t | base_ts_prev, | ||
uint32_t | ssrc_peer, | ||
uint32_t | ssrc_local, | ||
uint32_t | ssrc_expected, | ||
gboolean | video ) |
Method to fix incoming RTCP SR and RR data.
[in] | packet | The message data |
[in] | len | The message data length in bytes |
[in] | base_ts | RTP context base timestamp to compute offset |
[in] | base_ts_prev | RTP context base timestamp to compute offset |
[in] | ssrc_peer | The remote SSRC in usage for this stream |
[in] | ssrc_local | The local SSRC in usage for this stream |
[in] | ssrc_expected | The expected SSRC for this RTCP packet |
[in] | video | Whether the RTCP packet contains report for video data |
int janus_rtcp_fix_ssrc | ( | janus_rtcp_context * | ctx, |
char * | packet, | ||
int | len, | ||
int | fixssrc, | ||
uint32_t | newssrcl, | ||
uint32_t | newssrcr ) |
Method to fix an RTCP message (http://tools.ietf.org/html/draft-ietf-straw-b2bua-rtcp-00)
[in] | ctx | RTCP context to update, if needed (optional) |
[in] | packet | The message data |
[in] | len | The message data length in bytes |
[in] | fixssrc | Whether the method needs to fix the message or just parse it |
[in] | newssrcl | The SSRC of the sender to put in the message |
[in] | newssrcr | The SSRC of the receiver to put in the message |
GSList * janus_rtcp_get_nacks | ( | char * | packet, |
int | len ) |
Method to parse an RTCP NACK message.
[in] | packet | The message data |
[in] | len | The message data length in bytes |
guint32 janus_rtcp_get_receiver_ssrc | ( | char * | packet, |
int | len ) |
Method to quickly retrieve the received SSRC (needed for demuxing RTCP in BUNDLE)
[in] | packet | The message data |
[in] | len | The message data length in bytes |
uint32_t janus_rtcp_get_remb | ( | char * | packet, |
int | len ) |
Inspect an existing RTCP REMB message to retrieve the reported bitrate.
[in] | packet | The message data |
[in] | len | The message data length in bytes |
guint32 janus_rtcp_get_sender_ssrc | ( | char * | packet, |
int | len ) |
Method to quickly retrieve the sender SSRC (needed for demuxing RTCP in BUNDLE)
[in] | packet | The message data |
[in] | len | The message data length in bytes |
gboolean janus_rtcp_has_bye | ( | char * | packet, |
int | len ) |
Method to check whether an RTCP message contains a BYE message.
[in] | packet | The message data |
[in] | len | The message data length in bytes |
gboolean janus_rtcp_has_fir | ( | char * | packet, |
int | len ) |
Method to check whether an RTCP message contains a FIR request.
[in] | packet | The message data |
[in] | len | The message data length in bytes |
gboolean janus_rtcp_has_pli | ( | char * | packet, |
int | len ) |
Method to check whether an RTCP message contains a PLI request.
[in] | packet | The message data |
[in] | len | The message data length in bytes |
int janus_rtcp_nacks | ( | char * | packet, |
int | len, | ||
GSList * | nacks ) |
Method to generate a new RTCP NACK message to report lost packets.
[in] | packet | The buffer data (MUST be at least 16 chars) |
[in] | len | The message data length in bytes (MUST be 16) |
[in] | nacks | List of packets to NACK |
int janus_rtcp_parse | ( | janus_rtcp_context * | ctx, |
char * | packet, | ||
int | len ) |
Method to parse/validate an RTCP message.
[in] | ctx | RTCP context to update, if needed (optional) |
[in] | packet | The message data |
[in] | len | The message data length in bytes |
int janus_rtcp_pli | ( | char * | packet, |
int | len ) |
Method to generate a new RTCP PLI message to request a key frame.
[in] | packet | The buffer data (MUST be at least 12 chars) |
[in] | len | The message data length in bytes (MUST be 12) |
int janus_rtcp_process_incoming_rtp | ( | janus_rtcp_context * | ctx, |
char * | packet, | ||
int | len, | ||
gboolean | rfc4588_pkt, | ||
gboolean | rfc4588_enabled, | ||
gboolean | retransmissions_disabled, | ||
GHashTable * | clock_rates ) |
Method to quickly process the header of an incoming RTP packet to update the associated RTCP context.
[in] | ctx | RTCP context to update, if needed (optional) |
[in] | packet | The RTP packet |
[in] | len | The packet data length in bytes |
[in] | rfc4588_pkt | True if this is a RTX packet |
[in] | rfc4588_enabled | True if this packet comes from a RTX enabled stream |
[in] | retransmissions_disabled | True if retransmissions are not supported at all for this stream |
[in] | clock_rates | Mapping between payload types and clock rates, if available |
int janus_rtcp_remb | ( | char * | packet, |
int | len, | ||
uint32_t | bitrate ) |
Method to generate a new RTCP REMB message to cap the reported bitrate.
[in] | packet | The buffer data (MUST be at least 24 chars) |
[in] | len | The message data length in bytes (MUST be 24) |
[in] | bitrate | The bitrate to report (e.g., 128000) |
int janus_rtcp_remb_ssrcs | ( | char * | packet, |
int | len, | ||
uint32_t | bitrate, | ||
uint8_t | numssrc ) |
Method to generate a new RTCP REMB message to cap the reported bitrate, but for more SSRCs.
[in] | packet | The buffer data (MUST be at least 24 chars) |
[in] | len | The message data length in bytes (MUST be 24) |
[in] | bitrate | The bitrate to report (e.g., 128000) |
[in] | numssrc | The number of SSRCs to include in the request |
int janus_rtcp_remove_nacks | ( | char * | packet, |
int | len ) |
Method to remove an RTCP NACK message.
[in] | packet | The message data |
[in] | len | The message data length in bytes |
int janus_rtcp_report_block | ( | janus_rtcp_context * | ctx, |
janus_report_block * | rb ) |
Method to fill in a Report Block in a Receiver Report.
[in] | ctx | The RTCP context to use for the report |
[in] | rb | Pointer to a valid report_block area of the RTCP data |
int janus_rtcp_sdes_cname | ( | char * | packet, |
int | len, | ||
const char * | cname, | ||
int | cnamelen ) |
Method to generate a new RTCP SDES message.
[in] | packet | The buffer data |
[in] | len | The buffer data length in bytes |
[in] | cname | The CNAME to write |
[in] | cnamelen | The CNAME data length in bytes |
void janus_rtcp_swap_report_blocks | ( | char * | packet, |
int | len, | ||
uint32_t | rtx_ssrc ) |
Method to swap Report Blocks and move media RB in first position in case rtx SSRC comes first.
[in] | packet | The message data |
[in] | len | The message data length in bytes |
[in] | rtx_ssrc | The rtx SSRC |
int janus_rtcp_transport_wide_cc_feedback | ( | char * | packet, |
size_t | len, | ||
guint32 | ssrc, | ||
guint32 | media, | ||
guint8 | feedback_packet_count, | ||
GQueue * | transport_wide_cc_stats ) |
Method to generate a new RTCP transport wide message to report reception stats.
[in] | packet | The buffer data (MUST be at least 16 chars) |
[in] | len | The message data length in bytes |
[in] | ssrc | SSRC of the origin stream |
[in] | media | SSRC of the destination stream |
[in] | feedback_packet_count | Feedback paccket count |
[in] | transport_wide_cc_stats | List of rtp packet reception stats |