webrtc_rtcp (webrtc v0.1.0)
View SourceRTCP compound packet codec (RFC 3550 §6).
decode/1 splits a compound packet into its individual packets and returns them as records (see webrtc_rtp_rtcp.hrl): SR, RR, SDES, BYE and APP here; the feedback messages of RFC 4585, RFC 5104, RFC 8888, transport-wide CC and REMB in webrtc_rtcp_fb; extended reports in webrtc_rtcp_xr. Packets of unknown type or feedback format are returned as #rtcp_raw{} so they can be forwarded.
By default any sequence of valid RTCP packets is accepted, which covers reduced-size RTCP (RFC 5506). decode/2 with #{mode => compound} also applies the compound checks of RFC 3550 §6.1 and Appendix A.2: the first packet is an SR or RR and only the last packet carries padding. In both modes every packet must have version 2, a valid padding count and lengths that add up to the datagram size.
encode/1 takes one record or a list of records and never adds padding. It raises badarg on records that cannot be encoded.
Summary
Functions
Check a list of decoded packets against RFC 3550 §6.1: the first packet is an SR or RR and an SDES packet carries a CNAME.
Types
-type decode_error() :: truncated | bad_version | bad_padding | first_not_report | padding_not_last | {bad_packet, PT :: 0..255, term()}.
-type packet() :: #rtcp_sr{ssrc :: rtcp_u32(), ntp :: 0..18446744073709551615, rtp_ts :: rtcp_u32(), packets :: rtcp_u32(), octets :: rtcp_u32(), reports :: [#rtcp_rb{ssrc :: rtcp_u32(), fraction_lost :: 0..255, lost :: -8388608..8388607, ext_seq :: rtcp_u32(), jitter :: rtcp_u32(), lsr :: rtcp_u32(), dlsr :: rtcp_u32()}], ext :: binary()} | #rtcp_rr{ssrc :: rtcp_u32(), reports :: [#rtcp_rb{ssrc :: rtcp_u32(), fraction_lost :: 0..255, lost :: -8388608..8388607, ext_seq :: rtcp_u32(), jitter :: rtcp_u32(), lsr :: rtcp_u32(), dlsr :: rtcp_u32()}], ext :: binary()} | #rtcp_sdes{chunks :: [{rtcp_u32(), [{webrtc_rtcp:sdes_item(), binary()}]}]} | #rtcp_bye{ssrcs :: [rtcp_u32()], reason :: undefined | binary()} | #rtcp_app{subtype :: 0..31, ssrc :: rtcp_u32(), name :: <<_:32>>, data :: binary()} | #rtcp_nack{sender_ssrc :: rtcp_u32(), media_ssrc :: rtcp_u32(), items :: [{0..65535, 0..65535}]} | #rtcp_tmmbr{sender_ssrc :: rtcp_u32(), media_ssrc :: rtcp_u32(), entries :: [{rtcp_u32(), non_neg_integer(), 0..511}]} | #rtcp_tmmbn{sender_ssrc :: rtcp_u32(), media_ssrc :: rtcp_u32(), entries :: [{rtcp_u32(), non_neg_integer(), 0..511}]} | #rtcp_pause{sender_ssrc :: rtcp_u32(), entries :: [{rtcp_u32(), pause | resume | paused | refused, 0..65535, undefined | rtcp_u32()}]} | #rtcp_twcc{sender_ssrc :: rtcp_u32(), media_ssrc :: rtcp_u32(), base_seq :: 0..65535, ref_time :: -8388608..8388607, fb_count :: 0..255, packets :: [{0..65535, not_received | -32768..32767}]} | #rtcp_ccfb{sender_ssrc :: rtcp_u32(), reports :: [{rtcp_u32(), 0..65535, [not_received | {0..3, 0..8191}]}], timestamp :: rtcp_u32()} | #rtcp_pli{sender_ssrc :: rtcp_u32(), media_ssrc :: rtcp_u32()} | #rtcp_sli{sender_ssrc :: rtcp_u32(), media_ssrc :: rtcp_u32(), entries :: [{0..8191, 0..8191, 0..63}]} | #rtcp_srreq{sender_ssrc :: rtcp_u32(), media_ssrc :: rtcp_u32()} | #rtcp_rpsi{sender_ssrc :: rtcp_u32(), media_ssrc :: rtcp_u32(), pt :: 0..127, bits :: bitstring()} | #rtcp_fir{sender_ssrc :: rtcp_u32(), media_ssrc :: rtcp_u32(), entries :: [{rtcp_u32(), 0..255}]} | #rtcp_remb{sender_ssrc :: rtcp_u32(), media_ssrc :: rtcp_u32(), bitrate :: non_neg_integer(), ssrcs :: [rtcp_u32()]} | #rtcp_xr{ssrc :: rtcp_u32(), blocks :: [webrtc_rtcp_xr:block()]} | #rtcp_raw{pt :: 0..255, count :: 0..31, body :: binary()}.
-type rtcp_u32() :: 0..4294967295.
-type sdes_item() :: cname | name | email | phone | loc | tool | note | mid | rid | repaired_rid | {priv, Prefix :: binary()} | 1..255.
Functions
-spec decode(binary()) -> {ok, [packet()]} | {error, decode_error()}.
-spec decode(binary(), #{mode => reduced_size | compound}) -> {ok, [packet()]} | {error, decode_error()}.
-spec validate_compound([packet()]) -> ok | {error, first_not_report | no_cname}.
Check a list of decoded packets against RFC 3550 §6.1: the first packet is an SR or RR and an SDES packet carries a CNAME.