From 579c024653e66fd4a08c91a80b34d3208e5faf6c Mon Sep 17 00:00:00 2001 From: Torbjörn Andersson Date: Mon, 19 Sep 2016 07:24:07 +0200 Subject: AUDIO: Keep packetized MP3 stream from ending prematurely This fixes the audio in the intro AVI movie for German Fullpipe. --- audio/decoders/mp3.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'audio') diff --git a/audio/decoders/mp3.cpp b/audio/decoders/mp3.cpp index 36233a2e13..93c21b9072 100644 --- a/audio/decoders/mp3.cpp +++ b/audio/decoders/mp3.cpp @@ -438,6 +438,7 @@ PacketizedMP3Stream::PacketizedMP3Stream(uint channels, uint rate) : } PacketizedMP3Stream::~PacketizedMP3Stream() { + Common::StackLock lock(_mutex); while (!_queue.empty()) { delete _queue.front(); _queue.pop(); @@ -447,12 +448,13 @@ PacketizedMP3Stream::~PacketizedMP3Stream() { int PacketizedMP3Stream::readBuffer(int16 *buffer, const int numSamples) { int samples = 0; + Common::StackLock lock(_mutex); while (samples < numSamples) { - Common::StackLock lock(_mutex); - - // Empty? Bail out for now - if (_queue.empty()) + // Empty? Bail out for now, and mark the stream as ended + if (_queue.empty()) { + _state = MP3_STATE_EOS; return samples; + } Common::SeekableReadStream *packet = _queue.front(); @@ -473,6 +475,12 @@ int PacketizedMP3Stream::readBuffer(int16 *buffer, const int numSamples) { } } + // This will happen if the audio runs out just as the last sample is + // decoded. But there may still be more audio queued up. + if (_state == MP3_STATE_EOS && !_queue.empty()) { + _state = MP3_STATE_READY; + } + return samples; } @@ -492,6 +500,12 @@ void PacketizedMP3Stream::queuePacket(Common::SeekableReadStream *packet) { Common::StackLock lock(_mutex); assert(!_finished); _queue.push(packet); + + // If the audio had finished (buffer underrun?), there is more to + // decode now. + if (_state == MP3_STATE_EOS) { + _state = MP3_STATE_READY; + } } void PacketizedMP3Stream::finish() { -- cgit v1.2.3