Skip to main content

Producer

Struct Producer 

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

Manages tracks within a broadcast.

Create tracks up front with Self::create_track, reserve a name to fill in later with Self::reserve_track, or handle on-demand consumer requests via Self::requests.

§Lifetime

A broadcast lives until Self::close or until the last Producer (or Requests) drops, whichever comes first; both end it the same way. A publisher whose input ended cleanly finishes its tracks first: a subscriber still catching up drains them after the close. Children do not keep it alive: cloning a Consumer or holding a track::Producer does nothing for the broadcast’s lifetime.

Implementations§

Source§

impl Producer

Source

pub fn new(info: Info) -> Self

Create a producer for the given broadcast metadata. Prefer Info::produce.

Source

pub fn info(&self) -> &Info

The broadcast’s static metadata, fixed when it was created.

Source

pub fn demand(&self) -> Demand

A watch-only handle to whether anyone reads the broadcast. See Demand.

Source

pub fn create_track( &self, name: impl Into<Arc<str>>, info: impl Into<Option<Info>>, ) -> Option<Producer>

Produce a new track and insert it into the broadcast, or None while a live track holds the name.

A track whose last producer dropped while read keeps holding its name until the broadcast’s Requests handler answers the renewal. While the renewal is still queued, this fulfils it when info is the one the track was first accepted with, and otherwise replaces it, ending its readers with Error::MalformedTrack as an accept with another info would. Once the handler took it, this returns None.

Pass a name and an optional track::Info, so a bare name works: create_track("video", None) creates an untimed track.

Source

pub fn create_datagrams( &self, name: impl Into<Arc<str>>, info: Info, ) -> Option<Producer>

Produce a new datagram track and insert it into the broadcast, listed until it ends.

Datagram tracks are a namespace apart from stream tracks, so this never conflicts with Self::create_track. Returns None while a live datagram track holds the name.

Moq-lite 05 and 06 carry it on its name’s stream track subscriptions, but only those that start once it exists: create it before, or with, a stream track of the same name. See datagram.

Source

pub fn reserve_track(&self, name: impl Into<Arc<str>>) -> Option<Request>

Reserve a track by name without finalizing its track::Info, or None while a live track holds the name.

Returns a track::Request already discoverable by consumers; call track::Request::accept to set its info and start producing. Use this when the producer can’t pick the track’s properties (e.g. timescale) until it has inspected the media, the same shape as a consumer-driven Requests::poll_requested_track.

Subscribers wait on the name until it is accepted, so a reservation the producer ends up never filling has to be dropped or rejected. Ending the broadcast resolves whatever is left.

Source

pub fn reserve_unlisted_track( &self, name: impl Into<Arc<str>>, ) -> Option<Request>

Self::reserve_track for a track no listing ever names, so only a reader who already knows the name finds it, such as a per-session track whose name the two sides agreed on.

Unlisted controls discovery, not authorization: anyone allowed to subscribe to the broadcast can read the track by name.

Source

pub fn unique_track( &self, suffix: &str, info: impl Into<Option<Info>>, ) -> Producer

Create a track with a unique name using the given suffix.

Uses Self::unique_name; minted names are never reused, even after closure.

Source

pub fn unique_name(&self, suffix: &str) -> String

Generate a unique track name from a suffix without creating the track.

Returns {id}{suffix} with an increasing ID shared across all suffixes and producer clones in this broadcast, skipping names already in the lookup. A digit-leading suffix gets a - separator so it cannot be confused with the ID. Minted names are never reused, even if no track is created or it is closed. Explicit calls to Self::create_track can still reuse names.

§Panics

Panics if the broadcast exhausts its u64 IDs.

Source

pub fn requests(&self) -> Requests

Create a dynamic producer that handles on-demand track requests from consumers.

Source

pub fn consume(&self) -> Consumer

Create a consumer of this one publisher’s broadcast.

A view of this broadcast object, not of its path: a new publisher at the same path never feeds it, so it ends when this broadcast does. Go through an origin for a consumer that should not care which publisher serves the path.

Source

pub fn close(&self)

End the broadcast for good, whether or not other clones are still alive.

Retracts its announcement and local discovery; a later super::origin::Route::announce fails with Error::Closed. Tracks already handed out carry on and end with their own finish or abort. Every later Consumer::track, and every name reserved or still queued for a handler, answers Error::Unroutable: the same answer an origin gives for a path nobody publishes. A request a Requests already took is left for that handler to answer.

Dropping the last producer does the same. Closing twice is a no-op.

Source

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

Return true if this is the same broadcast identity.

Trait Implementations§

Source§

impl Clone for Producer

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