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

1use crate::*;
2
3#[derive(Debug, Clone, PartialEq, Eq, Default)]
4#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5pub struct Hvc1 {
6    pub visual: Visual,
7    pub hvcc: Hvcc,
8    // TODO support SPS/PPS/VPS atoms
9    pub btrt: Option<Btrt>,
10    pub colr: Option<Colr>,
11    pub pasp: Option<Pasp>,
12    pub taic: Option<Taic>,
13}
14
15impl Atom for Hvc1 {
16    const KIND: FourCC = FourCC::new(b"hvc1");
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        while let Some(atom) = Any::decode_maybe(buf)? {
27            match atom {
28                Any::Hvcc(atom) => hvcc = atom.into(),
29                Any::Btrt(atom) => btrt = atom.into(),
30                Any::Colr(atom) => colr = atom.into(),
31                Any::Pasp(atom) => pasp = atom.into(),
32                Any::Taic(atom) => taic = atom.into(),
33                _ => tracing::warn!("unknown atom: {:?}", atom),
34            }
35        }
36
37        Ok(Self {
38            visual,
39            hvcc: hvcc.ok_or(Error::MissingBox(Hvcc::KIND))?,
40            btrt,
41            colr,
42            pasp,
43            taic,
44        })
45    }
46
47    fn encode_body<B: BufMut>(&self, buf: &mut B) -> Result<()> {
48        self.visual.encode(buf)?;
49        self.hvcc.encode(buf)?;
50        if self.btrt.is_some() {
51            self.btrt.encode(buf)?;
52        }
53        if self.colr.is_some() {
54            self.colr.encode(buf)?;
55        }
56        if self.pasp.is_some() {
57            self.pasp.encode(buf)?;
58        }
59        if self.taic.is_some() {
60            self.taic.encode(buf)?;
61        }
62
63        Ok(())
64    }
65}