NANCY: Make sure getCurFrame() is correct for AVF videos

This fixes an edge case in SecondaryMovie where a frame
flag wouldn't fire when playing in reverse.
This commit is contained in:
Kaloyan Chehlarski 2023-10-23 21:57:57 +03:00
parent e23b573e7a
commit e2bc4a7bcd
2 changed files with 13 additions and 3 deletions

View File

@ -130,7 +130,7 @@ bool AVFDecoder::atEnd() const {
AVFDecoder::AVFVideoTrack::AVFVideoTrack(Common::SeekableReadStream *stream, uint32 chunkFileFormat, CacheHint cacheHint) {
assert(stream);
_fileStream = stream;
_curFrame = 0;
_curFrame = -1;
_reversed = false;
_dec = new Decompressor;
@ -202,6 +202,14 @@ AVFDecoder::AVFVideoTrack::~AVFVideoTrack() {
bool AVFDecoder::AVFVideoTrack::seek(const Audio::Timestamp &time) {
_curFrame = getFrameAtTime(time);
// Offset by 1 to ensure decodeNextFrame() actually decodes the frame we want
if (!_reversed) {
--_curFrame;
} else {
++_curFrame;
}
return true;
}
@ -360,7 +368,7 @@ const Graphics::Surface *AVFDecoder::AVFVideoTrack::decodeFrame(uint frameNr) {
}
const Graphics::Surface *AVFDecoder::AVFVideoTrack::decodeNextFrame() {
return decodeFrame(_reversed ? --_curFrame : _curFrame++);
return decodeFrame(_reversed ? --_curFrame : ++_curFrame);
}
} // End of namespace Nancy

View File

@ -63,7 +63,7 @@ private:
uint16 getWidth() const override { return _width; }
uint16 getHeight() const override { return _height; }
Graphics::PixelFormat getPixelFormat() const override { return _pixelFormat; }
int getCurFrame() const override { return _reversed ? _curFrame : _curFrame - 1; }
int getCurFrame() const override { return _curFrame; }
int getFrameCount() const override { return _frameCount; }
bool isSeekable() const override { return true; }
bool seek(const Audio::Timestamp &time) override;
@ -88,6 +88,8 @@ private:
bool decode(byte *outBuf, uint32 frameSize, Common::ReadStream &inBuf) const;
const AVFDecoder *_owner;
Common::SeekableReadStream *_fileStream;
Graphics::PixelFormat _pixelFormat;
uint _width, _height, _depth, _frameSize;