Skip to content

Commit

Permalink
Recover from FLAC deocding errors
Browse files Browse the repository at this point in the history
  • Loading branch information
uklotzde committed Oct 5, 2019
1 parent b9de27a commit 3f2c326
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/sources/soundsourceflac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ ReadableSampleFrames SoundSourceFLAC::readSampleFramesClamped(
m_sampleBuffer.clear();
invalidateCurFrameIndex();
if (FLAC__stream_decoder_seek_absolute(m_decoder, seekFrameIndex)) {
DEBUG_ASSERT(FLAC__STREAM_DECODER_SEEK_ERROR != FLAC__stream_decoder_get_state(m_decoder));
// Success: Set the new position
m_curFrameIndex = seekFrameIndex;
DEBUG_ASSERT(FLAC__STREAM_DECODER_SEEK_ERROR != FLAC__stream_decoder_get_state(m_decoder));
} else {
// Failure
kLogger.warning()
Expand Down Expand Up @@ -179,8 +179,14 @@ ReadableSampleFrames SoundSourceFLAC::readSampleFramesClamped(
} else {
// We have already reached the beginning of the file
// and cannot move the seek position backwards any
// further!
break; // exit loop
// further! As a last resort try to reset the decoder.
kLogger.warning()
<< "Resetting decoder after seek errors";
if (!FLAC__stream_decoder_reset(m_decoder)) {
kLogger.critical()
<< "Failed to reset decoder after seek errors";
break; // exit loop
}
}
}
}
Expand All @@ -193,8 +199,12 @@ ReadableSampleFrames SoundSourceFLAC::readSampleFramesClamped(
&& (precedingFrames != readSampleFramesClamped(
WritableSampleFrames(precedingFrames)).frameIndexRange())) {
kLogger.warning()
<< "Failed to skip preceding frames"
<< "Resetting decoder after failure to skip preceding frames"
<< precedingFrames;
if (!FLAC__stream_decoder_reset(m_decoder)) {
kLogger.critical()
<< "Failed to reset decoder after skip errors";
}
// Abort
return ReadableSampleFrames(
IndexRange::between(
Expand Down

0 comments on commit 3f2c326

Please sign in to comment.