# HG changeset patch # User Chris Cannam # Date 1727690722 -3600 # Mon Sep 30 11:05:22 2024 +0100 # Node ID 83c7942e4b3d5bc06225847ceae6404d88f74899 # Parent ae6b35bdcb0c89335329be19a45396bb86107668 Handle separately the "decode error" case which arises from a change in frame properties mid-stream diff --git a/src/MiniMP3ReadStream.cpp b/src/MiniMP3ReadStream.cpp --- a/src/MiniMP3ReadStream.cpp +++ b/src/MiniMP3ReadStream.cpp @@ -109,15 +109,22 @@ if (m_error != "" || m_channelCount == 0) return 0; if (count == 0) return 0; -// cerr << "getFrames: working" << endl; - size_t desired = count * m_channelCount; size_t obtained = mp3dec_ex_read(&m_d->dec, frames, desired); //!!! have to provide our own tags support? if (obtained < desired) { - if (m_d->dec.last_error) { + if (m_d->dec.last_error == MP3D_E_DECODE) { + // Marks a change in sample rate, layer, or channels. We + // can't throw an exception here because we may actually + // have valid data and we don't want to lose it. (This + // applies even if obtained == 0, as otherwise whether we + // treated the situation as an error or not would depend + // on how many frames were requested.) + std::cerr << "MiniMP3ReadStream: Decoding interrupted (sample rate, layer, or channels changed)" << std::endl; + } else if (m_d->dec.last_error != 0) { + // Some other error (not just EOF) std::ostringstream os; os << "MiniMP3ReadStream: Failed to read from file (error code " << m_d->dec.last_error << ")";