aboutsummaryrefslogtreecommitdiff
path: root/audio
diff options
context:
space:
mode:
authorTorbjörn Andersson2016-09-19 07:24:07 +0200
committerTorbjörn Andersson2016-09-19 07:25:55 +0200
commit579c024653e66fd4a08c91a80b34d3208e5faf6c (patch)
treeec70a7a825a87417c2a3ad92f933b8284ca54bc7 /audio
parent1670cb035ffef58af7dff4c87f5408736e10f8ff (diff)
downloadscummvm-rg350-579c024653e66fd4a08c91a80b34d3208e5faf6c.tar.gz
scummvm-rg350-579c024653e66fd4a08c91a80b34d3208e5faf6c.tar.bz2
scummvm-rg350-579c024653e66fd4a08c91a80b34d3208e5faf6c.zip
AUDIO: Keep packetized MP3 stream from ending prematurely
This fixes the audio in the intro AVI movie for German Fullpipe.
Diffstat (limited to 'audio')
-rw-r--r--audio/decoders/mp3.cpp22
1 files changed, 18 insertions, 4 deletions
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() {