From c7fa1074fbc55e9e519f9c7e08dea9603af22e61 Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Mon, 17 May 2010 21:59:05 +0000 Subject: Change VideoDecoder::getCurFrame() to mean the last frame drawn instead of the next frame to draw. This is patch 1 from patch #2963496 (VideoDecoder Rewrite). svn-id: r49063 --- graphics/video/avi_decoder.cpp | 17 ++++++++--------- graphics/video/dxa_decoder.cpp | 8 +++++--- graphics/video/flic_decoder.cpp | 12 ++++++------ graphics/video/smk_decoder.cpp | 8 +++++--- graphics/video/video_player.cpp | 13 ++++++++----- graphics/video/video_player.h | 13 +++++++++---- 6 files changed, 41 insertions(+), 30 deletions(-) (limited to 'graphics') diff --git a/graphics/video/avi_decoder.cpp b/graphics/video/avi_decoder.cpp index fe5999328e..1e0fb389b3 100644 --- a/graphics/video/avi_decoder.cpp +++ b/graphics/video/avi_decoder.cpp @@ -213,8 +213,7 @@ bool AviDecoder::loadFile(const char *fileName) { _decodedHeader = false; // Seek to the first frame - _videoInfo.currentFrame = 0; - + _videoInfo.currentFrame = -1; // Read chunks until we have decoded the header while (!_decodedHeader) @@ -379,14 +378,11 @@ Surface *AviDecoder::getNextFrame() { } bool AviDecoder::decodeNextFrame() { - if (_videoInfo.currentFrame == 0) - _videoInfo.startTime = g_system->getMillis(); - Surface *surface = NULL; - uint32 curFrame = _videoInfo.currentFrame; + int32 curFrame = _videoInfo.currentFrame; - while (!surface && _videoInfo.currentFrame < _videoInfo.frameCount && !_fileStream->eos()) + while (!surface && !endOfVideo() && !_fileStream->eos()) surface = getNextFrame(); if (curFrame == _videoInfo.currentFrame) { @@ -397,7 +393,10 @@ bool AviDecoder::decodeNextFrame() { if (surface) memcpy(_videoFrameBuffer, surface->pixels, _header.width * _header.height); - return _videoInfo.currentFrame < _videoInfo.frameCount; + if (_videoInfo.currentFrame == 0) + _videoInfo.startTime = g_system->getMillis(); + + return !endOfVideo(); } int32 AviDecoder::getAudioLag() { @@ -405,7 +404,7 @@ int32 AviDecoder::getAudioLag() { return 0; int32 frameDelay = getFrameDelay(); - int32 videoTime = _videoInfo.currentFrame * frameDelay; + int32 videoTime = (_videoInfo.currentFrame + 1) * frameDelay; int32 audioTime; if (!_audStream) { diff --git a/graphics/video/dxa_decoder.cpp b/graphics/video/dxa_decoder.cpp index 827ee0846f..86f2415922 100644 --- a/graphics/video/dxa_decoder.cpp +++ b/graphics/video/dxa_decoder.cpp @@ -56,7 +56,7 @@ DXADecoder::DXADecoder() { _frameSize = 0; _videoInfo.frameCount = 0; - _videoInfo.currentFrame = 0; + _videoInfo.currentFrame = -1; _videoInfo.frameRate = 0; _videoInfo.frameDelay = 0; @@ -159,7 +159,7 @@ bool DXADecoder::loadFile(const char *fileName) { // Read the sound header _soundTag = _fileStream->readUint32BE(); - _videoInfo.currentFrame = 0; + _videoInfo.currentFrame = -1; _videoInfo.firstframeOffset = _fileStream->pos(); @@ -484,6 +484,8 @@ void DXADecoder::decode13(int size) { bool DXADecoder::decodeNextFrame() { uint32 tag; + _videoInfo.currentFrame++; + if (_videoInfo.currentFrame == 0) _videoInfo.startTime = g_system->getMillis(); @@ -557,7 +559,7 @@ bool DXADecoder::decodeNextFrame() { break; } - return ++_videoInfo.currentFrame < _videoInfo.frameCount; + return !endOfVideo(); } } // End of namespace Graphics diff --git a/graphics/video/flic_decoder.cpp b/graphics/video/flic_decoder.cpp index bef232b6e6..9dae1171ac 100644 --- a/graphics/video/flic_decoder.cpp +++ b/graphics/video/flic_decoder.cpp @@ -86,7 +86,7 @@ bool FlicDecoder::loadFile(const char *fileName) { _paletteChanged = false; // Seek to the first frame - _videoInfo.currentFrame = 0; + _videoInfo.currentFrame = -1; _fileStream->seek(_offsetFrame1); return true; } @@ -195,9 +195,6 @@ void FlicDecoder::decodeDeltaFLC(uint8 *data) { #define FRAME_TYPE 0xF1FA bool FlicDecoder::decodeNextFrame() { - if (_videoInfo.currentFrame == 0) - _videoInfo.startTime = g_system->getMillis(); - // Read chunk uint32 frameSize = _fileStream->readUint32LE(); uint16 frameType = _fileStream->readUint16LE(); @@ -222,6 +219,9 @@ bool FlicDecoder::decodeNextFrame() { _videoInfo.height = newHeight; _videoInfo.currentFrame++; + + if (_videoInfo.currentFrame == 0) + _videoInfo.startTime = g_system->getMillis(); } break; default: @@ -261,12 +261,12 @@ bool FlicDecoder::decodeNextFrame() { } // If we just processed the ring frame, set the next frame - if (_videoInfo.currentFrame == _videoInfo.frameCount + 1) { + if (_videoInfo.currentFrame == (int32)_videoInfo.frameCount + 1) { _videoInfo.currentFrame = 1; _fileStream->seek(_offsetFrame2); } - return _videoInfo.currentFrame < _videoInfo.frameCount; + return !endOfVideo(); } void FlicDecoder::reset() { diff --git a/graphics/video/smk_decoder.cpp b/graphics/video/smk_decoder.cpp index a919c60574..2f796c4a65 100644 --- a/graphics/video/smk_decoder.cpp +++ b/graphics/video/smk_decoder.cpp @@ -368,7 +368,7 @@ int32 SmackerDecoder::getAudioLag() { return 0; int32 frameDelay = getFrameDelay(); - int32 videoTime = _videoInfo.currentFrame * frameDelay; + int32 videoTime = (_videoInfo.currentFrame + 1) * frameDelay; int32 audioTime; if (!_audioStream) { @@ -396,7 +396,7 @@ bool SmackerDecoder::loadFile(const char *fileName) { return false; // Seek to the first frame - _videoInfo.currentFrame = 0; + _videoInfo.currentFrame = -1; _header.signature = _fileStream->readUint32BE(); // No BINK support available @@ -535,6 +535,8 @@ bool SmackerDecoder::decodeNextFrame() { uint32 startPos = _fileStream->pos(); + _videoInfo.currentFrame++; + if (_videoInfo.currentFrame == 0) _videoInfo.startTime = g_system->getMillis(); @@ -749,7 +751,7 @@ bool SmackerDecoder::decodeNextFrame() { free(_frameData); - return ++_videoInfo.currentFrame < _videoInfo.frameCount; + return !endOfVideo(); } void SmackerDecoder::queueCompressedBuffer(byte *buffer, uint32 bufferSize, diff --git a/graphics/video/video_player.cpp b/graphics/video/video_player.cpp index ed96ac5fc5..a8676ed594 100644 --- a/graphics/video/video_player.cpp +++ b/graphics/video/video_player.cpp @@ -39,6 +39,7 @@ namespace Graphics { VideoDecoder::VideoDecoder() : _fileStream(0) { _curFrameBlack = 0; _curFrameWhite = 255; + _videoInfo.currentFrame = -1; } VideoDecoder::~VideoDecoder() { @@ -56,13 +57,11 @@ int VideoDecoder::getHeight() { return _videoInfo.height; } -int32 VideoDecoder::getCurFrame() { - if (!_fileStream) - return -1; +int32 VideoDecoder::getCurFrame() const { return _videoInfo.currentFrame; } -int32 VideoDecoder::getFrameCount() { +int32 VideoDecoder::getFrameCount() const { if (!_fileStream) return 0; return _videoInfo.frameCount; @@ -152,6 +151,10 @@ void VideoDecoder::setPalette(byte *pal) { g_system->setPalette(videoPalette, 0, 256); } +bool VideoDecoder::endOfVideo() const { + return !isVideoLoaded() || getCurFrame() >= (int32)getFrameCount() - 1; +} + /* * VideoPlayer @@ -192,7 +195,7 @@ bool VideoPlayer::playVideo(Common::List &stopEvents) { int frameX = (g_system->getWidth() - _decoder->getWidth()) / 2; int frameY = (g_system->getHeight() - _decoder->getHeight()) / 2; - while (_decoder->getCurFrame() < _decoder->getFrameCount() && !_skipVideo) { + while (!_decoder->endOfVideo() && !_skipVideo) { processVideoEvents(stopEvents); uint32 startTime = 0; diff --git a/graphics/video/video_player.h b/graphics/video/video_player.h index 333c39f700..4f38bd9740 100644 --- a/graphics/video/video_player.h +++ b/graphics/video/video_player.h @@ -60,13 +60,13 @@ public: * Returns the current frame number of the video * @return the current frame number of the video */ - virtual int32 getCurFrame(); + virtual int32 getCurFrame() const; /** * Returns the amount of frames in the video * @return the amount of frames in the video */ - virtual int32 getFrameCount(); + virtual int32 getFrameCount() const; /** * Returns the frame rate of the video @@ -108,7 +108,7 @@ public: /** * Returns if a video file is loaded or not */ - bool isVideoLoaded() { return (_fileStream != NULL); } + bool isVideoLoaded() const { return (_fileStream != NULL); } /** * Set RGB palette, based on current frame @@ -158,6 +158,11 @@ public: */ virtual bool decodeNextFrame() = 0; + /** + * Returns if the video is finished or not + */ + virtual bool endOfVideo() const; + protected: struct { uint32 width; @@ -166,7 +171,7 @@ protected: int32 frameRate; int32 frameDelay; // 1/100 ms (to avoid rounding errors) uint32 firstframeOffset; - uint32 currentFrame; + int32 currentFrame; uint32 startTime; } _videoInfo; -- cgit v1.2.3