aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/agos/animation.cpp22
-rw-r--r--engines/sci/video/seq_decoder.cpp6
-rw-r--r--engines/sci/video/vmd_decoder.cpp6
-rw-r--r--engines/scumm/he/animation_he.cpp3
-rw-r--r--engines/scumm/he/script_v100he.cpp2
-rw-r--r--engines/scumm/he/script_v90he.cpp2
-rw-r--r--engines/sword1/animation.cpp6
-rw-r--r--engines/sword2/animation.cpp2
-rw-r--r--graphics/video/avi_decoder.cpp17
-rw-r--r--graphics/video/dxa_decoder.cpp8
-rw-r--r--graphics/video/flic_decoder.cpp12
-rw-r--r--graphics/video/smk_decoder.cpp8
-rw-r--r--graphics/video/video_player.cpp13
-rw-r--r--graphics/video/video_player.h13
14 files changed, 67 insertions, 53 deletions
diff --git a/engines/agos/animation.cpp b/engines/agos/animation.cpp
index 8155bfb8d9..eccb51c732 100644
--- a/engines/agos/animation.cpp
+++ b/engines/agos/animation.cpp
@@ -272,7 +272,7 @@ void MoviePlayerDXA::playVideo() {
_vm->clearSurfaces();
}
- while (getCurFrame() < getFrameCount() && !_skipMovie && !_vm->shouldQuit())
+ while (!endOfVideo() && !_skipMovie && !_vm->shouldQuit())
handleNextFrame();
}
@@ -318,18 +318,18 @@ void MoviePlayerDXA::startSound() {
}
void MoviePlayerDXA::nextFrame() {
- if (_bgSoundStream && _vm->_mixer->isSoundHandleActive(_bgSound) && (_vm->_mixer->getSoundElapsedTime(_bgSound) * getFrameRate()) / 1000 < (uint32)getCurFrame()) {
+ if (_bgSoundStream && _vm->_mixer->isSoundHandleActive(_bgSound) && (_vm->_mixer->getSoundElapsedTime(_bgSound) * getFrameRate()) / 1000 <= (uint32)getCurFrame()) {
copyFrameToBuffer(_vm->getBackBuf(), 465, 222, _vm->_screenWidth);
return;
}
- if (_vm->_interactiveVideo == TYPE_LOOPING && getCurFrame() == getFrameCount()) {
+ if (_vm->_interactiveVideo == TYPE_LOOPING && endOfVideo()) {
_fileStream->seek(_videoInfo.firstframeOffset);
- _videoInfo.currentFrame = 0;
+ _videoInfo.currentFrame = -1;
startSound();
}
- if (getCurFrame() < getFrameCount()) {
+ if (!endOfVideo()) {
decodeNextFrame();
if (_vm->_interactiveVideo == TYPE_OMNITV) {
copyFrameToBuffer(_vm->getBackBuf(), 465, 222, _vm->_screenWidth);
@@ -370,10 +370,10 @@ bool MoviePlayerDXA::processFrame() {
copyFrameToBuffer((byte *)screen->pixels, (_vm->_screenWidth - getWidth()) / 2, (_vm->_screenHeight - getHeight()) / 2, _vm->_screenWidth);
_vm->_system->unlockScreen();
- if ((_bgSoundStream == NULL) || ((int)(_mixer->getSoundElapsedTime(_bgSound) * getFrameRate()) / 1000 < getCurFrame() + 1)) {
+ if ((_bgSoundStream == NULL) || ((int)(_mixer->getSoundElapsedTime(_bgSound) * getFrameRate()) / 1000 <= getCurFrame())) {
if (_bgSoundStream && _mixer->isSoundHandleActive(_bgSound)) {
- while (_mixer->isSoundHandleActive(_bgSound) && (_mixer->getSoundElapsedTime(_bgSound) * getFrameRate()) / 1000 < (uint32)getCurFrame()) {
+ while (_mixer->isSoundHandleActive(_bgSound) && (_mixer->getSoundElapsedTime(_bgSound) * getFrameRate()) / 1000 <= (uint32)getCurFrame()) {
_vm->_system->delayMillis(10);
}
// In case the background sound ends prematurely, update
@@ -421,7 +421,7 @@ bool MoviePlayerSMK::load() {
}
void MoviePlayerSMK::playVideo() {
- while (getCurFrame() < getFrameCount() && !_skipMovie && !_vm->shouldQuit())
+ while (!endOfVideo() && !_skipMovie && !_vm->shouldQuit())
handleNextFrame();
}
@@ -440,12 +440,12 @@ void MoviePlayerSMK::handleNextFrame() {
}
void MoviePlayerSMK::nextFrame() {
- if (_vm->_interactiveVideo == TYPE_LOOPING && getCurFrame() == getFrameCount()) {
+ if (_vm->_interactiveVideo == TYPE_LOOPING && endOfVideo()) {
_fileStream->seek(_videoInfo.firstframeOffset);
- _videoInfo.currentFrame = 0;
+ _videoInfo.currentFrame = -1;
}
- if (getCurFrame() < getFrameCount()) {
+ if (!endOfVideo()) {
decodeNextFrame();
if (_vm->_interactiveVideo == TYPE_OMNITV) {
copyFrameToBuffer(_vm->getBackBuf(), 465, 222, _vm->_screenWidth);
diff --git a/engines/sci/video/seq_decoder.cpp b/engines/sci/video/seq_decoder.cpp
index ef2622704d..ccce873a15 100644
--- a/engines/sci/video/seq_decoder.cpp
+++ b/engines/sci/video/seq_decoder.cpp
@@ -61,7 +61,7 @@ bool SeqDecoder::loadFile(const char *fileName, int frameDelay) {
return false;
// Seek to the first frame
- _videoInfo.currentFrame = 0;
+ _videoInfo.currentFrame = -1;
_videoInfo.width = SCREEN_WIDTH;
_videoInfo.height = SCREEN_HEIGHT;
@@ -129,6 +129,8 @@ bool SeqDecoder::decodeNextFrame() {
_fileStream->seek(offset);
+ _videoInfo.currentFrame++;
+
if (_videoInfo.currentFrame == 0)
_videoInfo.startTime = g_system->getMillis();
@@ -151,7 +153,7 @@ bool SeqDecoder::decodeNextFrame() {
delete[] buf;
}
- return ++_videoInfo.currentFrame < _videoInfo.frameCount;
+ return !endOfVideo();
}
#define WRITE_TO_BUFFER(n) \
diff --git a/engines/sci/video/vmd_decoder.cpp b/engines/sci/video/vmd_decoder.cpp
index 4e56e51054..9e95521ebb 100644
--- a/engines/sci/video/vmd_decoder.cpp
+++ b/engines/sci/video/vmd_decoder.cpp
@@ -75,7 +75,7 @@ bool VMDDecoder::loadFile(const char *fileName) {
_videoInfo.frameCount = _vmdDecoder->getFramesCount();
_videoInfo.frameRate = _vmdDecoder->getFrameRate();
_videoInfo.frameDelay = _videoInfo.frameRate * 100;
- _videoInfo.currentFrame = 0;
+ _videoInfo.currentFrame = -1;
_videoInfo.firstframeOffset = 0; // not really necessary for VMDs
if (_vmdDecoder->hasExtraData())
@@ -103,6 +103,8 @@ void VMDDecoder::closeFile() {
}
bool VMDDecoder::decodeNextFrame() {
+ _videoInfo.currentFrame++;
+
if (_videoInfo.currentFrame == 0)
_videoInfo.startTime = g_system->getMillis();
@@ -113,7 +115,7 @@ bool VMDDecoder::decodeNextFrame() {
setPalette(_palette);
}
- return ++_videoInfo.currentFrame < _videoInfo.frameCount;
+ return !endOfVideo();
}
void VMDDecoder::getPalette() {
diff --git a/engines/scumm/he/animation_he.cpp b/engines/scumm/he/animation_he.cpp
index 11d7e87f34..5bd60d32e3 100644
--- a/engines/scumm/he/animation_he.cpp
+++ b/engines/scumm/he/animation_he.cpp
@@ -128,9 +128,8 @@ void MoviePlayer::handleNextFrame() {
_vm->markRectAsDirty(kMainVirtScreen, imageRect);
}
- if (getCurFrame() == getFrameCount()) {
+ if (endOfVideo())
closeFile();
- }
}
void MoviePlayer::setPalette(byte *pal) {
diff --git a/engines/scumm/he/script_v100he.cpp b/engines/scumm/he/script_v100he.cpp
index b304454e19..e32409fe85 100644
--- a/engines/scumm/he/script_v100he.cpp
+++ b/engines/scumm/he/script_v100he.cpp
@@ -2937,7 +2937,7 @@ void ScummEngine_v100he::o100_getVideoData() {
break;
case 73:
pop();
- push(_moviePlay->getCurFrame());
+ push(_moviePlay->endOfVideo() ? -1 : (_moviePlay->getCurFrame() + 1));
break;
case 84:
pop();
diff --git a/engines/scumm/he/script_v90he.cpp b/engines/scumm/he/script_v90he.cpp
index cff34412bd..091bf5027b 100644
--- a/engines/scumm/he/script_v90he.cpp
+++ b/engines/scumm/he/script_v90he.cpp
@@ -1464,7 +1464,7 @@ void ScummEngine_v90he::o90_getVideoData() {
break;
case 52: // Get current frame
pop();
- push(_moviePlay->getCurFrame());
+ push(_moviePlay->endOfVideo() ? -1 : (_moviePlay->getCurFrame() + 1));
break;
case 63: // Get image number
pop();
diff --git a/engines/sword1/animation.cpp b/engines/sword1/animation.cpp
index 1c1f6dcf4e..221a20ba45 100644
--- a/engines/sword1/animation.cpp
+++ b/engines/sword1/animation.cpp
@@ -179,7 +179,7 @@ void MoviePlayer::play() {
void MoviePlayer::performPostProcessing(byte *screen) {
if (!_movieTexts.empty()) {
- if (_decoder->getCurFrame() == _movieTexts[0]->_startFrame) {
+ if (_decoder->getCurFrame() + 1 == _movieTexts[0]->_startFrame) {
_textMan->makeTextSprite(2, (uint8 *)_movieTexts[0]->_text, 600, LETTER_COL);
FrameHeader *frame = _textMan->giveSpriteData(2);
@@ -188,7 +188,7 @@ void MoviePlayer::performPostProcessing(byte *screen) {
_textX = 320 - _textWidth / 2;
_textY = 420 - _textHeight;
}
- if (_decoder->getCurFrame() == _movieTexts[0]->_endFrame) {
+ if (_decoder->getCurFrame() + 1 == _movieTexts[0]->_endFrame) {
_textMan->releaseText(2, false);
delete _movieTexts.remove_at(0);
}
@@ -256,7 +256,7 @@ int32 DXADecoderWithSound::getAudioLag() {
return 0;
int32 frameDelay = getFrameDelay();
- int32 videoTime = _videoInfo.currentFrame * frameDelay;
+ int32 videoTime = (_videoInfo.currentFrame + 1) * frameDelay;
int32 audioTime;
const Audio::Timestamp ts = _mixer->getElapsedTime(*_bgSoundHandle);
diff --git a/engines/sword2/animation.cpp b/engines/sword2/animation.cpp
index 6c13f03f00..1c5c2e5f8c 100644
--- a/engines/sword2/animation.cpp
+++ b/engines/sword2/animation.cpp
@@ -240,7 +240,7 @@ void MoviePlayer::drawTextObject(uint32 index, byte *screen) {
void MoviePlayer::performPostProcessing(byte *screen) {
MovieText *text;
- int frame = _decoder->getCurFrame();
+ int frame = _decoder->getCurFrame() + 1;
if (_currentMovieText < _numMovieTexts) {
text = &_movieTexts[_currentMovieText];
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<Common::Event> &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;