Commit 37e8ae8e authored by Mounir Lamouri's avatar Mounir Lamouri Committed by Commit Bot

Picture-in-Picture: start pipeline to get surface id when needed.

In some cases, the pipeline will not be ready when trying to enter
Picture-in-Picture. It will happen if the video has preloaded its
metadata and has a poster. In this case, the Picture-in-Picture request
will be delayed until the pipeline has started and there is a surface.

Bug: 847671
Change-Id: I56b0560db37ac2e6466abbd3f089973777c49f0f
Reviewed-on: https://chromium-review.googlesource.com/1077453Reviewed-by: default avatarDan Sanders <sandersd@chromium.org>
Reviewed-by: default avatarapacible <apacible@chromium.org>
Commit-Queue: Mounir Lamouri <mlamouri@chromium.org>
Cr-Commit-Position: refs/heads/master@{#563131}
parent f7d59baf
......@@ -293,4 +293,30 @@ IN_PROC_BROWSER_TEST_F(PictureInPictureWindowControllerBrowserTest,
EXPECT_FALSE(in_picture_in_picture);
}
// Tests that we can enter Picture-in-Picture when a video is not preloaded,
// using the metadata optimizations. This test is checking that there are no
// crashes.
IN_PROC_BROWSER_TEST_F(PictureInPictureWindowControllerBrowserTest,
EnterMetadataPosterOptimisation) {
GURL test_page_url = ui_test_utils::GetTestUrl(
base::FilePath(base::FilePath::kCurrentDirectory),
base::FilePath(FILE_PATH_LITERAL(
"media/picture-in-picture/player_metadata_poster.html")));
ui_test_utils::NavigateToURL(browser(), test_page_url);
content::WebContents* active_web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(active_web_contents);
SetUpWindowController(active_web_contents);
EXPECT_TRUE(
content::ExecuteScript(active_web_contents, "enterPictureInPicture();"));
base::string16 expected_title = base::ASCIIToUTF16("entered_pip");
EXPECT_EQ(expected_title,
content::TitleWatcher(active_web_contents, expected_title)
.WaitAndGetTitle());
}
#endif // !defined(OS_LINUX) && !defined(OS_WIN)
<!DOCTYPE html>
<video preload=metadata poster='../../banners/image-512px.png' src='../bigbuck.webm'></video>
<script>
function enterPictureInPicture() {
document.querySelector('video').requestPictureInPicture().then(() => {
document.title = 'entered_pip';
});
}
</script>
......@@ -420,6 +420,13 @@ void WebMediaPlayerImpl::UnregisterContentsLayer(cc::Layer* layer) {
void WebMediaPlayerImpl::OnSurfaceIdUpdated(viz::SurfaceId surface_id) {
pip_surface_id_ = surface_id;
// If there was a request to enter Picture-in-Picture while the pipeline was
// suspended, this call should trigger Picture-in-Picture.
if (enter_pip_callback_) {
EnterPictureInPicture(std::move(*enter_pip_callback_));
enter_pip_callback_.reset();
}
// TODO(726619): Handle the behavior when Picture-in-Picture mode is
// disabled.
// The viz::SurfaceId may be updated when the video begins playback or when
......@@ -806,7 +813,17 @@ void WebMediaPlayerImpl::SetVolume(double volume) {
void WebMediaPlayerImpl::EnterPictureInPicture(
blink::WebMediaPlayer::PipWindowOpenedCallback callback) {
DCHECK(pip_surface_id_.is_valid());
// When the pipeline is suspended, there will be no valid surface. In this
// case, resuming the pipeline will auto-trigger Picture-in-Picture.
if (!pip_surface_id_.is_valid()) {
DCHECK(pipeline_controller_.IsSuspended());
enter_pip_callback_ = std::move(callback);
// This will trigger the pipeline to resume now that the player is pending
// to enter in Picture-in-Picture.
UpdatePlayState();
return;
}
// Notifies the browser process that the player should now be in
// Picture-in-Picture mode.
......@@ -2688,6 +2705,11 @@ WebMediaPlayerImpl::UpdatePlayState_ComputePlayState(bool is_remote,
result.is_suspended = is_remote || must_suspend || idle_suspended ||
background_suspended || can_stay_suspended;
// When Picture-in-Picture has been triggered, the pipeline needs to be
// resumed.
if (enter_pip_callback_ && !must_suspend && !is_remote)
result.is_suspended = false;
DVLOG(3) << __func__ << ": is_remote=" << is_remote
<< ", must_suspend=" << must_suspend
<< ", idle_suspended=" << idle_suspended
......
......@@ -427,6 +427,7 @@ class MEDIA_BLINK_EXPORT WebMediaPlayerImpl
// - is_idle_, must_suspend_,
// - paused_, ended_,
// - pending_suspend_resume_cycle_,
// - enter_pip_callback_,
void UpdatePlayState();
// Methods internal to UpdatePlayState().
......@@ -923,6 +924,13 @@ class MEDIA_BLINK_EXPORT WebMediaPlayerImpl
// route the video to be shown in the Picture-in-Picture window.
viz::SurfaceId pip_surface_id_;
// Sets when entering Picture-in-Picture was delayed because no
// |pip_surface_id_| was available. This happens when the
// PreloadMetadataSuspend optimization is enabled and the player wouldn't
// create the surface until playback.
base::Optional<blink::WebMediaPlayer::PipWindowOpenedCallback>
enter_pip_callback_;
DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerImpl);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment