diff options
author | Eugene Sandulenko | 2014-08-09 15:33:50 +0200 |
---|---|---|
committer | Eugene Sandulenko | 2014-08-09 15:33:50 +0200 |
commit | 6e794a9823440b6859ce65fb1097d710780a493d (patch) | |
tree | 9a8d90a53d7592cb11786521bee8ff8158e13aeb | |
parent | 908b4113c11686de5e8bcc3014917c92ff8961b6 (diff) | |
parent | dc155b23f02f6a462bf59a3f51dcdfea3e95c5b8 (diff) | |
download | scummvm-rg350-6e794a9823440b6859ce65fb1097d710780a493d.tar.gz scummvm-rg350-6e794a9823440b6859ce65fb1097d710780a493d.tar.bz2 scummvm-rg350-6e794a9823440b6859ce65fb1097d710780a493d.zip |
Merge pull request #487 from clone2727/audio_fixes
AUDIO: Miscellaneous AudioStream fixes
-rw-r--r-- | audio/audiostream.cpp | 55 | ||||
-rw-r--r-- | audio/audiostream.h | 7 | ||||
-rw-r--r-- | audio/decoders/aac.cpp | 1 | ||||
-rw-r--r-- | audio/decoders/qdm2.cpp | 1 |
4 files changed, 51 insertions, 13 deletions
diff --git a/audio/audiostream.cpp b/audio/audiostream.cpp index 4dd5d236be..c413edb73d 100644 --- a/audio/audiostream.cpp +++ b/audio/audiostream.cpp @@ -98,7 +98,7 @@ LoopingAudioStream::LoopingAudioStream(RewindableAudioStream *stream, uint loops // TODO: Properly indicate error _loops = _completeIterations = 1; } - if (stream->endOfData()) { + if (stream->endOfStream()) { // Apparently this is an empty stream _loops = _completeIterations = 1; } @@ -122,7 +122,7 @@ int LoopingAudioStream::readBuffer(int16 *buffer, const int numSamples) { _loops = _completeIterations = 1; return samplesRead; } - if (_parent->endOfData()) { + if (_parent->endOfStream()) { // Apparently this is an empty stream _loops = _completeIterations = 1; } @@ -134,7 +134,11 @@ int LoopingAudioStream::readBuffer(int16 *buffer, const int numSamples) { } bool LoopingAudioStream::endOfData() const { - return (_loops != 0 && (_completeIterations == _loops)); + return (_loops != 0 && _completeIterations == _loops) || _parent->endOfData(); +} + +bool LoopingAudioStream::endOfStream() const { + return _loops != 0 && _completeIterations == _loops; } AudioStream *makeLoopingAudioStream(RewindableAudioStream *stream, uint loops) { @@ -189,7 +193,7 @@ int SubLoopingAudioStream::readBuffer(int16 *buffer, const int numSamples) { int framesRead = _parent->readBuffer(buffer, framesLeft); _pos = _pos.addFrames(framesRead); - if (framesRead < framesLeft && _parent->endOfData()) { + if (framesRead < framesLeft && _parent->endOfStream()) { // TODO: Proper error indication. _done = true; return framesRead; @@ -216,6 +220,18 @@ int SubLoopingAudioStream::readBuffer(int16 *buffer, const int numSamples) { } } +bool SubLoopingAudioStream::endOfData() const { + // We're out of data if this stream is finished or the parent + // has run out of data for now. + return _done || _parent->endOfData(); +} + +bool SubLoopingAudioStream::endOfStream() const { + // The end of the stream has been reached only when we've gone + // through all the iterations. + return _done; +} + #pragma mark - #pragma mark --- SubSeekableAudioStream --- #pragma mark - @@ -315,18 +331,27 @@ public: virtual int readBuffer(int16 *buffer, const int numSamples); virtual bool isStereo() const { return _stereo; } virtual int getRate() const { return _rate; } + virtual bool endOfData() const { - //Common::StackLock lock(_mutex); - return _queue.empty(); + Common::StackLock lock(_mutex); + return _queue.empty() || _queue.front()._stream->endOfData(); + } + + virtual bool endOfStream() const { + Common::StackLock lock(_mutex); + return _finished && _queue.empty(); } - virtual bool endOfStream() const { return _finished && _queue.empty(); } // Implement the QueuingAudioStream API virtual void queueAudioStream(AudioStream *stream, DisposeAfterUse::Flag disposeAfterUse); - virtual void finish() { _finished = true; } + + virtual void finish() { + Common::StackLock lock(_mutex); + _finished = true; + } uint32 numQueuedStreams() const { - //Common::StackLock lock(_mutex); + Common::StackLock lock(_mutex); return _queue.size(); } }; @@ -356,11 +381,17 @@ int QueuingAudioStreamImpl::readBuffer(int16 *buffer, const int numSamples) { AudioStream *stream = _queue.front()._stream; samplesDecoded += stream->readBuffer(buffer + samplesDecoded, numSamples - samplesDecoded); - if (stream->endOfData()) { + // Done with the stream completely + if (stream->endOfStream()) { StreamHolder tmp = _queue.pop(); if (tmp._disposeAfterUse == DisposeAfterUse::YES) delete stream; + continue; } + + // Done with data but not the stream, bail out + if (stream->endOfData()) + break; } return samplesDecoded; @@ -416,12 +447,14 @@ public: return samplesRead; } - bool endOfData() const { return _parentStream->endOfData() || _samplesRead >= _totalSamples; } + bool endOfData() const { return _parentStream->endOfData() || reachedLimit(); } + bool endOfStream() const { return _parentStream->endOfStream() || reachedLimit(); } bool isStereo() const { return _parentStream->isStereo(); } int getRate() const { return _parentStream->getRate(); } private: int getChannels() const { return isStereo() ? 2 : 1; } + bool reachedLimit() const { return _samplesRead >= _totalSamples; } AudioStream *_parentStream; DisposeAfterUse::Flag _disposeAfterUse; diff --git a/audio/audiostream.h b/audio/audiostream.h index d5d7d0b6c7..5202a4711c 100644 --- a/audio/audiostream.h +++ b/audio/audiostream.h @@ -118,6 +118,7 @@ public: int readBuffer(int16 *buffer, const int numSamples); bool endOfData() const; + bool endOfStream() const; bool isStereo() const { return _parent->isStereo(); } int getRate() const { return _parent->getRate(); } @@ -247,7 +248,8 @@ public: DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES); int readBuffer(int16 *buffer, const int numSamples); - bool endOfData() const { return _done; } + bool endOfData() const; + bool endOfStream() const; bool isStereo() const { return _parent->isStereo(); } int getRate() const { return _parent->getRate(); } @@ -287,7 +289,8 @@ public: int getRate() const { return _parent->getRate(); } - bool endOfData() const { return (_pos >= _length) || _parent->endOfStream(); } + bool endOfData() const { return (_pos >= _length) || _parent->endOfData(); } + bool endOfStream() const { return (_pos >= _length) || _parent->endOfStream(); } bool seek(const Timestamp &where); diff --git a/audio/decoders/aac.cpp b/audio/decoders/aac.cpp index 7700bb3215..beabf7bff9 100644 --- a/audio/decoders/aac.cpp +++ b/audio/decoders/aac.cpp @@ -117,6 +117,7 @@ AudioStream *AACDecoder::decodeFrame(Common::SeekableReadStream &stream) { inBufferPos += frameInfo.bytesconsumed; } + audioStream->finish(); return audioStream; } diff --git a/audio/decoders/qdm2.cpp b/audio/decoders/qdm2.cpp index 743ca1cb7d..97d73b3a03 100644 --- a/audio/decoders/qdm2.cpp +++ b/audio/decoders/qdm2.cpp @@ -2607,6 +2607,7 @@ AudioStream *QDM2Stream::decodeFrame(Common::SeekableReadStream &stream) { while (qdm2_decodeFrame(stream, audioStream)) ; + audioStream->finish(); return audioStream; } |