Fork me on GitHub
Macros | Typedefs | Enumerations | Functions
rtcp.c File Reference

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"
Include dependency graph for rtcp.c:

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

int janus_rtcp_parse (janus_rtcp_context *ctx, char *packet, int len)
 Method to parse/validate an RTCP message. More...
 
guint32 janus_rtcp_get_sender_ssrc (char *packet, int len)
 Method to quickly retrieve the sender SSRC (needed for demuxing RTCP in BUNDLE) More...
 
guint32 janus_rtcp_get_receiver_ssrc (char *packet, int len)
 Method to quickly retrieve the received SSRC (needed for demuxing RTCP in BUNDLE) More...
 
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) More...
 
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) More...
 
int janus_rtcp_process_incoming_rtp (janus_rtcp_context *ctx, char *packet, int len)
 Method to quickly process the header of an incoming RTP packet to update the associated RTCP context. More...
 
uint32_t janus_rtcp_context_get_rtt (janus_rtcp_context *ctx)
 Method to retrieve the estimated round-trip time from an existing RTCP context. More...
 
uint32_t janus_rtcp_context_get_in_link_quality (janus_rtcp_context *ctx)
 Method to retrieve inbound link quality from an existing RTCP context. More...
 
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. More...
 
uint32_t janus_rtcp_context_get_out_link_quality (janus_rtcp_context *ctx)
 Method to retrieve outbound link quality from an existing RTCP context. More...
 
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. More...
 
uint32_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. More...
 
uint32_t janus_rtcp_context_get_jitter (janus_rtcp_context *ctx, gboolean remote)
 Method to retrieve the jitter from an existing RTCP context. More...
 
int janus_rtcp_report_block (janus_rtcp_context *ctx, janus_report_block *rb)
 Method to fill in a Report Block in a Receiver Report. More...
 
gboolean janus_rtcp_parse_lost_info (char *packet, int len, uint32_t *lost, int *fraction)
 Method to quickly fetch the lost packets info from an RR packet, if present. More...
 
gboolean janus_rtcp_has_bye (char *packet, int len)
 Method to check whether an RTCP message contains a BYE message. More...
 
gboolean janus_rtcp_has_fir (char *packet, int len)
 Method to check whether an RTCP message contains a FIR request. More...
 
gboolean janus_rtcp_has_pli (char *packet, int len)
 Method to check whether an RTCP message contains a PLI request. More...
 
GSList * janus_rtcp_get_nacks (char *packet, int len)
 Method to parse an RTCP NACK message. More...
 
int janus_rtcp_remove_nacks (char *packet, int len)
 Method to remove an RTCP NACK message. More...
 
uint32_t janus_rtcp_get_remb (char *packet, int len)
 Inspect an existing RTCP REMB message to retrieve the reported bitrate. More...
 
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. More...
 
int janus_rtcp_sdes_cname (char *packet, int len, const char *cname, int cnamelen)
 Method to generate a new RTCP SDES message. More...
 
int janus_rtcp_remb (char *packet, int len, uint32_t bitrate)
 Method to generate a new RTCP REMB message to cap the reported bitrate. More...
 
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. More...
 
int janus_rtcp_fir (char *packet, int len, int *seqnr)
 Method to generate a new RTCP FIR message to request a key frame. More...
 
int janus_rtcp_fir_legacy (char *packet, int len, int *seqnr)
 Method to generate a new legacy RTCP FIR (RFC2032) message to request a key frame. More...
 
int janus_rtcp_pli (char *packet, int len)
 Method to generate a new RTCP PLI message to request a key frame. More...
 
int janus_rtcp_nacks (char *packet, int len, GSList *nacks)
 Method to generate a new RTCP NACK message to report lost packets. More...
 
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. More...
 

Detailed Description

RTCP processing.

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

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.

Protocols

Macro Definition Documentation

#define LINK_QUALITY_FILTER_K   3.0

Typedef Documentation

Enumeration Type Documentation

Enumerator
janus_rtp_packet_status_notreceived 
janus_rtp_packet_status_smalldelta 
janus_rtp_packet_status_largeornegativedelta 
janus_rtp_packet_status_reserved 

Function Documentation

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.

Parameters
[in]packetThe message data
[in]lenThe message data length in bytes
[in]bitrateThe new bitrate to report (e.g., 128000)
Returns
0 in case of success, -1 on errors
uint32_t janus_rtcp_context_get_in_link_quality ( janus_rtcp_context ctx)

Method to retrieve inbound link quality from an existing RTCP context.

Parameters
[in]ctxThe RTCP context to query
Returns
Inbound link quality estimation
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.

