Skip to main content

Producer

Struct Producer 

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

Encode raw PCM and publish it as a moq-mux audio track.

The input PCM layout is fixed at construction via Input; the codec config via Options. Subsequent write calls just pass a Frame: payload bytes and a timestamp.

The catalog rendition is registered at construction (not on first write), so a subscriber that opens the catalog before any frames arrive still sees the track.

Implementations§

Source§

impl Producer

Source

pub fn new<E: CatalogExt>( broadcast: &mut Producer, catalog: Producer<E>, input: Input, options: &Options, ) -> Result<Self, Error>

Publish a track encoding input into broadcast, registering its rendition in catalog immediately.

Source

pub fn requested<E: CatalogExt>( request: Request, catalog: Producer<E>, input: Input, options: &Options, ) -> Result<Self, Error>

Publish a track encoding input on the track a subscriber’s request asks for, registering its rendition in catalog immediately, as new does.

This is how an on-demand publisher serves a track asked for again after its last producer dropped while read: serve it with the options it was first published with. Its readers hold the track info they set, so options that change it end the track with MalformedTrack and fail here. Nothing checks the rest: its readers also decode with the codec settings they were first given, so keep those too. The request names the track, so Options::track must be None. A config the codec refuses rejects the request with NotFound, or ends the accepted track with it.

Source

pub fn track_name(&self) -> &str

The name of the published track, which is Options::track resolved.

Source

pub fn demand(&self) -> Demand

A watch-only handle to the track’s subscriber demand, created eagerly so subscription state is observable before any frames arrive. Watch it via wanted / wanted_changed.

Source

pub fn activity(&self) -> Activity

Whether a Kind::Voice encode is sending its talker, or withholding the silence it is in.

A local “am I talking” indicator without running a second voice detector over the microphone. It reads Activity::Dtx from the end of speech the track declared until speech resumes, and Activity::Active otherwise, including for every other kind.

Source

pub fn bitrate(&self) -> Rate

Current encoder target bitrate.

Source

pub fn set_bitrate(&mut self, bitrate: Rate) -> Result<(), Error>

Retune the live encoder to bitrate.

Source

pub fn reanchor(&mut self)

Re-anchor the timeline to the next frame’s timestamp, dropping any partial input frame. Call this when resuming after an idle gap (e.g. a released-then-reopened microphone) so the gap appears in the PTS and audio stays aligned with a wall-clock video track, rather than the gap being compressed out by the running sample count. If the codec had started, a marker group is published before the next packet so subscribers jump the playhead.

This is for a gap the caller learns of only once audio returns, such as a device stall: until then subscribers see an undeclared stall. A stop known as it happens, such as a mute, takes discontinuity instead, which needs no reanchor after it.

Source

pub fn write(&mut self, frame: &Frame) -> Result<(), Error>

Push one Frame of PCM in the layout declared by Input. Encodes and publishes as many packets as the input contains; any partial trailing frame is carried to the next call.

The first frame after construction (or reanchor) anchors the timeline: its timestamp becomes the anchor, and emitted PTS then advances purely by the running sample count, so subsequent frames’ timestamps are ignored. A timeline only moves forward, so an anchor before where the packets already stamped end is raised to there. An idle gap is only reflected in the PTS if you call reanchor on resume (which re-anchors from the next frame’s wall-clock stamp); writing straight across a gap without resetting compresses it out.

Frame::activity is ignored: the encoder classifies what it actually produced, which activity reports.

Source

pub fn discontinuity(&mut self) -> Result<(), Error>

Mark a break in the published timeline and reset codec state.

Call this when capture stops rather than merely gapping between packets: going idle, switching source, or anything else that resumes on a new anchor. Buffered samples are dropped, and the next frame sets a fresh anchor. See Producer::discontinuity.

Unlike reanchor, the marker goes out now and closes the open group, so subscribers hear the silence as declared from its start: the decoder reports it as Read::End, and a player fills it with comfort noise rather than counting a gap.

Source

pub fn finish(self) -> Result<Finished, Error>

Flush pending samples, resampler output, and codec lookahead, then finalize the track.

Consumes the producer, releasing the codec and input scratch. The returned Finished keeps the track and its catalog rendition published, and can still abort them. A finish that fails ends the track with an error instead.

Source

pub fn abort(self, err: Error)

Abort the track with err instead of finishing it, so subscribers see the real cause rather than [moq_net::Error::Dropped]. Pending samples are dropped.

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<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

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<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

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, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

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