pub struct Producer<E: CatalogExt = ()> { /* private fields */ }Expand description
Produces both a hang and MSF catalog track for a broadcast.
Generic over the application extension E (defaulting to () for none). The catalog is a
Catalog<E>: video/audio are direct fields (catalog.video) and the
extension is reachable through catalog.ext (for example, catalog.ext.scte35). Define an
extension with CatalogExt. The MSF track carries the same catalog:
the media sections become MSF tracks and the extension’s sections ride the MSF root.
The JSON catalog is updated when tracks are added/removed but is not automatically published.
You’ll have to call modify to update and publish the catalog.
Both the hang (catalog.json) and MSF (catalog) tracks are published on drop of the guard.
The hang track is published through moq_json, which currently emits one snapshot per
group (deltas disabled). This routes catalog publishing through the JSON merge-patch helper
so deltas can be enabled later without changing the wire format used today.
Implementations§
Source§impl<E: CatalogExt> Producer<E>
impl<E: CatalogExt> Producer<E>
Sourcepub fn new(broadcast: &mut Producer, config: Config<E>) -> Result<Self>
pub fn new(broadcast: &mut Producer, config: Config<E>) -> Result<Self>
Create a new catalog producer from a full Config.
A sync.clock seeded through Config::with_catalog is adopted under the same rules as
modify: the producer runs on it, unless Config::with_clock fixed a
different mapping, which is refused.
Sourcepub fn track_info(&self, priority: i8) -> Info
pub fn track_info(&self, priority: i8) -> Info
Track properties for a media track under this catalog: hang’s media defaults, with the
Config::with_max_age policy.
priority should come from PRIORITY for the kind of media
the track carries. Chain with_timescale for a
container that carries the source’s own scale (CMAF and Matroska both do).
Sourcepub fn timestamp(&self, hint: Option<Timestamp>) -> Result<Timestamp>
pub fn timestamp(&self, hint: Option<Timestamp>) -> Result<Timestamp>
Resolve a timestamp, synthesizing one from the broadcast’s shared
Clock when the caller has none.
Sharing the clock across the catalog’s tracks keeps concurrently-produced audio and video on a single timeline.
Sourcepub fn mutate(
&mut self,
f: impl FnOnce(&mut Catalog<E>),
timestamp: Timestamp,
) -> Result<()>
pub fn mutate( &mut self, f: impl FnOnce(&mut Catalog<E>), timestamp: Timestamp, ) -> Result<()>
Edit the catalog in place and publish the result.
The closure receives the current catalog, composed from every owner so far. Edit it in place; on return the result is published, a no-op if the closure changed nothing. Independent owners can each edit only their own sections, so they compose instead of clobbering one another.
This is modify opened at timestamp and committed for you; take the guard
to hold the lock across several edits, or to reach a Guard method like
set_section.
Sourcepub fn modify(&mut self, timestamp: Timestamp) -> Result<Guard<'_, E>>
pub fn modify(&mut self, timestamp: Timestamp) -> Result<Guard<'_, E>>
Get mutable access to the catalog, publishing it after any changes stamped at timestamp.
A catalog is a timed track like any media track, so the caller says when the change takes
effect on the producer’s clock: the timestamp of the frame it happens at, or
next_timestamp for a change no frame times. Fails with
TimestampRewind before any edit unless timestamp is
past the last published catalog’s, or the stamp of a change still waiting on the initial
publish; batch the edits at one frame into one guard. An edit that re-bases the clock by
writing sync.clock is stamped on the clock it adopts, unmoved: a derivative times it on its
input’s timeline, the one it republishes. Don’t stamp such an edit with
next_timestamp, which reads the clock it replaces. So while a change
waits on the initial publish and nothing has fixed the clock, the guard checks its timestamp
when it publishes instead, against that change’s stamp moved onto the clock the edit leaves. A
rewind there discards the edit, leaving the catalog and clock as they were: Guard::commit
returns it, and a drop logs it with the tracks left open. A guard with no edit publishes
nothing, so it checks nothing then.
The publish happens when the returned Guard drops. Use mutate for a
single edit, which is this guard opened and committed for you. Fails once the catalog tracks
are closed, the one publication failure that happens in normal operation, so nothing is left
to check after the guard drops. Anything else that stops the drop from publishing (an extension
that won’t serialize, a catalog too large for a frame) aborts the catalog tracks with that
error: consumers see it instead of a stale catalog, and the next modify returns it here.
Call Guard::commit to get the error back immediately instead.
The in-memory catalog is already mutated, so a panic while the guard is held still
publishes: skipping would leave snapshot ahead of the wire with no dirty flag to catch up.
The sync.clock is the producer’s clock. Writing a different one re-bases
the clock on it until something fixes the clock (Config::with_clock, taking
clock, an importer’s first frame, or the first publish), so a derivative
adopts its input’s mapping, or the lack of one. After that a changed clock is refused; writing
the same mapping again is no change. Writes through
Reserved::video and the codec producers keep their timestamps
verbatim, so they mean something only under the mapping they were written for.
Sourcepub fn next_timestamp(&self) -> Timestamp
pub fn next_timestamp(&self) -> Timestamp
A timestamp for a change no frame times: the producer’s clock now, or a unit
past the last catalog when the clock hasn’t passed it, so two changes in one millisecond both
publish. Another thread’s publish between this and modify can still pass it,
such as an importer’s estimate racing a binding’s section edit: modify then returns
TimestampRewind and the catalog is unchanged. That
window is accepted over an edit that picks its own timestamp, since every caller states when
its change takes effect. While the initial publish is buffering on a clock nothing fixed, the
refusal comes from Guard::commit instead, as modify describes.
Sourcepub fn clock(&self) -> Clock
pub fn clock(&self) -> Clock
The broadcast’s shared clock: the timeline producers stamp against and the wall mapping
advertised as the catalog’s sync.clock.
Clones share the timeline, so handing them to concurrent producers keeps every track on one clock. Taking the clock fixes it: an importer whose first frame arrives later shifts its timestamps onto this clock rather than moving it, so a clone never goes stale.
Sourcepub fn timebase(&self) -> Timebase<E>
pub fn timebase(&self) -> Timebase<E>
A timestamp base for one source, shared by every importer reading it.
Hand it to each container importer with its with_timebase, or shift a source’s timestamps
through it directly, so they all shift by one offset. See Timebase.
Sourcepub fn reserve(&self) -> Reserved<E>
pub fn reserve(&self) -> Reserved<E>
Begin reserving the initial track set, returning a clonable Reserved.
Hand it (or clones) to importers, or call its role-specific track constructors. The catalog is
withheld until every reservation is dropped and every created producer either publishes its
config or drops, and after that until the catalog names a track. A one-shot muxer therefore
publishes the complete track list in its first snapshot instead of a half-converged one, and
input that declares no track publishes nothing. An application’s extension track counts only
once a track constructor such as track publishes it; one seeded or written
through modify is invisible to this check. Producers created directly on a
catalog that never reserved publish incrementally.
It only gates: timestamps written through it land verbatim on the catalog’s clock (see
Timebase for a source on a timeline of its own).
Sourcepub fn video<C: Container>(
&self,
track: Producer,
container: C,
config: impl Into<Option<VideoConfig>>,
) -> Result<Producer<C, VideoConfig>>
pub fn video<C: Container>( &self, track: Producer, container: C, config: impl Into<Option<VideoConfig>>, ) -> Result<Producer<C, VideoConfig>>
Publish a video track and own its catalog rendition.
Sourcepub fn audio<C: Container>(
&self,
track: Producer,
container: C,
config: impl Into<Option<AudioConfig>>,
) -> Result<Producer<C, AudioConfig>>
pub fn audio<C: Container>( &self, track: Producer, container: C, config: impl Into<Option<AudioConfig>>, ) -> Result<Producer<C, AudioConfig>>
Publish an audio track and own its catalog rendition.
Sourcepub fn text<C: Container>(
&self,
track: Producer,
container: C,
config: impl Into<Option<TextConfig>>,
) -> Result<Producer<C, TextConfig>>
pub fn text<C: Container>( &self, track: Producer, container: C, config: impl Into<Option<TextConfig>>, ) -> Result<Producer<C, TextConfig>>
Publish a text track and own its catalog rendition.
Sourcepub fn track<C, R>(
&self,
track: Producer,
container: C,
config: impl Into<Option<R>>,
) -> Result<Producer<C, R>>
pub fn track<C, R>( &self, track: Producer, container: C, config: impl Into<Option<R>>, ) -> Result<Producer<C, R>>
Publish a track using a custom catalog config.
Sourcepub fn is_claimed<R: RenditionConfig<E>>(&self, name: &str) -> bool
pub fn is_claimed<R: RenditionConfig<E>>(&self, name: &str) -> bool
Whether a live producer or published config already claims name in R’s section.
Sourcepub fn stats(&self) -> BTreeMap<String, Rendition>
pub fn stats(&self) -> BTreeMap<String, Rendition>
What each media track minted under this catalog has written, keyed by its catalog key: the
rendition ID, or the track name for a passthrough or verbatim mpegts track.
Counters are cumulative for the life of the catalog, so a track that ended keeps its final
counts and a later track under the same key continues them, until 1,024 keys are held: then
ended tracks make way for new ones. Fold this into a
hang::stats::Snapshot on the stats interval.
Sourcepub fn json_snapshot<T: Serialize>(
&self,
track: Producer,
config: impl IntoRendition<E, JsonConfig>,
options: Options,
) -> Result<Snapshot<T>>
pub fn json_snapshot<T: Serialize>( &self, track: Producer, config: impl IntoRendition<E, JsonConfig>, options: Options, ) -> Result<Snapshot<T>>
Publish track as a latest-value JSON track, advertising it in the catalog.
The caller creates the track on the broadcast, as it does for a media track; this writes its
catalog entry and removes the entry when the returned handle drops. The catalog key is
track.name() verbatim. Create track with a
timescale, since every write is stamped on the
broadcast clock, and with compression set: JSON is small and
repetitive.
config is a json::Config for the json section, or an
application’s own entry embedding a JsonConfig (see
IntoRendition). The producer sets its mode and fills an absent
bitrate from what it writes. options
configures the encoder and is not written into the catalog entry. With
deltas, create track with a
refresh ratio and drive
Snapshot::poll_refresh, so joiners get a fresh group.
Errors if the entry’s section already carries that name, for example an entry seeded
through Config::with_catalog or one pointing at a sibling broadcast, if the entry
references another broadcast, or with [moq_net::Error::TimestampMismatch] if track has no
timescale.
Sourcepub fn json_stream<T: Serialize>(
&self,
track: Producer,
config: impl IntoRendition<E, JsonConfig>,
) -> Result<Stream<T>>
pub fn json_stream<T: Serialize>( &self, track: Producer, config: impl IntoRendition<E, JsonConfig>, ) -> Result<Stream<T>>
Publish track as an append-log JSON track, advertising it in the catalog.
See json_snapshot for the lifecycle; this differs only in that every
record is preserved rather than superseded.