aboutsummaryrefslogtreecommitdiffstats
path: root/src/boxes/stsd.rs
diff options
context:
space:
mode:
authorFelix Kaaman <tmtu@tmtu.ee>2021-01-07 20:32:49 +0100
committerFelix Kaaman <tmtu@tmtu.ee>2021-01-07 20:32:49 +0100
commit9e6e4962f2346a3fbd96ab3e6c331858ef6ec0d1 (patch)
tree14b580295f71243def9c8df9c242c33f9f2c66a8 /src/boxes/stsd.rs
downloadfmp4-trunk.tar.gz
fmp4-trunk.zip
Initial commitHEADtrunk
Diffstat (limited to 'src/boxes/stsd.rs')
-rw-r--r--src/boxes/stsd.rs61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/boxes/stsd.rs b/src/boxes/stsd.rs
new file mode 100644
index 0000000..35ee5b2
--- /dev/null
+++ b/src/boxes/stsd.rs
@@ -0,0 +1,61 @@
+use byteorder::{BigEndian, ByteOrder};
+use four_cc::FourCC;
+
+use bytes::{BufMut, BytesMut};
+
+use crate::FullBoxHeader;
+use crate::Mp4Box;
+use crate::Mp4BoxError;
+
+use super::AvcSampleEntryBox;
+
+use std::mem::size_of;
+
+pub enum SampleEntry {
+ Avc(AvcSampleEntryBox),
+}
+
+impl SampleEntry {
+ fn size(&self) -> u64 {
+ match self {
+ SampleEntry::Avc(avc) => avc.size(),
+ }
+ }
+}
+
+pub struct SampleDescriptionBox {
+ pub entries: Vec<SampleEntry>,
+}
+
+impl Mp4Box for SampleDescriptionBox {
+ const NAME: FourCC = FourCC(*b"stsd");
+
+ fn get_full_box_header(&self) -> Option<FullBoxHeader> {
+ Some(FullBoxHeader::new(0, 0))
+ }
+
+ fn content_size(&self) -> u64 {
+ let mut size = size_of::<u32>() as u64;
+
+ for entry in &self.entries {
+ size += entry.size();
+ }
+
+ size
+ }
+
+ fn write_box_contents(&self, writer: &mut BytesMut) -> Result<(), Mp4BoxError> {
+ let mut contents = [0u8; 4];
+ BigEndian::write_u32(&mut contents, self.entries.len() as _);
+
+ writer.put_slice(&contents);
+
+ for entry in &self.entries {
+ match entry {
+ SampleEntry::Avc(avc) => avc.write(writer)?,
+ }
+ }
+
+ Ok(())
+ }
+}