Skip to content

Commit

Permalink
FIX: create first dummy ready frame
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-mogilko committed Feb 22, 2024
1 parent b1bc81d commit f2107aa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
19 changes: 6 additions & 13 deletions Engine/media/video/video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,10 @@ AGS::Common::HError play_video(const char *name, int video_flags, int &sprite_nu
// FIXME: return errors from slot_init?
return new Error(String::FromFormat("Failed to initialize video player for %s", name));

// Allocate a sprite slot for this video frames, use dummy empty bitmap as a placeholder
// FIXME: can we avoid this? alternatives:
// - allocate a sprite slot when the first video frame is buffered and ready.
// - ask videoplayer to create a dummy black frame, show in case frame is late or error, etc.
std::unique_ptr<AGS::Common::Bitmap> image(new Bitmap(1,1,game.GetColorDepth()));
int sprite_slot = add_dynamic_sprite(std::move(image));
// Allocate a sprite slot for this video player's frames;
// note that the very first frame could be a dummy frame created as a placeholder
auto first_frame = video_core_slot_acquire_vframe(video_slot);
int sprite_slot = add_dynamic_sprite(std::move(first_frame));
if (sprite_slot <= 0)
return new Error("No free sprite slot to render video to");

Expand Down Expand Up @@ -376,13 +374,8 @@ void sync_video_playback()
auto old_sprite = spriteset.RemoveSprite(sprite_slot);
spriteset.SetSprite(sprite_slot, std::move(new_frame), SPF_DYNAMICALLOC);
game_sprite_updated(sprite_slot, false);
// FIXME: this is a hack related to the temp frame,
// see comments in play_video and fix this
if (old_sprite->GetSize() != Size(1, 1))
{
// Give old frame back to video
video_core_slot_release_vframe(video_slot, std::move(old_sprite));
}
// Give old frame back to video
video_core_slot_release_vframe(video_slot, std::move(old_sprite));
++it;
}
else
Expand Down
2 changes: 1 addition & 1 deletion Engine/media/video/video_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ std::unique_ptr<AGS::Common::Bitmap> video_core_slot_acquire_vframe(int slot_han
std::lock_guard<std::mutex> lk(g_vcore.poll_mutex_m);
auto frame = g_vcore.slots_[slot_handle]->GetReadyFrame();
g_vcore.poll_cv.notify_all();
return std::move(frame);
return frame;
}

void video_core_slot_release_vframe(int slot_handle, std::unique_ptr<AGS::Common::Bitmap> frame)
Expand Down
14 changes: 14 additions & 0 deletions Engine/media/video/videoplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@ void VideoPlayer::SetTargetFrame(const Size &target_sz)
{
_hicolBuf.reset();
}

// TODO: reset the buffered queue, and seek back?

if (_videoReadyFrame)
{
auto old_frame = std::move(_videoReadyFrame);
_videoReadyFrame.reset(new Bitmap(_targetSize.Width, _targetSize.Height, _targetDepth));
_videoReadyFrame->StretchBlt(_videoReadyFrame.get(), RectWH(_targetSize));
}
else
{
_videoReadyFrame.reset(new Bitmap(_targetSize.Width, _targetSize.Height, _targetDepth));
_videoReadyFrame->ClearTransparent();
}
}

void VideoPlayer::Stop()
Expand Down

0 comments on commit f2107aa

Please sign in to comment.