Skip to main content

Allocator

Struct Allocator 

Source
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.

Clones share one registry, so hand a clone to each sender.

Implementations§

Source§

impl Allocator

Source

pub fn new(estimate: Consumer) -> Self

Divide estimate, normally a connection’s Session::send_bandwidth.

Source

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.

Source

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 is not what orders the local send queue: that ranks by each subscription’s own priority, so a subscriber asking for video ahead of audio is served that way whatever this decides. 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::consumer, which reports None while nothing is subscribed to the track or the connection has no estimate. That tells a sender to hold its current rate rather than encode at zero.

Trait Implementations§

Source§

impl Clone for Allocator

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Allocator

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Allocator

An allocator with nothing to divide, so a config that never sets one leaves its senders at their configured rates. See Allocator::unlimited.

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> MaybeSend for T
where T: Send + ?Sized,

Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> MaybeSync for T
where T: Sync,

Source§

impl<T> MaybeSync for T
where T: Sync,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more