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 MEDIA_BLINK_WEBMEDIAPLAYER_IMPL_H_ | 5 #ifndef MEDIA_BLINK_WEBMEDIAPLAYER_IMPL_H_ |
6 #define MEDIA_BLINK_WEBMEDIAPLAYER_IMPL_H_ | 6 #define MEDIA_BLINK_WEBMEDIAPLAYER_IMPL_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/linked_ptr.h" | 15 #include "base/memory/linked_ptr.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
19 #include "base/threading/thread.h" | 19 #include "base/threading/thread.h" |
20 #include "build/build_config.h" | 20 #include "build/build_config.h" |
21 #include "media/base/cdm_factory.h" | 21 #include "media/base/cdm_factory.h" |
22 #include "media/base/pipeline.h" | 22 #include "media/base/pipeline.h" |
23 #include "media/base/renderer_factory.h" | 23 #include "media/base/renderer_factory.h" |
24 #include "media/base/text_track.h" | 24 #include "media/base/text_track.h" |
25 #include "media/blink/buffered_data_source.h" | 25 #include "media/blink/buffered_data_source.h" |
26 #include "media/blink/buffered_data_source_host_impl.h" | 26 #include "media/blink/buffered_data_source_host_impl.h" |
27 #include "media/blink/encrypted_media_player_support.h" | 27 #include "media/blink/encrypted_media_player_support.h" |
28 #include "media/blink/media_blink_export.h" | 28 #include "media/blink/media_blink_export.h" |
29 #include "media/blink/multibuffer_data_source.h" | 29 #include "media/blink/multibuffer_data_source.h" |
| 30 #include "media/blink/pipeline_state.h" |
30 #include "media/blink/video_frame_compositor.h" | 31 #include "media/blink/video_frame_compositor.h" |
31 #include "media/blink/webmediaplayer_delegate.h" | 32 #include "media/blink/webmediaplayer_delegate.h" |
32 #include "media/blink/webmediaplayer_params.h" | 33 #include "media/blink/webmediaplayer_params.h" |
33 #include "media/blink/webmediaplayer_util.h" | 34 #include "media/blink/webmediaplayer_util.h" |
34 #include "media/renderers/skcanvas_video_renderer.h" | 35 #include "media/renderers/skcanvas_video_renderer.h" |
35 #include "third_party/WebKit/public/platform/WebAudioSourceProvider.h" | 36 #include "third_party/WebKit/public/platform/WebAudioSourceProvider.h" |
36 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h" | 37 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h" |
37 #include "third_party/WebKit/public/platform/WebMediaPlayer.h" | 38 #include "third_party/WebKit/public/platform/WebMediaPlayer.h" |
38 #include "url/gurl.h" | 39 #include "url/gurl.h" |
39 | 40 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 const blink::WebString& session_id) override; | 175 const blink::WebString& session_id) override; |
175 | 176 |
176 MediaKeyException cancelKeyRequest( | 177 MediaKeyException cancelKeyRequest( |
177 const blink::WebString& key_system, | 178 const blink::WebString& key_system, |
178 const blink::WebString& session_id) override; | 179 const blink::WebString& session_id) override; |
179 | 180 |
180 void setContentDecryptionModule( | 181 void setContentDecryptionModule( |
181 blink::WebContentDecryptionModule* cdm, | 182 blink::WebContentDecryptionModule* cdm, |
182 blink::WebContentDecryptionModuleResult result) override; | 183 blink::WebContentDecryptionModuleResult result) override; |
183 | 184 |
184 void OnPipelineSeeked(bool time_changed, PipelineStatus status); | |
185 void OnPipelineSuspended(PipelineStatus status); | |
186 void OnPipelineEnded(); | 185 void OnPipelineEnded(); |
187 void OnPipelineError(PipelineStatus error); | 186 void OnPipelineError(PipelineStatus error); |
188 void OnPipelineMetadata(PipelineMetadata metadata); | 187 void OnPipelineMetadata(PipelineMetadata metadata); |
189 void OnPipelineBufferingStateChanged(BufferingState buffering_state); | 188 void OnPipelineBufferingStateChanged(BufferingState buffering_state); |
190 void OnDemuxerOpened(); | 189 void OnDemuxerOpened(); |
191 void OnAddTextTrack(const TextTrackConfig& config, | 190 void OnAddTextTrack(const TextTrackConfig& config, |
192 const AddTextTrackDoneCB& done_cb); | 191 const AddTextTrackDoneCB& done_cb); |
193 | 192 |
| 193 void OnPipelineSeeked(bool time_updated); |
| 194 void OnPipelineSuspended(); |
| 195 |
194 // WebMediaPlayerDelegate::Observer implementation. | 196 // WebMediaPlayerDelegate::Observer implementation. |
195 void OnHidden() override; | 197 void OnHidden() override; |
196 void OnShown() override; | 198 void OnShown() override; |
197 | 199 |
198 #if defined(OS_ANDROID) // WMPI_CAST | 200 #if defined(OS_ANDROID) // WMPI_CAST |
199 bool isRemote() const override; | 201 bool isRemote() const override; |
200 void requestRemotePlayback() override; | 202 void requestRemotePlayback() override; |
201 void requestRemotePlaybackControl() override; | 203 void requestRemotePlaybackControl() override; |
202 | 204 |
203 void SetMediaPlayerManager( | 205 void SetMediaPlayerManager( |
204 RendererMediaPlayerManagerInterface* media_player_manager); | 206 RendererMediaPlayerManagerInterface* media_player_manager); |
205 void OnRemotePlaybackEnded(); | 207 void OnRemotePlaybackEnded(); |
206 void OnDisconnectedFromRemoteDevice(double t); | 208 void OnDisconnectedFromRemoteDevice(double t); |
207 void SuspendForRemote(); | 209 void SuspendForRemote(); |
208 void DisplayCastFrameAfterSuspend(const scoped_refptr<VideoFrame>& new_frame, | 210 void DisplayCastFrameAfterSuspend(const scoped_refptr<VideoFrame>& new_frame, |
209 PipelineStatus status); | 211 PipelineStatus status); |
210 gfx::Size GetCanvasSize() const; | 212 gfx::Size GetCanvasSize() const; |
211 void SetDeviceScaleFactor(float scale_factor); | 213 void SetDeviceScaleFactor(float scale_factor); |
212 #endif | 214 #endif |
213 | 215 |
214 private: | 216 private: |
215 // Ask for the pipeline to be suspended, will call Suspend() when ready. | 217 void DoSeek(base::TimeDelta time, bool time_updated); |
216 // (Possibly immediately.) | |
217 void ScheduleSuspend(); | |
218 | |
219 // Initiate suspending the pipeline. | |
220 void Suspend(); | |
221 | |
222 // Ask for the pipeline to be resumed, will call Resume() when ready. | |
223 // (Possibly immediately.) | |
224 void ScheduleResume(); | |
225 | |
226 // Initiate resuming the pipeline. | |
227 void Resume(); | |
228 | 218 |
229 // Called after |defer_load_cb_| has decided to allow the load. If | 219 // Called after |defer_load_cb_| has decided to allow the load. If |
230 // |defer_load_cb_| is null this is called immediately. | 220 // |defer_load_cb_| is null this is called immediately. |
231 void DoLoad(LoadType load_type, | 221 void DoLoad(LoadType load_type, |
232 const blink::WebURL& url, | 222 const blink::WebURL& url, |
233 CORSMode cors_mode); | 223 CORSMode cors_mode); |
234 | 224 |
235 // Called after asynchronous initialization of a data source completed. | 225 // Called after asynchronous initialization of a data source completed. |
236 void DataSourceInitialized(bool success); | 226 void DataSourceInitialized(bool success); |
237 | 227 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 // is not available. | 263 // is not available. |
274 void OnWaitingForDecryptionKey(); | 264 void OnWaitingForDecryptionKey(); |
275 | 265 |
276 // Sets |cdm_context| on the pipeline and fires |cdm_attached_cb| when done. | 266 // Sets |cdm_context| on the pipeline and fires |cdm_attached_cb| when done. |
277 // Parameter order is reversed for easy binding. | 267 // Parameter order is reversed for easy binding. |
278 void SetCdm(const CdmAttachedCB& cdm_attached_cb, CdmContext* cdm_context); | 268 void SetCdm(const CdmAttachedCB& cdm_attached_cb, CdmContext* cdm_context); |
279 | 269 |
280 // Called when a CDM has been attached to the |pipeline_|. | 270 // Called when a CDM has been attached to the |pipeline_|. |
281 void OnCdmAttached(bool success); | 271 void OnCdmAttached(bool success); |
282 | 272 |
283 // Updates |paused_time_| to the current media time with consideration for the | |
284 // |ended_| state by clamping current time to duration upon |ended_|. | |
285 void UpdatePausedTime(); | |
286 | |
287 // Notifies |delegate_| that playback has started or was paused; also starts | 273 // Notifies |delegate_| that playback has started or was paused; also starts |
288 // or stops the memory usage reporting timer respectively. | 274 // or stops the memory usage reporting timer respectively. |
289 void NotifyPlaybackStarted(); | 275 void NotifyPlaybackStarted(); |
290 void NotifyPlaybackPaused(); | 276 void NotifyPlaybackPaused(); |
291 | 277 |
292 // Called at low frequency to tell external observers how much memory we're | 278 // Called at low frequency to tell external observers how much memory we're |
293 // using for video playback. Called by |memory_usage_reporting_timer_|. | 279 // using for video playback. Called by |memory_usage_reporting_timer_|. |
294 // Memory usage reporting is done in two steps, because |demuxer_| must be | 280 // Memory usage reporting is done in two steps, because |demuxer_| must be |
295 // accessed on the media thread. | 281 // accessed on the media thread. |
296 void ReportMemoryUsage(); | 282 void ReportMemoryUsage(); |
(...skipping 13 matching lines...) Expand all Loading... |
310 BufferedDataSource::BufferingStrategy buffering_strategy_; | 296 BufferedDataSource::BufferingStrategy buffering_strategy_; |
311 | 297 |
312 // Task runner for posting tasks on Chrome's main thread. Also used | 298 // Task runner for posting tasks on Chrome's main thread. Also used |
313 // for DCHECKs so methods calls won't execute in the wrong thread. | 299 // for DCHECKs so methods calls won't execute in the wrong thread. |
314 const scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 300 const scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
315 | 301 |
316 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_; | 302 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_; |
317 scoped_refptr<base::TaskRunner> worker_task_runner_; | 303 scoped_refptr<base::TaskRunner> worker_task_runner_; |
318 scoped_refptr<MediaLog> media_log_; | 304 scoped_refptr<MediaLog> media_log_; |
319 Pipeline pipeline_; | 305 Pipeline pipeline_; |
| 306 PipelineState pipeline_state_; |
320 | 307 |
321 // The LoadType passed in the |load_type| parameter of the load() call. | 308 // The LoadType passed in the |load_type| parameter of the load() call. |
322 LoadType load_type_; | 309 LoadType load_type_; |
323 | 310 |
324 // Cache of metadata for answering hasAudio(), hasVideo(), and naturalSize(). | 311 // Cache of metadata for answering hasAudio(), hasVideo(), and naturalSize(). |
325 PipelineMetadata pipeline_metadata_; | 312 PipelineMetadata pipeline_metadata_; |
326 | 313 |
327 // Whether the video is known to be opaque or not. | 314 // Whether the video is known to be opaque or not. |
328 bool opaque_; | 315 bool opaque_; |
329 | 316 |
330 // Playback state. | 317 // Playback state. |
331 // | 318 // |
332 // TODO(scherkus): we have these because Pipeline favours the simplicity of a | 319 // TODO(scherkus): we have these because Pipeline favours the simplicity of a |
333 // single "playback rate" over worrying about paused/stopped etc... It forces | 320 // single "playback rate" over worrying about paused/stopped etc... It forces |
334 // all clients to manage the pause+playback rate externally, but is that | 321 // all clients to manage the pause+playback rate externally, but is that |
335 // really a bad thing? | 322 // really a bad thing? |
336 // | 323 // |
337 // TODO(scherkus): since SetPlaybackRate(0) is asynchronous and we don't want | 324 // TODO(scherkus): since SetPlaybackRate(0) is asynchronous and we don't want |
338 // to hang the render thread during pause(), we record the time at the same | 325 // to hang the render thread during pause(), we record the time at the same |
339 // time we pause and then return that value in currentTime(). Otherwise our | 326 // time we pause and then return that value in currentTime(). Otherwise our |
340 // clock can creep forward a little bit while the asynchronous | 327 // clock can creep forward a little bit while the asynchronous |
341 // SetPlaybackRate(0) is being executed. | 328 // SetPlaybackRate(0) is being executed. |
342 double playback_rate_; | 329 double playback_rate_; |
| 330 |
| 331 // Set while paused. |paused_time_| is only valid when |paused_| is true. |
343 bool paused_; | 332 bool paused_; |
344 base::TimeDelta paused_time_; | 333 base::TimeDelta paused_time_; |
| 334 |
| 335 // Set when starting, seeking, and resuming (all of which require a Pipeline |
| 336 // seek). |seek_time_| is only valid when |seeking_| is true. |
345 bool seeking_; | 337 bool seeking_; |
346 | |
347 // Set when seeking (|seeking_| is true) or resuming. | |
348 base::TimeDelta seek_time_; | 338 base::TimeDelta seek_time_; |
349 | 339 |
350 // Set when a suspend is required but another suspend or seek is in progress. | |
351 bool pending_suspend_; | |
352 | |
353 // Set when suspending immediately after a seek. The time change will happen | |
354 // after Resume(). | |
355 bool pending_time_change_; | |
356 | |
357 // Set when a resume is required but suspending is in progress. | |
358 bool pending_resume_; | |
359 | |
360 // Set for the entire period between suspend starting and resume completing. | |
361 bool suspending_; | |
362 | |
363 // Set while suspending to detect double-suspend. | |
364 bool suspended_; | |
365 | |
366 // Set while resuming to detect double-resume. | |
367 bool resuming_; | |
368 | |
369 // TODO(scherkus): Replace with an explicit ended signal to HTMLMediaElement, | 340 // TODO(scherkus): Replace with an explicit ended signal to HTMLMediaElement, |
370 // see http://crbug.com/409280 | 341 // see http://crbug.com/409280 |
371 bool ended_; | 342 bool ended_; |
372 | 343 |
373 // Indicates that a seek is queued after the current seek completes or, if the | |
374 // pipeline is suspended, after it resumes. Only the last queued seek will | |
375 // have any effect. | |
376 bool pending_seek_; | |
377 | |
378 // |pending_seek_time_| is meaningless when |pending_seek_| is false. | |
379 base::TimeDelta pending_seek_time_; | |
380 | |
381 // Tracks whether to issue time changed notifications during buffering state | 344 // Tracks whether to issue time changed notifications during buffering state |
382 // changes. | 345 // changes. |
383 bool should_notify_time_changed_; | 346 bool should_notify_time_changed_; |
384 | 347 |
385 blink::WebMediaPlayerClient* client_; | 348 blink::WebMediaPlayerClient* client_; |
386 blink::WebMediaPlayerEncryptedMediaClient* encrypted_client_; | 349 blink::WebMediaPlayerEncryptedMediaClient* encrypted_client_; |
387 | 350 |
388 base::WeakPtr<WebMediaPlayerDelegate> delegate_; | 351 base::WeakPtr<WebMediaPlayerDelegate> delegate_; |
389 | 352 |
390 WebMediaPlayerParams::DeferLoadCB defer_load_cb_; | 353 WebMediaPlayerParams::DeferLoadCB defer_load_cb_; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 #endif | 398 #endif |
436 | 399 |
437 scoped_ptr<RendererFactory> renderer_factory_; | 400 scoped_ptr<RendererFactory> renderer_factory_; |
438 | 401 |
439 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerImpl); | 402 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerImpl); |
440 }; | 403 }; |
441 | 404 |
442 } // namespace media | 405 } // namespace media |
443 | 406 |
444 #endif // MEDIA_BLINK_WEBMEDIAPLAYER_IMPL_H_ | 407 #endif // MEDIA_BLINK_WEBMEDIAPLAYER_IMPL_H_ |
OLD | NEW |