int QueuingAudioStreamImpl::readBuffer(int16 *buffer, const int numSamples) { Common::StackLock lock(_mutex); int samplesDecoded = 0; while (samplesDecoded < numSamples && !_queue.empty()) { AudioStream *stream = _queue.front()._stream; samplesDecoded += stream->readBuffer(buffer + samplesDecoded, numSamples - samplesDecoded); if (stream->endOfData()) { StreamHolder tmp = _queue.pop(); if (tmp._disposeAfterUse == DisposeAfterUse::YES) delete stream; } } return samplesDecoded; }
void QueuingAudioStreamImpl::queueAudioStream(AudioStream *stream, DisposeAfterUse::Flag disposeAfterUse) { assert(!_finished); if ((stream->getRate() != getRate()) || (stream->isStereo() != isStereo())) error("QueuingAudioStreamImpl::queueAudioStream: stream has mismatched parameters"); Common::StackLock lock(_mutex); _queue.push(StreamHolder(stream, disposeAfterUse)); }
int QueuingAudioStreamImpl::readBuffer(int16 *buffer, const int numSamples) { Common::StackLock lock(_mutex); int samplesDecoded = 0; while (samplesDecoded < numSamples && !_queue.empty()) { AudioStream *stream = _queue.front()._stream; samplesDecoded += stream->readBuffer(buffer + samplesDecoded, numSamples - samplesDecoded); // 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; }
uint32 numQueuedStreams() const { //Common::StackLock lock(_mutex); return _queue.size(); }
virtual bool endOfStream() const { return _finished && _queue.empty(); }
virtual bool endOfData() const { //Common::StackLock lock(_mutex); return _queue.empty(); }
virtual bool endOfStream() const { Common::StackLock lock(_mutex); return _finished && _queue.empty(); }
virtual bool endOfData() const { Common::StackLock lock(_mutex); return _queue.empty() || _queue.front()._stream->endOfData(); }