mirror of
https://github.com/alfg/mp4-rust.git
synced 2024-06-10 17:09:22 +00:00
0df82aec5f
* Add ReadBox trait * Add boxtype macro * Remove offset in BoxHeader * Fix parsing error when box has largesize * Remove duplicated codes reading version and flags * Add avc1 box * Add mp4a box * Add mp4a box * Add DecoderSpecificDescriptor in esds box * Add necessary sub-boxes to stbl box * Improve ReadBox::read_box() * Add smhd box * Refactor BoxHeader * Refactor BMFF * Refactor * Add some functions to get offset and size of sample * Add Mp4Reader::read_sample() that read media samples Co-authored-by: Byungwan Jun <unipro.kr@gmail.com>
68 lines
1.4 KiB
Rust
68 lines
1.4 KiB
Rust
use std::io::{Seek, Read, Write};
|
|
|
|
use crate::*;
|
|
use crate::atoms::*;
|
|
use crate::atoms::elst::ElstBox;
|
|
|
|
|
|
#[derive(Debug, Default)]
|
|
pub struct EdtsBox {
|
|
pub elst: Option<ElstBox>,
|
|
}
|
|
|
|
impl EdtsBox {
|
|
pub(crate) fn new() -> EdtsBox {
|
|
Default::default()
|
|
}
|
|
}
|
|
|
|
impl Mp4Box for EdtsBox {
|
|
fn box_type() -> BoxType {
|
|
BoxType::EdtsBox
|
|
}
|
|
|
|
fn box_size(&self) -> u64 {
|
|
let mut size = HEADER_SIZE;
|
|
if let Some(ref elst) = self.elst {
|
|
size += elst.box_size();
|
|
}
|
|
size
|
|
}
|
|
}
|
|
|
|
impl<R: Read + Seek> ReadBox<&mut R> for EdtsBox {
|
|
fn read_box(reader: &mut R, size: u64) -> Result<Self> {
|
|
let start = get_box_start(reader)?;
|
|
|
|
let mut edts = EdtsBox::new();
|
|
|
|
let header = BoxHeader::read(reader)?;
|
|
let BoxHeader{ name, size: s } = header;
|
|
|
|
match name {
|
|
BoxType::ElstBox => {
|
|
let elst = ElstBox::read_box(reader, s)?;
|
|
edts.elst = Some(elst);
|
|
}
|
|
_ => {}
|
|
}
|
|
|
|
skip_read_to(reader, start + size)?;
|
|
|
|
Ok(edts)
|
|
}
|
|
}
|
|
|
|
impl<W: Write> WriteBox<&mut W> for EdtsBox {
|
|
fn write_box(&self, writer: &mut W) -> Result<u64> {
|
|
let size = self.box_size();
|
|
BoxHeader::new(Self::box_type(), size).write(writer)?;
|
|
|
|
if let Some(ref elst) = self.elst {
|
|
elst.write_box(writer)?;
|
|
}
|
|
|
|
Ok(size)
|
|
}
|
|
}
|