pub struct Allocator { /* private fields */ }Expand description
Divides one connection’s bandwidth estimate among the tracks sharing it.
Every sender on a connection reads the same estimate, so N senders each
targeting all of it oversubscribe the uplink N times over. Register a track
here and it gets a Consumer reporting only its own slice, so the slices
sum to the estimate instead of each matching it.
Advisory, not enforced. A track that ignores its slice, or can’t follow it at all (PCM audio has a fixed bitrate), still sends what it sends; the transport sheds the excess by dropping groups. Rate estimation isn’t exact enough for the difference to be worth policing.
The reservations also set the session’s probe target: the sum of every live
reservation’s ceiling, demanded or not, so a sender that stopped for lack of
bandwidth keeps asking the connection for its room. A session probes for its own
allocator, so take it from Session::allocator (with the async feature) rather
than building one: an allocator from new divides an estimate but
probes for nothing.
Clones share one registry, so hand a clone to each sender.
Implementations§
Source§impl Allocator
impl Allocator
Sourcepub fn new(estimate: Consumer) -> Self
pub fn new(estimate: Consumer) -> Self
Divide estimate, with no session probing for the reservations.
For an estimate that is not a session’s, such as a test’s or another
reservation’s slice. A session’s own comes from
Session::allocator with the async feature.
Sourcepub fn set_target(&self, target: Option<Rate>)
pub fn set_target(&self, target: Option<Rate>)
Probe up to target instead of the sum of the reservations, or None to follow them again.
The override covers these reservations only: Some(Rate::ZERO) stops probing for
them, but a session still probes up to the PROBE target its peer sends, since it
probes to the larger of the two. The override is the registry’s, so it holds for
every clone and across the reconnects a persistent allocator spans.
Sourcepub fn unlimited() -> Self
pub fn unlimited() -> Self
An allocator with nothing to divide, so every reservation reports None.
None already means “no opinion, hold your rate” to a sender, so this is what
a transport with no congestion estimate, a local file, or a test harness wants,
and it saves every config struct on the way down from being an Option. It is
also Default, so a config that never sets one encodes at its configured rate.
Sourcepub fn reserve(&self, track: &Demand, max: Rate) -> Reservation
pub fn reserve(&self, track: &Demand, max: Rate) -> Reservation
Reserve up to max for track, returning the reservation.
max is a ceiling, not a measurement: reserve the most the track can ever
send, not what it happens to be sending. A VBR encoder sitting on a black
screen at 1 Mbps can jump to 6 Mbps between one frame and the next, and a
reservation that had followed it down would have already handed that room
to somebody else.
Priority comes from the track (track::Info::priority, higher served
first). A tier is filled to its reservations before the next one sees a
bit; within a tier the split is max-min fair, so a share asking for less
than an even cut takes all of it and leaves the difference to the others.
That is the publisher’s priority, which the send order only falls back on: it ranks by each subscription’s own priority first, so a subscriber asking for video ahead of audio is served that way whatever this decides, and this one breaks the ties (or alone orders a broadcast’s tracks on a session scheduled per broadcast). The publisher’s is still the right one to divide by, since allocation is a decision about what to produce, and there is no single subscriber priority to read when several are watching one track.
That last part carries a publisher that leaves priority at its default:
one tier of audio and video still serves audio’s small reservation in full
before video takes the remainder.
The reservation lasts as long as the returned Reservation: hold it for as
long as the sender is publishing, change the ceiling with
update, and drop it to hand the room back. It is
released when the track closes either way, since a track::Demand is a weak
handle and reserving never keeps a track alive.
Read the current slice through Reservation::consume, which reports None
while the connection has no estimate, telling a sender to hold its current rate
rather than encode at zero. While nothing is subscribed to the track it reports
the slice the track would get back, without claiming it from the others.