diff --git a/video/video_decoder.cpp b/video/video_decoder.cpp index 559880acee07..e79043629c03 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 5abe1d917c2c..7ccf49a0af16 100644 --- a/video/video_decoder.h +++ b/video/video_decoder.h @@ -777,6 +777,7 @@ class VideoDecoder { void stopAudio(); void startAudio(); void startAudioLimit(const Audio::Timestamp &limit); + bool hasFramesLeft() const; int32 _startTime; uint32 _pauseLevel;