void QuickTimeDecoder::updateAudioBuffer() { if (!_audStream) return; uint32 numberOfChunksNeeded = 0; if (_videoTrackIndex < 0 || _curFrame == (int32)_tracks[_videoTrackIndex]->frameCount - 1) { // If we have no video, there's nothing to base our buffer against // However, one must ask why a QuickTimeDecoder is being used instead of the nice makeQuickTimeStream() function // If we're on the last frame, make sure all audio remaining is buffered numberOfChunksNeeded = _tracks[_audioTrackIndex]->chunkCount; } else { Audio::QuickTimeAudioDecoder::AudioSampleDesc *entry = (Audio::QuickTimeAudioDecoder::AudioSampleDesc *)_tracks[_audioTrackIndex]->sampleDescs[0]; // Calculate the amount of chunks we need in memory until the next frame uint32 timeToNextFrame = getTimeToNextFrame(); uint32 timeFilled = 0; uint32 curAudioChunk = _curAudioChunk - _audStream->numQueuedStreams(); for (; timeFilled < timeToNextFrame && curAudioChunk < _tracks[_audioTrackIndex]->chunkCount; numberOfChunksNeeded++, curAudioChunk++) { uint32 sampleCount = entry->getAudioChunkSampleCount(curAudioChunk); assert(sampleCount); timeFilled += sampleCount * 1000 / entry->_sampleRate; } // Add a couple extra to ensure we don't underrun numberOfChunksNeeded += 3; } // Keep three streams in buffer so that if/when the first two end, it goes right into the next while (_audStream->numQueuedStreams() < numberOfChunksNeeded && _curAudioChunk < _tracks[_audioTrackIndex]->chunkCount) queueNextAudioChunk(); }
void QuickTimeDecoder::updateAudioBuffer() { if (_audioTrackIndex < 0) return; uint32 numberOfChunksNeeded = 0; if (_curFrame == (int32)_tracks[_videoTrackIndex]->frameCount - 1) { // If we're on the last frame, make sure all audio remaining is buffered numberOfChunksNeeded = _tracks[_audioTrackIndex]->chunkCount; } else { AudioSampleDesc *entry = (AudioSampleDesc *)_tracks[_audioTrackIndex]->sampleDescs[0]; // Calculate the amount of chunks we need in memory until the next frame uint32 timeToNextFrame = getTimeToNextFrame(); uint32 timeFilled = 0; uint32 curAudioChunk = _curAudioChunk - getNumQueuedStreams(); for (; timeFilled < timeToNextFrame && curAudioChunk < _tracks[_audioTrackIndex]->chunkCount; numberOfChunksNeeded++, curAudioChunk++) { uint32 sampleCount = entry->getAudioChunkSampleCount(curAudioChunk); assert(sampleCount); timeFilled += sampleCount * 1000 / entry->_sampleRate; } // Add a couple extra to ensure we don't underrun numberOfChunksNeeded += 3; } // Keep three streams in buffer so that if/when the first two end, it goes right into the next while (getNumQueuedStreams() < numberOfChunksNeeded && _curAudioChunk < _tracks[_audioTrackIndex]->chunkCount) queueNextAudioChunk(); }