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 // Delegate calls from WebCore::MediaPlayerPrivate to Chrome's video player. | 5 // Delegate calls from WebCore::MediaPlayerPrivate to Chrome's video player. |
6 // It contains Pipeline which is the actual media player pipeline, it glues | 6 // It contains Pipeline which is the actual media player pipeline, it glues |
7 // the media player pipeline, data source, audio renderer and renderer. | 7 // the media player pipeline, data source, audio renderer and renderer. |
8 // Pipeline would creates multiple threads and access some public methods | 8 // Pipeline would creates multiple threads and access some public methods |
9 // of this class, so we need to be extra careful about concurrent access of | 9 // of this class, so we need to be extra careful about concurrent access of |
10 // methods and members. | 10 // methods and members. |
(...skipping 27 matching lines...) Expand all Loading... |
38 #include "media/filters/skcanvas_video_renderer.h" | 38 #include "media/filters/skcanvas_video_renderer.h" |
39 #include "skia/ext/platform_canvas.h" | 39 #include "skia/ext/platform_canvas.h" |
40 #include "third_party/WebKit/public/platform/WebAudioSourceProvider.h" | 40 #include "third_party/WebKit/public/platform/WebAudioSourceProvider.h" |
41 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" | 41 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" |
42 #include "third_party/WebKit/public/web/WebMediaPlayer.h" | 42 #include "third_party/WebKit/public/web/WebMediaPlayer.h" |
43 #include "third_party/WebKit/public/web/WebMediaPlayerClient.h" | 43 #include "third_party/WebKit/public/web/WebMediaPlayerClient.h" |
44 #include "url/gurl.h" | 44 #include "url/gurl.h" |
45 | 45 |
46 class RenderAudioSourceProvider; | 46 class RenderAudioSourceProvider; |
47 | 47 |
48 namespace WebKit { | 48 namespace blink { |
49 class WebFrame; | 49 class WebFrame; |
50 } | 50 } |
51 | 51 |
52 namespace base { | 52 namespace base { |
53 class MessageLoopProxy; | 53 class MessageLoopProxy; |
54 } | 54 } |
55 | 55 |
56 namespace media { | 56 namespace media { |
57 class ChunkDemuxer; | 57 class ChunkDemuxer; |
58 class FFmpegDemuxer; | 58 class FFmpegDemuxer; |
59 class GpuVideoAcceleratorFactories; | 59 class GpuVideoAcceleratorFactories; |
60 class MediaLog; | 60 class MediaLog; |
61 } | 61 } |
62 | 62 |
63 namespace webkit { | 63 namespace webkit { |
64 class WebLayerImpl; | 64 class WebLayerImpl; |
65 } | 65 } |
66 | 66 |
67 namespace content { | 67 namespace content { |
68 class BufferedDataSource; | 68 class BufferedDataSource; |
69 class WebAudioSourceProviderImpl; | 69 class WebAudioSourceProviderImpl; |
70 class WebMediaPlayerDelegate; | 70 class WebMediaPlayerDelegate; |
71 class WebMediaPlayerParams; | 71 class WebMediaPlayerParams; |
72 class WebTextTrackImpl; | 72 class WebTextTrackImpl; |
73 | 73 |
74 class WebMediaPlayerImpl | 74 class WebMediaPlayerImpl |
75 : public WebKit::WebMediaPlayer, | 75 : public blink::WebMediaPlayer, |
76 public cc::VideoFrameProvider, | 76 public cc::VideoFrameProvider, |
77 public base::MessageLoop::DestructionObserver, | 77 public base::MessageLoop::DestructionObserver, |
78 public base::SupportsWeakPtr<WebMediaPlayerImpl> { | 78 public base::SupportsWeakPtr<WebMediaPlayerImpl> { |
79 public: | 79 public: |
80 // Constructs a WebMediaPlayer implementation using Chromium's media stack. | 80 // Constructs a WebMediaPlayer implementation using Chromium's media stack. |
81 // | 81 // |
82 // |delegate| may be null. | 82 // |delegate| may be null. |
83 WebMediaPlayerImpl( | 83 WebMediaPlayerImpl( |
84 WebKit::WebFrame* frame, | 84 blink::WebFrame* frame, |
85 WebKit::WebMediaPlayerClient* client, | 85 blink::WebMediaPlayerClient* client, |
86 base::WeakPtr<WebMediaPlayerDelegate> delegate, | 86 base::WeakPtr<WebMediaPlayerDelegate> delegate, |
87 const WebMediaPlayerParams& params); | 87 const WebMediaPlayerParams& params); |
88 virtual ~WebMediaPlayerImpl(); | 88 virtual ~WebMediaPlayerImpl(); |
89 | 89 |
90 virtual void load(LoadType load_type, | 90 virtual void load(LoadType load_type, |
91 const WebKit::WebURL& url, | 91 const blink::WebURL& url, |
92 CORSMode cors_mode) OVERRIDE; | 92 CORSMode cors_mode) OVERRIDE; |
93 | 93 |
94 // Playback controls. | 94 // Playback controls. |
95 virtual void play(); | 95 virtual void play(); |
96 virtual void pause(); | 96 virtual void pause(); |
97 virtual bool supportsFullscreen() const; | 97 virtual bool supportsFullscreen() const; |
98 virtual bool supportsSave() const; | 98 virtual bool supportsSave() const; |
99 virtual void seek(double seconds); | 99 virtual void seek(double seconds); |
100 virtual void setRate(double rate); | 100 virtual void setRate(double rate); |
101 virtual void setVolume(double volume); | 101 virtual void setVolume(double volume); |
102 virtual void setPreload(WebKit::WebMediaPlayer::Preload preload); | 102 virtual void setPreload(blink::WebMediaPlayer::Preload preload); |
103 virtual const WebKit::WebTimeRanges& buffered(); | 103 virtual const blink::WebTimeRanges& buffered(); |
104 virtual double maxTimeSeekable() const; | 104 virtual double maxTimeSeekable() const; |
105 | 105 |
106 // Methods for painting. | 106 // Methods for painting. |
107 virtual void paint(WebKit::WebCanvas* canvas, | 107 virtual void paint(blink::WebCanvas* canvas, |
108 const WebKit::WebRect& rect, | 108 const blink::WebRect& rect, |
109 unsigned char alpha); | 109 unsigned char alpha); |
110 | 110 |
111 // True if the loaded media has a playable video/audio track. | 111 // True if the loaded media has a playable video/audio track. |
112 virtual bool hasVideo() const; | 112 virtual bool hasVideo() const; |
113 virtual bool hasAudio() const; | 113 virtual bool hasAudio() const; |
114 | 114 |
115 // Dimensions of the video. | 115 // Dimensions of the video. |
116 virtual WebKit::WebSize naturalSize() const; | 116 virtual blink::WebSize naturalSize() const; |
117 | 117 |
118 // Getters of playback state. | 118 // Getters of playback state. |
119 virtual bool paused() const; | 119 virtual bool paused() const; |
120 virtual bool seeking() const; | 120 virtual bool seeking() const; |
121 virtual double duration() const; | 121 virtual double duration() const; |
122 virtual double currentTime() const; | 122 virtual double currentTime() const; |
123 | 123 |
124 // Internal states of loading and network. | 124 // Internal states of loading and network. |
125 // TODO(hclam): Ask the pipeline about the state rather than having reading | 125 // TODO(hclam): Ask the pipeline about the state rather than having reading |
126 // them from members which would cause race conditions. | 126 // them from members which would cause race conditions. |
127 virtual WebKit::WebMediaPlayer::NetworkState networkState() const; | 127 virtual blink::WebMediaPlayer::NetworkState networkState() const; |
128 virtual WebKit::WebMediaPlayer::ReadyState readyState() const; | 128 virtual blink::WebMediaPlayer::ReadyState readyState() const; |
129 | 129 |
130 virtual bool didLoadingProgress() const; | 130 virtual bool didLoadingProgress() const; |
131 | 131 |
132 virtual bool hasSingleSecurityOrigin() const; | 132 virtual bool hasSingleSecurityOrigin() const; |
133 virtual bool didPassCORSAccessCheck() const; | 133 virtual bool didPassCORSAccessCheck() const; |
134 | 134 |
135 virtual double mediaTimeForTimeValue(double timeValue) const; | 135 virtual double mediaTimeForTimeValue(double timeValue) const; |
136 | 136 |
137 virtual unsigned decodedFrameCount() const; | 137 virtual unsigned decodedFrameCount() const; |
138 virtual unsigned droppedFrameCount() const; | 138 virtual unsigned droppedFrameCount() const; |
139 virtual unsigned audioDecodedByteCount() const; | 139 virtual unsigned audioDecodedByteCount() const; |
140 virtual unsigned videoDecodedByteCount() const; | 140 virtual unsigned videoDecodedByteCount() const; |
141 | 141 |
142 // cc::VideoFrameProvider implementation. | 142 // cc::VideoFrameProvider implementation. |
143 virtual void SetVideoFrameProviderClient( | 143 virtual void SetVideoFrameProviderClient( |
144 cc::VideoFrameProvider::Client* client) OVERRIDE; | 144 cc::VideoFrameProvider::Client* client) OVERRIDE; |
145 virtual scoped_refptr<media::VideoFrame> GetCurrentFrame() OVERRIDE; | 145 virtual scoped_refptr<media::VideoFrame> GetCurrentFrame() OVERRIDE; |
146 virtual void PutCurrentFrame(const scoped_refptr<media::VideoFrame>& frame) | 146 virtual void PutCurrentFrame(const scoped_refptr<media::VideoFrame>& frame) |
147 OVERRIDE; | 147 OVERRIDE; |
148 | 148 |
149 virtual bool copyVideoTextureToPlatformTexture( | 149 virtual bool copyVideoTextureToPlatformTexture( |
150 WebKit::WebGraphicsContext3D* web_graphics_context, | 150 blink::WebGraphicsContext3D* web_graphics_context, |
151 unsigned int texture, | 151 unsigned int texture, |
152 unsigned int level, | 152 unsigned int level, |
153 unsigned int internal_format, | 153 unsigned int internal_format, |
154 unsigned int type, | 154 unsigned int type, |
155 bool premultiply_alpha, | 155 bool premultiply_alpha, |
156 bool flip_y); | 156 bool flip_y); |
157 | 157 |
158 virtual WebKit::WebAudioSourceProvider* audioSourceProvider(); | 158 virtual blink::WebAudioSourceProvider* audioSourceProvider(); |
159 | 159 |
160 virtual MediaKeyException generateKeyRequest( | 160 virtual MediaKeyException generateKeyRequest( |
161 const WebKit::WebString& key_system, | 161 const blink::WebString& key_system, |
162 const unsigned char* init_data, | 162 const unsigned char* init_data, |
163 unsigned init_data_length); | 163 unsigned init_data_length); |
164 | 164 |
165 virtual MediaKeyException addKey(const WebKit::WebString& key_system, | 165 virtual MediaKeyException addKey(const blink::WebString& key_system, |
166 const unsigned char* key, | 166 const unsigned char* key, |
167 unsigned key_length, | 167 unsigned key_length, |
168 const unsigned char* init_data, | 168 const unsigned char* init_data, |
169 unsigned init_data_length, | 169 unsigned init_data_length, |
170 const WebKit::WebString& session_id); | 170 const blink::WebString& session_id); |
171 | 171 |
172 virtual MediaKeyException cancelKeyRequest( | 172 virtual MediaKeyException cancelKeyRequest( |
173 const WebKit::WebString& key_system, | 173 const blink::WebString& key_system, |
174 const WebKit::WebString& session_id); | 174 const blink::WebString& session_id); |
175 | 175 |
176 // As we are closing the tab or even the browser, |main_loop_| is destroyed | 176 // As we are closing the tab or even the browser, |main_loop_| is destroyed |
177 // even before this object gets destructed, so we need to know when | 177 // even before this object gets destructed, so we need to know when |
178 // |main_loop_| is being destroyed and we can stop posting repaint task | 178 // |main_loop_| is being destroyed and we can stop posting repaint task |
179 // to it. | 179 // to it. |
180 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; | 180 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; |
181 | 181 |
182 void Repaint(); | 182 void Repaint(); |
183 | 183 |
184 void OnPipelineSeek(media::PipelineStatus status); | 184 void OnPipelineSeek(media::PipelineStatus status); |
(...skipping 13 matching lines...) Expand all Loading... |
198 const std::vector<uint8>& init_data); | 198 const std::vector<uint8>& init_data); |
199 scoped_ptr<media::TextTrack> OnTextTrack(media::TextKind kind, | 199 scoped_ptr<media::TextTrack> OnTextTrack(media::TextKind kind, |
200 const std::string& label, | 200 const std::string& label, |
201 const std::string& language); | 201 const std::string& language); |
202 void SetOpaque(bool); | 202 void SetOpaque(bool); |
203 | 203 |
204 private: | 204 private: |
205 // Called after |defer_load_cb_| has decided to allow the load. If | 205 // Called after |defer_load_cb_| has decided to allow the load. If |
206 // |defer_load_cb_| is null this is called immediately. | 206 // |defer_load_cb_| is null this is called immediately. |
207 void DoLoad(LoadType load_type, | 207 void DoLoad(LoadType load_type, |
208 const WebKit::WebURL& url, | 208 const blink::WebURL& url, |
209 CORSMode cors_mode); | 209 CORSMode cors_mode); |
210 | 210 |
211 // Called after asynchronous initialization of a data source completed. | 211 // Called after asynchronous initialization of a data source completed. |
212 void DataSourceInitialized(const GURL& gurl, bool success); | 212 void DataSourceInitialized(const GURL& gurl, bool success); |
213 | 213 |
214 // Called when the data source is downloading or paused. | 214 // Called when the data source is downloading or paused. |
215 void NotifyDownloading(bool is_downloading); | 215 void NotifyDownloading(bool is_downloading); |
216 | 216 |
217 // Finishes starting the pipeline due to a call to load(). | 217 // Finishes starting the pipeline due to a call to load(). |
218 void StartPipeline(); | 218 void StartPipeline(); |
219 | 219 |
220 // Helpers that set the network/ready state and notifies the client if | 220 // Helpers that set the network/ready state and notifies the client if |
221 // they've changed. | 221 // they've changed. |
222 void SetNetworkState(WebKit::WebMediaPlayer::NetworkState state); | 222 void SetNetworkState(blink::WebMediaPlayer::NetworkState state); |
223 void SetReadyState(WebKit::WebMediaPlayer::ReadyState state); | 223 void SetReadyState(blink::WebMediaPlayer::ReadyState state); |
224 | 224 |
225 // Destroy resources held. | 225 // Destroy resources held. |
226 void Destroy(); | 226 void Destroy(); |
227 | 227 |
228 // Getter method to |client_|. | 228 // Getter method to |client_|. |
229 WebKit::WebMediaPlayerClient* GetClient(); | 229 blink::WebMediaPlayerClient* GetClient(); |
230 | 230 |
231 // Lets V8 know that player uses extra resources not managed by V8. | 231 // Lets V8 know that player uses extra resources not managed by V8. |
232 void IncrementExternallyAllocatedMemory(); | 232 void IncrementExternallyAllocatedMemory(); |
233 | 233 |
234 // Actually do the work for generateKeyRequest/addKey so they can easily | 234 // Actually do the work for generateKeyRequest/addKey so they can easily |
235 // report results to UMA. | 235 // report results to UMA. |
236 MediaKeyException GenerateKeyRequestInternal( | 236 MediaKeyException GenerateKeyRequestInternal( |
237 const WebKit::WebString& key_system, | 237 const blink::WebString& key_system, |
238 const unsigned char* init_data, | 238 const unsigned char* init_data, |
239 unsigned init_data_length); | 239 unsigned init_data_length); |
240 MediaKeyException AddKeyInternal(const WebKit::WebString& key_system, | 240 MediaKeyException AddKeyInternal(const blink::WebString& key_system, |
241 const unsigned char* key, | 241 const unsigned char* key, |
242 unsigned key_length, | 242 unsigned key_length, |
243 const unsigned char* init_data, | 243 const unsigned char* init_data, |
244 unsigned init_data_length, | 244 unsigned init_data_length, |
245 const WebKit::WebString& session_id); | 245 const blink::WebString& session_id); |
246 MediaKeyException CancelKeyRequestInternal( | 246 MediaKeyException CancelKeyRequestInternal( |
247 const WebKit::WebString& key_system, | 247 const blink::WebString& key_system, |
248 const WebKit::WebString& session_id); | 248 const blink::WebString& session_id); |
249 | 249 |
250 // Gets the duration value reported by the pipeline. | 250 // Gets the duration value reported by the pipeline. |
251 double GetPipelineDuration() const; | 251 double GetPipelineDuration() const; |
252 | 252 |
253 // Notifies WebKit of the duration change. | 253 // Notifies WebKit of the duration change. |
254 void OnDurationChange(); | 254 void OnDurationChange(); |
255 | 255 |
256 // Called by VideoRendererBase on its internal thread with the new frame to be | 256 // Called by VideoRendererBase on its internal thread with the new frame to be |
257 // painted. | 257 // painted. |
258 void FrameReady(const scoped_refptr<media::VideoFrame>& frame); | 258 void FrameReady(const scoped_refptr<media::VideoFrame>& frame); |
259 | 259 |
260 // Called when a paint or a new frame arrives to indicate that we are | 260 // Called when a paint or a new frame arrives to indicate that we are |
261 // no longer waiting for |current_frame_| to be painted. | 261 // no longer waiting for |current_frame_| to be painted. |
262 // |painting_frame| is set to true if |current_frame_| is being painted. | 262 // |painting_frame| is set to true if |current_frame_| is being painted. |
263 // False indicates |current_frame_| is being replaced with a new frame. | 263 // False indicates |current_frame_| is being replaced with a new frame. |
264 void DoneWaitingForPaint(bool painting_frame); | 264 void DoneWaitingForPaint(bool painting_frame); |
265 | 265 |
266 WebKit::WebFrame* frame_; | 266 blink::WebFrame* frame_; |
267 | 267 |
268 // TODO(hclam): get rid of these members and read from the pipeline directly. | 268 // TODO(hclam): get rid of these members and read from the pipeline directly. |
269 WebKit::WebMediaPlayer::NetworkState network_state_; | 269 blink::WebMediaPlayer::NetworkState network_state_; |
270 WebKit::WebMediaPlayer::ReadyState ready_state_; | 270 blink::WebMediaPlayer::ReadyState ready_state_; |
271 | 271 |
272 // Keep a list of buffered time ranges. | 272 // Keep a list of buffered time ranges. |
273 WebKit::WebTimeRanges buffered_; | 273 blink::WebTimeRanges buffered_; |
274 | 274 |
275 // Message loops for posting tasks on Chrome's main thread. Also used | 275 // Message loops for posting tasks on Chrome's main thread. Also used |
276 // for DCHECKs so methods calls won't execute in the wrong thread. | 276 // for DCHECKs so methods calls won't execute in the wrong thread. |
277 const scoped_refptr<base::MessageLoopProxy> main_loop_; | 277 const scoped_refptr<base::MessageLoopProxy> main_loop_; |
278 | 278 |
279 scoped_ptr<media::Pipeline> pipeline_; | 279 scoped_ptr<media::Pipeline> pipeline_; |
280 scoped_refptr<base::MessageLoopProxy> media_loop_; | 280 scoped_refptr<base::MessageLoopProxy> media_loop_; |
281 | 281 |
282 // The currently selected key system. Empty string means that no key system | 282 // The currently selected key system. Empty string means that no key system |
283 // has been selected. | 283 // has been selected. |
284 WebKit::WebString current_key_system_; | 284 blink::WebString current_key_system_; |
285 | 285 |
286 // The LoadType passed in the |load_type| parameter of the load() call. | 286 // The LoadType passed in the |load_type| parameter of the load() call. |
287 LoadType load_type_; | 287 LoadType load_type_; |
288 | 288 |
289 // Playback state. | 289 // Playback state. |
290 // | 290 // |
291 // TODO(scherkus): we have these because Pipeline favours the simplicity of a | 291 // TODO(scherkus): we have these because Pipeline favours the simplicity of a |
292 // single "playback rate" over worrying about paused/stopped etc... It forces | 292 // single "playback rate" over worrying about paused/stopped etc... It forces |
293 // all clients to manage the pause+playback rate externally, but is that | 293 // all clients to manage the pause+playback rate externally, but is that |
294 // really a bad thing? | 294 // really a bad thing? |
295 // | 295 // |
296 // TODO(scherkus): since SetPlaybackRate(0) is asynchronous and we don't want | 296 // TODO(scherkus): since SetPlaybackRate(0) is asynchronous and we don't want |
297 // to hang the render thread during pause(), we record the time at the same | 297 // to hang the render thread during pause(), we record the time at the same |
298 // time we pause and then return that value in currentTime(). Otherwise our | 298 // time we pause and then return that value in currentTime(). Otherwise our |
299 // clock can creep forward a little bit while the asynchronous | 299 // clock can creep forward a little bit while the asynchronous |
300 // SetPlaybackRate(0) is being executed. | 300 // SetPlaybackRate(0) is being executed. |
301 bool paused_; | 301 bool paused_; |
302 bool seeking_; | 302 bool seeking_; |
303 double playback_rate_; | 303 double playback_rate_; |
304 base::TimeDelta paused_time_; | 304 base::TimeDelta paused_time_; |
305 | 305 |
306 // Seek gets pending if another seek is in progress. Only last pending seek | 306 // Seek gets pending if another seek is in progress. Only last pending seek |
307 // will have effect. | 307 // will have effect. |
308 bool pending_seek_; | 308 bool pending_seek_; |
309 double pending_seek_seconds_; | 309 double pending_seek_seconds_; |
310 | 310 |
311 WebKit::WebMediaPlayerClient* client_; | 311 blink::WebMediaPlayerClient* client_; |
312 | 312 |
313 base::WeakPtr<WebMediaPlayerDelegate> delegate_; | 313 base::WeakPtr<WebMediaPlayerDelegate> delegate_; |
314 | 314 |
315 base::Callback<void(const base::Closure&)> defer_load_cb_; | 315 base::Callback<void(const base::Closure&)> defer_load_cb_; |
316 | 316 |
317 scoped_refptr<media::MediaLog> media_log_; | 317 scoped_refptr<media::MediaLog> media_log_; |
318 | 318 |
319 // Since accelerated compositing status is only known after the first layout, | 319 // Since accelerated compositing status is only known after the first layout, |
320 // we delay reporting it to UMA until that time. | 320 // we delay reporting it to UMA until that time. |
321 bool accelerated_compositing_reported_; | 321 bool accelerated_compositing_reported_; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 | 374 |
375 // Text track objects get a unique index value when they're created. | 375 // Text track objects get a unique index value when they're created. |
376 int text_track_index_; | 376 int text_track_index_; |
377 | 377 |
378 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerImpl); | 378 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerImpl); |
379 }; | 379 }; |
380 | 380 |
381 } // namespace content | 381 } // namespace content |
382 | 382 |
383 #endif // CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_IMPL_H_ | 383 #endif // CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_IMPL_H_ |
OLD | NEW |