mp4_atom/moov/trak/mdia/minf/stbl/
saiz.rs

1use crate::*;
2
3#[derive(Debug, Clone, PartialEq, Eq)]
4#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5pub struct AuxInfo {
6    pub aux_info_type: FourCC,
7    pub aux_info_type_parameter: u32,
8}
9
10ext! {
11    name: Saiz,
12    versions: [0],
13    flags: {
14        aux_info_type_present  = 0,
15    }
16}
17
18ext! {
19    name: Saio,
20    versions: [0, 1],
21    flags: {
22        aux_info_type_present  = 0,
23    }
24}
25
26/// Sample AuxiliaryInformationSizesBox, ISO/IEC 14496-12:2022 Sect 8.7.8
27#[derive(Debug, Clone, PartialEq, Eq, Default)]
28#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
29pub struct Saiz {
30    pub aux_info: Option<AuxInfo>,
31    pub default_sample_info_size: u8,
32    pub sample_count: u32,
33    pub sample_info_size: Vec<u8>,
34}
35
36impl AtomExt for Saiz {
37    type Ext = SaizExt;
38
39    const KIND_EXT: FourCC = FourCC::new(b"saiz");
40
41    fn decode_body_ext<B: Buf>(buf: &mut B, ext: SaizExt) -> Result<Self> {
42        let mut aux_info = None;
43        if ext.aux_info_type_present {
44            let aux_info_type = FourCC::decode(buf)?;
45            let aux_info_type_parameter = u32::decode(buf)?;
46            aux_info = Some(AuxInfo {
47                aux_info_type,
48                aux_info_type_parameter,
49            });
50        }
51        let default_sample_info_size = u8::decode(buf)?;
52        let sample_count = u32::decode(buf)?;
53        if default_sample_info_size == 0 {
54            let mut sample_info_size = Vec::with_capacity(sample_count as usize);
55            for _ in 0..sample_count {
56                sample_info_size.push(u8::decode(buf)?);
57            }
58            Ok(Saiz {
59                aux_info,
60                default_sample_info_size,
61                sample_count,
62                sample_info_size,
63            })
64        } else {
65            Ok(Saiz {
66                aux_info,
67                default_sample_info_size,
68                sample_count,
69                sample_info_size: vec![],
70            })
71        }
72    }
73
74    fn encode_body_ext<B: BufMut>(&self, buf: &mut B) -> Result<SaizExt> {
75        let ext = SaizExt {
76            version: SaizVersion::V0,
77            aux_info_type_present: self.aux_info.is_some(),
78        };
79        if let Some(aux_info) = &self.aux_info {
80            aux_info.aux_info_type.encode(buf)?;
81            aux_info.aux_info_type_parameter.encode(buf)?;
82        }
83        self.default_sample_info_size.encode(buf)?;
84        self.sample_count.encode(buf)?;
85        if self.default_sample_info_size == 0 {
86            for size in &self.sample_info_size {
87                size.encode(buf)?;
88            }
89        }
90        Ok(ext)
91    }
92}
93
94/// SampleAuxiliaryInformationOffsetsBox, ISO/IEC 14496-12:2022 Sect 8.7.9
95#[derive(Debug, Clone, PartialEq, Eq, Default)]
96#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
97pub struct Saio {
98    pub aux_info: Option<AuxInfo>,
99    pub offsets: Vec<u64>,
100}
101
102impl AtomExt for Saio {
103    type Ext = SaioExt;
104
105    const KIND_EXT: FourCC = FourCC::new(b"saio");
106
107    fn decode_body_ext<B: Buf>(buf: &mut B, ext: SaioExt) -> Result<Self> {
108        let mut aux_info = None;
109        if ext.aux_info_type_present {
110            let aux_info_type = FourCC::decode(buf)?;
111            let aux_info_type_parameter = u32::decode(buf)?;
112            aux_info = Some(AuxInfo {
113                aux_info_type,
114                aux_info_type_parameter,
115            });
116        }
117        let entry_count = u32::decode(buf)?;
118        let mut offsets = Vec::with_capacity(entry_count as usize);
119        for _ in 0..entry_count {
120            if ext.version == SaioVersion::V0 {
121                let offset = u32::decode(buf)? as u64;
122                offsets.push(offset);
123            } else if ext.version == SaioVersion::V1 {
124                let offset = u64::decode(buf)?;
125                offsets.push(offset);
126            }
127        }
128        Ok(Saio { aux_info, offsets })
129    }
130
131    fn encode_body_ext<B: BufMut>(&self, buf: &mut B) -> Result<SaioExt> {
132        let mut version: SaioVersion = SaioVersion::V0;
133        for offset in &self.offsets {
134            if *offset > (u32::MAX as u64) {
135                version = SaioVersion::V1;
136                break;
137            }
138        }
139
140        let ext = SaioExt {
141            version,
142            aux_info_type_present: self.aux_info.is_some(),
143        };
144        if let Some(aux_info) = &self.aux_info {
145            aux_info.aux_info_type.encode(buf)?;
146            aux_info.aux_info_type_parameter.encode(buf)?;
147        }
148        let entry_count: u32 = self.offsets.len() as u32;
149        entry_count.encode(buf)?;
150        if ext.version == SaioVersion::V0 {
151            for i in 0..self.offsets.len() {
152                let offset: u32 = self.offsets[i] as u32;
153                offset.encode(buf)?;
154            }
155        } else {
156            for offset in &self.offsets {
157                offset.encode(buf)?;
158            }
159        }
160        Ok(ext)
161    }
162}
163
164#[cfg(test)]
165mod tests {
166    use super::*;
167
168    const ENCODED_SAIZ: &[u8] = &[
169        0x00, 0x00, 0x00, 0x11, 0x73, 0x61, 0x69, 0x7a, 0x00, 0x00, 0x00, 0x00, 0x46, 0x00, 0x00,
170        0x00, 0x32,
171    ];
172
173    const ENCODED_SAIZ_CENC: &[u8] = &[
174        0x00, 0x00, 0x03, 0x07, 0x73, 0x61, 0x69, 0x7a, 0x00, 0x00, 0x00, 0x01, 0x63, 0x65, 0x6e,
175        0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xee, 0x1e, 0x18, 0x18, 0x18, 0x18,
176        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
177        0x18, 0x18, 0x18, 0x18, 0x24, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
178        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x24,
179        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
180        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x24, 0x18, 0x18, 0x18, 0x18, 0x18,
181        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
182        0x18, 0x18, 0x18, 0x18, 0x24, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
183        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x24,
184        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
185        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x24, 0x18, 0x18, 0x18, 0x18, 0x18,
186        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
187        0x18, 0x18, 0x18, 0x18, 0x24, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
188        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x24,
189        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
190        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x24, 0x18, 0x18, 0x18, 0x18, 0x18,
191        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
192        0x18, 0x18, 0x18, 0x18, 0x24, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
193        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x24,
194        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
195        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x24, 0x18, 0x18, 0x18, 0x18, 0x18,
196        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
197        0x18, 0x18, 0x18, 0x18, 0x24, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
198        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x24,
199        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
200        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x24, 0x18, 0x18, 0x18, 0x18, 0x18,
201        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
202        0x18, 0x18, 0x18, 0x18, 0x24, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
203        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x24,
204        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
205        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x24, 0x18, 0x18, 0x18, 0x18, 0x18,
206        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
207        0x18, 0x18, 0x18, 0x18, 0x24, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
208        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x24,
209        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
210        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x24, 0x18, 0x18, 0x18, 0x18, 0x18,
211        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
212        0x18, 0x18, 0x18, 0x18, 0x24, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
213        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x24,
214        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
215        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x24, 0x18, 0x18, 0x18, 0x18, 0x18,
216        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
217        0x18, 0x18, 0x18, 0x18, 0x24, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
218        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x24,
219        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
220        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x24, 0x18, 0x18, 0x18, 0x18, 0x18,
221        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
222        0x18, 0x18, 0x18, 0x18, 0x24, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
223        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x24,
224        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
225        0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
226    ];
227
228    const ENCODED_SAIO: &[u8] = &[
229        0x00, 0x00, 0x00, 0x14, 0x73, 0x61, 0x69, 0x6f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
230        0x01, 0x00, 0x00, 0x04, 0xbc,
231    ];
232
233    const ENCODED_SAIO_CENC: &[u8] = &[
234        0x00, 0x00, 0x00, 0x1c, 0x73, 0x61, 0x69, 0x6f, 0x00, 0x00, 0x00, 0x01, 0x63, 0x65, 0x6e,
235        0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x04, 0x8e,
236    ];
237
238    #[test]
239    fn test_saiz_decode() {
240        let buf: &mut std::io::Cursor<&&[u8]> = &mut std::io::Cursor::new(&ENCODED_SAIZ);
241
242        let saiz = Saiz::decode(buf).expect("failed to decode saiz");
243
244        assert_eq!(
245            saiz,
246            Saiz {
247                aux_info: None,
248                default_sample_info_size: 70,
249                sample_count: 50,
250                sample_info_size: vec![]
251            },
252        );
253    }
254
255    #[test]
256    fn test_saiz_encode() {
257        let saiz = Saiz {
258            aux_info: None,
259            default_sample_info_size: 70,
260            sample_count: 50,
261            sample_info_size: vec![],
262        };
263
264        let mut buf = Vec::new();
265        saiz.encode(&mut buf).unwrap();
266
267        assert_eq!(buf.as_slice(), ENCODED_SAIZ);
268    }
269
270    #[test]
271    fn test_saiz_encode_cenc() {
272        let buf: &mut std::io::Cursor<&&[u8]> = &mut std::io::Cursor::new(&ENCODED_SAIZ_CENC);
273
274        let saiz = Saiz::decode(buf).expect("failed to decode saiz");
275
276        assert_eq!(
277            saiz,
278            Saiz {
279                aux_info: Some(AuxInfo {
280                    aux_info_type: FourCC::new(b"cenc"),
281                    aux_info_type_parameter: 0,
282                }),
283                default_sample_info_size: 0,
284                sample_count: 750,
285                sample_info_size: vec![
286                    30, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
287                    24, 24, 24, 24, 36, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
288                    24, 24, 24, 24, 24, 24, 24, 24, 24, 36, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
289                    24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 36, 24, 24, 24, 24, 24,
290                    24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 36,
291                    24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
292                    24, 24, 24, 24, 36, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
293                    24, 24, 24, 24, 24, 24, 24, 24, 24, 36, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
294                    24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 36, 24, 24, 24, 24, 24,
295                    24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 36,
296                    24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
297                    24, 24, 24, 24, 36, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
298                    24, 24, 24, 24, 24, 24, 24, 24, 24, 36, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
299                    24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 36, 24, 24, 24, 24, 24,
300                    24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 36,
301                    24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
302                    24, 24, 24, 24, 36, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
303                    24, 24, 24, 24, 24, 24, 24, 24, 24, 36, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
304                    24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 36, 24, 24, 24, 24, 24,
305                    24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 36,
306                    24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
307                    24, 24, 24, 24, 36, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
308                    24, 24, 24, 24, 24, 24, 24, 24, 24, 36, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
309                    24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 36, 24, 24, 24, 24, 24,
310                    24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 36,
311                    24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
312                    24, 24, 24, 24, 36, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
313                    24, 24, 24, 24, 24, 24, 24, 24, 24, 36, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
314                    24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 36, 24, 24, 24, 24, 24,
315                    24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 36,
316                    24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
317                    24, 24, 24, 24, 36, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
318                    24, 24, 24, 24, 24, 24, 24, 24, 24, 36, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
319                    24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 36, 24, 24, 24, 24, 24,
320                    24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 36,
321                    24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
322                    24, 24, 24, 24, 36, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
323                    24, 24, 24, 24, 24, 24, 24, 24, 24, 24
324                ]
325            },
326        );
327    }
328
329    #[test]
330    fn test_saiz_decode_cenc() {
331        let saiz = Saiz {
332            aux_info: Some(AuxInfo {
333                aux_info_type: FourCC::new(b"cenc"),
334                aux_info_type_parameter: 0,
335            }),
336            default_sample_info_size: 0,
337            sample_count: 750,
338            sample_info_size: vec![
339                30, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
340                24, 24, 24, 36, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
341                24, 24, 24, 24, 24, 24, 24, 36, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
342                24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 36, 24, 24, 24, 24, 24, 24, 24, 24, 24,
343                24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 36, 24, 24, 24, 24, 24,
344                24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 36, 24,
345                24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
346                24, 24, 36, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
347                24, 24, 24, 24, 24, 24, 36, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
348                24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 36, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
349                24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 36, 24, 24, 24, 24, 24, 24,
350                24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 36, 24, 24,
351                24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
352                24, 36, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
353                24, 24, 24, 24, 24, 36, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
354                24, 24, 24, 24, 24, 24, 24, 24, 24, 36, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
355                24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 36, 24, 24, 24, 24, 24, 24, 24,
356                24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 36, 24, 24, 24,
357                24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
358                36, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
359                24, 24, 24, 24, 36, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
360                24, 24, 24, 24, 24, 24, 24, 24, 36, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
361                24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 36, 24, 24, 24, 24, 24, 24, 24, 24,
362                24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 36, 24, 24, 24, 24,
363                24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 36,
364                24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
365                24, 24, 24, 36, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
366                24, 24, 24, 24, 24, 24, 24, 36, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
367                24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 36, 24, 24, 24, 24, 24, 24, 24, 24, 24,
368                24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 36, 24, 24, 24, 24, 24,
369                24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 36, 24,
370                24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
371                24, 24, 36, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
372                24, 24, 24, 24, 24, 24, 36, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
373                24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 36, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
374                24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
375            ],
376        };
377
378        let mut buf = Vec::new();
379        saiz.encode(&mut buf).unwrap();
380
381        assert_eq!(buf.as_slice(), ENCODED_SAIZ_CENC);
382    }
383
384    #[test]
385    fn test_saio_decode() {
386        let buf: &mut std::io::Cursor<&&[u8]> = &mut std::io::Cursor::new(&ENCODED_SAIO);
387
388        let saio = Saio::decode(buf).expect("failed to decode saio");
389
390        assert_eq!(
391            saio,
392            Saio {
393                aux_info: None,
394                offsets: vec![1212],
395            }
396        );
397    }
398
399    #[test]
400    fn test_saio_encode() {
401        let saio = Saio {
402            aux_info: None,
403            offsets: vec![1212],
404        };
405
406        let mut buf = Vec::new();
407        saio.encode(&mut buf).unwrap();
408
409        assert_eq!(buf.as_slice(), ENCODED_SAIO);
410    }
411
412    #[test]
413    fn test_saio_decode_cenc() {
414        let buf: &mut std::io::Cursor<&&[u8]> = &mut std::io::Cursor::new(&ENCODED_SAIO_CENC);
415
416        let saio = Saio::decode(buf).expect("failed to decode saio");
417
418        assert_eq!(
419            saio,
420            Saio {
421                aux_info: Some(AuxInfo {
422                    aux_info_type: FourCC::new(b"cenc"),
423                    aux_info_type_parameter: 0
424                }),
425                offsets: vec![1166],
426            }
427        );
428    }
429
430    #[test]
431    fn test_saio_encode_cenc() {
432        let saio = Saio {
433            aux_info: Some(AuxInfo {
434                aux_info_type: FourCC::new(b"cenc"),
435                aux_info_type_parameter: 0,
436            }),
437            offsets: vec![1166],
438        };
439
440        let mut buf = Vec::new();
441        saio.encode(&mut buf).unwrap();
442
443        assert_eq!(buf.as_slice(), ENCODED_SAIO_CENC);
444    }
445}