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/stsz.rs | |
| download | fmp4-trunk.tar.gz fmp4-trunk.zip | |
Diffstat (limited to 'src/boxes/stsz.rs')
| -rw-r--r-- | src/boxes/stsz.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/boxes/stsz.rs b/src/boxes/stsz.rs new file mode 100644 index 0000000..7dc3eba --- /dev/null +++ b/src/boxes/stsz.rs @@ -0,0 +1,42 @@ +use byteorder::{BigEndian, WriteBytesExt}; +use four_cc::FourCC; + +use bytes::{BufMut, BytesMut}; + +use crate::Mp4BoxError; +use crate::{FullBoxHeader, Mp4Box}; + +use std::mem::size_of; + +pub struct SampleSizeBox { + pub sample_sizes: Vec<u32>, +} + +impl Mp4Box for SampleSizeBox { + const NAME: FourCC = FourCC(*b"stsz"); + + fn get_full_box_header(&self) -> Option<FullBoxHeader> { + Some(FullBoxHeader::new(0, 0)) + } + + fn content_size(&self) -> u64 { + size_of::<u32>() as u64 + + size_of::<u32>() as u64 + + size_of::<u32>() as u64 * self.sample_sizes.len() as u64 + } + + fn write_box_contents(&self, writer: &mut BytesMut) -> Result<(), Mp4BoxError> { + let mut v = Vec::new(); + + v.write_u32::<BigEndian>(0)?; + v.write_u32::<BigEndian>(self.sample_sizes.len() as u32)?; + + for &size in &self.sample_sizes { + v.write_u32::<BigEndian>(size)?; + } + + writer.put_slice(&v); + + Ok(()) + } +} |
