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, | |
57 public base::SupportsWeakPtr<WebMediaPlayerMS> { | 56 public base::SupportsWeakPtr<WebMediaPlayerMS> { |
58 public: | 57 public: |
59 // Construct a WebMediaPlayerMS with reference to the client, and | 58 // Construct a WebMediaPlayerMS with reference to the client, and |
60 // a MediaStreamClient which provides VideoFrameProvider. | 59 // a MediaStreamClient which provides VideoFrameProvider. |
61 WebMediaPlayerMS(blink::WebFrame* frame, | 60 WebMediaPlayerMS(blink::WebFrame* frame, |
62 blink::WebMediaPlayerClient* client, | 61 blink::WebMediaPlayerClient* client, |
63 base::WeakPtr<media::WebMediaPlayerDelegate> delegate, | 62 base::WeakPtr<media::WebMediaPlayerDelegate> delegate, |
64 media::MediaLog* media_log, | 63 media::MediaLog* media_log, |
65 scoped_ptr<MediaStreamRendererFactory> factory); | 64 scoped_ptr<MediaStreamRendererFactory> factory, |
| 65 const scoped_refptr<base::SingleThreadTaskRunner>& |
| 66 compositor_task_runner); |
| 67 |
66 virtual ~WebMediaPlayerMS(); | 68 virtual ~WebMediaPlayerMS(); |
67 | 69 |
68 virtual void load(LoadType load_type, | 70 virtual void load(LoadType load_type, |
69 const blink::WebURL& url, | 71 const blink::WebURL& url, |
70 CORSMode cors_mode); | 72 CORSMode cors_mode); |
71 | 73 |
72 // Playback controls. | 74 // Playback controls. |
73 virtual void play(); | 75 virtual void play(); |
74 virtual void pause(); | 76 virtual void pause(); |
75 virtual bool supportsSave() const; | 77 virtual bool supportsSave() const; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 virtual unsigned videoDecodedByteCount() const; | 120 virtual unsigned videoDecodedByteCount() const; |
119 | 121 |
120 bool copyVideoTextureToPlatformTexture( | 122 bool copyVideoTextureToPlatformTexture( |
121 blink::WebGraphicsContext3D* web_graphics_context, | 123 blink::WebGraphicsContext3D* web_graphics_context, |
122 unsigned int texture, | 124 unsigned int texture, |
123 unsigned int internal_format, | 125 unsigned int internal_format, |
124 unsigned int type, | 126 unsigned int type, |
125 bool premultiply_alpha, | 127 bool premultiply_alpha, |
126 bool flip_y) override; | 128 bool flip_y) override; |
127 | 129 |
128 // VideoFrameProvider implementation. | 130 private: |
129 void SetVideoFrameProviderClient( | 131 class Compositor : public cc::VideoFrameProvider { |
130 cc::VideoFrameProvider::Client* client) override; | 132 public: |
131 bool UpdateCurrentFrame(base::TimeTicks deadline_min, | 133 explicit Compositor(const scoped_refptr<base::SingleThreadTaskRunner>& |
132 base::TimeTicks deadline_max) override; | 134 compositor_task_runner); |
133 bool HasCurrentFrame() override; | 135 ~Compositor() override; |
134 scoped_refptr<media::VideoFrame> GetCurrentFrame() override; | |
135 void PutCurrentFrame() override; | |
136 | 136 |
137 private: | 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 |
138 // The callback for VideoFrameProvider to signal a new frame is available. | 192 // The callback for VideoFrameProvider to signal a new frame is available. |
139 void OnFrameAvailable(const scoped_refptr<media::VideoFrame>& frame); | 193 void OnFrameAvailable(const scoped_refptr<media::VideoFrame>& frame); |
140 // Need repaint due to state change. | 194 // Need repaint due to state change. |
141 void RepaintInternal(); | 195 void RepaintInternal(); |
142 | 196 |
143 // The callback for source to report error. | 197 // The callback for source to report error. |
144 void OnSourceError(); | 198 void OnSourceError(); |
145 | 199 |
146 // Helpers that set the network/ready state and notifies the client if | 200 // Helpers that set the network/ready state and notifies the client if |
147 // they've changed. | 201 // they've changed. |
(...skipping 16 matching lines...) Expand all Loading... |
164 base::ThreadChecker thread_checker_; | 218 base::ThreadChecker thread_checker_; |
165 | 219 |
166 blink::WebMediaPlayerClient* client_; | 220 blink::WebMediaPlayerClient* client_; |
167 | 221 |
168 base::WeakPtr<media::WebMediaPlayerDelegate> delegate_; | 222 base::WeakPtr<media::WebMediaPlayerDelegate> delegate_; |
169 | 223 |
170 // Specify content:: to disambiguate from cc::. | 224 // Specify content:: to disambiguate from cc::. |
171 scoped_refptr<content::VideoFrameProvider> video_frame_provider_; | 225 scoped_refptr<content::VideoFrameProvider> video_frame_provider_; |
172 bool paused_; | 226 bool paused_; |
173 | 227 |
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 | |
187 scoped_ptr<cc_blink::WebLayerImpl> video_weblayer_; | 228 scoped_ptr<cc_blink::WebLayerImpl> video_weblayer_; |
188 | 229 |
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 | |
193 bool received_first_frame_; | 230 bool received_first_frame_; |
194 base::TimeDelta current_time_; | |
195 unsigned total_frame_count_; | |
196 unsigned dropped_frame_count_; | |
197 media::SkCanvasVideoRenderer video_renderer_; | |
198 | 231 |
199 scoped_refptr<MediaStreamAudioRenderer> audio_renderer_; | 232 scoped_refptr<MediaStreamAudioRenderer> audio_renderer_; |
200 | 233 |
| 234 media::SkCanvasVideoRenderer video_renderer_; |
| 235 |
201 scoped_refptr<media::MediaLog> media_log_; | 236 scoped_refptr<media::MediaLog> media_log_; |
202 | 237 |
203 scoped_ptr<MediaStreamRendererFactory> renderer_factory_; | 238 scoped_ptr<MediaStreamRendererFactory> renderer_factory_; |
204 | 239 |
| 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 |
205 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerMS); | 246 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerMS); |
206 }; | 247 }; |
207 | 248 |
208 } // namespace content | 249 } // namespace content |
209 | 250 |
210 #endif // CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_MS_H_ | 251 #endif // CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_MS_H_ |
OLD | NEW |