[Scummvm-cvs-logs] SF.net SVN: scummvm:[54929] scummvm/trunk
mthreepwood at users.sourceforge.net
mthreepwood at users.sourceforge.net
Thu Dec 16 02:49:29 CET 2010
Revision: 54929
http://scummvm.svn.sourceforge.net/scummvm/?rev=54929&view=rev
Author: mthreepwood
Date: 2010-12-16 01:49:29 +0000 (Thu, 16 Dec 2010)
Log Message:
-----------
VIDEO: Remove the need to call updateAudioBuffer() externally for QuickTime
Modified Paths:
--------------
scummvm/trunk/engines/mohawk/video.cpp
scummvm/trunk/graphics/video/qt_decoder.cpp
scummvm/trunk/graphics/video/qt_decoder.h
Modified: scummvm/trunk/engines/mohawk/video.cpp
===================================================================
--- scummvm/trunk/engines/mohawk/video.cpp 2010-12-16 01:41:11 UTC (rev 54928)
+++ scummvm/trunk/engines/mohawk/video.cpp 2010-12-16 01:49:29 UTC (rev 54929)
@@ -223,9 +223,6 @@
}
}
}
-
- // Update the audio buffer too
- _videoStreams[i]->updateAudioBuffer();
}
// Return true if we need to update the screen
Modified: scummvm/trunk/graphics/video/qt_decoder.cpp
===================================================================
--- scummvm/trunk/graphics/video/qt_decoder.cpp 2010-12-16 01:41:11 UTC (rev 54928)
+++ scummvm/trunk/graphics/video/qt_decoder.cpp 2010-12-16 01:49:29 UTC (rev 54929)
@@ -226,6 +226,9 @@
_curFrame++;
_nextFrameStartTime += getFrameDuration();
+ // Update the audio while we're at it
+ updateAudioBuffer();
+
// Get the next packet
uint32 descId;
Common::SeekableReadStream *frameData = getNextFramePacket(descId);
@@ -1277,23 +1280,49 @@
return NULL;
}
+uint32 QuickTimeDecoder::getAudioChunkSampleCount(uint chunk) {
+ if (_audioStreamIndex < 0)
+ return 0;
+
+ uint32 sampleCount = 0;
+
+ for (uint32 j = 0; j < _streams[_audioStreamIndex]->sample_to_chunk_sz; j++)
+ if (chunk >= (_streams[_audioStreamIndex]->sample_to_chunk[j].first - 1))
+ sampleCount = _streams[_audioStreamIndex]->sample_to_chunk[j].count;
+
+ return sampleCount;
+}
+
void QuickTimeDecoder::updateAudioBuffer() {
if (!_audStream)
return;
STSDEntry *entry = &_streams[_audioStreamIndex]->stsdEntries[0];
+ // Calculate the amount of chunks we need in memory until the next frame
+ uint32 timeToNextFrame = getTimeToNextFrame();
+ uint32 numberOfChunksNeeded = 0;
+ uint32 timeFilled = 0;
+ uint32 curAudioChunk = _curAudioChunk - _audStream->numQueuedStreams();
+
+ for (; timeFilled < timeToNextFrame && curAudioChunk < _streams[_audioStreamIndex]->chunk_count; numberOfChunksNeeded++, curAudioChunk++) {
+ uint32 sampleCount = 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
- for (; _audStream->numQueuedStreams() < 3 && _curAudioChunk < _streams[_audioStreamIndex]->chunk_count; _curAudioChunk++) {
+ for (; _audStream->numQueuedStreams() < numberOfChunksNeeded && _curAudioChunk < _streams[_audioStreamIndex]->chunk_count; _curAudioChunk++) {
Common::MemoryWriteStreamDynamic *wStream = new Common::MemoryWriteStreamDynamic();
_fd->seek(_streams[_audioStreamIndex]->chunk_offsets[_curAudioChunk]);
// First, we have to get the sample count
- uint32 sampleCount = 0;
- for (uint32 j = 0; j < _streams[_audioStreamIndex]->sample_to_chunk_sz; j++)
- if (_curAudioChunk >= (_streams[_audioStreamIndex]->sample_to_chunk[j].first - 1))
- sampleCount = _streams[_audioStreamIndex]->sample_to_chunk[j].count;
+ uint32 sampleCount = getAudioChunkSampleCount(_curAudioChunk);
assert(sampleCount);
// Then calculate the right sizes
Modified: scummvm/trunk/graphics/video/qt_decoder.h
===================================================================
--- scummvm/trunk/graphics/video/qt_decoder.h 2010-12-16 01:41:11 UTC (rev 54928)
+++ scummvm/trunk/graphics/video/qt_decoder.h 2010-12-16 01:49:29 UTC (rev 54929)
@@ -116,13 +116,7 @@
// RewindableVideoDecoder API
void rewind();
- // TODO: This audio function need to be removed from the public and/or added to
- // the VideoDecoder API directly. I plan on replacing this function with something
- // that can figure out how much audio is needed instead of constantly keeping two
- // chunks in memory.
- void updateAudioBuffer();
-
-protected:
+private:
// This is the file handle from which data is read from. It can be the actual file handle or a decompressed stream.
Common::SeekableReadStream *_fd;
@@ -245,6 +239,8 @@
Audio::QueuingAudioStream *_audStream;
void startAudio();
void stopAudio();
+ void updateAudioBuffer();
+ uint32 getAudioChunkSampleCount(uint chunk);
int8 _audioStreamIndex;
uint _curAudioChunk;
Audio::SoundHandle _audHandle;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list