webrtc_rtcp_twcc (webrtc v0.1.0)

View Source

Transport-wide congestion control feedback, RTPFB FMT 15 (draft-holmer-rmcat-transport-wide-cc-extensions-01 §3.1).

The record #rtcp_twcc{} lists one entry per transport-wide sequence number from base_seq: not_received or the receive delta in multiples of 250 microseconds. The first delta is relative to ref_time (multiples of 64 ms), each next one to the previous received packet.

Packet status chunks follow the draft and libwebrtc: a run length chunk, a one-bit status vector (1 = received with a small delta, 0 = not received; the draft text has the two values swapped but its example and every implementation use this order) or a two-bit status vector. Symbol 3 is reserved and rejected. The encoder picks run length chunks for runs of 14 or more, then one-bit vectors when the next 14 symbols allow it, then run length chunks for runs of 7 or more, otherwise two-bit vectors. Deltas in 0..255 use the small symbol, others the large (signed 16-bit) one.

from_arrivals/4 builds feedback messages from absolute arrival times and arrivals/1 does the reverse.

Summary

Functions

Absolute arrival times in microseconds, on the time base of the feedback sender (ref_time * 64 ms plus the cumulative deltas).

Encode the FCI part (everything after the two SSRCs), padded with zero bytes to a multiple of 4. Raises badarg when the packets are not consecutive from base_seq or a field is out of range.

Build feedback messages from [{Seq, ArrivalUs}], arrival times in microseconds on any monotonic clock. Packets are ordered by sequence number relative to the first one; gaps become not_received. A new message is started when a delta does not fit 16 bits or the status count would overflow. Feedback counts start at FbCount and increase by one per message.

Types

rtcp_u32/0

-type rtcp_u32() :: 0..4294967295.

Functions

arrivals(Rtcp_twcc)

-spec arrivals(#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}]}) ->
                  [{0..65535, integer() | not_received}].

Absolute arrival times in microseconds, on the time base of the feedback sender (ref_time * 64 ms plus the cumulative deltas).

decode(Sender, Media, _)

-spec decode(0..4294967295, 0..4294967295, binary()) ->
                {ok,
                 #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}]}} |
                {error, term()}.

encode_fci(Rtcp_twcc)

-spec encode_fci(#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}]}) ->
                    binary().

Encode the FCI part (everything after the two SSRCs), padded with zero bytes to a multiple of 4. Raises badarg when the packets are not consecutive from base_seq or a field is out of range.

from_arrivals(Sender, Media, FbCount, Arrivals)

-spec from_arrivals(0..4294967295, 0..4294967295, 0..255, [{0..65535, integer()}]) ->
                       [#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}]}].

Build feedback messages from [{Seq, ArrivalUs}], arrival times in microseconds on any monotonic clock. Packets are ordered by sequence number relative to the first one; gaps become not_received. A new message is started when a delta does not fit 16 bits or the status count would overflow. Feedback counts start at FbCount and increase by one per message.