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::Repaint() { | 37 void WebMediaPlayerProxy::FrameReady( |
| 38 const scoped_refptr<media::VideoFrame>& frame) { |
38 base::AutoLock auto_lock(lock_); | 39 base::AutoLock auto_lock(lock_); |
| 40 current_frame_ = frame; |
| 41 |
39 if (outstanding_repaints_ < kMaxOutstandingRepaints) { | 42 if (outstanding_repaints_ < kMaxOutstandingRepaints) { |
40 ++outstanding_repaints_; | 43 ++outstanding_repaints_; |
41 | 44 |
42 render_loop_->PostTask(FROM_HERE, base::Bind( | 45 render_loop_->PostTask(FROM_HERE, base::Bind( |
43 &WebMediaPlayerProxy::RepaintTask, this)); | 46 &WebMediaPlayerProxy::RepaintTask, this)); |
44 } | 47 } |
45 } | 48 } |
46 | 49 |
47 void WebMediaPlayerProxy::Paint(SkCanvas* canvas, | 50 void WebMediaPlayerProxy::Paint(SkCanvas* canvas, |
48 const gfx::Rect& dest_rect, | 51 const gfx::Rect& dest_rect, |
49 uint8_t alpha) { | 52 uint8_t alpha) { |
50 DCHECK(render_loop_->BelongsToCurrentThread()); | 53 DCHECK(render_loop_->BelongsToCurrentThread()); |
51 if (frame_provider_) { | 54 |
52 scoped_refptr<media::VideoFrame> video_frame; | 55 // Use GetCurrentFrame() to avoid locking while painting in software. |
53 frame_provider_->GetCurrentFrame(&video_frame); | 56 scoped_refptr<media::VideoFrame> video_frame; |
54 video_renderer_.Paint(video_frame, canvas, dest_rect, alpha); | 57 GetCurrentFrame(&video_frame); |
55 frame_provider_->PutCurrentFrame(video_frame); | 58 video_renderer_.Paint(video_frame, canvas, dest_rect, alpha); |
56 } | |
57 } | 59 } |
58 | 60 |
59 bool WebMediaPlayerProxy::HasSingleOrigin() { | 61 bool WebMediaPlayerProxy::HasSingleOrigin() { |
60 DCHECK(render_loop_->BelongsToCurrentThread()); | 62 DCHECK(render_loop_->BelongsToCurrentThread()); |
61 if (data_source_) | 63 if (data_source_) |
62 return data_source_->HasSingleOrigin(); | 64 return data_source_->HasSingleOrigin(); |
63 return true; | 65 return true; |
64 } | 66 } |
65 | 67 |
66 bool WebMediaPlayerProxy::DidPassCORSAccessCheck() const { | 68 bool WebMediaPlayerProxy::DidPassCORSAccessCheck() const { |
67 DCHECK(render_loop_->BelongsToCurrentThread()); | 69 DCHECK(render_loop_->BelongsToCurrentThread()); |
68 if (data_source_) | 70 if (data_source_) |
69 return data_source_->DidPassCORSAccessCheck(); | 71 return data_source_->DidPassCORSAccessCheck(); |
70 return false; | 72 return false; |
71 } | 73 } |
72 | 74 |
73 void WebMediaPlayerProxy::AbortDataSource() { | 75 void WebMediaPlayerProxy::AbortDataSource() { |
74 DCHECK(render_loop_->BelongsToCurrentThread()); | 76 DCHECK(render_loop_->BelongsToCurrentThread()); |
75 if (data_source_) | 77 if (data_source_) |
76 data_source_->Abort(); | 78 data_source_->Abort(); |
77 } | 79 } |
78 | 80 |
79 void WebMediaPlayerProxy::Detach() { | 81 void WebMediaPlayerProxy::Detach() { |
80 DCHECK(render_loop_->BelongsToCurrentThread()); | 82 DCHECK(render_loop_->BelongsToCurrentThread()); |
81 webmediaplayer_ = NULL; | 83 webmediaplayer_ = NULL; |
82 data_source_ = NULL; | 84 data_source_ = NULL; |
83 frame_provider_ = NULL; | |
84 } | 85 } |
85 | 86 |
86 void WebMediaPlayerProxy::RepaintTask() { | 87 void WebMediaPlayerProxy::RepaintTask() { |
87 DCHECK(render_loop_->BelongsToCurrentThread()); | 88 DCHECK(render_loop_->BelongsToCurrentThread()); |
88 { | 89 { |
89 base::AutoLock auto_lock(lock_); | 90 base::AutoLock auto_lock(lock_); |
90 --outstanding_repaints_; | 91 --outstanding_repaints_; |
91 DCHECK_GE(outstanding_repaints_, 0); | 92 DCHECK_GE(outstanding_repaints_, 0); |
92 } | 93 } |
93 if (webmediaplayer_) { | 94 if (webmediaplayer_) { |
94 webmediaplayer_->Repaint(); | 95 webmediaplayer_->Repaint(); |
95 } | 96 } |
96 } | 97 } |
97 | 98 |
98 void WebMediaPlayerProxy::GetCurrentFrame( | 99 void WebMediaPlayerProxy::GetCurrentFrame( |
99 scoped_refptr<media::VideoFrame>* frame_out) { | 100 scoped_refptr<media::VideoFrame>* frame_out) { |
100 if (frame_provider_) | 101 base::AutoLock auto_lock(lock_); |
101 frame_provider_->GetCurrentFrame(frame_out); | 102 *frame_out = current_frame_; |
102 } | |
103 | |
104 void WebMediaPlayerProxy::PutCurrentFrame( | |
105 scoped_refptr<media::VideoFrame> frame) { | |
106 if (frame_provider_) | |
107 frame_provider_->PutCurrentFrame(frame); | |
108 } | 103 } |
109 | 104 |
110 } // namespace webkit_media | 105 } // namespace webkit_media |
OLD | NEW |