diff --git a/Engine/media/video/video.cpp b/Engine/media/video/video.cpp index 0696179b9f7..4486f4f1b8d 100644 --- a/Engine/media/video/video.cpp +++ b/Engine/media/video/video.cpp @@ -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 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"); @@ -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 diff --git a/Engine/media/video/video_core.cpp b/Engine/media/video/video_core.cpp index 89c993221c5..27afa5378ec 100644 --- a/Engine/media/video/video_core.cpp +++ b/Engine/media/video/video_core.cpp @@ -166,7 +166,7 @@ std::unique_ptr video_core_slot_acquire_vframe(int slot_han std::lock_guard 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 frame) diff --git a/Engine/media/video/videoplayer.cpp b/Engine/media/video/videoplayer.cpp index c1bbd1b774d..8bd85746a3f 100644 --- a/Engine/media/video/videoplayer.cpp +++ b/Engine/media/video/videoplayer.cpp @@ -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()