scuffle_mp4/boxes/types/
av1c.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use std::io;

use bytes::Bytes;
use scuffle_av1::AV1CodecConfigurationRecord;

use crate::boxes::header::BoxHeader;
use crate::boxes::traits::BoxType;

#[derive(Debug, Clone, PartialEq)]
/// AV1 Configuration Box
/// <https://aomediacodec.github.io/av1-isobmff/#av1codecconfigurationbox-section>
pub struct Av1C {
    pub header: BoxHeader,
    pub av1_config: AV1CodecConfigurationRecord,
}

impl Av1C {
    pub fn new(av1_config: AV1CodecConfigurationRecord) -> Self {
        Self {
            header: BoxHeader::new(Self::NAME),
            av1_config,
        }
    }
}

impl BoxType for Av1C {
    const NAME: [u8; 4] = *b"av1C";

    fn demux(header: BoxHeader, data: Bytes) -> io::Result<Self> {
        let mut reader = io::Cursor::new(data);
        Ok(Self {
            header,
            av1_config: AV1CodecConfigurationRecord::demux(&mut reader)?,
        })
    }

    fn primitive_size(&self) -> u64 {
        self.av1_config.size()
    }

    fn primitive_mux<T: io::Write>(&self, writer: &mut T) -> io::Result<()> {
        self.av1_config.mux(writer)
    }
}