From e72a1d7c46a352e9d8d7850212275eee78cf4c39 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 3 Sep 2017 19:52:48 -0400 Subject: VIDEO: Simplify AVIDecoder reverse playback special handling --- video/avi_decoder.cpp | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'video') diff --git a/video/avi_decoder.cpp b/video/avi_decoder.cpp index 13b2c98994..ea10b95f5a 100644 --- a/video/avi_decoder.cpp +++ b/video/avi_decoder.cpp @@ -130,20 +130,35 @@ bool AVIDecoder::isSeekable() const { } const Graphics::Surface *AVIDecoder::decodeNextFrame() { - // When playing in reverse, we need to seek to the correct prior frame AVIVideoTrack *track = nullptr; bool isReversed = false; + int frameNum; + + // Check whether the video is playing in revese for (int idx = _videoTracks.size() - 1; idx >= 0; --idx) { track = static_cast(_videoTracks[idx].track); isReversed |= track->isReversed(); } if (isReversed) { - Audio::Timestamp time = track->getFrameTime(getCurFrame()); - seekIntern(time); + // For reverse mode we need to keep seeking to just before the + // desired frame prior to actually decoding a frame + frameNum = getCurFrame(); + seekIntern(track->getFrameTime(frameNum)); + } + + // Decode the next frame + const Graphics::Surface *frame = VideoDecoder::decodeNextFrame(); + + if (isReversed) { + // In reverse mode, set next frame to be the prior frame number + for (int idx = _videoTracks.size() - 1; idx >= 0; --idx) { + track = static_cast(_videoTracks[idx].track); + track->setCurFrame(frameNum - 1); + } } - return VideoDecoder::decodeNextFrame(); + return frame; } const Graphics::Surface *AVIDecoder::decodeNextTransparency() { @@ -746,7 +761,7 @@ bool AVIDecoder::seekIntern(const Audio::Timestamp &time) { seekTransparencyFrame(frame); // Set the video track's frame - videoTrack->setCurFrame(videoTrack->isReversed() ? frame : frame - 1); + videoTrack->setCurFrame(frame - 1); // Set the video track's search offset to the right spot _videoTracks[0].chunkSearchOffset = _indexEntries[frameIndex].offset; @@ -788,7 +803,7 @@ void AVIDecoder::seekTransparencyFrame(int frame) { } } - transTrack->setCurFrame((int)frame - 1); + transTrack->setCurFrame(frame - 1); } byte AVIDecoder::getStreamIndex(uint32 tag) { -- cgit v1.2.3