pub struct Control { /* private fields */ }Expand description
Maps bandwidth estimates onto a target bitrate, per a Policy.
Feed it every estimate from a
bandwidth::Consumer; it returns a new
target only when one is worth applying, so a caller can hand the result
straight to an encoder without rate-limiting it further:
let mut control = Control::new(Policy::new(4_000_000));
// A 2 Mbps estimate takes the 4 Mbps target down to 2 Mbps * 0.9 headroom.
assert_eq!(control.update(Some(2_000_000), Instant::now()), Some(1_800_000));The time source is a parameter rather than an Instant::now call so the
policy stays pure and testable. Pass the time the estimate was observed.
Implementations§
Source§impl Control
impl Control
Sourcepub fn new(policy: Policy) -> Self
pub fn new(policy: Policy) -> Self
Start at Policy::max, the optimistic case: until an estimate says
otherwise, send what the caller configured.
Sourcepub fn update(&mut self, estimate: Option<u64>, now: Instant) -> Option<u64>
pub fn update(&mut self, estimate: Option<u64>, now: Instant) -> Option<u64>
Feed a new estimate, returning the new target when it moved enough to be
worth applying and None when it didn’t.
A None estimate (no congestion controller, or disconnected) holds the
current target rather than resetting to Policy::max: losing the
estimate is not evidence the uplink got better.