diff options
Diffstat (limited to 'audio')
| -rw-r--r-- | audio/decoders/mp3.cpp | 22 | 
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() {  | 
