Skip to main content

Producer

Struct Producer 

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

Source

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.

Source

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

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn snapshot(&self) -> Catalog<E>

Get a snapshot of the current catalog.

Source

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.

Source

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.

Source

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

Source

pub fn video<C: Container>( &self, track: Producer, container: C, config: impl Into<Option<VideoConfig>>, ) -> Result<Producer<C, VideoConfig>>
where Error: From<C::Error>,

Publish a video track and own its catalog rendition.

Source

pub fn audio<C: Container>( &self, track: Producer, container: C, config: impl Into<Option<AudioConfig>>, ) -> Result<Producer<C, AudioConfig>>
where Error: From<C::Error>,

Publish an audio track and own its catalog rendition.

Source

pub fn text<C: Container>( &self, track: Producer, container: C, config: impl Into<Option<TextConfig>>, ) -> Result<Producer<C, TextConfig>>
where Error: From<C::Error>,

Publish a text track and own its catalog rendition.

Source

pub fn track<C, R>( &self, track: Producer, container: C, config: impl Into<Option<R>>, ) -> Result<Producer<C, R>>
where C: Container, R: RenditionConfig<E>, Error: From<C::Error>,

Publish a track using a custom catalog config.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn consume(&self) -> Result<Consumer<E>, Error>

Create a consumer for this catalog, receiving updates as they’re published.

Source

pub fn abort(self, err: Error)

Abort every catalog track with err, preventing further edits.

Source

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

Finish publishing to this catalog.

An estimate rise still held by the once-a-second limit is not published: media has ended.

A failure is final: both catalog tracks end (the other one aborted with that error), and every later call reports it.

Trait Implementations§

Source§

impl<E: CatalogExt> Clone for Producer<E>

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

Auto Trait Implementations§

§

impl<E> Freeze for Producer<E>

§

impl<E> RefUnwindSafe for Producer<E>

§

impl<E> Send for Producer<E>

§

impl<E> Sync for Producer<E>

§

impl<E> Unpin for Producer<E>

§

impl<E> UnsafeUnpin for Producer<E>

§

impl<E> UnwindSafe for Producer<E>

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