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