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.

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

Source

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.

Source

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.

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

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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