pub struct Producer { /* private fields */ }Expand description
Encode raw Frames and publish them as a moq video track (avc3 / hev1 by codec).
The counterpart of moq_audio::encode::Producer: it owns its encoder, registers the catalog
rendition at construction, probed from the encoder so a subscriber can discover the track
before a frame is written, and follows the bandwidth grant between
frames. Publisher is the layer below, for frames you encoded yourself.
While nobody watches, a rendition with no lower one encodes at its
ceiling and ignores the grant: its groups wait in the cache rather than being paced to a
subscriber, and the next viewer’s grant applies afresh. A rung keeps following the grant,
which reports the slice it would get back, so it resumes after its viewers left.
The async methods are not cancel-safe, as Sink’s are not: a cancelled one leaves the
encoder refusing every later call, so drop the producer instead.
Implementations§
Source§impl Producer
impl Producer
Sourcepub async fn new<E: CatalogExt>(
broadcast: &Producer,
catalog: Producer<E>,
options: Options,
) -> Result<Self, Error>
pub async fn new<E: CatalogExt>( broadcast: &Producer, catalog: Producer<E>, options: Options, ) -> Result<Self, Error>
Open the encoder and publish a track for it in broadcast, registering its rendition in
catalog immediately.
The rendition comes from Config::probe, so it says what the first keyframe will. An
unsupported codec, resolution, or backend fails here, before the track exists.
Sourcepub async fn requested<E: CatalogExt>(
request: Request,
catalog: Producer<E>,
options: Options,
) -> Result<Self, Error>
pub async fn requested<E: CatalogExt>( request: Request, catalog: Producer<E>, options: Options, ) -> Result<Self, Error>
Open the encoder and publish 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 (such as the priority a
lower rung sets) 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 this machine can’t
encode rejects the request with NotFound, and a
rendition the catalog refuses ends the accepted track with it.
Sourcepub fn demand(&self) -> Demand
pub fn demand(&self) -> Demand
A watch-only handle to the published track’s subscriber demand. A frame that changes the
decoder identity, such as a resume at a ceiling past the declared level, moves the
rendition to a newly named track, so read this again after write.
Sourcepub fn abort_handle(&self) -> AbortHandle
pub fn abort_handle(&self) -> AbortHandle
Sourcepub fn rung(&self) -> Rung
pub fn rung(&self) -> Rung
This rendition’s place in a simulcast ladder, for the next rendition up to take as its
Options::lower.
Sourcepub fn reservation(&self) -> &Arc<Reservation> ⓘ
pub fn reservation(&self) -> &Arc<Reservation> ⓘ
Sourcepub fn bitrate(&self) -> Option<Rate>
pub fn bitrate(&self) -> Option<Rate>
The bitrate the encoder produces at, or None while a rung is disabled.
Sourcepub async fn write(&mut self, frame: impl Into<Arc<Frame>>) -> Result<(), Error>
pub async fn write(&mut self, frame: impl Into<Arc<Frame>>) -> Result<(), Error>
Encode and publish one frame at its own timestamp, at the configured size.
Follows any grant change first, so the encoder retunes between frames rather than mid- encode. A backend that pipelines publishes an earlier frame’s output here, so a call that publishes nothing is normal. While a rung is disabled, the frame is dropped unencoded.
Takes the frame as anything that can become an Arc, like Sink::encode, so a
source fanning one frame out to a ladder hands each rung a clone of the handle.
Sourcepub async fn cut(&mut self) -> Result<(), Error>
pub async fn cut(&mut self) -> Result<(), Error>
Cut a new group at the next written frame.
Optional: the encoder already keyframes every join, and each of those cuts
a group. Reach for it to place a boundary the encoder cannot see, such as a scene change.
Fails when the encoder cannot force a keyframe, leaving groups to that interval. A stopped
encoder opens with a keyframe anyway, so this does nothing then.
Sourcepub async fn set_bitrate(&mut self, bitrate: Rate) -> Result<(), Error>
pub async fn set_bitrate(&mut self, bitrate: Rate) -> Result<(), Error>
Set the ceiling to bitrate, retuning the encoder to it from roughly the next frame. No
keyframe is forced. The reservation moves with it, so a later grant never retunes above it.
Some backends cannot raise past the bitrate they opened at (openh264), so configure the
highest you will ask for and adapt downwards. A refused rate, such as
Error::BitrateUnsupported or openh264’s raise past its opening rate, changes nothing:
the encoder keeps encoding at its current rate. Only Error::CodecGone means it stopped.
Sourcepub async fn discontinuity(&mut self) -> Result<(), Error>
pub async fn discontinuity(&mut self) -> Result<(), Error>
Mark a break in the published timeline: what is written next does not continue what came before.
Call this when the source stops rather than merely pausing between frames, such as a paused game or a source switch. The encoder drains into the track and closes, so what resumes opens a group with a keyframe from a fresh one. Errors when the drain fails, after the break is marked anyway: only those last frames are lost.
Sourcepub async fn finish(self) -> Result<Finished, Error>
pub async fn finish(self) -> Result<Finished, Error>
Drain the encoder into the track and finish it.
Consumes the producer, releasing the encoder and the bandwidth claim. The returned
Finished keeps the track and its catalog rendition published, and can still
abort them. A drain that fails ends the track with an error instead,
since a clean end promises a subscriber everything the publisher produced.
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.