From 6d19ee6e64c9c6bf5ba5efa58028a300ffd4ce69 Mon Sep 17 00:00:00 2001 From: Sven Hesse Date: Fri, 19 Dec 2008 00:14:18 +0000 Subject: Adding convenience functions to get the time to wait for the next frame, while keeping A/V sync svn-id: r35431 --- graphics/smk_player.cpp | 32 ++++++++++++++++++++++++++++++++ graphics/smk_player.h | 20 ++++++++++++++++++++ 2 files changed, 52 insertions(+) (limited to 'graphics') 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 @@ -82,6 +82,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 -- cgit v1.2.3