Parameters
[in]ctxThe RTCP context to query
Returns
Inbound media link quality estimation
uint32_t janus_rtcp_context_get_jitter ( janus_rtcp_context ctx,
gboolean  remote 
)

Method to retrieve the jitter from an existing RTCP context.

Parameters
[in]ctxThe RTCP context to query
[in]remoteWhether we're quering the remote (provided by peer) or local (computed by Janus) info
Returns
The computed jitter
uint32_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.

Parameters
[in]ctxThe RTCP context to query
[in]remoteWhether we're quering the remote (provided by peer) or local (computed by Janus) info
Returns
The total number of lost packets
uint32_t janus_rtcp_context_get_out_link_quality ( janus_rtcp_context ctx)

Method to retrieve outbound link quality from an existing RTCP context.

Parameters
[in]ctxThe RTCP context to query
Returns
Outbound link quality estimation
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.

Parameters
[in]ctxThe RTCP context to query
Returns
Outbound media link quality estimation
uint32_t janus_rtcp_context_get_rtt ( janus_rtcp_context ctx)

Method to retrieve the estimated round-trip time from an existing RTCP context.

Parameters
[in]ctxThe RTCP context to query
Returns
The estimated round-trip time
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)

Parameters
[in]packetThe message data
[in]lenThe message data length in bytes
[in,out]newlenThe data length of the filtered RTCP message
Returns
A pointer to the new RTCP message data, NULL in case all messages have been filtered out
int janus_rtcp_fir ( char *  packet,
int  len,
int *  seqnr 
)

Method to generate a new RTCP FIR message to request a key frame.

Parameters
[in]packetThe buffer data (MUST be at least 20 chars)
[in]lenThe message data length in bytes (MUST be 20)
[in,out]seqnrThe current FIR sequence number (will be incremented by the method)
Returns
The message data length in bytes, if successful, -1 on errors
int janus_rtcp_fir_legacy ( char *  packet,
int  len,
int *  seqnr 
)

Method to generate a new legacy RTCP FIR (RFC2032) message to request a key frame.

Note
This is actually identical to janus_rtcp_fir(), with the difference that we set 192 as packet type
Parameters
[in]packetThe buffer data (MUST be at least 20 chars)
[in]lenThe message data length in bytes (MUST be 20)
[in,out]seqnrThe current FIR sequence number (will be incremented by the method)
Returns
The message data length in bytes, if successful, -1 on errors
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)

Parameters
[in]ctxRTCP context to update, if needed (optional)
[in]packetThe message data
[in]lenThe message data length in bytes
[in]fixssrcWhether the method needs to fix the message or just parse it
[in]fixssrcWhether the method needs to fix the message or just parse it
[in]newssrclThe SSRC of the sender to put in the message
[in]newssrcrThe SSRC of the receiver to put in the message
Returns
0 in case of success, -1 on errors
GSList* janus_rtcp_get_nacks ( char *  packet,
int  len 
)

Method to parse an RTCP NACK message.

Parameters
[in]packetThe message data
[in]lenThe message data length in bytes
Returns
A list of janus_nack elements containing the sequence numbers to send again
guint32 janus_rtcp_get_receiver_ssrc ( char *  packet,
int  len 
)

Method to quickly retrieve the received SSRC (needed for demuxing RTCP in BUNDLE)

Parameters
[in]packetThe message data
[in]lenThe message data length in bytes
Returns
The receiver SSRC, or 0 in case of error
uint32_t janus_rtcp_get_remb ( char *  packet,
int  len 
)

Inspect an existing RTCP REMB message to retrieve the reported bitrate.

Parameters
[in]packetThe message data
[in]lenThe message data length in bytes
Returns
The reported bitrate if successful, 0 if no REMB packet was available
guint32 janus_rtcp_get_sender_ssrc ( char *  packet,
int  len 
)

Method to quickly retrieve the sender SSRC (needed for demuxing RTCP in BUNDLE)

Parameters
[in]packetThe message data
[in]lenThe message data length in bytes
Returns
The sender SSRC, or 0 in case of error
gboolean janus_rtcp_has_bye ( char *  packet,
int  len 
)

Method to check whether an RTCP message contains a BYE message.

Parameters
[in]packetThe message data
[in]lenThe message data length in bytes
Returns
TRUE in case of success, FALSE otherwise
gboolean janus_rtcp_has_fir ( char *  packet,
int  len 
)

Method to check whether an RTCP message contains a FIR request.

