diff --git a/src/mp4box/data.rs b/src/mp4box/data.rs index 2f54dd0..19b5c77 100644 --- a/src/mp4box/data.rs +++ b/src/mp4box/data.rs @@ -54,7 +54,7 @@ impl ReadBox<&mut R> for DataBox { reader.read_u32::()?; // reserved = 0 - let current = reader.seek(SeekFrom::Current(0))?; + let current = reader.stream_position()?; let mut data = vec![0u8; (start + size - current) as usize]; reader.read_exact(&mut data)?; diff --git a/src/mp4box/dinf.rs b/src/mp4box/dinf.rs index 3d9a95b..b404ae9 100644 --- a/src/mp4box/dinf.rs +++ b/src/mp4box/dinf.rs @@ -43,7 +43,7 @@ impl ReadBox<&mut R> for DinfBox { let mut dref = None; - let mut current = reader.seek(SeekFrom::Current(0))?; + let mut current = reader.stream_position()?; let end = start + size; while current < end { // Get box header. @@ -60,7 +60,7 @@ impl ReadBox<&mut R> for DinfBox { } } - current = reader.seek(SeekFrom::Current(0))?; + current = reader.stream_position()?; } if dref.is_none() { @@ -140,7 +140,7 @@ impl ReadBox<&mut R> for DrefBox { fn read_box(reader: &mut R, size: u64) -> Result { let start = box_start(reader)?; - let mut current = reader.seek(SeekFrom::Current(0))?; + let mut current = reader.stream_position()?; let (version, flags) = read_box_header_ext(reader)?; let end = start + size; @@ -166,7 +166,7 @@ impl ReadBox<&mut R> for DrefBox { } } - current = reader.seek(SeekFrom::Current(0))?; + current = reader.stream_position()?; } skip_bytes_to(reader, start + size)?; diff --git a/src/mp4box/ilst.rs b/src/mp4box/ilst.rs index ccb306b..19b0f91 100644 --- a/src/mp4box/ilst.rs +++ b/src/mp4box/ilst.rs @@ -52,7 +52,7 @@ impl ReadBox<&mut R> for IlstBox { let mut items = HashMap::new(); - let mut current = reader.seek(SeekFrom::Current(0))?; + let mut current = reader.stream_position()?; let end = start + size; while current < end { // Get box header. @@ -78,7 +78,7 @@ impl ReadBox<&mut R> for IlstBox { } } - current = reader.seek(SeekFrom::Current(0))?; + current = reader.stream_position()?; } skip_bytes_to(reader, start + size)?; @@ -123,7 +123,7 @@ impl ReadBox<&mut R> for IlstItemBox { let mut data = None; - let mut current = reader.seek(SeekFrom::Current(0))?; + let mut current = reader.stream_position()?; let end = start + size; while current < end { // Get box header. @@ -140,7 +140,7 @@ impl ReadBox<&mut R> for IlstItemBox { } } - current = reader.seek(SeekFrom::Current(0))?; + current = reader.stream_position()?; } if data.is_none() { diff --git a/src/mp4box/mdia.rs b/src/mp4box/mdia.rs index c77b767..8279ea2 100644 --- a/src/mp4box/mdia.rs +++ b/src/mp4box/mdia.rs @@ -1,5 +1,5 @@ use serde::Serialize; -use std::io::{Read, Seek, SeekFrom, Write}; +use std::io::{Read, Seek, Write}; use crate::mp4box::*; use crate::mp4box::{hdlr::HdlrBox, mdhd::MdhdBox, minf::MinfBox}; @@ -48,7 +48,7 @@ impl ReadBox<&mut R> for MdiaBox { let mut hdlr = None; let mut minf = None; - let mut current = reader.seek(SeekFrom::Current(0))?; + let mut current = reader.stream_position()?; let end = start + size; while current < end { // Get box header. @@ -71,7 +71,7 @@ impl ReadBox<&mut R> for MdiaBox { } } - current = reader.seek(SeekFrom::Current(0))?; + current = reader.stream_position()?; } if mdhd.is_none() { diff --git a/src/mp4box/meta.rs b/src/mp4box/meta.rs index 27fe682..df57c77 100644 --- a/src/mp4box/meta.rs +++ b/src/mp4box/meta.rs @@ -97,7 +97,7 @@ impl ReadBox<&mut R> for MetaBox { let mut ilst = None; - let mut current = reader.seek(SeekFrom::Current(0))?; + let mut current = reader.stream_position()?; let end = start + size; match hdlr.handler_type { @@ -117,7 +117,7 @@ impl ReadBox<&mut R> for MetaBox { } } - current = reader.seek(SeekFrom::Current(0))?; + current = reader.stream_position()?; } Ok(MetaBox::Mdir { ilst }) diff --git a/src/mp4box/minf.rs b/src/mp4box/minf.rs index 1551db8..c8ecf72 100644 --- a/src/mp4box/minf.rs +++ b/src/mp4box/minf.rs @@ -1,5 +1,5 @@ use serde::Serialize; -use std::io::{Read, Seek, SeekFrom, Write}; +use std::io::{Read, Seek, Write}; use crate::mp4box::*; use crate::mp4box::{dinf::DinfBox, smhd::SmhdBox, stbl::StblBox, vmhd::VmhdBox}; @@ -63,7 +63,7 @@ impl ReadBox<&mut R> for MinfBox { let mut dinf = None; let mut stbl = None; - let mut current = reader.seek(SeekFrom::Current(0))?; + let mut current = reader.stream_position()?; let end = start + size; while current < end { // Get box header. @@ -89,7 +89,7 @@ impl ReadBox<&mut R> for MinfBox { } } - current = reader.seek(SeekFrom::Current(0))?; + current = reader.stream_position()?; } if dinf.is_none() { diff --git a/src/mp4box/mod.rs b/src/mp4box/mod.rs index 1d75500..0af14b5 100644 --- a/src/mp4box/mod.rs +++ b/src/mp4box/mod.rs @@ -293,7 +293,7 @@ pub fn write_box_header_ext(w: &mut W, v: u8, f: u32) -> Result { } pub fn box_start(seeker: &mut R) -> Result { - Ok(seeker.seek(SeekFrom::Current(0))? - HEADER_SIZE) + Ok(seeker.stream_position()? - HEADER_SIZE) } pub fn skip_bytes(seeker: &mut S, size: u64) -> Result<()> { diff --git a/src/mp4box/moof.rs b/src/mp4box/moof.rs index b9ab1d4..ab24bee 100644 --- a/src/mp4box/moof.rs +++ b/src/mp4box/moof.rs @@ -1,5 +1,5 @@ use serde::Serialize; -use std::io::{Read, Seek, SeekFrom, Write}; +use std::io::{Read, Seek, Write}; use crate::mp4box::*; use crate::mp4box::{mfhd::MfhdBox, traf::TrafBox}; @@ -52,7 +52,7 @@ impl ReadBox<&mut R> for MoofBox { let mut mfhd = None; let mut trafs = Vec::new(); - let mut current = reader.seek(SeekFrom::Current(0))?; + let mut current = reader.stream_position()?; let end = start + size; while current < end { // Get box header. @@ -72,7 +72,7 @@ impl ReadBox<&mut R> for MoofBox { skip_box(reader, s)?; } } - current = reader.seek(SeekFrom::Current(0))?; + current = reader.stream_position()?; } if mfhd.is_none() { diff --git a/src/mp4box/moov.rs b/src/mp4box/moov.rs index b6fd589..fe42ef5 100644 --- a/src/mp4box/moov.rs +++ b/src/mp4box/moov.rs @@ -1,5 +1,5 @@ use serde::Serialize; -use std::io::{Read, Seek, SeekFrom, Write}; +use std::io::{Read, Seek, Write}; use crate::meta::MetaBox; use crate::mp4box::*; @@ -71,7 +71,7 @@ impl ReadBox<&mut R> for MoovBox { let mut mvex = None; let mut traks = Vec::new(); - let mut current = reader.seek(SeekFrom::Current(0))?; + let mut current = reader.stream_position()?; let end = start + size; while current < end { // Get box header. @@ -101,7 +101,7 @@ impl ReadBox<&mut R> for MoovBox { } } - current = reader.seek(SeekFrom::Current(0))?; + current = reader.stream_position()?; } if mvhd.is_none() { diff --git a/src/mp4box/mp4a.rs b/src/mp4box/mp4a.rs index a7e0a95..bc69fc6 100644 --- a/src/mp4box/mp4a.rs +++ b/src/mp4box/mp4a.rs @@ -90,7 +90,7 @@ impl ReadBox<&mut R> for Mp4aBox { let samplerate = FixedPointU16::new_raw(reader.read_u32::()?); let mut esds = None; - let current = reader.seek(SeekFrom::Current(0))?; + let current = reader.stream_position()?; if current < start + size { let header = BoxHeader::read(reader)?; let BoxHeader { name, size: s } = header; @@ -181,7 +181,7 @@ impl ReadBox<&mut R> for EsdsBox { let mut es_desc = None; - let mut current = reader.seek(SeekFrom::Current(0))?; + let mut current = reader.stream_position()?; let end = start + size; while current < end { let (desc_tag, desc_size) = read_desc(reader)?; @@ -191,7 +191,7 @@ impl ReadBox<&mut R> for EsdsBox { } _ => break, } - current = reader.seek(SeekFrom::Current(0))?; + current = reader.stream_position()?; } if es_desc.is_none() { @@ -313,7 +313,7 @@ impl Descriptor for ESDescriptor { impl ReadDesc<&mut R> for ESDescriptor { fn read_desc(reader: &mut R, size: u32) -> Result { - let start = reader.seek(SeekFrom::Current(0))?; + let start = reader.stream_position()?; let es_id = reader.read_u16::()?; reader.read_u8()?; // XXX flags must be 0 @@ -321,7 +321,7 @@ impl ReadDesc<&mut R> for ESDescriptor { let mut dec_config = None; let mut sl_config = None; - let mut current = reader.seek(SeekFrom::Current(0))?; + let mut current = reader.stream_position()?; let end = start + size as u64; while current < end { let (desc_tag, desc_size) = read_desc(reader)?; @@ -336,7 +336,7 @@ impl ReadDesc<&mut R> for ESDescriptor { skip_bytes(reader, desc_size as u64)?; } } - current = reader.seek(SeekFrom::Current(0))?; + current = reader.stream_position()?; } Ok(ESDescriptor { @@ -402,7 +402,7 @@ impl Descriptor for DecoderConfigDescriptor { impl ReadDesc<&mut R> for DecoderConfigDescriptor { fn read_desc(reader: &mut R, size: u32) -> Result { - let start = reader.seek(SeekFrom::Current(0))?; + let start = reader.stream_position()?; let object_type_indication = reader.read_u8()?; let byte_a = reader.read_u8()?; @@ -414,7 +414,7 @@ impl ReadDesc<&mut R> for DecoderConfigDescriptor { let mut dec_specific = None; - let mut current = reader.seek(SeekFrom::Current(0))?; + let mut current = reader.stream_position()?; let end = start + size as u64; while current < end { let (desc_tag, desc_size) = read_desc(reader)?; @@ -426,7 +426,7 @@ impl ReadDesc<&mut R> for DecoderConfigDescriptor { skip_bytes(reader, desc_size as u64)?; } } - current = reader.seek(SeekFrom::Current(0))?; + current = reader.stream_position()?; } Ok(DecoderConfigDescriptor { diff --git a/src/mp4box/mvex.rs b/src/mp4box/mvex.rs index ec8c76f..da61b95 100644 --- a/src/mp4box/mvex.rs +++ b/src/mp4box/mvex.rs @@ -1,5 +1,5 @@ use serde::Serialize; -use std::io::{Read, Seek, SeekFrom, Write}; +use std::io::{Read, Seek, Write}; use crate::mp4box::*; use crate::mp4box::{mehd::MehdBox, trex::TrexBox}; @@ -46,7 +46,7 @@ impl ReadBox<&mut R> for MvexBox { let mut mehd = None; let mut trex = None; - let mut current = reader.seek(SeekFrom::Current(0))?; + let mut current = reader.stream_position()?; let end = start + size; while current < end { // Get box header. @@ -66,7 +66,7 @@ impl ReadBox<&mut R> for MvexBox { } } - current = reader.seek(SeekFrom::Current(0))?; + current = reader.stream_position()?; } if trex.is_none() { diff --git a/src/mp4box/stbl.rs b/src/mp4box/stbl.rs index e8b78b6..9656f4b 100644 --- a/src/mp4box/stbl.rs +++ b/src/mp4box/stbl.rs @@ -1,5 +1,5 @@ use serde::Serialize; -use std::io::{Read, Seek, SeekFrom, Write}; +use std::io::{Read, Seek, Write}; use crate::mp4box::*; use crate::mp4box::{ @@ -86,7 +86,7 @@ impl ReadBox<&mut R> for StblBox { let mut stco = None; let mut co64 = None; - let mut current = reader.seek(SeekFrom::Current(0))?; + let mut current = reader.stream_position()?; let end = start + size; while current < end { // Get box header. @@ -123,7 +123,7 @@ impl ReadBox<&mut R> for StblBox { skip_box(reader, s)?; } } - current = reader.seek(SeekFrom::Current(0))?; + current = reader.stream_position()?; } if stsd.is_none() { diff --git a/src/mp4box/traf.rs b/src/mp4box/traf.rs index 44d78f2..8c01dc5 100644 --- a/src/mp4box/traf.rs +++ b/src/mp4box/traf.rs @@ -1,5 +1,5 @@ use serde::Serialize; -use std::io::{Read, Seek, SeekFrom, Write}; +use std::io::{Read, Seek, Write}; use crate::mp4box::*; use crate::mp4box::{tfdt::TfdtBox, tfhd::TfhdBox, trun::TrunBox}; @@ -53,7 +53,7 @@ impl ReadBox<&mut R> for TrafBox { let mut tfdt = None; let mut trun = None; - let mut current = reader.seek(SeekFrom::Current(0))?; + let mut current = reader.stream_position()?; let end = start + size; while current < end { // Get box header. @@ -76,7 +76,7 @@ impl ReadBox<&mut R> for TrafBox { } } - current = reader.seek(SeekFrom::Current(0))?; + current = reader.stream_position()?; } if tfhd.is_none() { diff --git a/src/mp4box/trak.rs b/src/mp4box/trak.rs index cb81e0c..9a83229 100644 --- a/src/mp4box/trak.rs +++ b/src/mp4box/trak.rs @@ -1,5 +1,5 @@ use serde::Serialize; -use std::io::{Read, Seek, SeekFrom, Write}; +use std::io::{Read, Seek, Write}; use crate::meta::MetaBox; use crate::mp4box::*; @@ -62,7 +62,7 @@ impl ReadBox<&mut R> for TrakBox { let mut meta = None; let mut mdia = None; - let mut current = reader.seek(SeekFrom::Current(0))?; + let mut current = reader.stream_position()?; let end = start + size; while current < end { // Get box header. @@ -88,7 +88,7 @@ impl ReadBox<&mut R> for TrakBox { } } - current = reader.seek(SeekFrom::Current(0))?; + current = reader.stream_position()?; } if tkhd.is_none() { diff --git a/src/mp4box/udta.rs b/src/mp4box/udta.rs index 744d6a4..64bad5c 100644 --- a/src/mp4box/udta.rs +++ b/src/mp4box/udta.rs @@ -49,7 +49,7 @@ impl ReadBox<&mut R> for UdtaBox { let mut meta = None; - let mut current = reader.seek(SeekFrom::Current(0))?; + let mut current = reader.stream_position()?; let end = start + size; while current < end { // Get box header. @@ -66,7 +66,7 @@ impl ReadBox<&mut R> for UdtaBox { } } - current = reader.seek(SeekFrom::Current(0))?; + current = reader.stream_position()?; } skip_bytes_to(reader, start + size)?; diff --git a/src/mp4box/vp09.rs b/src/mp4box/vp09.rs index 2e5fe57..0e34146 100644 --- a/src/mp4box/vp09.rs +++ b/src/mp4box/vp09.rs @@ -79,7 +79,7 @@ impl Mp4Box for Vp09Box { } fn summary(&self) -> Result { - Ok(format!("{:?}", self)) + Ok(format!("{self:?}")) } } diff --git a/src/mp4box/vpcc.rs b/src/mp4box/vpcc.rs index c1782b8..c9861c6 100644 --- a/src/mp4box/vpcc.rs +++ b/src/mp4box/vpcc.rs @@ -36,7 +36,7 @@ impl Mp4Box for VpccBox { } fn summary(&self) -> Result { - Ok(format!("{:?}", self)) + Ok(format!("{self:?}")) } } diff --git a/src/reader.rs b/src/reader.rs index 4986442..38fde46 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -1,5 +1,5 @@ use std::collections::HashMap; -use std::io::{Read, Seek, SeekFrom}; +use std::io::{Read, Seek}; use std::time::Duration; use crate::meta::MetaBox; @@ -19,7 +19,7 @@ pub struct Mp4Reader { impl Mp4Reader { pub fn read_header(mut reader: R, size: u64) -> Result { - let start = reader.seek(SeekFrom::Current(0))?; + let start = reader.stream_position()?; let mut ftyp = None; let mut moov = None; @@ -64,7 +64,7 @@ impl Mp4Reader { skip_box(&mut reader, s)?; } } - current = reader.seek(SeekFrom::Current(0))?; + current = reader.stream_position()?; } if ftyp.is_none() { diff --git a/src/track.rs b/src/track.rs index ed8b12e..e9b4397 100644 --- a/src/track.rs +++ b/src/track.rs @@ -784,7 +784,7 @@ impl Mp4TrackWriter { if self.chunk_buffer.is_empty() { return Ok(()); } - let chunk_offset = writer.seek(SeekFrom::Current(0))?; + let chunk_offset = writer.stream_position()?; writer.write_all(&self.chunk_buffer)?; diff --git a/src/types.rs b/src/types.rs index 667359a..19fd40b 100644 --- a/src/types.rs +++ b/src/types.rs @@ -75,14 +75,14 @@ impl FixedPointU16 { impl fmt::Debug for BoxType { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let fourcc: FourCC = From::from(*self); - write!(f, "{}", fourcc) + write!(f, "{fourcc}") } } impl fmt::Display for BoxType { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let fourcc: FourCC = From::from(*self); - write!(f, "{}", fourcc) + write!(f, "{fourcc}") } } @@ -142,7 +142,7 @@ impl fmt::Debug for FourCC { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let code: u32 = self.into(); let string = String::from_utf8_lossy(&self.value[..]); - write!(f, "{} / {:#010X}", string, code) + write!(f, "{string} / {code:#010X}") } } @@ -179,7 +179,7 @@ impl fmt::Display for TrackType { TrackType::Audio => DISPLAY_TYPE_AUDIO, TrackType::Subtitle => DISPLAY_TYPE_SUBTITLE, }; - write!(f, "{}", s) + write!(f, "{s}") } } @@ -235,7 +235,7 @@ pub enum MediaType { impl fmt::Display for MediaType { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let s: &str = self.into(); - write!(f, "{}", s) + write!(f, "{s}") } } @@ -312,7 +312,7 @@ impl fmt::Display for AvcProfile { AvcProfile::AvcExtended => "Extended", AvcProfile::AvcHigh => "High", }; - write!(f, "{}", profile) + write!(f, "{profile}") } } @@ -459,7 +459,7 @@ impl fmt::Display for AudioObjectType { AudioObjectType::SpatialAudioObjectCodingDialogueEnhancement => "SAOC-DE", AudioObjectType::AudioSync => "Audio Sync", }; - write!(f, "{}", type_str) + write!(f, "{type_str}") } } @@ -560,7 +560,7 @@ impl fmt::Display for ChannelConfig { ChannelConfig::FiveOne => "five.one", ChannelConfig::SevenOne => "seven.one", }; - write!(f, "{}", s) + write!(f, "{s}") } } diff --git a/src/writer.rs b/src/writer.rs index 3dec951..a83a888 100644 --- a/src/writer.rs +++ b/src/writer.rs @@ -69,7 +69,7 @@ impl Mp4Writer { ftyp.write_box(&mut writer)?; // TODO largesize - let mdat_pos = writer.seek(SeekFrom::Current(0))?; + let mdat_pos = writer.stream_position()?; BoxHeader::new(BoxType::MdatBox, HEADER_SIZE).write(&mut writer)?; BoxHeader::new(BoxType::WideBox, HEADER_SIZE).write(&mut writer)?; @@ -115,7 +115,7 @@ impl Mp4Writer { } fn update_mdat_size(&mut self) -> Result<()> { - let mdat_end = self.writer.seek(SeekFrom::Current(0))?; + let mdat_end = self.writer.stream_position()?; let mdat_size = mdat_end - self.mdat_pos; if mdat_size > std::u32::MAX as u64 { self.writer.seek(SeekFrom::Start(self.mdat_pos))?;