Skip to main content

Producer

Struct Producer 

Source
pub struct Producer<E: CatalogExt = ()> { /* 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 settings 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<E: CatalogExt> Producer<E>

Source

pub fn new( 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 track_name(&self) -> &str

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

Source

pub fn track(&self) -> &Producer

The underlying track producer, e.g. to watch subscriber state via used / unused.

Source

pub fn activity(&self) -> Activity

Whether the packet published most recently coded audio, or withheld it because the input was silent.

A local “am I talking” indicator without running a second voice detector over the microphone, though a silent run is punctuated by coded frames that read Activity::Active, so hold the indicator across those rather than following it packet by packet. Activity::Active until the first packet, and for codecs without a discontinuous mode.

Source

pub fn bitrate(&self) -> u64

Current encoder target bitrate in bits per second.

Source

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

Retune the live encoder to bitrate bits per second.

Source

pub fn reset_epoch(&mut self)

Re-anchor the timeline to the next frame’s timestamp, dropping any buffered samples. 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. Mirrors moq-boy’s reset_epoch. If the codec had started, an empty group is published before the next packet so subscribers reset their decoders too.

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 reset_epoch) anchors the timeline: its timestamp becomes the epoch, and emitted PTS then advances purely by the running sample count, so subsequent frames’ timestamps are ignored. An idle gap is only reflected in the PTS if you call reset_epoch 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 re-anchored epoch. Buffered samples are dropped, and the next frame anchors a fresh codec epoch. See Producer::discontinuity.

Source

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

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

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§

§

impl<E = ()> !RefUnwindSafe for Producer<E>

§

impl<E = ()> !Sync for Producer<E>

§

impl<E = ()> !UnwindSafe for Producer<E>

§

impl<E> Freeze for Producer<E>
where Rendition<E>: Freeze,

§

impl<E> Send for Producer<E>
where Rendition<E>: Send,

§

impl<E> Unpin for Producer<E>
where Rendition<E>: Unpin,

§

impl<E> UnsafeUnpin for Producer<E>
where Rendition<E>: UnsafeUnpin,

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

Source§

fn into_sample(self) -> T

Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> MaybeSend for T
where T: Send + ?Sized,

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