Parameters
[in]packetThe message data
[in]lenThe message data length in bytes
Returns
TRUE in case of success, FALSE otherwise
gboolean janus_rtcp_has_pli ( char *  packet,
int  len 
)

Method to check whether an RTCP message contains a PLI request.

Parameters
[in]packetThe message data
[in]lenThe message data length in bytes
Returns
TRUE in case of success, FALSE otherwise
int janus_rtcp_nacks ( char *  packet,
int  len,
GSList *  nacks 
)

Method to generate a new RTCP NACK message to report lost packets.

Parameters
[in]packetThe buffer data (MUST be at least 16 chars)
[in]lenThe message data length in bytes (MUST be 16)
[in]nacksList of packets to NACK
Returns
The message data length in bytes, if successful, -1 on errors
int janus_rtcp_parse ( janus_rtcp_context ctx,
char *  packet,
int  len 
)

Method to parse/validate an RTCP message.

Parameters
[in]ctxRTCP context to update, if needed (optional)
[in]packetThe message data
[in]lenThe message data length in bytes
Returns
0 in case of success, -1 on errors
gboolean janus_rtcp_parse_lost_info ( char *  packet,
int  len,
uint32_t *  lost,
int *  fraction 
)

Method to quickly fetch the lost packets info from an RR packet, if present.

Note
This is just means as a simple way for plugins to extract this information from a packet, without the need to setup a dedicated RTCP context for tracking the stats flow
Parameters
[in]packetThe message data
[in]lenThe message data length in bytes
[out]lostThe number of lost packets as a whole
[out]fractionThe fraction of lost packets since the last RR/SR
Returns
TRUE in case of success, FALSE otherwise
int janus_rtcp_pli ( char *  packet,
int  len 
)

Method to generate a new RTCP PLI message to request a key frame.

Parameters
[in]packetThe buffer data (MUST be at least 12 chars)
[in]lenThe message data length in bytes (MUST be 12)
Returns
The message data length in bytes, if successful, -1 on errors
int janus_rtcp_process_incoming_rtp ( janus_rtcp_context ctx,
char *  packet,
int  len 
)

Method to quickly process the header of an incoming RTP packet to update the associated RTCP context.

Parameters
[in]ctxRTCP context to update, if needed (optional)
[in]packetThe RTP packet
[in]lenThe packet data length in bytes
Returns
0 in case of success, -1 on errors
int janus_rtcp_remb ( char *  packet,
int  len,
uint32_t  bitrate 
)

Method to generate a new RTCP REMB message to cap the reported bitrate.

Parameters
[in]packetThe buffer data (MUST be at least 24 chars)
[in]lenThe message data length in bytes (MUST be 24)
[in]bitrateThe bitrate to report (e.g., 128000)
Returns
The message data length in bytes, if successful, -1 on errors
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.

Parameters
[in]packetThe buffer data (MUST be at least 24 chars)
[in]lenThe message data length in bytes (MUST be 24)
[in]bitrateThe bitrate to report (e.g., 128000)
[in]numssrcThe number of SSRCs to include in the request
Returns
The message data length in bytes, if successful, -1 on errors
int janus_rtcp_remove_nacks ( char *  packet,
int  len 
)

Method to remove an RTCP NACK message.

Parameters
[in]packetThe message data
[in]lenThe message data length in bytes
Returns
The new message data length in bytes
Note
This is mostly a placeholder: for the sake of simplicity, whenever we handle some sequence numbers in a NACK, we remove the NACK as a whole before forwarding the RTCP message. Future versions will only selectively remove the sequence numbers that have been handled.
int janus_rtcp_report_block ( janus_rtcp_context ctx,
janus_report_block rb 
)

Method to fill in a Report Block in a Receiver Report.

Parameters
[in]ctxThe RTCP context to use for the report
[in]rbPointer to a valid report_block area of the RTCP data
Returns
0 in case of success, -1 on errors
int janus_rtcp_sdes_cname ( char *  packet,
int  len,
const char *  cname,
int  cnamelen 
)

Method to generate a new RTCP SDES message.

Parameters
[in]packetThe buffer data
[in]lenThe buffer data length in bytes
[in]cnameThe CNAME to write
[in]cnamelenThe CNAME data length in bytes
Returns
The message data length in bytes, if successful, -1 on errors
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.

Parameters
[in]packetThe buffer data (MUST be at least 16 chars)
[in]lenThe message data length in bytes
[in]ssrcSSRC of the origin stream
[in]mediaSSRC of the destination stream
[in]feedback_packet_countFeedback paccket count
[in]transport_wide_cc_statsList of rtp packet reception stats
Returns
The message data length in bytes, if successful, -1 on errors