From 9e6e4962f2346a3fbd96ab3e6c331858ef6ec0d1 Mon Sep 17 00:00:00 2001 From: Felix Kaaman Date: Thu, 7 Jan 2021 20:32:49 +0100 Subject: Initial commit --- src/boxes/ftyp.rs | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/boxes/ftyp.rs (limited to 'src/boxes/ftyp.rs') 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, +} + +impl FileTypeBox { + pub fn new(major_brand: FourCC, minor_version: u32, compatible_brands: Vec) -> 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::() as u64 + // major_brand + size_of::() as u64 + // minor_version + size_of::() 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::(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(()) + } +} -- cgit v1.2.3-70-g09d2