mirror of
https://github.com/alfg/mp4-rust.git
synced 2024-05-20 09:18:16 +00:00
4df9fa1bd4
* 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 test code for all leaves in box tree * Remove entry_count that is duplacated with entries.len() * Change volume type to Ratio<u16> Co-authored-by: Byungwan Jun <unipro.kr@gmail.com>
60 lines
1.4 KiB
Rust
60 lines
1.4 KiB
Rust
use std::io::{BufReader, SeekFrom, Seek, Read, BufWriter, Write};
|
|
use byteorder::{BigEndian, ReadBytesExt};
|
|
|
|
use crate::*;
|
|
|
|
|
|
#[derive(Debug)]
|
|
pub struct StsdBox {
|
|
pub version: u8,
|
|
pub flags: u32,
|
|
}
|
|
|
|
impl Mp4Box for StsdBox {
|
|
fn box_type(&self) -> BoxType {
|
|
BoxType::StsdBox
|
|
}
|
|
|
|
fn box_size(&self) -> u64 {
|
|
// TODO
|
|
0
|
|
}
|
|
}
|
|
|
|
impl<R: Read + Seek> ReadBox<&mut BufReader<R>> for StsdBox {
|
|
fn read_box(reader: &mut BufReader<R>, size: u64) -> Result<Self> {
|
|
let current = reader.seek(SeekFrom::Current(0))?; // Current cursor position.
|
|
|
|
let (version, flags) = read_box_header_ext(reader)?;
|
|
|
|
let _entry_count = reader.read_u32::<BigEndian>()?;
|
|
|
|
let mut start = 0u64;
|
|
while start < size {
|
|
// Get box header.
|
|
let header = read_box_header(reader, start)?;
|
|
let BoxHeader{ name, size: s } = header;
|
|
|
|
match name {
|
|
BoxType::Avc1Box => {}
|
|
BoxType::Mp4aBox => {}
|
|
_ => break
|
|
}
|
|
start += s - HEADER_SIZE;
|
|
}
|
|
skip_read(reader, current, size)?;
|
|
|
|
Ok(StsdBox {
|
|
version,
|
|
flags,
|
|
})
|
|
}
|
|
}
|
|
|
|
impl<W: Write> WriteBox<&mut BufWriter<W>> for StsdBox {
|
|
fn write_box(&self, _writer: &mut BufWriter<W>) -> Result<u64> {
|
|
// TODO
|
|
Ok(0)
|
|
}
|
|
}
|