Handle format reset and decode errors.

This change fixes two issues with the error handling of the
Symphonia decode loop.

1) `Error::ResetRequired` should always be propagated to jump
    to the next Spotify track.

2) On a decode error, get a new packet and try again instead of
   propagating the error and jumping to the next track.
This commit is contained in:
Philip Deljanov 2022-01-05 00:03:54 -05:00
parent 3e09eff906
commit 5d44f910f3

View file

@ -171,6 +171,7 @@ impl AudioDecoder for SymphoniaDecoder {
} }
fn next_packet(&mut self) -> DecoderResult<Option<(u32, AudioPacket)>> { fn next_packet(&mut self) -> DecoderResult<Option<(u32, AudioPacket)>> {
loop {
let packet = match self.format.next_packet() { let packet = match self.format.next_packet() {
Ok(packet) => packet, Ok(packet) => packet,
Err(Error::IoError(err)) => { Err(Error::IoError(err)) => {
@ -180,10 +181,6 @@ impl AudioDecoder for SymphoniaDecoder {
return Err(DecoderError::SymphoniaDecoder(err.to_string())); return Err(DecoderError::SymphoniaDecoder(err.to_string()));
} }
} }
Err(Error::ResetRequired) => {
self.decoder.reset();
return self.next_packet();
}
Err(err) => { Err(err) => {
return Err(err.into()); return Err(err.into());
} }
@ -203,11 +200,15 @@ impl AudioDecoder for SymphoniaDecoder {
let sample_buffer = self.sample_buffer.as_mut().unwrap(); // guaranteed above let sample_buffer = self.sample_buffer.as_mut().unwrap(); // guaranteed above
sample_buffer.copy_interleaved_ref(decoded); sample_buffer.copy_interleaved_ref(decoded);
let samples = AudioPacket::Samples(sample_buffer.samples().to_vec()); let samples = AudioPacket::Samples(sample_buffer.samples().to_vec());
Ok(Some((position_ms, samples))) return Ok(Some((position_ms, samples)));
}
Err(Error::DecodeError(_)) => {
// The packet failed to decode due to corrupted or invalid data, get a new
// packet and try again.
continue;
}
Err(err) => return Err(err.into()),
} }
// Also propagate `ResetRequired` errors from the decoder to the player,
// so that it will skip to the next track and reload the entire Symphonia decoder.
Err(err) => Err(err.into()),
} }
} }
} }