webrtc_nack (webrtc v0.1.0)

View Source

Receiver-side NACK generator (sans-IO).

Feed every received RTP sequence number of one stream with packet/3 (for RTX packets, the original sequence number). Gaps are remembered as missing; each missing packet is requested with a NACK after reorder_delay, then again every max(RTT, min_interval) until it arrives, max_retries requests have been sent or it is older than max_age. The owner arms one timer at next_timeout/1 and calls handle_timeout/2.

Actions:

  • {nack, [Seq]}: send a generic NACK for these sequence numbers (see webrtc_rtcp_fb:nack_items/1);
  • {give_up, [Seq]}: these packets will not be requested again;
  • request_keyframe: the gap is too large to recover with NACK (more than max_missing packets); send a PLI or FIR.

Times are integers in milliseconds on a monotonic clock.

Summary

Functions

Send due NACKs and drop expired entries.

Sequence numbers currently missing, oldest first.

Defaults: rtt 100 ms, max_retries 10, max_age 1000 ms, max_missing 1000, min_interval 5 ms, reorder_delay 0.

Absolute time of the next NACK or expiry, or infinity.

Types

action/0

-type action() :: {nack, [0..65535]} | {give_up, [0..65535]} | request_keyframe.

opts/0

-type opts() ::
          #{rtt => non_neg_integer(),
            max_retries => pos_integer(),
            max_age => pos_integer(),
            max_missing => pos_integer(),
            min_interval => non_neg_integer(),
            reorder_delay => non_neg_integer()}.

state/0

-opaque state()

Functions

handle_timeout(Now, Nack)

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

Send due NACKs and drop expired entries.

missing(Nack)

-spec missing(state()) -> [0..65535].

Sequence numbers currently missing, oldest first.

new(Opts)

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

Defaults: rtt 100 ms, max_retries 10, max_age 1000 ms, max_missing 1000, min_interval 5 ms, reorder_delay 0.

next_timeout(Nack)

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

Absolute time of the next NACK or expiry, or infinity.

packet(Seq, Now, Nack)

-spec packet(0..65535, integer(), state()) -> {state(), [action()]}.

set_rtt(Rtt, Nack)

-spec set_rtt(non_neg_integer(), state()) -> state().