diff options
author | Paul Gilbert | 2016-07-23 11:38:39 -0400 |
---|---|---|
committer | Paul Gilbert | 2016-07-23 11:38:39 -0400 |
commit | 71b76acc630af3537b7379be24d59d38326f2606 (patch) | |
tree | edd15fee35901cb1697f298481b14ff47c5c1b65 /engines/titanic/support | |
parent | 9c5f3c305a5edcc60d0415b92fa4dfc533af8918 (diff) | |
download | scummvm-rg350-71b76acc630af3537b7379be24d59d38326f2606.tar.gz scummvm-rg350-71b76acc630af3537b7379be24d59d38326f2606.tar.bz2 scummvm-rg350-71b76acc630af3537b7379be24d59d38326f2606.zip |
TITANIC: Fixes and simplification of AVISurface
Diffstat (limited to 'engines/titanic/support')
-rw-r--r-- | engines/titanic/support/avi_surface.cpp | 58 | ||||
-rw-r--r-- | engines/titanic/support/avi_surface.h | 12 | ||||
-rw-r--r-- | engines/titanic/support/movie.cpp | 12 |
3 files changed, 45 insertions, 37 deletions
diff --git a/engines/titanic/support/avi_surface.cpp b/engines/titanic/support/avi_surface.cpp index 38bccafa89..c64edca7a4 100644 --- a/engines/titanic/support/avi_surface.cpp +++ b/engines/titanic/support/avi_surface.cpp @@ -54,11 +54,8 @@ static bool secondaryTrackSelect(bool isVideo, int trackCounter) { AVISurface::AVISurface(const CResourceKey &key) { _videoSurface = nullptr; - _currentPos = 0; - _priorFrame = 0; _streamCount = 0; _movieFrameSurface[0] = _movieFrameSurface[1] = nullptr; - _isPlaying = false; // Create a decoder for the audio (if any) and primary video track _decoders[0] = new AVIDecoder(Audio::Mixer::kPlainSoundType, primaryTrackSelect); @@ -122,14 +119,13 @@ bool AVISurface::play(int startFrame, int endFrame, int initialFrame, uint flags _movieRangeInfo.push_back(info); if (_movieRangeInfo.size() == 1) { - return changeFrame(initialFrame); + return startAtFrame(initialFrame); } else { return true; } } void AVISurface::stop() { - _isPlaying = false; _decoders[0]->stop(); if (_decoders[1]) _decoders[1]->stop(); @@ -137,37 +133,46 @@ void AVISurface::stop() { _movieRangeInfo.destroyContents(); } -bool AVISurface::changeFrame(int frameNumber) { - if (_isPlaying) +bool AVISurface::startAtFrame(int frameNumber) { + if (isPlaying()) + // If it's already playing, then don't allow it return false; if (frameNumber == -1) // Default to starting frame of first movie range frameNumber = _movieRangeInfo.front()->_startFrame; + // Get the initial frame seekToFrame(frameNumber); renderFrame(); - _isPlaying = true; + // Start the playback + _decoders[0]->start(); + if (_decoders[1]) + _decoders[1]->start(); + return true; } void AVISurface::seekToFrame(uint frameNumber) { - _decoders[0]->seekToFrame(frameNumber); - if (_decoders[1]) - _decoders[1]->seekToFrame(frameNumber); + if ((int)frameNumber != getFrame()) { + _decoders[0]->seekToFrame(frameNumber); + if (_decoders[1]) + _decoders[1]->seekToFrame(frameNumber); + } - _priorFrame = frameNumber; + renderFrame(); } bool AVISurface::handleEvents(CMovieEventList &events) { - if (!_isPlaying) + if (!isPlaying()) return true; CMovieRangeInfo *info = _movieRangeInfo.front(); - _currentPos += info->_isReversed ? -1 : 1; - if ((info->_isReversed && _currentPos < info->_endFrame) || - (!info->_isReversed && _currentPos > info->_endFrame)) { + int currentPos = getFrame(); + + if ((info->_isReversed && currentPos < info->_endFrame) || + (!info->_isReversed && currentPos > info->_endFrame)) { if (info->_isFlag1) { info->getMovieEnd(events); _movieRangeInfo.remove(info); @@ -179,19 +184,20 @@ bool AVISurface::handleEvents(CMovieEventList &events) { } else { // Not empty, so move onto new first one info = _movieRangeInfo.front(); - _currentPos = info->_startFrame; + currentPos = info->_startFrame; } } else { - _currentPos = info->_startFrame; + currentPos = info->_startFrame; } } - if (_isPlaying) { - // SInce movie ranges can change the position in the movie, - // ensure the decoder is kept in sync - seekToFrame(_currentPos); - - info->getMovieFrame(events, _currentPos); + if (isPlaying()) { + if (currentPos != getFrame()) + // The frame has been changed, so move to new position + seekToFrame(currentPos); + + // Get any events for the given position + info->getMovieFrame(events, currentPos); return renderFrame(); } else { return false; @@ -245,7 +251,7 @@ uint AVISurface::getHeight() const { void AVISurface::setFrame(int frameNumber) { // If playback was in process, stop it - if (_isPlaying) + if (isPlaying()) stop(); // Ensure the frame number is valid @@ -307,7 +313,7 @@ bool AVISurface::addEvent(int frameNumber, CGameObject *obj) { me->_gameObject = obj; tail->addEvent(me); - return _movieRangeInfo.size() == 1 && frameNumber == _priorFrame; + return _movieRangeInfo.size() == 1 && frameNumber == getFrame(); } return false; diff --git a/engines/titanic/support/avi_surface.h b/engines/titanic/support/avi_surface.h index dfd4c59267..4372757bc6 100644 --- a/engines/titanic/support/avi_surface.h +++ b/engines/titanic/support/avi_surface.h @@ -52,8 +52,6 @@ class AVISurface { private: AVIDecoder *_decoders[2]; CVideoSurface *_videoSurface; - int _currentPos; - int _priorFrame; CMovieRangeInfoList _movieRangeInfo; int _streamCount; Graphics::ManagedSurface *_movieFrameSurface[2]; @@ -69,9 +67,9 @@ private: void setupDecompressor(); protected: /** - * Change the frame with ??? checking + * Start playback at the specified frame */ - virtual bool changeFrame(int frameNumber); + virtual bool startAtFrame(int frameNumber); /** * Seeks to a given frame number in the video @@ -80,7 +78,6 @@ protected: public: CSoundManager *_soundManager; bool _hasAudio; - bool _isPlaying; double _frameRate; public: AVISurface(const CResourceKey &key); @@ -107,6 +104,11 @@ public: virtual void stop(); /** + * Return true if a video is currently playing + */ + virtual bool isPlaying() const { return _decoders[0]->isPlaying(); } + + /** * Handle any movie events relevent for the frame */ virtual bool handleEvents(CMovieEventList &events); diff --git a/engines/titanic/support/movie.cpp b/engines/titanic/support/movie.cpp index 3856c44e7f..9dc57b897a 100644 --- a/engines/titanic/support/movie.cpp +++ b/engines/titanic/support/movie.cpp @@ -95,21 +95,21 @@ OSMovie::~OSMovie() { void OSMovie::play(uint flags, CGameObject *obj) { _aviSurface.play(flags, obj); - if (_aviSurface._isPlaying) + if (_aviSurface.isPlaying()) movieStarted(); } void OSMovie::play(uint startFrame, uint endFrame, uint flags, CGameObject *obj) { _aviSurface.play(startFrame, endFrame, flags, obj); - if (_aviSurface._isPlaying) + if (_aviSurface.isPlaying()) movieStarted(); } void OSMovie::play(uint startFrame, uint endFrame, uint initialFrame, uint flags, CGameObject *obj) { _aviSurface.play(startFrame, endFrame, initialFrame, flags, obj); - if (_aviSurface._isPlaying) + if (_aviSurface.isPlaying()) movieStarted(); } @@ -160,10 +160,10 @@ void OSMovie::setFrame(uint frameNumber) { } bool OSMovie::handleEvents(CMovieEventList &events) { - if (!_aviSurface._isPlaying) + if (!_aviSurface.isPlaying()) return false; if (!_aviSurface.isFrameReady()) - return _aviSurface._isPlaying; + return _aviSurface.isPlaying(); // Handle updating the frame while (_aviSurface.isFrameReady()) { @@ -174,7 +174,7 @@ bool OSMovie::handleEvents(CMovieEventList &events) { // Flag there's a video frame _hasVideoFrame = true; - return _aviSurface._isPlaying; + return _aviSurface.isPlaying(); } const CMovieRangeInfoList *OSMovie::getMovieRangeInfo() const { |