diff options
author | Matthew Hoops | 2010-05-20 18:38:06 +0000 |
---|---|---|
committer | Matthew Hoops | 2010-05-20 18:38:06 +0000 |
commit | 2e0fdda51ff9ff48bb8cbfcc770f9fd99cccd43e (patch) | |
tree | 415ceedd9e1e46b743edc1155549252ef1773b61 | |
parent | f76f64774aa5c7d9669196c0258767d1e9f43cfb (diff) | |
download | scummvm-rg350-2e0fdda51ff9ff48bb8cbfcc770f9fd99cccd43e.tar.gz scummvm-rg350-2e0fdda51ff9ff48bb8cbfcc770f9fd99cccd43e.tar.bz2 scummvm-rg350-2e0fdda51ff9ff48bb8cbfcc770f9fd99cccd43e.zip |
Add a pause level system to VideoDecoder (blatantly ripped off from Engine) and adapt Mohawk to it.
svn-id: r49120
-rw-r--r-- | engines/mohawk/video/qt_player.cpp | 29 | ||||
-rw-r--r-- | engines/mohawk/video/qt_player.h | 8 | ||||
-rw-r--r-- | engines/mohawk/video/video.cpp | 12 | ||||
-rw-r--r-- | engines/mohawk/video/video.h | 1 | ||||
-rw-r--r-- | graphics/video/video_decoder.cpp | 18 | ||||
-rw-r--r-- | graphics/video/video_decoder.h | 38 |
6 files changed, 69 insertions, 37 deletions
diff --git a/engines/mohawk/video/qt_player.cpp b/engines/mohawk/video/qt_player.cpp index b19343005e..28ddc446e9 100644 --- a/engines/mohawk/video/qt_player.cpp +++ b/engines/mohawk/video/qt_player.cpp @@ -187,23 +187,20 @@ Graphics::Codec *QTPlayer::createCodec(uint32 codecTag, byte bitsPerPixel) { } void QTPlayer::startAudio() { - if (!_audStream) // No audio/audio not supported - return; - - g_system->getMixer()->playStream(Audio::Mixer::kPlainSoundType, &_audHandle, _audStream); + if (_audStream) // No audio/audio not supported + g_system->getMixer()->playStream(Audio::Mixer::kPlainSoundType, &_audHandle, _audStream); } -void QTPlayer::pauseAudio() { - g_system->getMixer()->pauseHandle(_audHandle, true); -} - -void QTPlayer::resumeAudio() { - g_system->getMixer()->pauseHandle(_audHandle, false); +void QTPlayer::stopAudio() { + if (_audStream) { + g_system->getMixer()->stopHandle(_audHandle); + _audStream = NULL; // the mixer automatically frees the stream + } } -void QTPlayer::stopAudio() { - g_system->getMixer()->stopHandle(_audHandle); - _audStream = NULL; // the mixer automatically frees the stream +void QTPlayer::pauseVideoIntern(bool pause) { + if (_audStream) + g_system->getMixer()->pauseHandle(_audHandle, pause); } Graphics::Surface *QTPlayer::decodeNextFrame() { @@ -244,12 +241,6 @@ bool QTPlayer::endOfVideo() const { return (!_audStream || _audStream->endOfData()) && (!_videoCodec || _curFrame >= (int32)getFrameCount() - 1); } -void QTPlayer::addPauseTime(uint32 p) { - Graphics::VideoDecoder::addPauseTime(p); - if (_videoStreamIndex >= 0) - _nextFrameStartTime += p * _streams[_videoStreamIndex]->time_scale / 1000; -} - bool QTPlayer::needsUpdate() const { return !endOfVideo() && getTimeToNextFrame() == 0; } diff --git a/engines/mohawk/video/qt_player.h b/engines/mohawk/video/qt_player.h index 205b18f99c..6a6b6b43d0 100644 --- a/engines/mohawk/video/qt_player.h +++ b/engines/mohawk/video/qt_player.h @@ -104,7 +104,6 @@ public: void setChunkBeginOffset(uint32 offset) { _beginOffset = offset; } bool isVideoLoaded() const { return _fd != 0; } - void addPauseTime(uint32 p); Graphics::Surface *decodeNextFrame(); bool needsUpdate() const; bool endOfVideo() const; @@ -112,13 +111,14 @@ public: uint32 getTimeToNextFrame() const; Graphics::PixelFormat getPixelFormat() const; + // RewindableVideoDecoder API void rewind(); // TODO: These audio functions need to be removed from the public and/or added to // the VideoDecoder API directly. void updateAudioBuffer(); // This is going to be problematic. - void pauseAudio(); - void resumeAudio(); + + protected: // This is the file handle from which data is read from. It can be the actual file handle or a decompressed stream. @@ -255,6 +255,8 @@ protected: Graphics::Surface *scaleSurface(Graphics::Surface *frame); ScaleMode getScaleMode() const; + void pauseVideoIntern(bool pause); + int readDefault(MOVatom atom); int readLeaf(MOVatom atom); int readELST(MOVatom atom); diff --git a/engines/mohawk/video/video.cpp b/engines/mohawk/video/video.cpp index c4991ec06c..ce50653c73 100644 --- a/engines/mohawk/video/video.cpp +++ b/engines/mohawk/video/video.cpp @@ -32,7 +32,6 @@ namespace Mohawk { VideoManager::VideoManager(MohawkEngine* vm) : _vm(vm) { - _pauseStart = 0; } VideoManager::~VideoManager() { @@ -42,17 +41,12 @@ VideoManager::~VideoManager() { void VideoManager::pauseVideos() { for (uint16 i = 0; i < _videoStreams.size(); i++) - _videoStreams[i]->pauseAudio(); - _pauseStart = _vm->_system->getMillis() * 100; + _videoStreams[i]->pauseVideo(true); } void VideoManager::resumeVideos() { - for (uint16 i = 0; i < _videoStreams.size(); i++) { - _videoStreams[i]->addPauseTime(_vm->_system->getMillis() * 100 - _pauseStart); - _videoStreams[i]->resumeAudio(); - } - - _pauseStart = 0; + for (uint16 i = 0; i < _videoStreams.size(); i++) + _videoStreams[i]->pauseVideo(false); } void VideoManager::stopVideos() { diff --git a/engines/mohawk/video/video.h b/engines/mohawk/video/video.h index 84fab24e33..a5d2bde65d 100644 --- a/engines/mohawk/video/video.h +++ b/engines/mohawk/video/video.h @@ -97,7 +97,6 @@ private: // Keep tabs on any videos playing Common::Array<VideoEntry> _videoStreams; - uint32 _pauseStart; VideoHandle createVideoHandle(uint16 id, uint16 x, uint16 y, bool loop); VideoHandle createVideoHandle(Common::String filename, uint16 x, uint16 y, bool loop); diff --git a/graphics/video/video_decoder.cpp b/graphics/video/video_decoder.cpp index a3f63921a8..fe4a5848f3 100644 --- a/graphics/video/video_decoder.cpp +++ b/graphics/video/video_decoder.cpp @@ -71,12 +71,30 @@ bool VideoDecoder::needsUpdate() const { void VideoDecoder::reset() { _curFrame = -1; _startTime = 0; + _pauseLevel = 0; } bool VideoDecoder::endOfVideo() const { return !isVideoLoaded() || (getCurFrame() >= (int32)getFrameCount() - 1); } +void VideoDecoder::pauseVideo(bool pause) { + if (pause) { + _pauseLevel++; + } else { + assert(_pauseLevel); // We can't go negative + _pauseLevel--; + } + + if (_pauseLevel == 1 && pause) { + _pauseStartTime = g_system->getMillis(); // Store the starting time from pausing to keep it for later + pauseVideoIntern(true); + } else if (_pauseLevel == 0) { + pauseVideoIntern(false); + addPauseTime(g_system->getMillis() - _pauseStartTime); + } +} + uint32 FixedRateVideoDecoder::getTimeToNextFrame() const { if (endOfVideo() || _curFrame < 0) return 0; diff --git a/graphics/video/video_decoder.h b/graphics/video/video_decoder.h index 2ab8306d76..d96545d2c1 100644 --- a/graphics/video/video_decoder.h +++ b/graphics/video/video_decoder.h @@ -128,11 +128,6 @@ public: virtual bool hasDirtyPalette() const { return false; } /** - * Add the time the video has been paused to maintain sync - */ - virtual void addPauseTime(uint32 ms) { _startTime += ms; } - - /** * Returns if the video is finished or not */ virtual bool endOfVideo() const; @@ -147,14 +142,47 @@ public: */ virtual uint32 getTimeToNextFrame() const = 0; + /** + * Pause or resume the video. This should stop/resume any audio playback + * and other stuff. The initial pause time is kept so that any timing + * variables can be updated appropriately. + * + * This is a convenience tracker which automatically keeps track on how + * often the video has been paused, ensuring that after pausing an video + * e.g. twice, it has to be unpaused twice before actuallying resuming. + * + * @param pause true to pause the video, false to resume it + */ + void pauseVideo(bool pause); + + /** + * Return whether the video is currently paused or not. + */ + bool isPaused() const { return _pauseLevel != 0; } + protected: /** * Resets _curFrame and _startTime. Should be called from every close() function. */ void reset(); + /** + * Actual implementation of pause by subclasses. See pause() + * for details. + */ + virtual void pauseVideoIntern(bool pause) {} + + /** + * Add the time the video has been paused to maintain sync + */ + virtual void addPauseTime(uint32 ms) { _startTime += ms; } + int32 _curFrame; uint32 _startTime; + +private: + uint32 _pauseLevel; + uint32 _pauseStartTime; }; /** |