webrtc_circuit_breaker (webrtc v0.1.0)

View Source

RTP media circuit breakers (RFC 8083 §4), as a sans-IO engine.

Streams are identified by an opaque key (the media session uses the mid). sent/4 records every RTP packet sent, report/5 every RTCP report block about the stream, with the round-trip time when known. Three breakers are implemented; each reports {circuit_breaker, Key, Reason} once when it triggers, and is re-armed when the condition clears:

  • rtcp_timeout (§4.1): packets were sent but no report block arrived for rtcp_timeout ms, three times the deterministic reporting interval with Tmin = 5 s (default 15000).
  • media_timeout (§4.2): MEDIA_TIMEOUT consecutive reports show a non-increasing extended highest sequence number while packets were sent, MEDIA_TIMEOUT = ceil(k x max(Tr, Tdr) / Tdr) with k = 5. The frame interval Tf is not known to this layer and is left out.
  • congestion (§4.3): over the last CB_INTERVAL reports (fraction lost weighted by the reporting intervals), the sending rate is more than ten times the simplified TCP throughput X = s / (Tr sqrt(2 b p / 3)) with b = 1. CB_INTERVAL = ceil(3 min(max(10 Tr, 3 Tdr), max(15, 3 Td)) / (3 Tdr)), the 10 G Tf term being unknown. Only checked when the RTT is known and a packet was sent in every reporting interval.

RFC 8083 says the sender SHOULD then cease transmission: this module detects, webrtc_cc acts (rate cut by ten then halt for congestion, halt for the timeouts).

Summary

Functions

RFC 8083 §4.3: after the sender cut its rate by ten, the congestion breaker is evaluated afresh over the next CB_INTERVAL reports; a new trigger then means the sender must cease.

Types

event/0

-type event() :: {circuit_breaker, term(), reason()}.

reason/0

-type reason() :: rtcp_timeout | media_timeout | congestion.

rtcp_u32/0

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

state/0

-opaque state()

Functions

handle_timeout(Now, Cb)

-spec handle_timeout(integer(), state()) -> {[event()], state()}.

new(Opts)

-spec new(map()) -> state().

next_timeout(Cb)

-spec next_timeout(state()) -> integer() | infinity.

rearm_congestion(Key, Cb)

-spec rearm_congestion(term(), state()) -> state().

RFC 8083 §4.3: after the sender cut its rate by ten, the congestion breaker is evaluated afresh over the next CB_INTERVAL reports; a new trigger then means the sender must cease.

report(Key, Rtcp_rb, Rtt, Now, Cb)

-spec report(term(),
             #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()},
             non_neg_integer() | undefined,
             integer(),
             state()) ->
                {[event()], state()}.

sent(Key, Size, Now, Cb)

-spec sent(term(), non_neg_integer(), integer(), state()) -> state().

stats(Cb)

-spec stats(state()) -> map().