diff options
| author | Felix Kaaman <tmtu@tmtu.ee> | 2021-01-07 20:32:49 +0100 |
|---|---|---|
| committer | Felix Kaaman <tmtu@tmtu.ee> | 2021-01-07 20:32:49 +0100 |
| commit | 9e6e4962f2346a3fbd96ab3e6c331858ef6ec0d1 (patch) | |
| tree | 14b580295f71243def9c8df9c242c33f9f2c66a8 /src/boxes/ftyp.rs | |
| download | fmp4-9e6e4962f2346a3fbd96ab3e6c331858ef6ec0d1.tar.gz fmp4-9e6e4962f2346a3fbd96ab3e6c331858ef6ec0d1.zip | |
Diffstat (limited to 'src/boxes/ftyp.rs')
| -rw-r--r-- | src/boxes/ftyp.rs | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/boxes/ftyp.rs b/src/boxes/ftyp.rs new file mode 100644 index 0000000..f959e51 --- /dev/null +++ b/src/boxes/ftyp.rs @@ -0,0 +1,52 @@ +use byteorder::{BigEndian, WriteBytesExt}; +use four_cc::FourCC; + +use bytes::{BufMut, BytesMut}; + +use std::io::Write; +use std::mem::size_of; + +use crate::{Mp4Box, Mp4BoxError}; + +pub struct FileTypeBox { + major_brand: FourCC, + minor_version: u32, + compatible_brands: Vec<FourCC>, +} + +impl FileTypeBox { + pub fn new(major_brand: FourCC, minor_version: u32, compatible_brands: Vec<FourCC>) -> Self { + FileTypeBox { + major_brand, + minor_version, + compatible_brands, + } + } +} + +impl Mp4Box for FileTypeBox { + const NAME: FourCC = FourCC(*b"ftyp"); + + fn content_size(&self) -> u64 { + size_of::<u32>() as u64 + // major_brand + size_of::<u32>() as u64 + // minor_version + size_of::<u32>() as u64 * self.compatible_brands.len() as u64 // compatible_brands + } + + fn write_box_contents(&self, writer: &mut BytesMut) -> Result<(), Mp4BoxError> { + let mut v = Vec::new(); + + Write::write_all(&mut v, &self.major_brand.0)?; + v.write_u32::<BigEndian>(self.minor_version)?; + + for brand in &self.compatible_brands { + Write::write_all(&mut v, &brand.0)?; + } + + assert_eq!(self.content_size() as usize, v.len()); + + writer.put_slice(&v); + + Ok(()) + } +} |
