| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/media/webmediaplayer_proxy.h" | 5 #include "webkit/media/webmediaplayer_proxy.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
| 10 #include "media/base/pipeline_status.h" | 10 #include "media/base/pipeline_status.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 webmediaplayer_(webmediaplayer), | 27 webmediaplayer_(webmediaplayer), |
| 28 outstanding_repaints_(0) { | 28 outstanding_repaints_(0) { |
| 29 DCHECK(render_loop_); | 29 DCHECK(render_loop_); |
| 30 DCHECK(webmediaplayer_); | 30 DCHECK(webmediaplayer_); |
| 31 } | 31 } |
| 32 | 32 |
| 33 WebMediaPlayerProxy::~WebMediaPlayerProxy() { | 33 WebMediaPlayerProxy::~WebMediaPlayerProxy() { |
| 34 Detach(); | 34 Detach(); |
| 35 } | 35 } |
| 36 | 36 |
| 37 void WebMediaPlayerProxy::FrameReady( | 37 void WebMediaPlayerProxy::Repaint() { |
| 38 const scoped_refptr<media::VideoFrame>& frame) { | |
| 39 base::AutoLock auto_lock(lock_); | 38 base::AutoLock auto_lock(lock_); |
| 40 current_frame_ = frame; | |
| 41 | |
| 42 if (outstanding_repaints_ < kMaxOutstandingRepaints) { | 39 if (outstanding_repaints_ < kMaxOutstandingRepaints) { |
| 43 ++outstanding_repaints_; | 40 ++outstanding_repaints_; |
| 44 | 41 |
| 45 render_loop_->PostTask(FROM_HERE, base::Bind( | 42 render_loop_->PostTask(FROM_HERE, base::Bind( |
| 46 &WebMediaPlayerProxy::RepaintTask, this)); | 43 &WebMediaPlayerProxy::RepaintTask, this)); |
| 47 } | 44 } |
| 48 } | 45 } |
| 49 | 46 |
| 50 void WebMediaPlayerProxy::Paint(SkCanvas* canvas, | 47 void WebMediaPlayerProxy::Paint(SkCanvas* canvas, |
| 51 const gfx::Rect& dest_rect, | 48 const gfx::Rect& dest_rect, |
| 52 uint8_t alpha) { | 49 uint8_t alpha) { |
| 53 DCHECK(render_loop_->BelongsToCurrentThread()); | 50 DCHECK(render_loop_->BelongsToCurrentThread()); |
| 54 | 51 if (frame_provider_) { |
| 55 // Use GetCurrentFrame() to avoid locking while painting in software. | 52 scoped_refptr<media::VideoFrame> video_frame; |
| 56 scoped_refptr<media::VideoFrame> video_frame; | 53 frame_provider_->GetCurrentFrame(&video_frame); |
| 57 GetCurrentFrame(&video_frame); | 54 video_renderer_.Paint(video_frame, canvas, dest_rect, alpha); |
| 58 video_renderer_.Paint(video_frame, canvas, dest_rect, alpha); | 55 frame_provider_->PutCurrentFrame(video_frame); |
| 56 } |
| 59 } | 57 } |
| 60 | 58 |
| 61 bool WebMediaPlayerProxy::HasSingleOrigin() { | 59 bool WebMediaPlayerProxy::HasSingleOrigin() { |
| 62 DCHECK(render_loop_->BelongsToCurrentThread()); | 60 DCHECK(render_loop_->BelongsToCurrentThread()); |
| 63 if (data_source_) | 61 if (data_source_) |
| 64 return data_source_->HasSingleOrigin(); | 62 return data_source_->HasSingleOrigin(); |
| 65 return true; | 63 return true; |
| 66 } | 64 } |
| 67 | 65 |
| 68 bool WebMediaPlayerProxy::DidPassCORSAccessCheck() const { | 66 bool WebMediaPlayerProxy::DidPassCORSAccessCheck() const { |
| 69 DCHECK(render_loop_->BelongsToCurrentThread()); | 67 DCHECK(render_loop_->BelongsToCurrentThread()); |
| 70 if (data_source_) | 68 if (data_source_) |
| 71 return data_source_->DidPassCORSAccessCheck(); | 69 return data_source_->DidPassCORSAccessCheck(); |
| 72 return false; | 70 return false; |
| 73 } | 71 } |
| 74 | 72 |
| 75 void WebMediaPlayerProxy::AbortDataSource() { | 73 void WebMediaPlayerProxy::AbortDataSource() { |
| 76 DCHECK(render_loop_->BelongsToCurrentThread()); | 74 DCHECK(render_loop_->BelongsToCurrentThread()); |
| 77 if (data_source_) | 75 if (data_source_) |
| 78 data_source_->Abort(); | 76 data_source_->Abort(); |
| 79 } | 77 } |
| 80 | 78 |
| 81 void WebMediaPlayerProxy::Detach() { | 79 void WebMediaPlayerProxy::Detach() { |
| 82 DCHECK(render_loop_->BelongsToCurrentThread()); | 80 DCHECK(render_loop_->BelongsToCurrentThread()); |
| 83 webmediaplayer_ = NULL; | 81 webmediaplayer_ = NULL; |
| 84 data_source_ = NULL; | 82 data_source_ = NULL; |
| 83 frame_provider_ = NULL; |
| 85 } | 84 } |
| 86 | 85 |
| 87 void WebMediaPlayerProxy::RepaintTask() { | 86 void WebMediaPlayerProxy::RepaintTask() { |
| 88 DCHECK(render_loop_->BelongsToCurrentThread()); | 87 DCHECK(render_loop_->BelongsToCurrentThread()); |
| 89 { | 88 { |
| 90 base::AutoLock auto_lock(lock_); | 89 base::AutoLock auto_lock(lock_); |
| 91 --outstanding_repaints_; | 90 --outstanding_repaints_; |
| 92 DCHECK_GE(outstanding_repaints_, 0); | 91 DCHECK_GE(outstanding_repaints_, 0); |
| 93 } | 92 } |
| 94 if (webmediaplayer_) { | 93 if (webmediaplayer_) { |
| 95 webmediaplayer_->Repaint(); | 94 webmediaplayer_->Repaint(); |
| 96 } | 95 } |
| 97 } | 96 } |
| 98 | 97 |
| 99 void WebMediaPlayerProxy::GetCurrentFrame( | 98 void WebMediaPlayerProxy::GetCurrentFrame( |
| 100 scoped_refptr<media::VideoFrame>* frame_out) { | 99 scoped_refptr<media::VideoFrame>* frame_out) { |
| 101 base::AutoLock auto_lock(lock_); | 100 if (frame_provider_) |
| 102 *frame_out = current_frame_; | 101 frame_provider_->GetCurrentFrame(frame_out); |
| 102 } |
| 103 |
| 104 void WebMediaPlayerProxy::PutCurrentFrame( |
| 105 scoped_refptr<media::VideoFrame> frame) { |
| 106 if (frame_provider_) |
| 107 frame_provider_->PutCurrentFrame(frame); |
| 103 } | 108 } |
| 104 | 109 |
| 105 } // namespace webkit_media | 110 } // namespace webkit_media |
| OLD | NEW |