forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'simplify/w0u-probe' into simplify/w0

Browse files at this commit

2efb2708af70943fb87f1ad50db1fa20ab39a740Ahmet Kaan GümüşParent: 1dbe78465e0b1a
crates/ec-flac/src/decode.rsmodified+13 -0
@@ -534,6 +534,19 @@ pub fn find_frame_sync(data: &[u8], from: usize, info: Option<&StreamInfo>) -> O
534 None534 None
535 }535 }
536 536
537+pub fn next_frame_start(data: &[u8], from: usize, info: Option<&StreamInfo>) -> Option<usize> {
538+ let mut at = from;
539+ let mut first = None;
540+ while let Some(c) = find_frame_sync(data, at, info) {
541+ first.get_or_insert(c);
542+ if c >= 2 && crc16(&data[..c - 2]) == u16::from_be_bytes([data[c - 2], data[c - 1]]) {
543+ return Some(c);
544+ }
545+ at = c + 1;
546+ }
547+ first
548+}
549+
537 /// Parse a frame header, resolving the "same as `STREAMINFO`" codes.550 /// Parse a frame header, resolving the "same as `STREAMINFO`" codes.
538 pub fn parse_frame_header(r: &mut BitReader<'_>, info: Option<&StreamInfo>) -> Result<FrameHeader> {551 pub fn parse_frame_header(r: &mut BitReader<'_>, info: Option<&StreamInfo>) -> Result<FrameHeader> {
539 if r.read_bits(14)? != 0x3ffe {552 if r.read_bits(14)? != 0x3ffe {
crates/ec-probe/src/raw.rsmodified+1 -1
@@ -320,7 +320,7 @@ fn frame_at(kind: Kind, data: &[u8], flac: Option<&ec_flac::StreamInfo>) -> Resu
320 let header = ec_flac::decode::parse_frame_header(&mut r, flac)?;320 let header = ec_flac::decode::parse_frame_header(&mut r, flac)?;
321 // A frame ends where the next one starts; the last frame of a file321 // A frame ends where the next one starts; the last frame of a file
322 // ends at the file's end, which the caller's `NeedMore` handles.322 // ends at the file's end, which the caller's `NeedMore` handles.
323- let bytes = ec_flac::decode::find_frame_sync(data, 1, flac).ok_or(Error::NeedMore)?;323+ let bytes = ec_flac::decode::next_frame_start(data, 1, flac).ok_or(Error::NeedMore)?;
324 Ok(Framing {324 Ok(Framing {
325 bytes,325 bytes,
326 samples: header.block_size as u64,326 samples: header.block_size as u64,