Skip to main content

ChannelLayout

Enum ChannelLayout 

Source
#[non_exhaustive]
pub enum ChannelLayout {
Show 16 variants Mono, Stereo, Stereo21, Surround30, Quad, Surround40, Surround41, Surround50, Surround51, Surround60, Surround61, Surround70, Surround71, LoRo, LtRt, DiscreteN(u16),
}
Expand description

Audio channel layout — names a fixed ordered tuple of speaker positions, OR carries a discrete fallback count when the layout is unknown / non-standard.

Channel orderings are taken from ITU-R BS.775 (5.1 / 7.1 surround reference) and SMPTE ST 2036-2 (audio channel ordering for UHDTV). For 5.1 the canonical order this crate adopts is L, R, C, LFE, Ls, Rs (the WAVEFORMATEXTENSIBLE / Vorbis / Opus convention). 7.1 extends that with Lb, Rb (back-rear pair).

The Stereo variant covers both regular two-channel stereo and the AC-3 / AC-4 matrix-encoded downmix carriers Lo/Ro (“two of”, downmix-compatible) and Lt/Rt (“matrix-encoded for Pro Logic extraction”); the dedicated [LoRo] / [LtRt] variants surface the distinction explicitly when a downstream filter or muxer needs it.

DiscreteN(n) is the catch-all for “we know there are n channels but no recognised layout” — used when a codec produces an unusual channel count (>8) or when the container failed to surface a layout flag. It is the only variant whose position() returns None.

Marked #[non_exhaustive] so additional standard layouts (Atmos 7.1.4, Auro-3D 9.1, …) can be added without breaking match-exhaustive downstream consumers.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Mono

Mono (1ch): C.

§

Stereo

Stereo (2ch): L, R.

§

Stereo21

2.1 (3ch): L, R, LFE.

§

Surround30

3.0 surround (3ch): L, R, C.

§

Quad

Quadraphonic (4ch): L, R, Ls, Rs — no centre, side surrounds.

§

Surround40

4.0 surround per BS.775 (4ch): L, R, C, Cs — centre + back surround.

§

Surround41

4.1 surround (5ch): L, R, C, Cs, LFE.

§

Surround50

5.0 surround (5ch): L, R, C, Ls, Rs.

§

Surround51

5.1 surround (6ch): L, R, C, LFE, Ls, Rs.

§

Surround60

6.0 surround (6ch): L, R, C, Cs, Ls, Rs.

§

Surround61

6.1 surround (7ch): L, R, C, LFE, Cs, Ls, Rs.

§

Surround70

7.0 surround (7ch): L, R, C, Ls, Rs, Lb, Rb.

§

Surround71

7.1 surround (8ch): L, R, C, LFE, Ls, Rs, Lb, Rb.

§

LoRo

AC-3 / AC-4 Lo/Ro stereo downmix (2ch). Two-channel mix preserving downmix-compatibility coefficients; not matrix-encoded.

§

LtRt

AC-3 / AC-4 Lt/Rt stereo downmix (2ch). Two-channel matrix-encoded downmix carrying surround information for Dolby Pro Logic decoding.

§

DiscreteN(u16)

Discrete fallback: n channels with no recognised layout. Used for unusual / >8ch / unknown layouts surfaced by exotic codecs or containers that drop layout flags.

Implementations§

Source§

impl ChannelLayout

Source

pub fn channel_count(&self) -> u16

Number of channels in this layout.

Source

pub fn positions(&self) -> &'static [ChannelPosition]

Speaker positions in canonical order. Returns an empty slice for DiscreteN since the layout is unknown — call positions_owned to get a Vec if you need to enumerate slots regardless of known/unknown status.

Source

pub fn positions_owned(&self) -> Vec<ChannelPosition>

Owned position list. For known layouts this clones positions; for DiscreteN(n) it returns an empty Vec (positions remain unknown). Provided so callers that just want “give me positions for any layout” don’t have to special-case the discrete arm.

Source

pub fn position(&self, idx: usize) -> Option<ChannelPosition>

Speaker position at slot idx in canonical order, or None for out-of-range slots and for DiscreteN (where the layout is unknown).

Source

pub fn has_lfe(&self) -> bool

True when this layout carries a low-frequency-effects (LFE) channel.

Source

pub fn is_surround(&self) -> bool

True when this layout carries surround information (more than two channels OR an LFE). Stereo / Mono return false; LoRo / LtRt are 2-channel downmixes and also return false even though they encode surround content (that’s the whole point of a downmix).

Source

pub fn from_count(n: u16) -> ChannelLayout

Back-compat bridge: infer a layout from a bare channel count.

This mapping is what lets codecs that haven’t been updated to set a layout explicitly continue to work: they keep producing a count and we infer the most-common layout for that count. The choices follow industry defaults — 5.1 wins for 6ch (more common than 6.0), 7.1 wins for 8ch, and so on.

countlayout
1Mono
2Stereo
3Surround30
4Quad
5Surround50
6Surround51
7Surround61
8Surround71
otherDiscreteN

Trait Implementations§

Source§

impl Clone for ChannelLayout

Source§

fn clone(&self) -> ChannelLayout

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ChannelLayout

Source§

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

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

impl Display for ChannelLayout

Source§

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

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

impl FromStr for ChannelLayout

Source§

type Err = ParseChannelLayoutError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for ChannelLayout

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for ChannelLayout

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for ChannelLayout

Source§

impl Eq for ChannelLayout

Source§

impl StructuralPartialEq for ChannelLayout

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.