flowly_mp4/mp4box/
mdia.rs1use serde::Serialize;
2use std::io::Write;
3
4use crate::mp4box::*;
5use crate::mp4box::{hdlr::HdlrBox, mdhd::MdhdBox, minf::MinfBox};
6
7#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize)]
8pub struct MdiaBox {
9 pub mdhd: MdhdBox,
10 pub hdlr: HdlrBox,
11 pub minf: MinfBox,
12}
13
14impl MdiaBox {
15 pub fn get_type(&self) -> BoxType {
16 BoxType::MdiaBox
17 }
18
19 pub fn get_size(&self) -> u64 {
20 HEADER_SIZE + self.mdhd.box_size() + self.hdlr.box_size() + self.minf.box_size()
21 }
22}
23
24impl Mp4Box for MdiaBox {
25 const TYPE: BoxType = BoxType::MdiaBox;
26
27 fn box_size(&self) -> u64 {
28 self.get_size()
29 }
30
31 fn to_json(&self) -> Result<String, Error> {
32 Ok(serde_json::to_string(&self).unwrap())
33 }
34
35 fn summary(&self) -> Result<String, Error> {
36 let s = String::new();
37 Ok(s)
38 }
39}
40
41impl BlockReader for MdiaBox {
42 fn read_block<'a>(reader: &mut impl Reader<'a>) -> Result<Self, Error> {
43 let (mdhd, hdlr, minf) = reader.find_box3()?;
44 Ok(MdiaBox { mdhd, hdlr, minf })
45 }
46
47 fn size_hint() -> usize {
48 0
49 }
50}
51
52impl<W: Write> WriteBox<&mut W> for MdiaBox {
53 fn write_box(&self, writer: &mut W) -> Result<u64, Error> {
54 let size = self.box_size();
55 BoxHeader::new(Self::TYPE, size).write(writer)?;
56
57 self.mdhd.write_box(writer)?;
58 self.hdlr.write_box(writer)?;
59 self.minf.write_box(writer)?;
60
61 Ok(size)
62 }
63}