mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Merge pull request #925 from pdeljanov/new-api-symphonia-fixes
Handle reset and decode errors
This commit is contained in:
commit
6c25fb79dc
1 changed files with 34 additions and 33 deletions
|
@ -171,6 +171,7 @@ impl AudioDecoder for SymphoniaDecoder {
|
|||
}
|
||||
|
||||
fn next_packet(&mut self) -> DecoderResult<Option<(u32, AudioPacket)>> {
|
||||
loop {
|
||||
let packet = match self.format.next_packet() {
|
||||
Ok(packet) => packet,
|
||||
Err(Error::IoError(err)) => {
|
||||
|
@ -180,10 +181,6 @@ impl AudioDecoder for SymphoniaDecoder {
|
|||
return Err(DecoderError::SymphoniaDecoder(err.to_string()));
|
||||
}
|
||||
}
|
||||
Err(Error::ResetRequired) => {
|
||||
self.decoder.reset();
|
||||
return self.next_packet();
|
||||
}
|
||||
Err(err) => {
|
||||
return Err(err.into());
|
||||
}
|
||||
|
@ -203,11 +200,15 @@ impl AudioDecoder for SymphoniaDecoder {
|
|||
let sample_buffer = self.sample_buffer.as_mut().unwrap(); // guaranteed above
|
||||
sample_buffer.copy_interleaved_ref(decoded);
|
||||
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()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue