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 activity(&self) -> Activity
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.
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. If the codec had started, an empty group is published before
the next packet so subscribers reset their decoders too.
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.
Frame::activity is ignored: the encoder classifies what it actually
produced, which activity reports.
Sourcepub fn discontinuity(&mut self) -> Result<(), Error>
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.
Sourcepub fn finish(self) -> Result<(), Error>
pub fn finish(self) -> Result<(), Error>
Flush pending samples, resampler output, and codec lookahead, then 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.