From 0bb052da344778e30e806a296a8e4195cec20ab9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 2 Dec 2026 15:14:29 +0300 Subject: [PATCH] S1: read_window helper for the seek-and-read window in the DTS, MP3 and ADTS openers --- crates/ec-probe/src/raw_open.rs | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/crates/ec-probe/src/raw_open.rs b/crates/ec-probe/src/raw_open.rs index 0d429f0f..e5cde7e9 100644 --- a/crates/ec-probe/src/raw_open.rs +++ b/crates/ec-probe/src/raw_open.rs @@ -21,10 +21,7 @@ fn wav_dts_span(src: &mut R, end: u64) -> Result(src: &mut R, end: u64) -> Result(src: &mut R, start: u64, end: u64) -> Result> { + let mut window = vec![0u8; HEAD.min(end.saturating_sub(start) as usize)]; + src.seek(SeekFrom::Start(start))?; + let got = read_upto(src, &mut window)?; + window.truncate(got); + Ok(window) +} + fn open_dts_span( mut src: R, format: Format, start: u64, end: u64, ) -> Result { - let mut window = vec![0u8; HEAD.min(end.saturating_sub(start) as usize)]; - src.seek(SeekFrom::Start(start))?; - let got = read_upto(&mut src, &mut window)?; - window.truncate(got); + let window = read_window(&mut src, start, end)?; let (core, _) = dts::access_unit(&window) .ok_or_else(|| Error::corrupt("dts: no frame at the start of the stream"))?; let total = dts_total(&window, end, start); @@ -143,10 +145,7 @@ pub(crate) fn open_flac(mut src: R, head: &[u8] pub(crate) fn open_mp3(mut src: R, head: &[u8], end: u64) -> Result { let (start, tags) = id3(&mut src, head, end)?; - let mut window = vec![0u8; HEAD.min(end.saturating_sub(start) as usize)]; - src.seek(SeekFrom::Start(start))?; - let got = read_upto(&mut src, &mut window)?; - window.truncate(got); + let window = read_window(&mut src, start, end)?; let at = frame_sync(&window, Format::Mp3) .ok_or_else(|| Error::corrupt("mp3: no frame in the first 64 KiB"))?; let header = ec_mp3::FrameHeader::parse(&window[at..])?; @@ -197,10 +196,7 @@ pub(crate) fn open_mp3(mut src: R, head: &[u8], pub(crate) fn open_adts(mut src: R, head: &[u8], end: u64) -> Result { let (start, tags) = id3(&mut src, head, end)?; - let mut window = vec![0u8; HEAD.min(end.saturating_sub(start) as usize)]; - src.seek(SeekFrom::Start(start))?; - let got = read_upto(&mut src, &mut window)?; - window.truncate(got); + let window = read_window(&mut src, start, end)?; let at = frame_sync(&window, Format::Adts) .ok_or_else(|| Error::corrupt("aac: no ADTS frame in the first 64 KiB"))?; let header = ec_aac::parse_adts(&window[at..])?;