webrtc_rate_limit (webrtc v0.1.0)
View SourceToken bucket that holds one media stream to a bit rate, as a sans-IO engine: the limit a peer set with TMMBR (RFC 5104 §4.2.1.2, RFC 8834 §5.1.6).
- Items are opaque, each with the number of bits it counts for. The budget grows by rate x elapsed time and is capped at
burst_msof the rate (at least one 1500 byte packet); an item leaves while the budget is positive and takes its bits from it. Over any interval the bits released are at most rate x interval plus the cap plus one item. charge/3takes bits sent outside the queue (FEC) from the budget.- The queue holds at most
max_items; when full the oldest item is dropped. At rate 0 every item is dropped. Drops are counted. - With rate
infinityitems pass at once. packet_rate/2is the number of items released over the last second, for the limits that depend on it.
Times are integer milliseconds supplied by the caller.
Summary
Functions
Take Bits sent without the queue from the budget.
Queue an item that counts for Bits; returns the items that may leave now, in order.
Options: rate (bits per second or infinity, default infinity), burst_ms (default 40), max_items (default 256).
Items released over the last second, as a packet rate.
Change the rate; the budget earned so far is kept up to the new cap. Queued items are released by the next handle_timeout/2.
Types
Functions
-spec charge(non_neg_integer(), integer(), state()) -> state().
Take Bits sent without the queue from the budget.
-spec dropped(state()) -> non_neg_integer().
Queue an item that counts for Bits; returns the items that may leave now, in order.
Options: rate (bits per second or infinity, default infinity), burst_ms (default 40), max_items (default 256).
-spec packet_rate(integer(), state()) -> non_neg_integer().
Items released over the last second, as a packet rate.
-spec queue_length(state()) -> non_neg_integer().
-spec rate(state()) -> non_neg_integer() | infinity.
-spec set_rate(non_neg_integer() | infinity, integer(), state()) -> state().
Change the rate; the budget earned so far is kept up to the new cap. Queued items are released by the next handle_timeout/2.