Skip to content

Commit

Permalink
Engine: fixed FLIC playback after threaded buffering
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-mogilko committed Mar 7, 2024
1 parent c59267f commit b78c1b1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
7 changes: 6 additions & 1 deletion Engine/media/video/flic_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ FlicPlayer::~FlicPlayer()
}

HError FlicPlayer::OpenImpl(std::unique_ptr<Common::Stream> data_stream,
const String &/*name*/, int& /*flags*/, int /*target_depth*/)
const String &/*name*/, int& flags, int /*target_depth*/)
{
data_stream->Seek(8);
const int fliwidth = data_stream->ReadInt16();
Expand All @@ -52,6 +52,11 @@ HError FlicPlayer::OpenImpl(std::unique_ptr<Common::Stream> data_stream,
_frameTime = fli_speed;
_frameCount = fli_frame_count;
_durationMs = fli_frame_count * fli_speed;
// FLIC must accumulate frame image and not be dropping frames,
// because its frames contain diff since the last frame;
// skipping will cause visual garbage.
flags &= ~kVideo_DropFrames;
flags |= kVideo_AccumFrame;
return HError::None();
}

Expand Down
6 changes: 4 additions & 2 deletions Engine/media/video/videoplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ void VideoPlayer::SetTargetFrame(const Size &target_sz)
_targetSize = target_sz.IsNull() ? _frameSize : target_sz;

// Create helper bitmaps in case of stretching or color depth conversion
if ((_targetSize != _frameSize) || (_targetDepth != _frameDepth))
if ((_targetSize != _frameSize) || (_targetDepth != _frameDepth)
|| ((_flags & kVideo_AccumFrame) != 0))
{
_vframeBuf.reset(new Bitmap(_frameSize.Width, _frameSize.Height, _frameDepth));
}
Expand Down Expand Up @@ -334,7 +335,8 @@ void VideoPlayer::BufferVideo()
}

// Try to retrieve one video frame from decoder
const bool must_conv = (_targetSize != _frameSize || _targetDepth != _frameDepth);
const bool must_conv = (_targetSize != _frameSize || _targetDepth != _frameDepth
|| ((_flags & kVideo_AccumFrame) != 0));
Bitmap *usebuf = must_conv ? _vframeBuf.get() : target_frame.get();
if (!NextVideoFrame(usebuf))
{ // failed to get frame, so move prepared target frame into the pool for now
Expand Down
3 changes: 3 additions & 0 deletions Engine/media/video/videoplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ enum VideoFlags
kVideo_LegacyFrameSize= 0x0008,
// Allow to drop late video frames in autoplay mode
kVideo_DropFrames = 0x0010,
// Must accumulate decoded frames, when format's frames
// do not have a full image, but diff from the previous frame
kVideo_AccumFrame = 0x0020,
};

// Parent video player class, provides basic playback logic,
Expand Down

0 comments on commit b78c1b1

Please sign in to comment.