ffmpeg_the_third/util/channel_layout/
order.rs

1use crate::ffi::AVChannelOrder;
2
3use AVChannelOrder::*;
4use ChannelOrder::*;
5
6/// Specifies an order for audio channels.
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum ChannelOrder {
9    /// No channel order. Only the channel count is specified.
10    Unspecified,
11
12    /// Native channel order, i.e. the channels are in the same order in which they
13    /// are defined in the [`Channel`][super::Channel] enum. This supports up to 63 channels.
14    Native,
15
16    /// The channel order does not correspond to any predefined order and is stored as an
17    /// explicit map. This can be used to support layouts with more than 64 channels or with
18    /// empty channels at arbitrary positions.
19    Custom,
20
21    /// The audio is represented as the decomposition of the sound field into spherical harmonics.
22    Ambisonic,
23}
24
25impl From<AVChannelOrder> for ChannelOrder {
26    fn from(value: AVChannelOrder) -> Self {
27        match value {
28            AV_CHANNEL_ORDER_UNSPEC => Unspecified,
29            AV_CHANNEL_ORDER_NATIVE => Native,
30            AV_CHANNEL_ORDER_CUSTOM => Custom,
31            AV_CHANNEL_ORDER_AMBISONIC => Ambisonic,
32            #[cfg(feature = "ffmpeg_7_0")]
33            // Not part of the API, should never be used
34            FF_CHANNEL_ORDER_NB => unreachable!(),
35            #[cfg(feature = "non-exhaustive-enums")]
36            _ => unimplemented!(),
37        }
38    }
39}
40
41impl From<ChannelOrder> for AVChannelOrder {
42    fn from(value: ChannelOrder) -> Self {
43        match value {
44            Unspecified => AV_CHANNEL_ORDER_UNSPEC,
45            Native => AV_CHANNEL_ORDER_NATIVE,
46            Custom => AV_CHANNEL_ORDER_CUSTOM,
47            Ambisonic => AV_CHANNEL_ORDER_AMBISONIC,
48        }
49    }
50}