Skip to main content

Muxer

Struct Muxer 

Source
pub struct Muxer { /* private fields */ }
Expand description

Muxes one rendition’s fetched groups into standalone CMAF, without a live subscription.

The pull-based Export subscribes to a whole broadcast and interleaves its tracks; Muxer is the building block for a fetch-on-demand consumer (an HLS/DASH origin) that retrieves one group at a time via track::Consumer::fetch_group:

  1. read decodes a fetched group into media Frames, normalizing the codec shape (Annex-B H.264/H.265 becomes length-prefixed, with the config record synthesized from the in-band parameter sets).
  2. init builds the rendition’s init segment (ftyp+moov).
  3. fragment encodes frames as one moof+mdat whose tfdt carries their real presentation time, so a fragment built from a mid-stream group stands alone.

For video missing codec configuration or geometry, init returns None until a group has been read to resolve the missing fields from a keyframe.

Implementations§

Source§

impl Muxer

Source

pub fn video(config: &VideoConfig) -> Result<Self>

A muxer for a video rendition described by config.

Source

pub fn audio(config: &AudioConfig) -> Result<Self>

A muxer for an audio rendition described by config.

Source

pub fn timescale(&self) -> Timescale

The media timescale this muxer’s init segment and fragments are expressed in.

Derived from the catalog: a Cmaf rendition’s own init scale, a cadence-compatible scale for video (falling back to 90 kHz) and the sample rate for audio, unless with_timescale overrode it.

Source

pub fn with_timescale(self, timescale: Timescale) -> Result<Self>

Emit at an explicit timescale instead of the one derived from the catalog.

For a consumer whose downstream timeline is fixed, for example an HLS or DASH origin working in 90 kHz ticks.

Errors for a Cmaf rendition, whose init segment passes through from the catalog at its own scale: overriding would leave the init and the fragments on different timelines. Also errors above u32::MAX, which the init segment’s mdhd.timescale field cannot hold.

Source

pub async fn read(&mut self, group: &mut Consumer) -> Result<Vec<Frame>>

Decode one fetched group into media frames, in decode order.

Reads the group to its end, so call it only on a finished group (a live group would block until the publisher closes it). Parameter-set frames are absorbed into the codec config record; the group’s first emitted frame is marked a keyframe (a group opens on one by convention).

Source

pub fn poll_read( &mut self, waiter: &Waiter, group: &mut Consumer, out: &mut Vec<Frame>, ) -> Poll<Result<Vec<Frame>>>

read, polled: ready with the group’s frames once it ends. Pass the same empty out to every poll of one group, which holds the frames decoded so far.

Source

pub fn picture_size(&mut self, keyframe: &Frame) -> Result<Option<(u32, u32)>>

The picture size keyframe decodes to: from its in-band parameter sets (Annex-B, or length-prefixed beside an avc3/hev1 record) or its frame header (VP8, VP9, and AV1, whose frame may override its sequence maximum), else the catalog description, or None for audio or a codec that declares neither.

Pass a group’s first frame: the picture size of a track may change at any keyframe, which only the media says, so reading this per group tells which config muxes it. It leaves the init untouched.

Source

pub fn init(&self) -> Result<Option<Bytes>>

Build the rendition’s CMAF init segment (ftyp+moov), or None if it isn’t buildable yet.

A Cmaf rendition’s catalog init passes through (with the track id normalized to match fragment); a Legacy/Loc rendition’s is synthesized from the catalog config. None means a video rendition whose codec config or geometry hasn’t been resolved yet: read a group (its keyframe carries those fields) and call again.

Source

pub fn fragment( &self, sequence: u32, frames: &[Frame], end: Option<Timestamp>, ) -> Result<Bytes>

Encode frames as one moof+mdat fragment.

The tfdt base decode time is the first frame’s real presentation timestamp (at the init segment’s timescale), so the fragment is self-contained regardless of which group it came from. Frames without a duration get one inferred from the following frame’s timestamp (falling back to the catalog frame rate / sample rate), so multi-sample fragments stay decodable. sequence is the moof sequence number, informative only.

frames may span several groups, and a sample is never timed by one in the next group even so: consecutive sequence numbers say nothing about whether the publisher paused across the boundary.

end, when the caller knows where the content ends (such as the next segment’s start), times the last presented sample if neither its codec nor a duration marker does.

Auto Trait Implementations§

§

impl !Freeze for Muxer

§

impl RefUnwindSafe for Muxer

§

impl Send for Muxer

§

impl Sync for Muxer

§

impl Unpin for Muxer

§

impl UnsafeUnpin for Muxer

§

impl UnwindSafe for Muxer

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<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, 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> 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