Commit e9559700 authored by Thomas Guilbert's avatar Thomas Guilbert Committed by Commit Bot

Set OnFramePresentedCB from main thread

Currently, we jump to the compositor thread in order to set the
new frame presented callback on the VideoFrameCompositor.

This CL is a small change that allows us to set that callback from the
main thread. This should help minimize the amount of frames we miss in
video.rAF calls.

Bug: 1012063
Change-Id: I521eb0bf0a6e71f59552c60276006e1884c1f989
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2040436
Commit-Queue: Thomas Guilbert <tguilbert@chromium.org>
Auto-Submit: Thomas Guilbert <tguilbert@chromium.org>
Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738770}
parent fe8864a4
...@@ -261,7 +261,7 @@ void VideoFrameCompositor::SetOnNewProcessedFrameCallback( ...@@ -261,7 +261,7 @@ void VideoFrameCompositor::SetOnNewProcessedFrameCallback(
void VideoFrameCompositor::SetOnFramePresentedCallback( void VideoFrameCompositor::SetOnFramePresentedCallback(
OnNewFramePresentedCB present_cb) { OnNewFramePresentedCB present_cb) {
DCHECK(task_runner_->BelongsToCurrentThread()); base::AutoLock lock(new_presented_frame_cb_lock_);
new_presented_frame_cb_ = std::move(present_cb); new_presented_frame_cb_ = std::move(present_cb);
} }
...@@ -284,8 +284,16 @@ bool VideoFrameCompositor::ProcessNewFrame(scoped_refptr<VideoFrame> frame, ...@@ -284,8 +284,16 @@ bool VideoFrameCompositor::ProcessNewFrame(scoped_refptr<VideoFrame> frame,
if (new_processed_frame_cb_) if (new_processed_frame_cb_)
std::move(new_processed_frame_cb_).Run(tick_clock_->NowTicks()); std::move(new_processed_frame_cb_).Run(tick_clock_->NowTicks());
if (new_presented_frame_cb_) { // Copy to a local variable to avoid potential deadlock when executing the
std::move(new_presented_frame_cb_) // callback.
OnNewFramePresentedCB frame_presented_cb;
{
base::AutoLock lock(new_presented_frame_cb_lock_);
frame_presented_cb = std::move(new_presented_frame_cb_);
}
if (frame_presented_cb) {
std::move(frame_presented_cb)
.Run(GetCurrentFrame(), tick_clock_->NowTicks(), presentation_time, .Run(GetCurrentFrame(), tick_clock_->NowTicks(), presentation_time,
presentation_counter_); presentation_counter_);
} }
......
...@@ -224,9 +224,13 @@ class MEDIA_BLINK_EXPORT VideoFrameCompositor : public VideoRendererSink, ...@@ -224,9 +224,13 @@ class MEDIA_BLINK_EXPORT VideoFrameCompositor : public VideoRendererSink,
base::TimeTicks last_background_render_; base::TimeTicks last_background_render_;
OnNewProcessedFrameCB new_processed_frame_cb_; OnNewProcessedFrameCB new_processed_frame_cb_;
OnNewFramePresentedCB new_presented_frame_cb_;
cc::UpdateSubmissionStateCB update_submission_state_callback_; cc::UpdateSubmissionStateCB update_submission_state_callback_;
// Callback used to satisfy video.rAF requests.
// Set on the main thread, fired on the compositor thread.
base::Lock new_presented_frame_cb_lock_;
OnNewFramePresentedCB new_presented_frame_cb_;
// Set on the compositor thread, but also read on the media thread. Lock is // Set on the compositor thread, but also read on the media thread. Lock is
// not used when reading |current_frame_| on the compositor thread. // not used when reading |current_frame_| on the compositor thread.
base::Lock current_frame_lock_; base::Lock current_frame_lock_;
......
...@@ -3332,13 +3332,8 @@ base::Optional<viz::SurfaceId> WebMediaPlayerImpl::GetSurfaceId() { ...@@ -3332,13 +3332,8 @@ base::Optional<viz::SurfaceId> WebMediaPlayerImpl::GetSurfaceId() {
} }
void WebMediaPlayerImpl::RequestAnimationFrame() { void WebMediaPlayerImpl::RequestAnimationFrame() {
vfc_task_runner_->PostTask( compositor_->SetOnFramePresentedCallback(BindToCurrentLoop(base::BindOnce(
FROM_HERE, &WebMediaPlayerImpl::OnNewFramePresentedCallback, weak_this_)));
base::BindOnce(&VideoFrameCompositor::SetOnFramePresentedCallback,
base::Unretained(compositor_.get()),
BindToCurrentLoop(base::BindOnce(
&WebMediaPlayerImpl::OnNewFramePresentedCallback,
weak_factory_.GetWeakPtr()))));
} }
void WebMediaPlayerImpl::OnNewFramePresentedCallback( void WebMediaPlayerImpl::OnNewFramePresentedCallback(
......
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