Skip to main content

VideoConfig

Struct VideoConfig 

Source
#[non_exhaustive]
pub struct VideoConfig {
Show 22 fields pub broadcast: Option<Relative>, pub track: Option<String>, pub label: Option<String>, pub codec: VideoCodec, pub description: Option<Bytes>, pub coded_width: Option<u32>, pub coded_height: Option<u32>, pub display_aspect_width: Option<u32>, pub display_aspect_height: Option<u32>, pub color: Option<Color>, pub projection: Option<Projection>, pub stereo: Option<Stereo>, pub interlaced: bool, pub bitrate: Option<u64>, pub enabled: bool, pub preference: i32, pub framerate: Option<f64>, pub reorder: Option<u8>, pub optimize_for_latency: Option<bool>, pub container: Container, pub jitter: Option<Duration>, pub delay: Option<Duration>,
}
Expand description

Video decoder configuration based on WebCodecs VideoDecoderConfig.

This struct contains all the information needed to initialize a video decoder, including codec-specific parameters, resolution, and optional metadata.

Reference: https://www.w3.org/TR/webcodecs/#video-decoder-config

Marked #[non_exhaustive] so additional optional fields can be added without bumping the major version. External callers build a config with VideoConfig::new and then assign whichever optional fields they need; struct-literal construction (with or without ..base) is not available outside this crate.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§broadcast: Option<Relative>

Optional reference to another broadcast that publishes this track, expressed relative to the broadcast that served this catalog (e.g. ./source). If unset, the track lives in the same broadcast as the catalog.

This allows a transcoder to author a downstream catalog that points unchanged renditions at the source broadcast without re-publishing the bytes.

Resolve it with Path::resolve: a reference that walks above the root names no broadcast, so the catalog is rejected.

§track: Option<String>

The track’s name in its broadcast, when it differs from this entry’s ID: its key in the catalog. Absent means the ID is the track name, as in every catalog before this field.

Set it only when the ID can’t be the name, such as two renditions of same-named tracks from different broadcasts. Readers resolve the name with Reference::track; one that predates the field subscribes to the ID instead.

§label: Option<String>

Human-readable rendition name for track pickers.

§codec: VideoCodec

The codec, see the registry for details: https://w3c.github.io/webcodecs/codec_registry.html

§description: Option<Bytes>

Information used to initialize the decoder on a per-codec basis.

One of the best examples is H264, which needs the sps/pps to function. If not provided, this information is (automatically) inserted before each key-frame (marginally higher overhead).

§coded_width: Option<u32>

The largest encoded width/height the track carries, fixed for its name, never zero.

The picture resizes in band at a keyframe below these ceilings, unless the description pins it. Absent means unknown; a publisher may fill it once.

§coded_height: Option<u32>

The height counterpart of coded_width.

§display_aspect_width: Option<u32>

The aspect ratio the whole picture is displayed at, as WebCodecs’ VideoDecoderConfig.displayAspectWidth / displayAspectHeight, never zero.

Absent means the decoded picture’s own shape. A publisher with non-square samples sets the picture’s aspect here, never the sample aspect.

§display_aspect_height: Option<u32>

The height counterpart of display_aspect_width.

§color: Option<Color>

The colour the decoded pixels carry, so a renderer need not guess or reparse the bitstream.

Live state, not identity: a publisher may fill it in once the bitstream reveals it.

§projection: Option<Projection>

How the picture maps onto the viewer’s field of view. Absent means rectilinear.

Live state, like color.

§stereo: Option<Stereo>

How each eye’s view is packed into the frame. Absent means mono.

Live state, like color.

§interlaced: bool

Each picture weaves two fields, so a renderer deinterlaces it. Only written when true.

Decides decoder configuration, since some hardware decoders refuse interlaced streams.

§bitrate: Option<u64>

The maximum bitrate of the video track, if known, at most 2^53 - 1.

§enabled: bool

Whether this rendition may be selected. When false, no frames are coming and a consumer must not select it. Only written when false.

§preference: i32

Higher is preferred: a consumer selects among the highest preference it can decode, then by picture and bitrate within it. A compatibility transcode is -1 so only a consumer that can’t decode the source pulls it. A player with a viewport first keeps the renditions of its orientation, so preference ranks within one: a publisher ranks its secondary orientation lower, and a consumer without a viewport takes the main one. Only written when nonzero.

§framerate: Option<f64>

The maximum frame rate of the video track, if known.

§reorder: Option<u8>

The most frames that can precede a frame in decode order and follow it in presentation order, as H.264 max_num_reorder_frames and HEVC sps_max_num_reorder_pics count them.

0 declares that presentation order is decode order. Absent declares nothing: a consumer that authors decode times infers them from the timestamps instead. A publisher that declares it keeps it for the track’s life, and never reorders deeper.

§optimize_for_latency: Option<bool>

If true, the decoder will optimize for latency.

Default: true

§container: Container

Container format for frame encoding. Defaults to “legacy” for backward compatibility.

§jitter: Option<Duration>

The largest media span the publisher hands to the transport behind a frame’s presentation timestamp: the reorder delay of a frame presented after frames decoded behind it, or the span of a batch written together, such as an fMP4 fragment. A consumer’s jitter buffer should be at least this large. Absent when the publisher measured none.

Measured from media timestamps alone, so a frame written in presentation order adds nothing, whatever the frame rate; encoder latency and the network don’t count. It only ever grows over the life of a stream.

Serialized as a whole number of milliseconds, rounded up, so an upper bound never rounds down into a promise the publisher can’t keep.

§delay: Option<Duration>

How far this rendition’s frames reach the transport behind the broadcast’s other renditions: a constant offset, either supplied by the publisher or measured as the least its frames trailed the others’ over a window of a second of media, keeping the largest window. Lateness only some frames have, such as B-frame reorder, is left out, since a consumer measures it. Absent on a rendition that trails nothing, and on any rendition the publisher neither supplied nor measured.

A consumer adds a frame duration on top, so a publisher that knows its frames trail by no more than their own duration, such as an encoder configured not to reorder or queue, states Some(Duration::ZERO). It is never measured, and is omitted on the wire like an absent value, which means the same to a consumer. None leaves it to measurement.

A consumer holds delay + jitter for this rendition and MUST NOT subtract one rendition’s delay from another’s: each is taken against whichever rendition was ahead, so two need not share an origin. It only ever grows over the life of a stream, and is serialized like jitter.

Implementations§

Source§

impl VideoConfig

Source

pub fn new(codec: impl Into<VideoCodec>) -> Self

Construct a config with the required codec set and every optional field cleared. container defaults to Container::default. Fields are pub, so callers set whatever they need by assignment afterwards.

This is the only path external crates have to build a VideoConfig since the type is #[non_exhaustive].

Source

pub fn same_identity(&self, other: &Self) -> bool

Whether other keeps this config’s track identity: the fields a consumer cannot change without reinitializing its decoder or demuxer (codec, description, container, display_aspect_width, display_aspect_height, and interlaced).

A track name always means the same content, so a publisher that changes any of them publishes under a new name; every other field may update in place. See the draft’s Track Identity.

Trait Implementations§

Source§

impl Clone for VideoConfig

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for VideoConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for VideoConfig

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for VideoConfig

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Reference for VideoConfig

Source§

fn broadcast(&self) -> Option<&Relative>

The broadcast publishing the track, relative to the catalog’s; None is the catalog’s own.
Source§

fn track<'a>(&'a self, id: &'a str) -> &'a str

The track’s name in its broadcast, given this entry’s ID.
Source§

impl Serialize for VideoConfig

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for VideoConfig

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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