Skip to main content

BandwidthEstimator

Trait BandwidthEstimator 

Source
pub trait BandwidthEstimator: Send + Sync {
Show 14 methods // Required methods fn on_reports(&mut self, now: Instant, reports: &[PacketReport]); fn target_bitrate(&self) -> f64; // Provided methods fn handle_timeout(&mut self, _now: Instant) { ... } fn poll_timeout(&self) -> Option<Instant> { ... } fn on_packet_sent(&mut self, _now: Instant, _size: usize) { ... } fn on_unreported_packet_sent(&mut self, _now: Instant, _size: usize) { ... } fn on_round_trip_time(&mut self, _now: Instant, _round_trip_time: Duration) { ... } fn set_external_bounds(&mut self, _min: Option<f64>, _max: Option<f64>) { ... } fn min_bitrate(&self) -> Option<f64> { ... } fn on_receiver_report(&mut self, _now: Instant, _fraction_lost: f64) { ... } fn on_path_change(&mut self, _now: Instant) { ... } fn on_congestion_marks( &mut self, _now: Instant, _marked: u64, _packets: u64, ) { ... } fn on_probe_result(&mut self, _now: Instant, _bits_per_second: f64) { ... } fn stats(&self) -> EstimatorStats { ... }
}
Expand description

A congestion control algorithm: acknowledged packets in, a target bitrate out.

§Why this is not an Interceptor

An estimator does not transform packets, it observes them. Making it an interceptor would give it a position in the chain ordering it does not need, four bind methods it has no use for, and — fatally — bury it inside a Box<dyn Interceptor> the application cannot reach. CongestionControlInterceptor is the interceptor; this is the algorithm it drives.

§Why the seam is here rather than at the RTCP packet

Upstream’s equivalent interface has six methods, of which one returns a writer, one takes raw RTCP, and one takes a callback. A custom estimator there must parse feedback, own a history of sent packets, own a pacer, and correctly wrap a writer — four responsibilities that have nothing to do with the algorithm, reimplemented per algorithm.

Here PacketReport is already resolved by History: departure joined with arrival, per packet, in send order. What is left is a function from acknowledgements to a number, which is what a congestion control algorithm actually is.

§Clocks

There are none. Every instant arrives as a parameter, so a test can pin an exact bitrate trajectory for a given feedback sequence rather than asserting that something eventually happens.

Required Methods§

Source

fn on_reports(&mut self, now: Instant, reports: &[PacketReport])

Packets whose fate the remote has now reported, in send order.

Each report carries the instant it left this endpoint — the pacer’s release instant, not the instant the application enqueued it — the instant it arrived on the receiver’s clock, its size, and whether it arrived at all. That is everything a delay-based or loss-based estimator needs.

May be called with an empty slice; an implementation should treat that as “no news”.

Source

fn target_bitrate(&self) -> f64

The current estimate, in bits per second.

Read after every on_reports and after every handle_timeout; a change is what reaches the pacer.

Provided Methods§

Source

fn handle_timeout(&mut self, _now: Instant)

Periodic work, for an estimator that has any. Most do not.

Source

fn poll_timeout(&self) -> Option<Instant>

When this estimator next wants waking, or None if it does not.

None when idle, and the instant must advance — a deadline at or before the now just handed to handle_timeout is a busy-loop that wakes the whole chain.

Source

fn on_packet_sent(&mut self, _now: Instant, _size: usize)

A packet left for the network. With on_reports this is what lets an estimator tell “nothing was sent” from “something was sent and nothing came back”.

Source

fn on_unreported_packet_sent(&mut self, _now: Instant, _size: usize)

A packet left for the network on a stream that negotiated no per-packet feedback (no transport-wide sequence numbers, no RFC 8888): nothing will ever report it, so an estimator that counts on feedback for what it sent (on_packet_sent) must not wait for this packet’s.

Source

fn on_round_trip_time(&mut self, _now: Instant, _round_trip_time: Duration)

A round trip time measured from feedback: the instant a packet left to the instant the feedback naming it was read, less nothing, so it includes the receiver’s reporting delay.

Source

fn set_external_bounds(&mut self, _min: Option<f64>, _max: Option<f64>)

Limits from outside the algorithm, in bits per second: what was negotiated (b=AS, b=TIAS), what the receiver asked for (TMMBR, REMB), what the circuit breaker allows. The interceptor combines them and hands over the tightest; None lifts the limit. An estimator that honours them keeps its target at or below max whatever it measures.

Source

fn min_bitrate(&self) -> Option<f64>

The floor the target never goes under, in bits per second, when the estimator has one. It rides with the target as MinimumTarget, so the NACK responder knows where the original media cannot be lowered for retransmissions (RFC 4588 section 7).

Source

fn on_receiver_report(&mut self, _now: Instant, _fraction_lost: f64)

The fraction lost a receiver report gave for a stream this endpoint sends, handed over only while the receiver sends no per-packet feedback (no TWCC, no RFC 8888): the loss-based half of an estimator can still run on it (draft-ietf-rmcat-gcc-02 section 7).

Source

fn on_path_change(&mut self, _now: Instant)

The network path changed (a new selected candidate pair, a new interface): what was learnt about the old path says nothing about this one (RFC 8836 section 2, 1d).

Source

fn on_congestion_marks(&mut self, _now: Instant, _marked: u64, _packets: u64)

Of packets RTP packets the receiver counted since its last ECN report, marked arrived ECN-CE (RFC 6679 section 5: the cumulative counters of its RTCP ECN Feedback packets and XR ECN Summary Reports, for a stream whose per-packet feedback is not RFC 8888, which carries the marks itself). Section 7.3.3: “The default reaction on the reception of these ECN-CE-marked packets MUST be to provide the congestion control algorithm with a congestion notification that triggers the algorithm to react as if packet loss had occurred.”

Source

fn on_probe_result(&mut self, _now: Instant, _bits_per_second: f64)

A probe cluster showed the path carries bits_per_second (probe_estimate). Called only when bandwidth probing is on (CongestionControlBuilder::with_bandwidth_probing). An estimator that ignores it loses nothing but the faster start.

Source

fn stats(&self) -> EstimatorStats

Whatever the algorithm wants to expose. Never load-bearing.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§