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
impl Producer
Sourcepub fn new<E: CatalogExt>(
broadcast: &mut Producer,
catalog: Producer<E>,
input: Input,
options: &Options,
) -> Result<Self, Error>
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.
Sourcepub fn requested<E: CatalogExt>(
request: Request,
catalog: Producer<E>,
input: Input,
options: &Options,
) -> Result<Self, Error>
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.
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 demand(&self) -> Demand
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.
Sourcepub fn activity(&self) -> Activity
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.
Sourcepub fn set_bitrate(&mut self, bitrate: Rate) -> Result<(), Error>
pub fn set_bitrate(&mut self, bitrate: Rate) -> Result<(), Error>
Retune the live encoder to bitrate.
Sourcepub fn reanchor(&mut self)
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.
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 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.
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 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.
Sourcepub fn finish(self) -> Result<Finished, Error>
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.