AUDIO: Keep packetized MP3 stream from ending prematurely

This fixes the audio in the intro AVI movie for German Fullpipe.
This commit is contained in:
Torbjörn Andersson 2016-09-19 07:24:07 +02:00
parent 1670cb035f
commit 579c024653

View File

@ -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() {