webrtc_rtp_ext (webrtc v0.1.0)
View SourceRTP header extensions (RFC 8285) and the typed values carried in them.
decode/2 takes the profile and data of an RTP header extension and returns [{Id, Data}] in wire order. Both the one-byte form (profile 0xBEDE, ids 1..14, 1..16 data bytes) and the two-byte form (profile 0x100X, ids 1..255, 0..255 data bytes) are handled; zero bytes between elements are padding. In the one-byte form id 15 stops processing and only the elements before it are returned (RFC 8285 §4.2).
encode/1 picks the one-byte form when every element fits and the two-byte form otherwise. Using the two-byte form for some packets of a stream and the one-byte form for others is only allowed when a=extmap-allow-mixed was negotiated (RFC 8285 §6); encode/2 with #{form => one_byte} forces the one-byte form and fails when an element does not fit.
Typed helpers encode and decode element data for: abs-send-time, transport-wide-cc, ssrc-audio-level (RFC 6464), the SDES items mid / rid / repaired-rid (RFC 9143, RFC 8852), toffset (RFC 5450), video-orientation (3GPP TS 26.114) and playout-delay.
Summary
Functions
Encode an abs-send-time value given as 24-bit 6.18 fixed point.
6.18 fixed point abs-send-time from a 64-bit NTP timestamp.
Decode an audio level. RFC 6464 allows the two-byte form to carry padding after the level byte; only the first byte is read.
Decode a mid / rid value. Some senders pad the value with zero bytes; trailing zeros are removed.
Encode elements, choosing the form automatically.
Encode elements into {Profile, Data}, Data padded with zero bytes to a multiple of 4. Raises badarg when an element does not fit the requested form or an id is out of range.
Data of the first element with Id.
True when Profile is one of the RFC 8285 profiles.
RFC 6051 §3.3 Variant B: the low 24 bits of the seconds and the fraction (urn:ietf:params:rtp-hdrext:ntp-56); the receiver takes the upper 8 bits from SR.
RFC 6051 §3.3 Variant A: the 64-bit NTP timestamp of the packet's RTP timestamp (urn:ietf:params:rtp-hdrext:ntp-64).
Encode a playout delay given in milliseconds (rounded down to a multiple of 10, at most 40950 ms).
Types
Functions
-spec abs_send_time(0..16777215) -> <<_:24>>.
Encode an abs-send-time value given as 24-bit 6.18 fixed point.
-spec abs_send_time_from_ntp(0..18446744073709551615) -> 0..16777215.
6.18 fixed point abs-send-time from a 64-bit NTP timestamp.
-spec audio_level(boolean(), 0..127) -> <<_:8>>.
-spec decode_abs_send_time(binary()) -> {ok, 0..16777215} | {error, bad_length}.
-spec decode_audio_level(binary()) -> {ok, {Voice :: boolean(), Level :: 0..127}} | {error, bad_length}.
Decode an audio level. RFC 6464 allows the two-byte form to carry padding after the level byte; only the first byte is read.
-spec decode_playout_delay(binary()) -> {ok, {MinMs :: non_neg_integer(), MaxMs :: non_neg_integer()}} | {error, bad_length}.
Decode a mid / rid value. Some senders pad the value with zero bytes; trailing zeros are removed.
-spec decode_twcc_seq(binary()) -> {ok, 0..65535} | {error, bad_length}.
-spec decode_video_orientation(binary()) -> {ok, orientation()} | {error, bad_length}.
Encode elements, choosing the form automatically.
Encode elements into {Profile, Data}, Data padded with zero bytes to a multiple of 4. Raises badarg when an element does not fit the requested form or an id is out of range.
Data of the first element with Id.
-spec is_rfc8285(0..65535) -> boolean().
True when Profile is one of the RFC 8285 profiles.
-spec ntp56(0..18446744073709551615) -> <<_:56>>.
RFC 6051 §3.3 Variant B: the low 24 bits of the seconds and the fraction (urn:ietf:params:rtp-hdrext:ntp-56); the receiver takes the upper 8 bits from SR.
-spec ntp64(0..18446744073709551615) -> <<_:64>>.
RFC 6051 §3.3 Variant A: the 64-bit NTP timestamp of the packet's RTP timestamp (urn:ietf:params:rtp-hdrext:ntp-64).
-spec playout_delay(0..40950, 0..40950) -> <<_:24>>.
Encode a playout delay given in milliseconds (rounded down to a multiple of 10, at most 40950 ms).
-spec toffset(-8388608..8388607) -> <<_:24>>.
-spec twcc_seq(0..65535) -> <<_:16>>.
-spec video_orientation(orientation()) -> <<_:8>>.