Skip to content

Commit

Permalink
Some manual clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Sep 23, 2024
1 parent c109d2b commit daa9062
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 57 deletions.
1 change: 1 addition & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ doc-valid-idents = [
"OBJ",
"OpenGL",
"PyPI",
"QuickTime",
"sRGB",
"sRGBA",
"WebGL",
Expand Down
4 changes: 3 additions & 1 deletion src/mp4box/emsg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,10 @@ fn read_null_terminated_utf8_string<R: Read + Seek>(reader: &mut R) -> Result<St
break;
}
}
#[allow(unsafe_code)]
// SAFETY: we ensure there is exactly one nul-byte at the end of the slice
if let Ok(str) = unsafe { CStr::from_bytes_with_nul_unchecked(&bytes) }.to_str() {
Ok(str.to_string())
Ok(str.to_owned())
} else {
Err(Error::InvalidData("invalid utf8"))
}
Expand Down
6 changes: 1 addition & 5 deletions src/mp4box/ilst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ impl IlstBox {
}

pub fn get_size(&self) -> u64 {
let mut size = HEADER_SIZE;
for item in self.items.values() {
size += item.get_size();
}
size
HEADER_SIZE + self.items.values().map(|item| item.get_size()).sum::<u64>()
}
}

Expand Down
72 changes: 33 additions & 39 deletions src/mp4box/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,53 +143,47 @@ impl<R: Read + Seek> ReadBox<&mut R> for MetaBox {

let mut ilst = None;

match hdlr.handler_type {
MDIR => {
while current < end {
// Get box header.
let header = BoxHeader::read(reader)?;
let BoxHeader { name, size: s } = header;

match name {
BoxType::IlstBox => {
ilst = Some(IlstBox::read_box(reader, s)?);
}
_ => {
// XXX warn!()
skip_box(reader, s)?;
}
if hdlr.handler_type == MDIR {
while current < end {
// Get box header.
let header = BoxHeader::read(reader)?;
let BoxHeader { name, size: s } = header;

match name {
BoxType::IlstBox => {
ilst = Some(IlstBox::read_box(reader, s)?);
}
_ => {
// XXX warn!()
skip_box(reader, s)?;
}

current = reader.stream_position()?;
}

Ok(Self::Mdir { ilst })
current = reader.stream_position()?;
}
_ => {
let mut data = Vec::new();

while current < end {
// Get box header.
let header = BoxHeader::read(reader)?;
let BoxHeader { name, size: s } = header;

match name {
BoxType::HdlrBox => {
skip_box(reader, s)?;
}
_ => {
let mut box_data = vec![0; (s - HEADER_SIZE) as usize];
reader.read_exact(&mut box_data)?;

data.push((name, box_data));
}
}

current = reader.stream_position()?;
Ok(Self::Mdir { ilst })
} else {
let mut data = Vec::new();

while current < end {
// Get box header.
let header = BoxHeader::read(reader)?;
let BoxHeader { name, size: s } = header;

if name == BoxType::HdlrBox {
skip_box(reader, s)?;
} else {
let mut box_data = vec![0; (s - HEADER_SIZE) as usize];
reader.read_exact(&mut box_data)?;

data.push((name, box_data));
}

Ok(Self::Unknown { hdlr, data })
current = reader.stream_position()?;
}

Ok(Self::Unknown { hdlr, data })
}
}
}
9 changes: 5 additions & 4 deletions src/mp4box/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
//! * ISO/IEC 14496-17 - Streaming text format
//! * [ISO 23009-1](https://www.iso.org/standard/79329.html) -Dynamic adaptive streaming over HTTP (DASH)
//!
//! http://developer.apple.com/documentation/QuickTime/QTFF/index.html
//! http://www.adobe.com/devnet/video/articles/mp4_movie_atom.html
//! http://mp4ra.org/#/atoms
//! * <http://developer.apple.com/documentation/QuickTime/QTFF/index.html>
//! * <http://www.adobe.com/devnet/video/articles/mp4_movie_atom.html>
//! * <http://mp4ra.org/#/atoms>
//!
//! Supported Atoms:
//! ```text
//! ftyp
//! moov
//! mvhd
Expand Down Expand Up @@ -54,7 +55,7 @@
//! trun
//! mdat
//! free
//!
//! ```

use byteorder::{BigEndian, ReadBytesExt};
use serde::Serialize;
Expand Down
13 changes: 5 additions & 8 deletions src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,15 +417,13 @@ impl Mp4 {
sample.offset = data_offset as u64;
}

track.duration = if track.duration == 0 {
track
if track.duration == 0 {
track.duration = track
.samples
.last()
.map(|v| v.timestamp + v.duration)
.unwrap_or_default()
} else {
track.duration
};
.unwrap_or_default();
}
}

Ok(())
Expand Down Expand Up @@ -501,7 +499,6 @@ impl Track {
} else if let Some(Hvc1Box { hvcc, .. }) = &sample_description.hvc1 {
let mut codec = "hvc1".to_owned();
match hvcc.general_profile_space {
0 => {}
1 => codec.push_str(".A"),
2 => codec.push_str(".B"),
3 => codec.push_str(".C"),
Expand Down Expand Up @@ -596,7 +593,7 @@ impl Mp4 {
self.moov.udta.as_ref().and_then(|udta| {
udta.meta.as_ref().and_then(|meta| match meta {
MetaBox::Mdir { ilst } => ilst.as_ref(),
_ => None,
MetaBox::Unknown { .. } => None,
})
})
}
Expand Down

0 comments on commit daa9062

Please sign in to comment.