From daa9062a2fc7dd1963edfd75b9d84fe77dd01f7a Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Mon, 23 Sep 2024 10:44:42 +0200 Subject: [PATCH] Some manual clippy fixes --- clippy.toml | 1 + src/mp4box/emsg.rs | 4 ++- src/mp4box/ilst.rs | 6 +--- src/mp4box/meta.rs | 72 +++++++++++++++++++++------------------------- src/mp4box/mod.rs | 9 +++--- src/reader.rs | 13 ++++----- 6 files changed, 48 insertions(+), 57 deletions(-) diff --git a/clippy.toml b/clippy.toml index 9673121..1a23265 100644 --- a/clippy.toml +++ b/clippy.toml @@ -71,6 +71,7 @@ doc-valid-idents = [ "OBJ", "OpenGL", "PyPI", + "QuickTime", "sRGB", "sRGBA", "WebGL", diff --git a/src/mp4box/emsg.rs b/src/mp4box/emsg.rs index 74e9fdb..8c69b37 100644 --- a/src/mp4box/emsg.rs +++ b/src/mp4box/emsg.rs @@ -132,8 +132,10 @@ fn read_null_terminated_utf8_string(reader: &mut R) -> Result 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::() } } diff --git a/src/mp4box/meta.rs b/src/mp4box/meta.rs index 2054869..93b8f0f 100644 --- a/src/mp4box/meta.rs +++ b/src/mp4box/meta.rs @@ -143,53 +143,47 @@ impl 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 }) } } } diff --git a/src/mp4box/mod.rs b/src/mp4box/mod.rs index 7278618..7987fa9 100644 --- a/src/mp4box/mod.rs +++ b/src/mp4box/mod.rs @@ -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 +//! * +//! * +//! * //! //! Supported Atoms: +//! ```text //! ftyp //! moov //! mvhd @@ -54,7 +55,7 @@ //! trun //! mdat //! free -//! +//! ``` use byteorder::{BigEndian, ReadBytesExt}; use serde::Serialize; diff --git a/src/reader.rs b/src/reader.rs index e7ea86f..7da3fdb 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -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(()) @@ -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"), @@ -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, }) }) }