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/minf.rs | |
| download | fmp4-trunk.tar.gz fmp4-trunk.zip | |
Diffstat (limited to 'src/boxes/minf.rs')
| -rw-r--r-- | src/boxes/minf.rs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/boxes/minf.rs b/src/boxes/minf.rs new file mode 100644 index 0000000..70a6cc4 --- /dev/null +++ b/src/boxes/minf.rs @@ -0,0 +1,46 @@ +use four_cc::FourCC; + +use bytes::BytesMut; + +use crate::Mp4Box; +use crate::Mp4BoxError; + +use super::{DataInformationBox, SampleTableBox, SoundMediaHeaderBox, VideoMediaHeaderBox}; + +pub enum MediaHeader { + Video(VideoMediaHeaderBox), + Sound(SoundMediaHeaderBox), +} + +pub struct MediaInformationBox { + pub media_header: MediaHeader, + pub dinf: DataInformationBox, + pub stbl: SampleTableBox, +} + +impl Mp4Box for MediaInformationBox { + const NAME: FourCC = FourCC(*b"minf"); + + fn content_size(&self) -> u64 { + let mut size = self.dinf.size() + self.stbl.size(); + + match &self.media_header { + MediaHeader::Video(vmhd) => size += vmhd.size(), + MediaHeader::Sound(smhd) => size += smhd.size(), + } + + size + } + + fn write_box_contents(&self, writer: &mut BytesMut) -> Result<(), Mp4BoxError> { + match &self.media_header { + MediaHeader::Video(vmhd) => vmhd.write(writer)?, + MediaHeader::Sound(smhd) => smhd.write(writer)?, + } + + self.dinf.write(writer)?; + self.stbl.write(writer)?; + + Ok(()) + } +} |
