Skip to main content

Producer

Struct Producer 

Source
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

Source

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.

Source

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.

Source

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.

Source

pub fn abort_handle(&self) -> AbortHandle

A handle that aborts the published track without keeping it open, so an owner can end it while a write still holds this producer. Like demand, read it again after a write.

Source

pub fn rung(&self) -> Rung

This rendition’s place in a simulcast ladder, for the next rendition up to take as its Options::lower.

Source

pub fn reservation(&self) -> &Arc<Reservation> ⓘ

This track’s claim on the bandwidth allocator, whose rate is the grant the encoder follows. A frame that moves the rendition to a new track claims on that one instead, so read this again after write.

Source

pub fn bitrate(&self) -> Option<Rate>

The bitrate the encoder produces at, or None while a rung is disabled.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

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.

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

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

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