From ddffd74094768fe7c992c568d484de06f389b7a0 Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Fri, 31 Aug 2012 21:47:52 -0400 Subject: VIDEO: Improve setEndTime() endOfVideo() and needsUpdate() are now more accurate --- video/video_decoder.cpp | 25 +++++++++++++------------ video/video_decoder.h | 1 + 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/video/video_decoder.cpp b/video/video_decoder.cpp index 559880acee..e79043629c 100644 --- a/video/video_decoder.cpp +++ b/video/video_decoder.cpp @@ -87,7 +87,7 @@ bool VideoDecoder::loadFile(const Common::String &filename) { } bool VideoDecoder::needsUpdate() const { - return !endOfVideo() && getTimeToNextFrame() == 0; + return hasFramesLeft() && getTimeToNextFrame() == 0; } void VideoDecoder::pauseVideo(bool pause) { @@ -249,18 +249,8 @@ uint32 VideoDecoder::getTimeToNextFrame() const { } bool VideoDecoder::endOfVideo() const { - if (!isVideoLoaded()) - return true; - - if (_endTimeSet) { - const VideoTrack *track = findNextVideoTrack(); - - if (track && track->getNextFrameStartTime() >= (uint)_endTime.msecs()) - return true; - } - for (TrackList::const_iterator it = _tracks.begin(); it != _tracks.end(); it++) - if (!(*it)->endOfTrack()) + if (!(*it)->endOfTrack() && ((*it)->getTrackType() != Track::kTrackTypeVideo || !_endTimeSet || ((VideoTrack *)*it)->getNextFrameStartTime() < (uint)_endTime.msecs())) return false; return true; @@ -679,4 +669,15 @@ void VideoDecoder::startAudioLimit(const Audio::Timestamp &limit) { ((AudioTrack *)*it)->start(limit); } +bool VideoDecoder::hasFramesLeft() const { + // This is similar to endOfVideo(), except it doesn't take Audio into account (and returns true if not the end of the video) + // This is only used for needsUpdate() atm so that setEndTime() works properly + // And unlike endOfVideoTracks(), this takes into account _endTime + for (TrackList::const_iterator it = _tracks.begin(); it != _tracks.end(); it++) + if ((*it)->getTrackType() == Track::kTrackTypeVideo && !(*it)->endOfTrack() && (!_endTimeSet || ((VideoTrack *)*it)->getNextFrameStartTime() < (uint)_endTime.msecs())) + return true; + + return false; +} + } // End of namespace Video diff --git a/video/video_decoder.h b/video/video_decoder.h index 5abe1d917c..7ccf49a0af 100644 --- a/video/video_decoder.h +++ b/video/video_decoder.h @@ -777,6 +777,7 @@ private: void stopAudio(); void startAudio(); void startAudioLimit(const Audio::Timestamp &limit); + bool hasFramesLeft() const; int32 _startTime; uint32 _pauseLevel; -- cgit v1.2.3