mp4_atom/moov/trak/mdia/minf/stbl/stsd/hevc/
hev1.rs

1use 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}
9
10impl Atom for Hev1 {
11    const KIND: FourCC = FourCC::new(b"hev1");
12
13    fn decode_body<B: Buf>(buf: &mut B) -> Result<Self> {
14        let visual = Visual::decode(buf)?;
15
16        let mut hvcc = None;
17        while let Some(atom) = Any::decode_maybe(buf)? {
18            match atom {
19                Any::Hvcc(atom) => hvcc = atom.into(),
20                _ => tracing::warn!("unknown atom: {:?}", atom),
21            }
22        }
23
24        Ok(Hev1 {
25            visual,
26            hvcc: hvcc.ok_or(Error::MissingBox(Hvcc::KIND))?,
27        })
28    }
29
30    fn encode_body<B: BufMut>(&self, buf: &mut B) -> Result<()> {
31        self.visual.encode(buf)?;
32        self.hvcc.encode(buf)?;
33
34        Ok(())
35    }
36}
37
38#[cfg(test)]
39mod tests {
40    use super::*;
41
42    #[test]
43    fn test_hev1() {
44        let expected = Hev1 {
45            visual: Visual {
46                data_reference_index: 1,
47                width: 320,
48                height: 240,
49                horizresolution: 0x48.into(),
50                vertresolution: 0x48.into(),
51                frame_count: 1,
52                compressor: "ya boy".into(),
53                depth: 24,
54            },
55            hvcc: Hvcc {
56                configuration_version: 1,
57                ..Default::default()
58            },
59        };
60        let mut buf = Vec::new();
61        expected.encode(&mut buf).unwrap();
62
63        let mut buf = buf.as_ref();
64        let decoded = Hev1::decode(&mut buf).unwrap();
65        assert_eq!(decoded, expected);
66    }
67}