diff options
author | Sven Hesse | 2008-12-19 00:14:18 +0000 |
---|---|---|
committer | Sven Hesse | 2008-12-19 00:14:18 +0000 |
commit | 6d19ee6e64c9c6bf5ba5efa58028a300ffd4ce69 (patch) | |
tree | 6ff7514785629d117325ad361e5f3c656022e2b3 | |
parent | 9cd759c526c53a4065cb2ae33b09e448788918f0 (diff) | |
download | scummvm-rg350-6d19ee6e64c9c6bf5ba5efa58028a300ffd4ce69.tar.gz scummvm-rg350-6d19ee6e64c9c6bf5ba5efa58028a300ffd4ce69.tar.bz2 scummvm-rg350-6d19ee6e64c9c6bf5ba5efa58028a300ffd4ce69.zip |
Adding convenience functions to get the time to wait for the next frame, while keeping A/V sync
svn-id: r35431
-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 */ |