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

§Lifetime

You must keep this producer alive for as long as the broadcast should stay available. A broadcast lives as long as at least one Producer exists; children do not keep it alive (cloning a Consumer or holding a track::Producer does nothing for the broadcast’s lifetime). When the last producer goes away every consumer observes Error::Dropped.

End the broadcast with Self::finish rather than dropping it. Dropping is an easy footgun in garbage-collected bindings (Go, Python, …), where the handle can be collected the moment it falls out of scope even while you are still publishing, tearing the stream down mid-broadcast. Dropping the last producer without Self::finish logs a warning.

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 the broadcast’s demand. See Demand.

Source

pub fn remove_track(&mut self, name: &str) -> Result<(), Error>

Remove a track from the lookup.

Source

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

Produce a new track and insert it into the broadcast.

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

Source

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

Reserve a track by name without finalizing its track::Info.

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 Dynamic::requested_track.

Source

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

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

Generates names like 0{suffix}, 1{suffix}, etc. and picks the first one not already used in this broadcast.

Source

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

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

Returns a fresh name like 0{suffix}, 1{suffix}, etc. Use this when you need to set non-default Track properties (e.g. with_timescale, with_latency_max) before handing the Track to Self::create_track.

Source

pub fn dynamic(&self) -> Dynamic

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

Source

pub fn set_route(&mut self, route: Route) -> Result<(), Error>

Set the broadcast’s Route: the hop chain and cost it advertises.

Call this when the path to the content changes (an upstream failover) or the publisher’s preference changes (e.g. a transcoder warming up lowers its cost). Consumers observe the change via Consumer::route_changed and sessions forward it downstream as a restart, never as a new broadcast. Setting the current route again is a no-op.

Source

pub fn consume(&self) -> Consumer

Create a consumer that can subscribe to tracks in this broadcast.

Source

pub fn finish(&mut self)

Cleanly finish the broadcast once you are done publishing.

Marks the broadcast as deliberately finished so consumers observe a normal end. Prefer this over dropping the producer: an accidental drop (see the note on Producer) logs a warning, whereas finish() is silent.

Ends the broadcast outright: consumers observe a normal end immediately and no new tracks are served, whether or not other producer clones are still alive. Existing tracks stay readable so consumers can drain what they already have.

Borrows rather than consumes, matching track::Producer::finish. Finishing declares the end, so it must not depend on the caller also surrendering the handle.

Source

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

Abort the broadcast, ending it for consumers with err.

Like finish the end is immediate, whether or not other producer clones are still alive, and existing tracks stay readable so consumers can drain what they already have (an abort does not cascade into the tracks). Unlike a finish, consumers observe err from Consumer::closed, and an origin treats the source as ungracefully lost, so the path may linger for a replacement (see origin::Info::linger).

Consumes the producer: an abort is terminal. Errors if the broadcast was already finished or aborted.

Source

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

Return true if this is the same broadcast instance.

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