scuffle_ffmpeg/enums/
av_channel_order.rs

1use nutype_enum::nutype_enum;
2
3use crate::ffi::*;
4
5nutype_enum! {
6    /// Audio channel ordering schemes used in FFmpeg's `AVChannelOrder`.
7    ///
8    /// This enum defines how channels are arranged in an audio stream, determining
9    /// their order and mapping.
10    ///
11    /// See the official FFmpeg documentation:
12    /// <https://ffmpeg.org/doxygen/trunk/channel__layout_8h.html>
13    pub enum AVChannelOrder(u32) {
14        /// Only the **channel count** is specified, without any further information
15        /// about the **channel order**.
16        /// - **Used for**: Unspecified channel layouts.
17        /// - **Equivalent to**: `AV_CHANNEL_ORDER_UNSPEC`
18        Unspecified = AV_CHANNEL_ORDER_UNSPEC,
19
20        /// Channels are in the **native order** defined in `AVChannel` (up to 63 channels).
21        /// - **Used for**: Standard layouts where channels are ordered as per the `AVChannel` enum.
22        /// - **Equivalent to**: `AV_CHANNEL_ORDER_NATIVE`
23        Native = AV_CHANNEL_ORDER_NATIVE,
24
25        /// The channel order does not correspond to any predefined order and is stored
26        /// as an **explicit map**.
27        /// - **Used for**:
28        ///   - Layouts with **64 or more channels**.
29        ///   - Layouts with **empty/skipped** (`AV_CHAN_UNUSED`) channels at arbitrary positions.
30        /// - **Example**: Custom surround sound layouts.
31        /// - **Equivalent to**: `AV_CHANNEL_ORDER_CUSTOM`
32        Custom = AV_CHANNEL_ORDER_CUSTOM,
33
34        /// **Ambisonic channel order**, where each channel represents a **spherical harmonic**
35        /// expansion component.
36        ///
37        /// **Channel arrangement (ACN - Ambisonic Channel Number)**:
38        /// - Channel index **n** is mapped to spherical harmonic degree **l** and order **m**:
39        ///   - `l = floor(sqrt(n))`
40        ///   - `m = n - l * (l + 1)`
41        /// - Conversely, given degree **l** and order **m**, the channel index is:
42        ///   - `n = l * (l + 1) + m`
43        ///
44        /// **Normalization**: SN3D (Schmidt Semi-Normalization) as defined in **AmbiX format ยง2.1**.
45        ///
46        /// - **Used for**: **Ambisonic (3D spatial audio)** representations.
47        /// - **Equivalent to**: `AV_CHANNEL_ORDER_AMBISONIC`
48        Ambisonic = AV_CHANNEL_ORDER_AMBISONIC,
49
50        /// **Number of channel orders** (internal use only).
51        /// - **DO NOT USE** in applications.
52        /// - **Equivalent to**: `FF_CHANNEL_ORDER_NB`
53        Nb = FF_CHANNEL_ORDER_NB,
54    }
55}
56
57impl PartialEq<u32> for AVChannelOrder {
58    fn eq(&self, other: &u32) -> bool {
59        self.0 == *other
60    }
61}
62
63impl From<AVChannelOrder> for i32 {
64    fn from(value: AVChannelOrder) -> Self {
65        value.0 as i32
66    }
67}
68
69impl From<i32> for AVChannelOrder {
70    fn from(value: i32) -> Self {
71        AVChannelOrder(value as u32)
72    }
73}