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
impl Producer
Sourcepub fn new(info: Info) -> Self
pub fn new(info: Info) -> Self
Create a producer for the given broadcast metadata. Prefer Info::produce.
Sourcepub fn demand(&self) -> Demand
pub fn demand(&self) -> Demand
A watch-only handle to whether anyone reads the broadcast. See Demand.
Sourcepub fn create_track(
&self,
name: impl Into<Arc<str>>,
info: impl Into<Option<Info>>,
) -> Option<Producer>
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.
Sourcepub fn create_datagrams(
&self,
name: impl Into<Arc<str>>,
info: Info,
) -> Option<Producer>
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.
Sourcepub fn reserve_track(&self, name: impl Into<Arc<str>>) -> Option<Request>
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.
Sourcepub fn reserve_unlisted_track(
&self,
name: impl Into<Arc<str>>,
) -> Option<Request>
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.
Sourcepub fn unique_track(
&self,
suffix: &str,
info: impl Into<Option<Info>>,
) -> Producer
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.
Sourcepub fn unique_name(&self, suffix: &str) -> String
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.
Sourcepub fn requests(&self) -> Requests
pub fn requests(&self) -> Requests
Create a dynamic producer that handles on-demand track requests from consumers.
Sourcepub fn consume(&self) -> Consumer
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.
Sourcepub fn close(&self)
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.