Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recover from FLAC decoding errors #2315

Merged
merged 2 commits into from
Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/engine/cachingreaderchunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ mixxx::IndexRange CachingReaderChunk::bufferSampleFrames(
mixxx::WritableSampleFrames(
sourceFrameIndexRange,
mixxx::SampleBuffer::WritableSlice(m_sampleBuffer)));
DEBUG_ASSERT(m_bufferedSampleFrames.frameIndexRange() <= sourceFrameIndexRange);
DEBUG_ASSERT(m_bufferedSampleFrames.frameIndexRange().empty() ||
m_bufferedSampleFrames.frameIndexRange() <= sourceFrameIndexRange);
return m_bufferedSampleFrames.frameIndexRange();
}

Expand Down
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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This crashes Mixxx, right? Doe we have alternatives?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not by default: "It exits if the environment variable QT_FATAL_CRITICALS is not empty."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If even resetting the decoder fails then we are in big trouble. Like a destructor this operation should never fail, but the API allows failure and we need to handle this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Playback was stuttering and Mixxx became almost unusable when not resetting the decoder. This is already our very last chance. If even this option fails everything is lost.

This is still only a DJ application, not the control unit of some deadly weapon. Let's keep things in perspective.

<< "Failed to reset decoder after skip errors";
}
// Abort
return ReadableSampleFrames(
IndexRange::between(
Expand Down