OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_MS_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_MS_H_ |
6 #define CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_MS_H_ | 6 #define CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_MS_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 // provides video frames for rendering. | 46 // provides video frames for rendering. |
47 // | 47 // |
48 // TODO(wjia): add AudioPlayer. | 48 // TODO(wjia): add AudioPlayer. |
49 // AudioPlayer | 49 // AudioPlayer |
50 // plays audio streams. | 50 // plays audio streams. |
51 // | 51 // |
52 // blink::WebMediaPlayerClient | 52 // blink::WebMediaPlayerClient |
53 // WebKit client of this media player object. | 53 // WebKit client of this media player object. |
54 class WebMediaPlayerMS | 54 class WebMediaPlayerMS |
55 : public blink::WebMediaPlayer, | 55 : public blink::WebMediaPlayer, |
| 56 public cc::VideoFrameProvider, |
56 public base::SupportsWeakPtr<WebMediaPlayerMS> { | 57 public base::SupportsWeakPtr<WebMediaPlayerMS> { |
57 public: | 58 public: |
58 // Construct a WebMediaPlayerMS with reference to the client, and | 59 // Construct a WebMediaPlayerMS with reference to the client, and |
59 // a MediaStreamClient which provides VideoFrameProvider. | 60 // a MediaStreamClient which provides VideoFrameProvider. |
60 WebMediaPlayerMS(blink::WebFrame* frame, | 61 WebMediaPlayerMS(blink::WebFrame* frame, |
61 blink::WebMediaPlayerClient* client, | 62 blink::WebMediaPlayerClient* client, |
62 base::WeakPtr<media::WebMediaPlayerDelegate> delegate, | 63 base::WeakPtr<media::WebMediaPlayerDelegate> delegate, |
63 media::MediaLog* media_log, | 64 media::MediaLog* media_log, |
64 scoped_ptr<MediaStreamRendererFactory> factory, | 65 scoped_ptr<MediaStreamRendererFactory> factory); |
65 const scoped_refptr<base::SingleThreadTaskRunner>& | |
66 compositor_task_runner); | |
67 | |
68 virtual ~WebMediaPlayerMS(); | 66 virtual ~WebMediaPlayerMS(); |
69 | 67 |
70 virtual void load(LoadType load_type, | 68 virtual void load(LoadType load_type, |
71 const blink::WebURL& url, | 69 const blink::WebURL& url, |
72 CORSMode cors_mode); | 70 CORSMode cors_mode); |
73 | 71 |
74 // Playback controls. | 72 // Playback controls. |
75 virtual void play(); | 73 virtual void play(); |
76 virtual void pause(); | 74 virtual void pause(); |
77 virtual bool supportsSave() const; | 75 virtual bool supportsSave() const; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 virtual unsigned videoDecodedByteCount() const; | 118 virtual unsigned videoDecodedByteCount() const; |
121 | 119 |
122 bool copyVideoTextureToPlatformTexture( | 120 bool copyVideoTextureToPlatformTexture( |
123 blink::WebGraphicsContext3D* web_graphics_context, | 121 blink::WebGraphicsContext3D* web_graphics_context, |
124 unsigned int texture, | 122 unsigned int texture, |
125 unsigned int internal_format, | 123 unsigned int internal_format, |
126 unsigned int type, | 124 unsigned int type, |
127 bool premultiply_alpha, | 125 bool premultiply_alpha, |
128 bool flip_y) override; | 126 bool flip_y) override; |
129 | 127 |
| 128 // VideoFrameProvider implementation. |
| 129 void SetVideoFrameProviderClient( |
| 130 cc::VideoFrameProvider::Client* client) override; |
| 131 bool UpdateCurrentFrame(base::TimeTicks deadline_min, |
| 132 base::TimeTicks deadline_max) override; |
| 133 bool HasCurrentFrame() override; |
| 134 scoped_refptr<media::VideoFrame> GetCurrentFrame() override; |
| 135 void PutCurrentFrame() override; |
| 136 |
130 private: | 137 private: |
131 class Compositor : public cc::VideoFrameProvider { | |
132 public: | |
133 explicit Compositor(const scoped_refptr<base::SingleThreadTaskRunner>& | |
134 compositor_task_runner); | |
135 ~Compositor() override; | |
136 | |
137 void EnqueueFrame(scoped_refptr<media::VideoFrame> const& frame); | |
138 | |
139 // Statistical data | |
140 gfx::Size GetCurrentSize(); | |
141 base::TimeDelta GetCurrentTime(); | |
142 unsigned GetTotalFrameCount(); | |
143 unsigned GetDroppedFrameCount(); | |
144 | |
145 // VideoFrameProvider implementation. | |
146 void SetVideoFrameProviderClient( | |
147 cc::VideoFrameProvider::Client* client) override; | |
148 bool UpdateCurrentFrame(base::TimeTicks deadline_min, | |
149 base::TimeTicks deadline_max) override; | |
150 bool HasCurrentFrame() override; | |
151 scoped_refptr<media::VideoFrame> GetCurrentFrame() override; | |
152 void PutCurrentFrame() override; | |
153 | |
154 void StartRendering(); | |
155 void StopRendering(); | |
156 | |
157 private: | |
158 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; | |
159 | |
160 // A pointer back to the compositor to inform it about state changes. This | |
161 // is not NULL while the compositor is actively using this webmediaplayer. | |
162 cc::VideoFrameProvider::Client* video_frame_provider_client_; | |
163 | |
164 // |current_frame_| is updated only on compositor thread. The object it | |
165 // holds can be freed on the compositor thread if it is the last to hold a | |
166 // reference but media::VideoFrame is a thread-safe ref-pointer. It is | |
167 // however read on the compositor and main thread so locking is required | |
168 // around all modifications and all reads on the any thread. | |
169 scoped_refptr<media::VideoFrame> current_frame_; | |
170 | |
171 // |current_frame_used_| is updated on compositor thread only. | |
172 // It's used to track whether |current_frame_| was painted for detecting | |
173 // when to increase |dropped_frame_count_|. | |
174 bool current_frame_used_; | |
175 | |
176 // TODO(qiangchen): To be replaced by VRA. | |
177 scoped_refptr<media::VideoFrame> staging_frame_; | |
178 | |
179 base::TimeTicks last_deadline_max_; | |
180 unsigned total_frame_count_; | |
181 unsigned dropped_frame_count_; | |
182 | |
183 bool paused_; | |
184 | |
185 media::SkCanvasVideoRenderer video_renderer_; | |
186 | |
187 // |current_frame_lock_| protects |current_frame_used_| and | |
188 // |current_frame_|. | |
189 base::Lock current_frame_lock_; | |
190 }; | |
191 | |
192 // The callback for VideoFrameProvider to signal a new frame is available. | 138 // The callback for VideoFrameProvider to signal a new frame is available. |
193 void OnFrameAvailable(const scoped_refptr<media::VideoFrame>& frame); | 139 void OnFrameAvailable(const scoped_refptr<media::VideoFrame>& frame); |
194 // Need repaint due to state change. | 140 // Need repaint due to state change. |
195 void RepaintInternal(); | 141 void RepaintInternal(); |
196 | 142 |
197 // The callback for source to report error. | 143 // The callback for source to report error. |
198 void OnSourceError(); | 144 void OnSourceError(); |
199 | 145 |
200 // Helpers that set the network/ready state and notifies the client if | 146 // Helpers that set the network/ready state and notifies the client if |
201 // they've changed. | 147 // they've changed. |
(...skipping 16 matching lines...) Expand all Loading... |
218 base::ThreadChecker thread_checker_; | 164 base::ThreadChecker thread_checker_; |
219 | 165 |
220 blink::WebMediaPlayerClient* client_; | 166 blink::WebMediaPlayerClient* client_; |
221 | 167 |
222 base::WeakPtr<media::WebMediaPlayerDelegate> delegate_; | 168 base::WeakPtr<media::WebMediaPlayerDelegate> delegate_; |
223 | 169 |
224 // Specify content:: to disambiguate from cc::. | 170 // Specify content:: to disambiguate from cc::. |
225 scoped_refptr<content::VideoFrameProvider> video_frame_provider_; | 171 scoped_refptr<content::VideoFrameProvider> video_frame_provider_; |
226 bool paused_; | 172 bool paused_; |
227 | 173 |
| 174 // |current_frame_| is updated only on main thread. The object it holds |
| 175 // can be freed on the compositor thread if it is the last to hold a |
| 176 // reference but media::VideoFrame is a thread-safe ref-pointer. It is |
| 177 // however read on the compositing thread so locking is required around all |
| 178 // modifications on the main thread, and all reads on the compositing thread. |
| 179 scoped_refptr<media::VideoFrame> current_frame_; |
| 180 // |current_frame_used_| is updated on both main and compositing thread. |
| 181 // It's used to track whether |current_frame_| was painted for detecting |
| 182 // when to increase |dropped_frame_count_|. |
| 183 bool current_frame_used_; |
| 184 // |current_frame_lock_| protects |current_frame_used_| and |current_frame_|. |
| 185 base::Lock current_frame_lock_; |
| 186 |
228 scoped_ptr<cc_blink::WebLayerImpl> video_weblayer_; | 187 scoped_ptr<cc_blink::WebLayerImpl> video_weblayer_; |
229 | 188 |
| 189 // A pointer back to the compositor to inform it about state changes. This is |
| 190 // not NULL while the compositor is actively using this webmediaplayer. |
| 191 cc::VideoFrameProvider::Client* video_frame_provider_client_; |
| 192 |
230 bool received_first_frame_; | 193 bool received_first_frame_; |
| 194 base::TimeDelta current_time_; |
| 195 unsigned total_frame_count_; |
| 196 unsigned dropped_frame_count_; |
| 197 media::SkCanvasVideoRenderer video_renderer_; |
231 | 198 |
232 scoped_refptr<MediaStreamAudioRenderer> audio_renderer_; | 199 scoped_refptr<MediaStreamAudioRenderer> audio_renderer_; |
233 | 200 |
234 media::SkCanvasVideoRenderer video_renderer_; | |
235 | |
236 scoped_refptr<media::MediaLog> media_log_; | 201 scoped_refptr<media::MediaLog> media_log_; |
237 | 202 |
238 scoped_ptr<MediaStreamRendererFactory> renderer_factory_; | 203 scoped_ptr<MediaStreamRendererFactory> renderer_factory_; |
239 | 204 |
240 // WebMediaPlayerMS owns the Compositor instance, but the destructions of | |
241 // compositor should take place on Compositor Thread. | |
242 scoped_ptr<Compositor> compositor_; | |
243 | |
244 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; | |
245 | |
246 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerMS); | 205 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerMS); |
247 }; | 206 }; |
248 | 207 |
249 } // namespace content | 208 } // namespace content |
250 | 209 |
251 #endif // CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_MS_H_ | 210 #endif // CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_MS_H_ |
OLD | NEW |