#[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
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
impl ChannelLayout
Sourcepub fn channel_count(&self) -> u16
pub fn channel_count(&self) -> u16
Number of channels in this layout.
Sourcepub fn positions(&self) -> &'static [ChannelPosition]
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.
Sourcepub fn positions_owned(&self) -> Vec<ChannelPosition>
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.
Sourcepub fn position(&self, idx: usize) -> Option<ChannelPosition>
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).
Sourcepub fn has_lfe(&self) -> bool
pub fn has_lfe(&self) -> bool
True when this layout carries a low-frequency-effects (LFE) channel.
Sourcepub fn is_surround(&self) -> bool
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).
Sourcepub fn from_count(n: u16) -> ChannelLayout
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.
| count | layout |
|---|---|
| 1 | Mono |
| 2 | Stereo |
| 3 | Surround30 |
| 4 | Quad |
| 5 | Surround50 |
| 6 | Surround51 |
| 7 | Surround61 |
| 8 | Surround71 |
| other | DiscreteN |
Trait Implementations§
Source§impl Clone for ChannelLayout
impl Clone for ChannelLayout
Source§fn clone(&self) -> ChannelLayout
fn clone(&self) -> ChannelLayout
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for ChannelLayout
Source§impl Debug for ChannelLayout
impl Debug for ChannelLayout
Source§impl Display for ChannelLayout
impl Display for ChannelLayout
impl Eq for ChannelLayout
Source§impl FromStr for ChannelLayout
impl FromStr for ChannelLayout
Source§impl Hash for ChannelLayout
impl Hash for ChannelLayout
Source§impl PartialEq for ChannelLayout
impl PartialEq for ChannelLayout
Source§fn eq(&self, other: &ChannelLayout) -> bool
fn eq(&self, other: &ChannelLayout) -> bool
self and other values to be equal, and is used by ==.