aboutsummaryrefslogtreecommitdiffstats
path: root/src/boxes/hdlr.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/hdlr.rs
downloadfmp4-trunk.tar.gz
fmp4-trunk.zip
Initial commitHEADtrunk
Diffstat (limited to 'src/boxes/hdlr.rs')
-rw-r--r--src/boxes/hdlr.rs48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/boxes/hdlr.rs b/src/boxes/hdlr.rs
new file mode 100644
index 0000000..0e8dfc8
--- /dev/null
+++ b/src/boxes/hdlr.rs
@@ -0,0 +1,48 @@
+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 HandlerBox {
+ pub handler_type: u32,
+ pub name: String,
+}
+
+impl Mp4Box for HandlerBox {
+ const NAME: FourCC = FourCC(*b"hdlr");
+
+ fn get_full_box_header(&self) -> Option<FullBoxHeader> {
+ Some(FullBoxHeader::new(0, 0))
+ }
+
+ fn content_size(&self) -> u64 {
+ size_of::<u32>() as u64 + // pre_defined
+ size_of::<u32>() as u64 + // handler_type
+ size_of::<u32>() as u64 * 3 + // reserved
+ self.name.as_bytes().len() as u64 + // name
+ 1
+ }
+
+ 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.handler_type)?;
+ v.write_u32::<BigEndian>(0)?;
+ v.write_u32::<BigEndian>(0)?;
+ v.write_u32::<BigEndian>(0)?;
+ v.extend(self.name.as_bytes());
+ v.push(0);
+
+ assert_eq!(v.len() as u64, self.content_size());
+
+ writer.put_slice(&v);
+
+ Ok(())
+ }
+}