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