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>
impl<E: CatalogExt> Producer<E>
Sourcepub fn new(
broadcast: &mut Producer,
catalog: Producer<E>,
input: Input,
options: &Options,
) -> Result<Self, Error>
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.
Sourcepub fn track_name(&self) -> &str
pub fn track_name(&self) -> &str
The name of the published track, which is Options::track resolved.
Sourcepub fn set_bitrate(&mut self, bitrate: u64) -> Result<(), Error>
pub fn set_bitrate(&mut self, bitrate: u64) -> Result<(), Error>
Retune the live encoder to bitrate bits per second.
Sourcepub fn reset_epoch(&mut self)
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.
Sourcepub fn write(&mut self, frame: &Frame) -> Result<(), Error>
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.
Sourcepub fn discontinuity(&mut self) -> Result<(), Error>
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.
Sourcepub fn finish(self) -> Result<(), Error>
pub fn finish(self) -> Result<(), Error>
Flush any pending samples (zero-padded to a full frame) and finalize the track.
Sourcepub fn abort(self, err: Error)
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.