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/mdhd.rs | |
| download | fmp4-trunk.tar.gz fmp4-trunk.zip | |
Diffstat (limited to 'src/boxes/mdhd.rs')
| -rw-r--r-- | src/boxes/mdhd.rs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/boxes/mdhd.rs b/src/boxes/mdhd.rs new file mode 100644 index 0000000..5befd67 --- /dev/null +++ b/src/boxes/mdhd.rs @@ -0,0 +1,48 @@ +use byteorder::{BigEndian, ByteOrder}; +use four_cc::FourCC; + +use bytes::{BufMut, BytesMut}; + +use crate::Mp4BoxError; +use crate::{FullBoxHeader, Mp4Box}; + +use std::mem::size_of; + +pub struct MediaHeaderBox { + pub creation_time: u64, + pub modification_time: u64, + pub timescale: u32, + pub duration: u64, +} + +impl Mp4Box for MediaHeaderBox { + const NAME: FourCC = FourCC(*b"mdhd"); + + fn get_full_box_header(&self) -> Option<FullBoxHeader> { + Some(FullBoxHeader::new(1, 0)) + } + + fn content_size(&self) -> u64 { + size_of::<u64>() as u64 + // creation_time + size_of::<u64>() as u64 + // modification_time + size_of::<u32>() as u64 + // timescale + size_of::<u64>() as u64 + // duration + size_of::<u16>() as u64 + // language + size_of::<u16>() as u64 // pre_defined + } + + fn write_box_contents(&self, writer: &mut BytesMut) -> Result<(), Mp4BoxError> { + let mut contents = [0u8; 32]; + + BigEndian::write_u64(&mut contents[..], self.creation_time); + BigEndian::write_u64(&mut contents[8..], self.modification_time); + BigEndian::write_u32(&mut contents[16..], self.timescale); + BigEndian::write_u64(&mut contents[20..], self.duration); + + BigEndian::write_u16(&mut contents[28..], 0); // language + + writer.put_slice(&contents); + + Ok(()) + } +} |
