Skip to main content

Viewers

Struct Viewers 

Source
pub struct Viewers { /* private fields */ }
Expand description

Divides one connection’s receive estimate among the broadcasts watched over it.

The receive-side mirror of Allocator. Every player on a connection reads the same receive estimate, so N players each selecting against all of it oversubscribe the downlink N times over. watch a broadcast here and its Viewer reports only its own slice, split max-min fair by each viewer’s ceiling, so the slices sum to the estimate instead of each matching it. Viewers carry no priority: a viewer asking for less than an even cut takes all it asked for and leaves the rest to the others.

The viewers’ ceilings summed are also the PROBE target the session sends its peer, which probes the connection up to it when it advertised Increase, so the estimate can rise to fund a larger rendition. The target never leaves this hop: a relay probes its own downlink for its viewers, and never forwards them upstream.

The ceilings may sum to at most MAX_TARGET, which every PROBE encoding carries: a viewer or override that would pass it is refused with Error::BoundsExceeded.

Holding a Viewer (or a Consumer read from one) requests PROBE, like holding Session::recv_bandwidth. Take it from Session::viewers (with the async feature) rather than building one, since only a session sends the target. Clones share one registry.

Implementations§

Source§

impl Viewers

Source

pub const MAX_TARGET: Rate

The largest PROBE target: the most the viewers’ ceilings, summed, or an override may be.

2^53 - 1 bits per second, the largest integer a JavaScript peer decodes exactly, and well inside the wire’s varint.

Source

pub fn new(estimate: Weak) -> Self

Divide the receive estimate estimate mints, with no session sending the target.

For an estimate that outlives a session, such as one a reconnect loop feeds from each session it dials. Hand the same registry to Client::with_viewers (with the async feature) so every session it dials sends the target.

Source

pub fn watch(&self, max: Rate) -> Result<Viewer>

Watch a broadcast receiving at most max, returning its viewer.

max is a ceiling: what the largest rendition the player would switch to needs, not what it happens to be receiving. The claim lasts as long as the returned Viewer: change the ceiling with update, and drop it once the broadcast stops being watched.

§Errors

Error::BoundsExceeded, watching nothing, when the ceilings would sum above MAX_TARGET.

Source

pub fn set_target(&self, target: Option<Rate>) -> Result<()>

Send target as the PROBE target instead of the viewers’ sum, or None to follow them again.

Some(Rate::ZERO) sends no target, so the peer stops probing for these viewers. The override is the registry’s, so it holds for every clone and across the reconnects a persistent registry spans.

§Errors

Error::BoundsExceeded, keeping the previous override, for a target above MAX_TARGET.

Trait Implementations§

Source§

impl Clone for Viewers

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 Viewers

Source§

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

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

impl Default for Viewers

No receive estimate to divide, with the PROBE target’s limit.

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