scuffle_mp4/boxes/types/
avcc.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_h264::AVCDecoderConfigurationRecord;

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

#[derive(Debug, Clone, PartialEq)]
/// AVC Configuration Box
/// ISO/IEC 14496-15:2022(E) - 5.4.2
pub struct AvcC {
    pub header: BoxHeader,
    pub avc_decoder_configuration_record: AVCDecoderConfigurationRecord,
}

impl AvcC {
    pub fn new(avc_decoder_configuration_record: AVCDecoderConfigurationRecord) -> Self {
        Self {
            header: BoxHeader::new(Self::NAME),
            avc_decoder_configuration_record,
        }
    }
}

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

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

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

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