diff options
-rw-r--r-- | graphics/smk_player.cpp | 32 | ||||
-rw-r--r-- | graphics/smk_player.h | 20 |
2 files changed, 52 insertions, 0 deletions
diff --git a/graphics/smk_player.cpp b/graphics/smk_player.cpp index 8252dd9c9b..41e118fc9e 100644 --- a/graphics/smk_player.cpp +++ b/graphics/smk_player.cpp @@ -351,6 +351,38 @@ int32 SMKPlayer::getFrameRate() { return _header.frameRate; } +int32 SMKPlayer::getFrameDelay() { + if (!_fileStream) + return 0; + + if (_header.frameRate > 0) + return _header.frameRate * 100; + if (_header.frameRate < 0) + return -_header.frameRate; + + return 10000; +} + +int32 SMKPlayer::getAudioLag() { + if (!_fileStream || !_audioStream) + return 0; + + int32 frameDelay = getFrameDelay(); + int32 videoTime = _currentSMKFrame * frameDelay; + int32 audioTime = (((int32) _mixer->getSoundElapsedTime(_audioHandle)) * 100); + + return videoTime - audioTime; +} + +uint32 SMKPlayer::getFrameWaitTime() { + int32 waitTime = (getFrameDelay() + getAudioLag()) / 100; + + if (waitTime < 0) + return 0; + + return waitTime; +} + bool SMKPlayer::loadFile(const char *fileName) { closeFile(); diff --git a/graphics/smk_player.h b/graphics/smk_player.h index 0e94ab0a39..d7f23b450b 100644 --- a/graphics/smk_player.h +++ b/graphics/smk_player.h @@ -83,6 +83,26 @@ public: int32 getFrameRate(); /** + * Returns the time to wait for each frame in 1/100 ms + * @return the time to wait for each frame in 1/100 ms + */ + int32 getFrameDelay(); + + /** + * Returns the current A/V lag in 1/100 ms + * If > 0, audio lags behind + * If < 0, video lags behind + * @return the current A/V lag in 1/100 ms + */ + int32 getAudioLag(); + + /** + * Returns the time to wait until the next frame in ms, minding any lag + * @return the time to wait until the next frame in ms + */ + uint32 getFrameWaitTime(); + + /** * Load an SMK encoded video file * @param filename the filename to load */ |