refactor(decoder/sympthonia) use for loop instead loop + match & escape

More readable, prep for using the same lines in new refine_position fn.
Since that is already pretty complex this needed to be made simpler.

This code retries on all errors not only decode errors. Retries will not
work on anything else then a decode error however they also wont cause
any problems. Not checking the result does however make the code
simpler.
This commit is contained in:
dvdsk 2024-04-05 13:28:16 +02:00
parent 1fcf4b8363
commit 40a9447fa1
No known key found for this signature in database
GPG key ID: 6CF9D20C5709A836

View file

@ -192,23 +192,16 @@ impl Iterator for SymphoniaDecoder {
#[inline]
fn next(&mut self) -> Option<i16> {
if self.current_frame_offset == self.buffer.len() {
let mut decode_errors: usize = 0;
let decoded = loop {
let packet = self.format.next_packet().ok()?;
match self.decoder.decode(&packet) {
Ok(decoded) => break decoded,
Err(Error::DecodeError(_)) => {
decode_errors += 1;
if decode_errors > MAX_DECODE_ERRORS {
return None;
} else {
continue;
}
}
Err(_) => return None,
};
};
if self.current_frame_offset >= self.buffer.len() {
let packet = self.format.next_packet().ok()?;
let mut decoded = self.decoder.decode(&packet);
for _ in 0..MAX_DECODE_RETRIES {
if decoded.is_err() {
let packet = self.format.next_packet().ok()?;
decoded = self.decoder.decode(&packet);
}
}
let decoded = decoded.ok()?;
self.spec = decoded.spec().to_owned();
self.buffer = SymphoniaDecoder::get_buffer(decoded, &self.spec);
self.current_frame_offset = 0;