diff options
author | Max Horn | 2011-02-07 22:57:35 +0000 |
---|---|---|
committer | Max Horn | 2011-02-07 22:57:35 +0000 |
commit | 85aabef6fe370766fa52ba92a7cf63c558bac772 (patch) | |
tree | 2e460a28d6f1911a2817b1a1fb55d9a85f472417 /video | |
parent | 04748b17446d485a1343e1f1ad9b499a41f5728f (diff) | |
download | scummvm-rg350-85aabef6fe370766fa52ba92a7cf63c558bac772.tar.gz scummvm-rg350-85aabef6fe370766fa52ba92a7cf63c558bac772.tar.bz2 scummvm-rg350-85aabef6fe370766fa52ba92a7cf63c558bac772.zip |
VIDEO: Replace Video::VideoTimestamp with Audio::Timestamp
svn-id: r55814
Diffstat (limited to 'video')
-rw-r--r-- | video/qt_decoder.cpp | 26 | ||||
-rw-r--r-- | video/qt_decoder.h | 4 | ||||
-rw-r--r-- | video/video_decoder.cpp | 12 | ||||
-rw-r--r-- | video/video_decoder.h | 41 |
4 files changed, 19 insertions, 64 deletions
diff --git a/video/qt_decoder.cpp b/video/qt_decoder.cpp index 9187f261bd..c9fcc7a9bf 100644 --- a/video/qt_decoder.cpp +++ b/video/qt_decoder.cpp @@ -177,26 +177,27 @@ void QuickTimeDecoder::seekToFrame(uint32 frame) { } // Adjust the video starting point - _startTime = g_system->getMillis() - Video::VideoTimestamp(_nextFrameStartTime, _streams[_videoStreamIndex]->time_scale).getUnitsInScale(1000); + const Audio::Timestamp curVideoTime(0, _nextFrameStartTime, _streams[_videoStreamIndex]->time_scale); + _startTime = g_system->getMillis() - curVideoTime.msecs(); resetPauseStartTime(); // Adjust the audio starting point if (_audioStreamIndex >= 0) { - _audioStartOffset = VideoTimestamp(_nextFrameStartTime, _streams[_videoStreamIndex]->time_scale); + _audioStartOffset = curVideoTime; // Re-create the audio stream STSDEntry *entry = &_streams[_audioStreamIndex]->stsdEntries[0]; _audStream = Audio::makeQueuingAudioStream(entry->sampleRate, entry->channels == 2); // First, we need to track down what audio sample we need - uint32 curTime = 0; + Audio::Timestamp curAudioTime(0, _streams[_audioStreamIndex]->time_scale); uint sample = 0; bool done = false; for (int32 i = 0; i < _streams[_audioStreamIndex]->stts_count && !done; i++) { for (int32 j = 0; j < _streams[_audioStreamIndex]->stts_data[i].count; j++) { - curTime += _streams[_audioStreamIndex]->stts_data[i].duration; + curAudioTime = curAudioTime.addFrames(_streams[_audioStreamIndex]->stts_data[i].duration); - if (curTime > Video::VideoTimestamp(_nextFrameStartTime, _streams[_videoStreamIndex]->time_scale).getUnitsInScale(_streams[_audioStreamIndex]->time_scale)) { + if (curAudioTime > curVideoTime) { done = true; break; } @@ -241,23 +242,20 @@ void QuickTimeDecoder::seekToFrame(uint32 frame) { } } -void QuickTimeDecoder::seekToTime(VideoTimestamp time) { +void QuickTimeDecoder::seekToTime(Audio::Timestamp time) { // TODO: Audio-only seeking (or really, have QuickTime sounds) if (_videoStreamIndex < 0) error("Audio-only seeking not supported"); - // Convert to the local time scale - uint32 localTime = time.getUnitsInScale(_streams[_videoStreamIndex]->time_scale); - // Try to find the last frame that should have been decoded uint32 frame = 0; - uint32 totalDuration = 0; + Audio::Timestamp totalDuration(0, _streams[_videoStreamIndex]->time_scale); bool done = false; for (int32 i = 0; i < _streams[_videoStreamIndex]->stts_count && !done; i++) { for (int32 j = 0; j < _streams[_videoStreamIndex]->stts_data[i].count; j++) { - totalDuration += _streams[_videoStreamIndex]->stts_data[i].duration; - if (localTime < totalDuration) { + totalDuration = totalDuration.addFrames(_streams[_videoStreamIndex]->stts_data[i].duration); + if (totalDuration > time) { done = true; break; } @@ -394,7 +392,7 @@ bool QuickTimeDecoder::endOfVideo() const { uint32 QuickTimeDecoder::getElapsedTime() const { if (_audStream) - return g_system->getMixer()->getSoundElapsedTime(_audHandle) + _audioStartOffset.getUnitsInScale(1000); + return g_system->getMixer()->getSoundElapsedTime(_audHandle) + _audioStartOffset.msecs(); return VideoDecoder::getElapsedTime(); } @@ -515,7 +513,7 @@ void QuickTimeDecoder::init() { startAudio(); } - _audioStartOffset = VideoTimestamp(0); + _audioStartOffset = Audio::Timestamp(0); } // Initialize video, if present diff --git a/video/qt_decoder.h b/video/qt_decoder.h index cc6b6738c5..47da683f39 100644 --- a/video/qt_decoder.h +++ b/video/qt_decoder.h @@ -121,7 +121,7 @@ public: // SeekableVideoDecoder API void seekToFrame(uint32 frame); - void seekToTime(VideoTimestamp time); + void seekToTime(Audio::Timestamp time); private: // This is the file handle from which data is read from. It can be the actual file handle or a decompressed stream. @@ -239,7 +239,7 @@ private: int8 _audioStreamIndex; uint _curAudioChunk; Audio::SoundHandle _audHandle; - VideoTimestamp _audioStartOffset; + Audio::Timestamp _audioStartOffset; Codec *createCodec(uint32 codecTag, byte bitsPerPixel); Codec *findDefaultVideoCodec() const; diff --git a/video/video_decoder.cpp b/video/video_decoder.cpp index 3e27b3c050..3f23d83761 100644 --- a/video/video_decoder.cpp +++ b/video/video_decoder.cpp @@ -126,16 +126,4 @@ uint32 FixedRateVideoDecoder::getFrameBeginTime(uint32 frame) const { return beginTime.toInt(); } -VideoTimestamp::VideoTimestamp() : _units(0), _scale(1) { -} - -VideoTimestamp::VideoTimestamp(uint units, uint scale) : _units(units), _scale(scale) { - assert(_scale); -} - -uint VideoTimestamp::getUnitsInScale(uint scale) const { - assert(scale); - return (_scale == scale) ? _units : _units * scale / _scale; -} - } // End of namespace Video diff --git a/video/video_decoder.h b/video/video_decoder.h index f8a6d6b080..1447dbf9b5 100644 --- a/video/video_decoder.h +++ b/video/video_decoder.h @@ -33,6 +33,9 @@ #include "graphics/surface.h" #include "graphics/pixelformat.h" +#include "sound/timestamp.h" // TODO: Move this to common/ ? + + namespace Common { class SeekableReadStream; } @@ -239,38 +242,6 @@ public: }; /** - * A simple video timestamp that holds time according to a specific scale. - * - * The scale is in terms of 1/x. For example, if you set units to 1 and the scale to - * 1000, the timestamp will hold the value of 1/1000s or 1ms. - */ -class VideoTimestamp { -public: - VideoTimestamp(); - VideoTimestamp(uint units, uint scale = 1000); - - /** - * Get the units in terms of _scale - */ - uint getUnits() const { return _units; } - - /** - * Get the scale of this timestamp - */ - uint getScale() const { return _scale; } - - /** - * Get the value of the units in terms of the specified scale - */ - uint getUnitsInScale(uint scale) const; - - // TODO: Simple comparisons (<, <=, >, >=, ==, !=) - -private: - uint _units, _scale; -}; - -/** * A VideoDecoder that can seek to a frame or point in time. */ class SeekableVideoDecoder : public virtual RewindableVideoDecoder { @@ -289,14 +260,12 @@ public: * frame. In other words, there is *no* subframe accuracy. This may change in a * later revision of the API. */ - virtual void seekToTime(VideoTimestamp time) = 0; + virtual void seekToTime(Audio::Timestamp time) = 0; /** * Seek to the specified time (in ms). - * - * @see seekToTime(VideoTimestamp) */ - void seekToTime(uint32 time) { seekToTime(VideoTimestamp(time)); } + void seekToTime(uint32 msecs) { seekToTime(Audio::Timestamp(msecs, 1000)); } /** * Implementation of RewindableVideoDecoder::rewind(). |