mp4_atom/moov/trak/mdia/minf/stbl/stsd/hevc/
hev1.rs1use crate::*;
2
3#[derive(Debug, Clone, PartialEq, Eq, Default)]
4#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5pub struct Hev1 {
6 pub visual: Visual,
7 pub hvcc: Hvcc,
8 pub btrt: Option<Btrt>,
9 pub colr: Option<Colr>,
10 pub pasp: Option<Pasp>,
11 pub taic: Option<Taic>,
12 pub fiel: Option<Fiel>,
13}
14
15impl Atom for Hev1 {
16 const KIND: FourCC = FourCC::new(b"hev1");
17
18 fn decode_body<B: Buf>(buf: &mut B) -> Result<Self> {
19 let visual = Visual::decode(buf)?;
20
21 let mut hvcc = None;
22 let mut btrt = None;
23 let mut colr = None;
24 let mut pasp = None;
25 let mut taic = None;
26 let mut fiel = None;
27 while let Some(atom) = Any::decode_maybe(buf)? {
28 match atom {
29 Any::Hvcc(atom) => hvcc = atom.into(),
30 Any::Btrt(atom) => btrt = atom.into(),
31 Any::Colr(atom) => colr = atom.into(),
32 Any::Pasp(atom) => pasp = atom.into(),
33 Any::Taic(atom) => taic = atom.into(),
34 Any::Fiel(atom) => fiel = atom.into(),
35 unknown => Self::decode_unknown(&unknown)?,
36 }
37 }
38
39 Ok(Hev1 {
40 visual,
41 hvcc: hvcc.ok_or(Error::MissingBox(Hvcc::KIND))?,
42 btrt,
43 colr,
44 pasp,
45 taic,
46 fiel,
47 })
48 }
49
50 fn encode_body<B: BufMut>(&self, buf: &mut B) -> Result<()> {
51 self.visual.encode(buf)?;
52 self.hvcc.encode(buf)?;
53 self.btrt.encode(buf)?;
54 self.colr.encode(buf)?;
55 self.pasp.encode(buf)?;
56 self.taic.encode(buf)?;
57 self.fiel.encode(buf)?;
58 Ok(())
59 }
60}
61
62#[cfg(test)]
63mod tests {
64 use super::*;
65
66 #[test]
67 fn test_hev1() {
68 let expected = Hev1 {
69 visual: Visual {
70 data_reference_index: 1,
71 width: 320,
72 height: 240,
73 horizresolution: 0x48.into(),
74 vertresolution: 0x48.into(),
75 frame_count: 1,
76 compressor: "ya boy".into(),
77 depth: 24,
78 },
79 hvcc: Hvcc {
80 configuration_version: 1,
81 ..Default::default()
82 },
83 btrt: None,
84 colr: None,
85 pasp: None,
86 taic: None,
87 fiel: None,
88 };
89 let mut buf = Vec::new();
90 expected.encode(&mut buf).unwrap();
91
92 let mut buf = buf.as_ref();
93 let decoded = Hev1::decode(&mut buf).unwrap();
94 assert_eq!(decoded, expected);
95 }
96}