Skip to main content

Producer

Struct Producer 

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

A producer for a track, used to create new groups.

Implementations§

Source§

impl Producer

Source

pub fn name(&self) -> &str

The track’s name, unique within its broadcast.

Source

pub fn broadcast(&self) -> &Info

The parent broadcast this track belongs to.

Source

pub fn create_group(&mut self, group: Info) -> Result<Producer>

Create a new group with the given sequence number.

Source

pub fn append_group(&mut self) -> Result<Producer>

Create a new group with the next sequence number.

Source

pub fn append_datagram<B: IntoBytes>( &mut self, timestamp: Timestamp, payload: B, ) -> Result<u64>

Append a datagram with the next sequence number, returning the assigned sequence.

A datagram is delivered best-effort over a single QUIC datagram, parallel to the track’s groups but drawing from the same sequence namespace (so interleaving with Self::append_group never reuses a number). There is no group fallback: each session drops (with a debug log) any datagram whose encoded body exceeds the transport’s datagram size, and sessions that can’t carry datagrams at all (IETF moq-transport, moq-lite before 05, or stream-only transports like WebSocket) never deliver them. Keep payloads well under the 1200-byte minimum path MTU. An origin publisher uses this; a relay preserving upstream numbering uses Self::write_datagram.

Source

pub fn write_datagram(&mut self, datagram: Datagram) -> Result<()>

Write a datagram with an explicit sequence number.

Preserves the supplied sequence (bumping the shared max_sequence if needed), so a relay can forward a datagram without renumbering it. Most origin publishers want Self::append_datagram instead.

Source

pub fn write_frame<B: IntoBytes>( &mut self, timestamp: Timestamp, frame: B, ) -> Result<()>

Create a group with a single frame, at the given presentation timestamp.

The timestamp is converted into the track’s timescale. For data without a presentation time, pass Timestamp::now explicitly.

Source

pub fn finish(&mut self) -> Result<()>

Mark the track as finished after the last appended group.

Sets the final sequence to one past the current max_sequence. No new groups at or above this sequence can be appended. NOTE: Old groups with lower sequence numbers can still arrive.

Source

pub fn finish_at(&mut self, final_sequence: u64) -> Result<()>

Declare the track’s exclusive final sequence, possibly ahead of the live edge.

final_sequence is the first sequence that will never be produced, so a track whose last group is 89 finishes at 90. Passing a boundary beyond the current max_sequence records a known ending before the remaining groups arrive (e.g. learning a track ends at group 89 while only 87 has been received). The boundary must be strictly greater than the highest produced group, otherwise it would orphan groups that already exist (Error::ProtocolViolation).

Groups below final_sequence may still be created afterwards; groups at or above it are rejected. Consumers only see end-of-stream once the live edge reaches the boundary. Use Self::finish to finish exactly at the live edge.

Source

pub fn final_sequence(&self) -> Option<u64>

The exclusive final sequence, once Self::finish or Self::finish_at declared one.

None while the track is still open ended. Both methods reject a second boundary, so callers that may have already declared one check here first.

Source

pub fn abort(self, err: Error) -> Result<()>

Abort the track with the given error.

Consumes the handle, since nothing can be written to an aborted track. Drops the cached groups so a stale Consumer can’t pin them (and their frame buffers) in memory forever. Consumers that haven’t drained yet surface the abort error instead of the leftover cache. Child groups are independent: a consumer that already pulled a group::Consumer keeps its own handle and can finish reading it.

finish is deliberately not terminal: it declares the final sequence, and lower-numbered groups may still be written afterwards.

Source

pub async fn unused(&self) -> Result<()>

Block until there are no active consumers.

Source

pub async fn used(&self) -> Result<()>

Block until there is at least one active consumer.

Source

pub async fn closed(&self) -> Error

Block until the track is closed or aborted, returning the cause.

Source

pub fn poll_closed(&self, waiter: &Waiter) -> Poll<Error>

Poll until the track is closed or aborted; ready with the cause.

Source

pub fn is_closed(&self) -> bool

Return true if the track has been closed.

Source

pub fn latest(&self) -> Option<u64>

Return the latest sequence number successfully appended to the track.

Source

pub fn is_clone(&self, other: &Self) -> bool

Return true if this is the same track.

Source

pub fn demand(&self) -> Demand

Create a Demand: a cloneable, watch-only handle to this track’s subscriber demand.

Lets a publisher gate work (e.g. on-demand capture) on whether anyone is subscribed, without the ability to publish frames or close the track. The handle is weak, so holding one neither keeps the track alive nor pins its cached groups.

Source

pub fn consume(&self) -> Consumer

Get a consumer handle for this in-process track.

Unlike a wire subscription, the info is already known, so a subscription opened from this handle resolves immediately.

Source

pub fn subscribe( &self, subscription: impl Into<Option<Subscription>>, ) -> Subscriber

Subscribing to this in-process track, resolving synchronously.

The info is fixed at creation, so there’s nothing to wait for (no SUBSCRIBE_OK round trip). Pass None for Subscription::default.

Source

pub async fn subscription_changed(&mut self) -> Result<Option<Subscription>>

Block until the aggregate subscription changes, then return the new value.

Yields the most demanding request across all live subscribers, or None once the last one drops. Used by relays to forward downstream demand upstream (e.g. SUBSCRIBE_UPDATE).

Source

pub fn subscription(&self) -> Option<Subscription>

A non-blocking snapshot of the current aggregate subscription, or None when there are no live subscribers. Unlike Self::subscription, this doesn’t wait for a change or advance the change cursor.

The aggregate’s Subscription::latency_max is clamped to this track’s Info::latency_max: no subscriber can wait for a late group longer than the publisher keeps it.

Source

pub fn poll_subscription_changed( &mut self, waiter: &Waiter, ) -> Poll<Result<Option<Subscription>>>

Poll counterpart to subscription_changed: the aggregate subscription whenever it changes, or None once nobody is subscribed. Errors once the track is aborted.

Source

pub fn poll_unused(&self, waiter: &Waiter) -> Poll<()>

Poll for the producer becoming unused (every consumer dropped).

Source

pub fn dynamic(&self) -> Dynamic

Create a Dynamic handle that serves on-demand fetches of uncached (old) groups. Most producers never need this; a relay creates one to fetch past groups from upstream.

Trait Implementations§

Source§

impl Clone for Producer

Source§

fn clone(&self) -> Producer

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 Consume<Consumer> for Producer

Source§

fn consume(&self) -> Consumer

Derive a read view (a consumer) from this handle.

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,

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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