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 void ReplaceCurrentFrameWithACopy(media::SkCanvasVideoRenderer* renderer); |
| 157 |
| 158 private: |
| 159 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; |
| 160 |
| 161 // A pointer back to the compositor to inform it about state changes. This |
| 162 // is not NULL while the compositor is actively using this webmediaplayer. |
| 163 cc::VideoFrameProvider::Client* video_frame_provider_client_; |
| 164 |
| 165 // |current_frame_| is updated only on compositor thread. The object it |
| 166 // holds can be freed on the compositor thread if it is the last to hold a |
| 167 // reference but media::VideoFrame is a thread-safe ref-pointer. It is |
| 168 // however read on the compositor and main thread so locking is required |
| 169 // around all modifications and all reads on the any thread. |
| 170 scoped_refptr<media::VideoFrame> current_frame_; |
| 171 |
| 172 // |current_frame_used_| is updated on compositor thread only. |
| 173 // It's used to track whether |current_frame_| was painted for detecting |
| 174 // when to increase |dropped_frame_count_|. |
| 175 bool current_frame_used_; |
| 176 |
| 177 base::TimeTicks last_deadline_max_; |
| 178 unsigned total_frame_count_; |
| 179 unsigned dropped_frame_count_; |
| 180 |
| 181 bool paused_; |
| 182 |
| 183 // |current_frame_lock_| protects |current_frame_used_| and |
| 184 // |current_frame_|. |
| 185 base::Lock current_frame_lock_; |
| 186 }; |
| 187 |
138 // The callback for VideoFrameProvider to signal a new frame is available. | 188 // The callback for VideoFrameProvider to signal a new frame is available. |
139 void OnFrameAvailable(const scoped_refptr<media::VideoFrame>& frame); | 189 void OnFrameAvailable(const scoped_refptr<media::VideoFrame>& frame); |
140 // Need repaint due to state change. | 190 // Need repaint due to state change. |
141 void RepaintInternal(); | 191 void RepaintInternal(); |
142 | 192 |
143 // The callback for source to report error. | 193 // The callback for source to report error. |
144 void OnSourceError(); | 194 void OnSourceError(); |
145 | 195 |
146 // Helpers that set the network/ready state and notifies the client if | 196 // Helpers that set the network/ready state and notifies the client if |
147 // they've changed. | 197 // they've changed. |
(...skipping 12 matching lines...) Expand all Loading... |
160 | 210 |
161 float volume_; | 211 float volume_; |
162 | 212 |
163 blink::WebMediaPlayerClient* const client_; | 213 blink::WebMediaPlayerClient* const client_; |
164 | 214 |
165 const base::WeakPtr<media::WebMediaPlayerDelegate> delegate_; | 215 const base::WeakPtr<media::WebMediaPlayerDelegate> delegate_; |
166 | 216 |
167 // Specify content:: to disambiguate from cc::. | 217 // Specify content:: to disambiguate from cc::. |
168 scoped_refptr<content::VideoFrameProvider> video_frame_provider_; | 218 scoped_refptr<content::VideoFrameProvider> video_frame_provider_; |
169 bool paused_; | 219 bool paused_; |
170 | 220 bool remote_; |
171 // |current_frame_| is updated only on main thread. The object it holds | |
172 // can be freed on the compositor thread if it is the last to hold a | |
173 // reference but media::VideoFrame is a thread-safe ref-pointer. It is | |
174 // however read on the compositing thread so locking is required around all | |
175 // modifications on the main thread, and all reads on the compositing thread. | |
176 scoped_refptr<media::VideoFrame> current_frame_; | |
177 // |current_frame_used_| is updated on both main and compositing thread. | |
178 // It's used to track whether |current_frame_| was painted for detecting | |
179 // when to increase |dropped_frame_count_|. | |
180 bool current_frame_used_; | |
181 // |current_frame_lock_| protects |current_frame_used_| and |current_frame_|. | |
182 base::Lock current_frame_lock_; | |
183 | 221 |
184 scoped_ptr<cc_blink::WebLayerImpl> video_weblayer_; | 222 scoped_ptr<cc_blink::WebLayerImpl> video_weblayer_; |
185 | 223 |
186 // A pointer back to the compositor to inform it about state changes. This is | |
187 // not NULL while the compositor is actively using this webmediaplayer. | |
188 cc::VideoFrameProvider::Client* video_frame_provider_client_; | |
189 | |
190 bool received_first_frame_; | 224 bool received_first_frame_; |
191 base::TimeDelta current_time_; | |
192 unsigned total_frame_count_; | |
193 unsigned dropped_frame_count_; | |
194 media::SkCanvasVideoRenderer video_renderer_; | |
195 | 225 |
196 scoped_refptr<MediaStreamAudioRenderer> audio_renderer_; | 226 scoped_refptr<MediaStreamAudioRenderer> audio_renderer_; |
197 | 227 |
| 228 media::SkCanvasVideoRenderer video_renderer_; |
| 229 |
198 scoped_refptr<media::MediaLog> media_log_; | 230 scoped_refptr<media::MediaLog> media_log_; |
199 | 231 |
200 scoped_ptr<MediaStreamRendererFactory> renderer_factory_; | 232 scoped_ptr<MediaStreamRendererFactory> renderer_factory_; |
201 | 233 |
| 234 |
202 // Used for DCHECKs to ensure methods calls executed in the correct thread. | 235 // Used for DCHECKs to ensure methods calls executed in the correct thread. |
203 base::ThreadChecker thread_checker_; | 236 base::ThreadChecker thread_checker_; |
204 | 237 |
| 238 // WebMediaPlayerMS owns the Compositor instance, but the destructions of |
| 239 // compositor should take place on Compositor Thread. |
| 240 scoped_ptr<Compositor> compositor_; |
| 241 |
| 242 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; |
| 243 |
| 244 |
205 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerMS); | 245 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerMS); |
206 }; | 246 }; |
207 | 247 |
208 } // namespace content | 248 } // namespace content |
209 | 249 |
210 #endif // CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_MS_H_ | 250 #endif // CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_MS_H_ |
OLD | NEW |