mp4_atom/moov/trak/mdia/minf/stbl/stsd/
mod.rs

1mod av01;
2mod avc1;
3mod hev1;
4mod mp4a;
5mod tx3g;
6mod visual;
7mod vp09;
8mod vpcc;
9
10pub use av01::*;
11pub use avc1::*;
12pub use hev1::*;
13pub use mp4a::*;
14pub use tx3g::*;
15pub use visual::*;
16pub use vp09::*;
17pub use vpcc::*;
18
19use crate::*;
20
21#[derive(Debug, Clone, PartialEq, Eq, Default)]
22#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
23pub struct Stsd {
24    pub avc1: Option<Avc1>,
25    pub hev1: Option<Hev1>,
26    pub vp09: Option<Vp09>,
27    pub mp4a: Option<Mp4a>,
28    pub tx3g: Option<Tx3g>,
29    pub av01: Option<Av01>,
30}
31
32impl AtomExt for Stsd {
33    type Ext = ();
34
35    const KIND_EXT: FourCC = FourCC::new(b"stsd");
36
37    fn decode_body_ext<B: Buf>(buf: &mut B, _ext: ()) -> Result<Self> {
38        let entries = u32::decode(buf)?;
39
40        let mut avc1 = None;
41        let mut hev1 = None;
42        let mut vp09 = None;
43        let mut mp4a = None;
44        let mut tx3g = None;
45        let mut av01 = None;
46
47        for _ in 0..entries {
48            let atom = Any::decode(buf)?;
49            match atom {
50                Any::Avc1(atom) => avc1 = atom.into(),
51                Any::Hev1(atom) => hev1 = atom.into(),
52                Any::Vp09(atom) => vp09 = atom.into(),
53                Any::Mp4a(atom) => mp4a = atom.into(),
54                Any::Tx3g(atom) => tx3g = atom.into(),
55                Any::Av01(atom) => av01 = atom.into(),
56                Any::Unknown(kind, _) => tracing::warn!("unknown atom: {:?}", kind),
57                _ => return Err(Error::UnexpectedBox(atom.kind())),
58            }
59        }
60
61        Ok(Stsd {
62            avc1,
63            hev1,
64            vp09,
65            mp4a,
66            tx3g,
67            av01,
68        })
69    }
70
71    fn encode_body_ext<B: BufMut>(&self, buf: &mut B) -> Result<()> {
72        (self.avc1.is_some() as u32
73            + self.hev1.is_some() as u32
74            + self.vp09.is_some() as u32
75            + self.mp4a.is_some() as u32
76            + self.tx3g.is_some() as u32)
77            .encode(buf)?;
78
79        self.avc1.encode(buf)?;
80        self.hev1.encode(buf)?;
81        self.vp09.encode(buf)?;
82        self.mp4a.encode(buf)?;
83        self.tx3g.encode(buf)?;
84
85        Ok(())
86    }
87}