Skip to content

Commit

Permalink
VIDEO: Improve setEndTime()
Browse files Browse the repository at this point in the history
endOfVideo() and needsUpdate() are now more accurate
  • Loading branch information
Matthew Hoops committed Sep 1, 2012
1 parent bf882b7 commit ddffd74
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
25 changes: 13 additions & 12 deletions video/video_decoder.cpp
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions video/video_decoder.h
Expand Up @@ -777,6 +777,7 @@ class VideoDecoder {
void stopAudio();
void startAudio();
void startAudioLimit(const Audio::Timestamp &limit);
bool hasFramesLeft() const;

int32 _startTime;
uint32 _pauseLevel;
Expand Down

0 comments on commit ddffd74

Please sign in to comment.