scuffle_ffmpeg/enums/av_sample_format.rs
1use nutype_enum::nutype_enum;
2
3use crate::ffi::*;
4
5const _: () = {
6 assert!(std::mem::size_of::<AVSampleFormat>() == std::mem::size_of_val(&AV_SAMPLE_FMT_NONE));
7};
8
9nutype_enum! {
10 /// Audio sample formats used in FFmpeg's `AVSampleFormat` enumeration.
11 ///
12 /// The sample format defines how audio samples are stored in memory, including:
13 /// - **Bit depth** (8-bit, 16-bit, 32-bit, 64-bit)
14 /// - **Signed vs Unsigned** (U8 is unsigned, others are signed)
15 /// - **Floating-point vs Integer**
16 /// - **Packed vs Planar** (Planar formats store each channel separately)
17 ///
18 /// See the official FFmpeg documentation:
19 /// <https://ffmpeg.org/doxygen/trunk/samplefmt_8h.html>
20 pub enum AVSampleFormat(i32) {
21 /// No sample format specified or unknown format.
22 /// Corresponds to `AV_SAMPLE_FMT_NONE`.
23 None = AV_SAMPLE_FMT_NONE as _,
24
25 /// Unsigned 8-bit PCM format (0 to 255 range).
26 /// - **Binary representation**: `0bxxxxxxxx` (8 bits)
27 /// - **Range**: `[0, 255]`
28 /// - **Stored as**: `u8`
29 /// - **Interleaved**
30 /// Corresponds to `AV_SAMPLE_FMT_U8`.
31 U8 = AV_SAMPLE_FMT_U8 as _,
32
33 /// Signed 16-bit PCM format.
34 /// - **Binary representation**: `0bxxxxxxxxxxxxxxxx` (16 bits)
35 /// - **Range**: `[-32,768, 32,767]`
36 /// - **Stored as**: `i16`
37 /// - **Interleaved**
38 /// Corresponds to `AV_SAMPLE_FMT_S16`.
39 S16 = AV_SAMPLE_FMT_S16 as _,
40
41 /// Signed 32-bit PCM format.
42 /// - **Binary representation**: `0bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx` (32 bits)
43 /// - **Range**: `[-2^31, 2^31-1]`
44 /// - **Stored as**: `i32`
45 /// - **Interleaved**
46 /// Corresponds to `AV_SAMPLE_FMT_S32`.
47 S32 = AV_SAMPLE_FMT_S32 as _,
48
49 /// 32-bit Floating-point PCM format.
50 /// - **Binary representation**: IEEE-754 32-bit float
51 /// - **Range**: `[-1.0, 1.0]` (normalized)
52 /// - **Stored as**: `f32`
53 /// - **Interleaved**
54 /// Corresponds to `AV_SAMPLE_FMT_FLT`.
55 Flt = AV_SAMPLE_FMT_FLT as _,
56
57 /// 64-bit Floating-point PCM format.
58 /// - **Binary representation**: IEEE-754 64-bit float
59 /// - **Range**: `[-1.0, 1.0]` (normalized)
60 /// - **Stored as**: `f64`
61 /// - **Interleaved**
62 /// Corresponds to `AV_SAMPLE_FMT_Dbl`.
63 Dbl = AV_SAMPLE_FMT_DBL as _,
64
65 /// **Planar** Unsigned 8-bit PCM format.
66 /// - **Binary representation**: `0bxxxxxxxx` (8 bits)
67 /// - **Range**: `[0, 255]`
68 /// - **Stored as**: `u8`
69 /// - **Planar (separate channel planes)**
70 /// Corresponds to `AV_SAMPLE_FMT_U8P`.
71 U8p = AV_SAMPLE_FMT_U8P as _,
72
73 /// **Planar** Signed 16-bit PCM format.
74 /// - **Binary representation**: `0bxxxxxxxxxxxxxxxx` (16 bits)
75 /// - **Range**: `[-32,768, 32,767]`
76 /// - **Stored as**: `i16`
77 /// - **Planar (separate channel planes)**
78 /// Corresponds to `AV_SAMPLE_FMT_S16P`.
79 S16p = AV_SAMPLE_FMT_S16P as _,
80
81 /// **Planar** Signed 32-bit PCM format.
82 /// - **Binary representation**: `0bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx` (32 bits)
83 /// - **Range**: `[-2^31, 2^31-1]`
84 /// - **Stored as**: `i32`
85 /// - **Planar (separate channel planes)**
86 /// Corresponds to `AV_SAMPLE_FMT_S32P`.
87 S32p = AV_SAMPLE_FMT_S32P as _,
88
89 /// **Planar** 32-bit Floating-point PCM format.
90 /// - **Binary representation**: IEEE-754 32-bit float
91 /// - **Range**: `[-1.0, 1.0]` (normalized)
92 /// - **Stored as**: `f32`
93 /// - **Planar (separate channel planes)**
94 /// Corresponds to `AV_SAMPLE_FMT_FLTP`.
95 Fltp = AV_SAMPLE_FMT_FLTP as _,
96
97 /// **Planar** 64-bit Floating-point PCM format.
98 /// - **Binary representation**: IEEE-754 64-bit float
99 /// - **Range**: `[-1.0, 1.0]` (normalized)
100 /// - **Stored as**: `f64`
101 /// - **Planar (separate channel planes)**
102 /// Corresponds to `AV_SAMPLE_FMT_DBLP`.
103 Dblp = AV_SAMPLE_FMT_DBLP as _,
104
105 /// Signed 64-bit PCM format.
106 /// - **Binary representation**: `0bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`
107 /// - **Range**: `[-2^63, 2^63-1]`
108 /// - **Stored as**: `i64`
109 /// - **Interleaved**
110 /// Corresponds to `AV_SAMPLE_FMT_S64`.
111 S64 = AV_SAMPLE_FMT_S64 as _,
112
113 /// **Planar** Signed 64-bit PCM format.
114 /// - **Binary representation**: `0bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`
115 /// - **Range**: `[-2^63, 2^63-1]`
116 /// - **Stored as**: `i64`
117 /// - **Planar (separate channel planes)**
118 /// Corresponds to `AV_SAMPLE_FMT_S64P`.
119 S64p = AV_SAMPLE_FMT_S64P as _,
120
121 /// Number of sample formats available (internal use only).
122 /// **DO NOT USE** if linking dynamically, as the number may change.
123 /// Corresponds to `AV_SAMPLE_FMT_NB`.
124 Nb = AV_SAMPLE_FMT_NB as _,
125 }
126}
127
128impl PartialEq<i32> for AVSampleFormat {
129 fn eq(&self, other: &i32) -> bool {
130 self.0 == *other
131 }
132}
133
134impl From<u32> for AVSampleFormat {
135 fn from(value: u32) -> Self {
136 AVSampleFormat(value as _)
137 }
138}
139
140impl From<AVSampleFormat> for u32 {
141 fn from(value: AVSampleFormat) -> Self {
142 value.0 as u32
143 }
144}