diff options
author | wjia@chromium.org <wjia@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-28 17:27:15 +0000 |
---|---|---|
committer | wjia@chromium.org <wjia@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-28 17:27:15 +0000 |
commit | 89932804289bd9ea377c5941257f50ac2faaf8a4 (patch) | |
tree | 8b9cd581495864543aebb9835c95e652d428ffce /webkit/media/webmediaplayer_ms.cc | |
parent | 051c02a5be40b5eb9e41f6892b3f1b22652c017e (diff) | |
download | chromium_src-89932804289bd9ea377c5941257f50ac2faaf8a4.zip chromium_src-89932804289bd9ea377c5941257f50ac2faaf8a4.tar.gz chromium_src-89932804289bd9ea377c5941257f50ac2faaf8a4.tar.bz2 |
Allow get/putCurrentFrame called from compositing thread for WebMediaPlayerMS.
getCurrentFrame and putCurrentFrame will be called from compositing thread other than main thread. Use lock to avoid racing.
Also calculate correct dropped frame count based on frame usage.
Review URL: https://codereview.chromium.org/11316143
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@169980 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/media/webmediaplayer_ms.cc')
-rw-r--r-- | webkit/media/webmediaplayer_ms.cc | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/webkit/media/webmediaplayer_ms.cc b/webkit/media/webmediaplayer_ms.cc index b7d68a75..bfbc3c1 100644 --- a/webkit/media/webmediaplayer_ms.cc +++ b/webkit/media/webmediaplayer_ms.cc @@ -47,6 +47,7 @@ WebMediaPlayerMS::WebMediaPlayerMS( delegate_(delegate), media_stream_client_(media_stream_client), paused_(true), + current_frame_used_(false), pending_repaint_(false), received_first_frame_(false), sequence_started_(false), @@ -286,6 +287,12 @@ void WebMediaPlayerMS::paint(WebCanvas* canvas, gfx::RectF dest_rect(rect.x, rect.y, rect.width, rect.height); video_renderer_.Paint(current_frame_, canvas, dest_rect, alpha); + + { + base::AutoLock auto_lock(current_frame_lock_); + if (current_frame_.get()) + current_frame_used_ = true; + } } bool WebMediaPlayerMS::hasSingleSecurityOrigin() const { @@ -333,10 +340,11 @@ unsigned WebMediaPlayerMS::videoDecodedByteCount() const { WebKit::WebVideoFrame* WebMediaPlayerMS::getCurrentFrame() { DVLOG(3) << "WebMediaPlayerMS::getCurrentFrame"; - DCHECK(thread_checker_.CalledOnValidThread()); + base::AutoLock auto_lock(current_frame_lock_); DCHECK(!pending_repaint_); if (current_frame_.get()) { pending_repaint_ = true; + current_frame_used_ = true; return new webkit_media::WebVideoFrameImpl(current_frame_); } return NULL; @@ -345,7 +353,7 @@ WebKit::WebVideoFrame* WebMediaPlayerMS::getCurrentFrame() { void WebMediaPlayerMS::putCurrentFrame( WebKit::WebVideoFrame* web_video_frame) { DVLOG(3) << "WebMediaPlayerMS::putCurrentFrame"; - DCHECK(thread_checker_.CalledOnValidThread()); + base::AutoLock auto_lock(current_frame_lock_); DCHECK(pending_repaint_); pending_repaint_ = false; if (web_video_frame) { @@ -360,7 +368,12 @@ void WebMediaPlayerMS::OnFrameAvailable( ++total_frame_count_; if (!received_first_frame_) { received_first_frame_ = true; - current_frame_ = media::VideoFrame::CreateBlackFrame(frame->natural_size()); + { + base::AutoLock auto_lock(current_frame_lock_); + DCHECK(!current_frame_used_); + current_frame_ = + media::VideoFrame::CreateBlackFrame(frame->natural_size()); + } SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); SetReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); GetClient()->sizeChanged(); @@ -377,27 +390,25 @@ void WebMediaPlayerMS::OnFrameAvailable( bool size_changed = !current_frame_ || current_frame_->natural_size() != frame->natural_size(); - current_frame_ = frame; - current_frame_->SetTimestamp(frame->GetTimestamp() - start_time_); + { + base::AutoLock auto_lock(current_frame_lock_); + if (!current_frame_used_ && current_frame_.get()) + ++dropped_frame_count_; + current_frame_ = frame; + current_frame_->SetTimestamp(frame->GetTimestamp() - start_time_); + current_frame_used_ = false; + } if (size_changed) GetClient()->sizeChanged(); - if (pending_repaint_) { - // TODO(wjia): Figure out how to calculate dropped frame count for - // both S/W and H/W compositing. - // ++dropped_frame_count_; - } else { - GetClient()->repaint(); - } + GetClient()->repaint(); } void WebMediaPlayerMS::RepaintInternal() { DVLOG(1) << "WebMediaPlayerMS::RepaintInternal"; DCHECK(thread_checker_.CalledOnValidThread()); - if (!pending_repaint_) { - GetClient()->repaint(); - } + GetClient()->repaint(); } void WebMediaPlayerMS::OnSourceError() { |