mirror of
https://github.com/RustAudio/rodio
synced 2024-12-12 21:22:36 +00:00
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:
parent
1fcf4b8363
commit
40a9447fa1
1 changed files with 10 additions and 17 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue