Skip to main content

Consumer

Struct Consumer 

Source
pub struct Consumer<F: Container> { /* private fields */ }
Expand description

Decode a moq-lite track into a stream of media Frames in age-bounded presentation order.

Consumer reads a [moq_net::track::Subscriber] through its Ordered reader and decodes it with a Container format implementation, typically catalog::hang::Wire. Yields decoded frames via poll_read.

§Ordering & age skipping

Groups can arrive on the wire out of order. The Ordered reader hands them out by start and decides every missing one: it waits for a group the track still owes until everything it could still present (bounded by where the next group begins) falls Delay::max behind the newest content, and reports what it gives up as a gap. With the default max delay of zero it gives up at once: any group that has a newer alternative is dropped. Delay::min only sets where the reader starts. A run the publisher declared skipped (skip_groups, which appending does) holds no group, and the consumer steps over it at once, as it does over keys the subscription’s ranges leave out.

Within a group the consumer reads frames in arrival order. A group already handed out that stalls behind newer ones is skipped by the same budget, measured from where the next group begins.

Delivery starts at the first group the ordered reader hands out: the publisher resolved a live join Delay::min plus any Playout::warmup behind the live edge, and the ordered reader waits for the groups below it that the feed owes. Until the first item, the start also moves past each group whose first frame trails the newest content by more than the max delay plus the warmup, as @moq/hang’s consumer measures, unless that group covers the live edge less the min delay and the warmup: a backlog that landed whole would otherwise play from its oldest group, since nothing blocks, and stay that far behind. From there the same budget is the one rule that catches the consumer up to the live edge.

A stalled group is also skipped early, regardless of the max delay budget, once it has presented up to where the next group begins. CMAF frames carry a per-sample duration, so a group whose most recent frame ends (timestamp + duration) at or past the next group’s first timestamp has nothing left worth waiting for. Containers without a duration report zero, which disables this check and falls back to the max delay budget.

Put the initial Delay on the [moq_net::track::Subscription] with Delay::subscription before subscribing. new inherits it, taking the min from the furthest live join among its ranges and reading none as zero, and set_delay changes the whole Delay while reading. To build one at a delay the subscription does not carry, or with a catalog warmup, use a Playout.

§Gaps and ends

poll_read yields Read::Gap wherever media after an item already read will never arrive: a latency skip, an evicted current group, or keys between two groups the publisher did not declare skipped whose boundary is not contiguous within 1 ms. The later group continues the earlier when any of its frames presents by where the earlier ended, so an open GOP’s leading pictures count, and its first frame waits until one shows it, at most as many frames as the track has reordered. Frames without a duration end one picture past the highest: the largest step between the group’s latest presentation times. A local track owes nothing, so there a discontinuous run is a gap the moment the group past it lands. Whatever is lost before the first item is no gap, since nothing was read before it. A marker group (no decodable frames: one empty payload, or on a data track one object with no bytes) is the publisher declaring a stop, read as Read::End; nothing is missing. A data track’s marker carries no timestamp, so it ends at the furthest point read, and reads as nothing before the first item. Empty groups (zero objects) mean nothing. Errors come in delivery order: a payload that fails to decode, or a group below an earlier group’s start, ends the reader where it sits, and a failed track once the groups already here drain. A skip returns the error of a malformed group it already read rather than a gap; a group dropped unread is not validated, since decoding data that is thrown away is work a peer could force. After an error the reader reads as finished.

§Memory

Decoded frames waiting to be read are charged to a byte cap, one group at the transport’s size cap, counting the whole wire payload they share, along with each buffered frame’s and group’s own overhead. Once it is full the consumer stops decoding ahead and stops pulling new groups past one successor to the cursor’s group, so the undecoded rest stays in the transport’s cache, which bounds it. The group the cursor is on still decodes a wire frame whenever it holds nothing, so reading never waits on its own lookahead. If that group stalls while the cap is full, the cursor moves on to the next group like a skip past a slow group, read or not: the consumer can hold no more of what it would wait behind.

Implementations§

Source§

impl<F: Container> Consumer<F>

Source

pub fn new(track: Subscriber, format: F) -> Self

Create a Consumer wrapping the given moq-lite consumer, decoding format.

The ordering window inherits the widest live join max the subscriber asks, none while it asks for history, clamped to the track’s max age. Put that budget on the [moq_net::track::Subscription] before awaiting the subscription, so the publisher preserves the same replay window.

Source

pub fn arrival(&self) -> Option<Instant>

When the wire frame behind the latest frame read landed in this node’s cache ([moq_net::frame::Frame::created]), or None before the first frame.

A gap or an end leaves it at the frame before. A frame from cache, such as a join on a track that already holds groups, reports when it landed, not when it was read. Frames packed into one wire frame, as a CMAF fragment packs its samples, share its arrival.

Source

pub fn backlog(&self) -> Option<Instant>

When the latest backlog group this reader dropped without delivering all of it landed in this node’s cache, or None before the first.

Backlog is a group at or below the publisher’s largest when the subscription began, so it was produced before. Its frames were never read, so a caller timing arrivals learns when a join’s backlog finished arriving even when the reader skipped it: one the ordered reader gave up as stale or late (see Item::Gap’s landed), or one a skip here passed over. A gap reaching past the join counts for none of it, since its landing may be a later group’s.

Source

pub fn poll_read( &mut self, waiter: &Waiter, ) -> Poll<Result<Option<Read>, F::Error>>

Read the next frame from the track.

This method handles timestamp decoding, group ordering, and age management automatically. It will skip groups that are too far behind to maintain the configured max delay.

Returns None when the track has ended, and after an error. See Read for the items between frames; an undeclared forward timestamp jump is not a gap, since nothing says media is missing.

Source

pub async fn read(&mut self) -> Result<Option<Read>, F::Error>

Read the next frame from the track.

This method handles timestamp decoding, group ordering, and age management automatically. It will skip groups that are too far behind to maintain the configured max delay.

Returns None when the track has ended, and after an error. See Read for the items between frames; an undeclared forward timestamp jump is not a gap, since nothing says media is missing.

Awaits poll_read.

Source

pub fn is_skipped(&self, groups: Range<u64>) -> bool

Whether the publisher declared every group start in groups skipped, so no group lies there; see [moq_net::track::Ordered::is_skipped]. A group with nothing possible below it is its track’s first. False once an error ended the reader.

Source

pub fn set_delay(&mut self, delay: Delay)

Set the Delay, mid-stream or before the first read.

Delay::max is clamped to the track’s max age like new. The subscription keeps the requested max verbatim, plus any Playout::warmup; its ranges keep the live join they were subscribed with (see Delay::subscription). A Delay::min moves where this reader keeps a start still to come, reading an unstated one as zero. A min past the max starts at the max, since the publisher serves nothing older. A missing group is given up by the subscription’s max alone.

Auto Trait Implementations§

§

impl<F> !Freeze for Consumer<F>

§

impl<F> RefUnwindSafe for Consumer<F>

§

impl<F> Send for Consumer<F>
where F: Send,

§

impl<F> Sync for Consumer<F>
where F: Sync,

§

impl<F> Unpin for Consumer<F>
where F: Unpin,

§

impl<F> UnsafeUnpin for Consumer<F>

§

impl<F> UnwindSafe for Consumer<F>
where F: UnwindSafe, <F as Container>::Error: UnwindSafe,

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