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

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.

Source

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

Mark a break in the published timeline: whatever is published next does not continue what came before.

Call this when capture stops rather than merely gapping between packets – going idle, switching source, anything that resumes on a re-anchored epoch (see reset_epoch). See Producer::discontinuity.

Source

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

Flush any pending samples (zero-padded to a full frame) and 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>

§

impl<E> Send for Producer<E>

§

impl<E> Unpin for Producer<E>

§

impl<E> UnsafeUnpin 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> 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> MaybeSend for T
where T: Send,

Source§

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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