1
0
Fork 0
mirror of https://github.com/alfg/mp4-rust.git synced 2024-05-09 03:52:53 +00:00
mp4-rust/src/mp4box/edts.rs
Ririsoft 5d648f1a72
fix clippy & enhance CI/CD (#78)
* fix clippy::unused_io_amount

See related clippy documentation,
but in short some partial reads can occur
in particular with io on the networl.
read_exact/write_all transparently handle such errors.

The fix actually revealed a bug
in 'mp4a' atom parsing, but this is a dangerous change:
Parsing bugs that were transparently ignored
are now failing with error (unattended io eof).

* fix trivial clippy errors

* fix clippy error with always 0 value

* run ci/cd with clippy and latest rust version
2022-07-07 20:02:00 -07:00

81 lines
1.7 KiB
Rust

use serde::Serialize;
use std::io::{Read, Seek, Write};
use crate::mp4box::elst::ElstBox;
use crate::mp4box::*;
#[derive(Debug, Clone, PartialEq, Default, Serialize)]
pub struct EdtsBox {
pub elst: Option<ElstBox>,
}
impl EdtsBox {
pub(crate) fn new() -> EdtsBox {
Default::default()
}
pub fn get_type(&self) -> BoxType {
BoxType::EdtsBox
}
pub fn get_size(&self) -> u64 {
let mut size = HEADER_SIZE;
if let Some(ref elst) = self.elst {
size += elst.box_size();
}
size
}
}
impl Mp4Box for EdtsBox {
fn box_type(&self) -> BoxType {
self.get_type()
}
fn box_size(&self) -> u64 {
self.get_size()
}
fn to_json(&self) -> Result<String> {
Ok(serde_json::to_string(&self).unwrap())
}
fn summary(&self) -> Result<String> {
let s = String::new();
Ok(s)
}
}
impl<R: Read + Seek> ReadBox<&mut R> for EdtsBox {
fn read_box(reader: &mut R, size: u64) -> Result<Self> {
let start = box_start(reader)?;
let mut edts = EdtsBox::new();
let header = BoxHeader::read(reader)?;
let BoxHeader { name, size: s } = header;
if let BoxType::ElstBox = name {
let elst = ElstBox::read_box(reader, s)?;
edts.elst = Some(elst);
}
skip_bytes_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)
}
}