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> |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "media/base/surface_manager.h" | 23 #include "media/base/surface_manager.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/media_blink_export.h" | 27 #include "media/blink/media_blink_export.h" |
28 #include "media/blink/multibuffer_data_source.h" | 28 #include "media/blink/multibuffer_data_source.h" |
29 #include "media/blink/video_frame_compositor.h" | 29 #include "media/blink/video_frame_compositor.h" |
30 #include "media/blink/webmediaplayer_delegate.h" | 30 #include "media/blink/webmediaplayer_delegate.h" |
31 #include "media/blink/webmediaplayer_params.h" | 31 #include "media/blink/webmediaplayer_params.h" |
32 #include "media/blink/webmediaplayer_util.h" | 32 #include "media/blink/webmediaplayer_util.h" |
| 33 #include "media/filters/pipeline_controller.h" |
33 #include "media/renderers/skcanvas_video_renderer.h" | 34 #include "media/renderers/skcanvas_video_renderer.h" |
34 #include "third_party/WebKit/public/platform/WebAudioSourceProvider.h" | 35 #include "third_party/WebKit/public/platform/WebAudioSourceProvider.h" |
35 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h" | 36 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h" |
36 #include "third_party/WebKit/public/platform/WebMediaPlayer.h" | 37 #include "third_party/WebKit/public/platform/WebMediaPlayer.h" |
37 #include "url/gurl.h" | 38 #include "url/gurl.h" |
38 | 39 |
39 #if defined(OS_ANDROID) // WMPI_CAST | 40 #if defined(OS_ANDROID) // WMPI_CAST |
40 // Delete this file when WMPI_CAST is no longer needed. | 41 // Delete this file when WMPI_CAST is no longer needed. |
41 #include "media/blink/webmediaplayer_cast_android.h" | 42 #include "media/blink/webmediaplayer_cast_android.h" |
42 #endif | 43 #endif |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 | 159 |
159 blink::WebAudioSourceProvider* audioSourceProvider() override; | 160 blink::WebAudioSourceProvider* audioSourceProvider() override; |
160 | 161 |
161 void setContentDecryptionModule( | 162 void setContentDecryptionModule( |
162 blink::WebContentDecryptionModule* cdm, | 163 blink::WebContentDecryptionModule* cdm, |
163 blink::WebContentDecryptionModuleResult result) override; | 164 blink::WebContentDecryptionModuleResult result) override; |
164 | 165 |
165 void enteredFullscreen() override; | 166 void enteredFullscreen() override; |
166 void exitedFullscreen() override; | 167 void exitedFullscreen() override; |
167 | 168 |
168 void OnPipelineSeeked(bool time_changed, PipelineStatus status); | |
169 void OnPipelineSuspended(PipelineStatus status); | |
170 void OnPipelineEnded(); | |
171 void OnPipelineError(PipelineStatus error); | |
172 void OnPipelineMetadata(PipelineMetadata metadata); | |
173 void OnPipelineBufferingStateChanged(BufferingState buffering_state); | |
174 void OnDemuxerOpened(); | |
175 void OnAddTextTrack(const TextTrackConfig& config, | |
176 const AddTextTrackDoneCB& done_cb); | |
177 | |
178 // WebMediaPlayerDelegate::Observer implementation. | 169 // WebMediaPlayerDelegate::Observer implementation. |
179 void OnHidden(bool must_suspend) override; | 170 void OnHidden(bool must_suspend) override; |
180 void OnShown() override; | 171 void OnShown() override; |
181 void OnPlay() override; | 172 void OnPlay() override; |
182 void OnPause() override; | 173 void OnPause() override; |
183 void OnVolumeMultiplierUpdate(double multiplier) override; | 174 void OnVolumeMultiplierUpdate(double multiplier) override; |
184 | 175 |
185 #if defined(OS_ANDROID) // WMPI_CAST | 176 #if defined(OS_ANDROID) // WMPI_CAST |
186 bool isRemote() const override; | 177 bool isRemote() const override; |
187 void requestRemotePlayback() override; | 178 void requestRemotePlayback() override; |
188 void requestRemotePlaybackControl() override; | 179 void requestRemotePlaybackControl() override; |
189 | 180 |
190 void SetMediaPlayerManager( | 181 void SetMediaPlayerManager( |
191 RendererMediaPlayerManagerInterface* media_player_manager); | 182 RendererMediaPlayerManagerInterface* media_player_manager); |
192 void OnRemotePlaybackEnded(); | 183 void OnRemotePlaybackEnded(); |
193 void OnDisconnectedFromRemoteDevice(double t); | 184 void OnDisconnectedFromRemoteDevice(double t); |
194 void SuspendForRemote(); | 185 void SuspendForRemote(); |
195 void DisplayCastFrameAfterSuspend(const scoped_refptr<VideoFrame>& new_frame, | 186 void DisplayCastFrameAfterSuspend(const scoped_refptr<VideoFrame>& new_frame, |
196 PipelineStatus status); | 187 PipelineStatus status); |
197 gfx::Size GetCanvasSize() const; | 188 gfx::Size GetCanvasSize() const; |
198 void SetDeviceScaleFactor(float scale_factor); | 189 void SetDeviceScaleFactor(float scale_factor); |
199 #endif | 190 #endif |
200 | 191 |
| 192 // Called from WebMediaPlayerCast. |
| 193 // TODO(hubbe): WMPI_CAST make private. |
| 194 void OnPipelineSeeked(bool time_updated); |
| 195 |
201 private: | 196 private: |
202 // Ask for the pipeline to be suspended, will call Suspend() when ready. | 197 void OnPipelineSuspended(); |
203 // (Possibly immediately.) | 198 void OnPipelineResumed(); |
204 void ScheduleSuspend(); | 199 void OnPipelineEnded(); |
| 200 void OnPipelineError(PipelineStatus error); |
| 201 void OnPipelineMetadata(PipelineMetadata metadata); |
| 202 void OnPipelineBufferingStateChanged(BufferingState buffering_state); |
| 203 void OnDemuxerOpened(); |
| 204 void OnAddTextTrack(const TextTrackConfig& config, |
| 205 const AddTextTrackDoneCB& done_cb); |
205 | 206 |
206 // Initiate suspending the pipeline. | 207 // Actually seek. Avoids causing |should_notify_time_changed_| to be set when |
207 void Suspend(); | 208 // |time_updated| is false. |
208 | 209 void DoSeek(base::TimeDelta time, bool time_updated); |
209 // Ask for the pipeline to be resumed, will call Resume() when ready. | |
210 // (Possibly immediately.) | |
211 void ScheduleResume(); | |
212 | |
213 // Initiate resuming the pipeline. | |
214 void Resume(); | |
215 | 210 |
216 // Ask for the renderer to be restarted (destructed and recreated). | 211 // Ask for the renderer to be restarted (destructed and recreated). |
217 void ScheduleRestart(); | 212 void ScheduleRestart(); |
218 | 213 |
219 // Called after |defer_load_cb_| has decided to allow the load. If | 214 // Called after |defer_load_cb_| has decided to allow the load. If |
220 // |defer_load_cb_| is null this is called immediately. | 215 // |defer_load_cb_| is null this is called immediately. |
221 void DoLoad(LoadType load_type, | 216 void DoLoad(LoadType load_type, |
222 const blink::WebURL& url, | 217 const blink::WebURL& url, |
223 CORSMode cors_mode); | 218 CORSMode cors_mode); |
224 | 219 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 // is not available. | 260 // is not available. |
266 void OnWaitingForDecryptionKey(); | 261 void OnWaitingForDecryptionKey(); |
267 | 262 |
268 // Sets |cdm_context| on the pipeline and fires |cdm_attached_cb| when done. | 263 // Sets |cdm_context| on the pipeline and fires |cdm_attached_cb| when done. |
269 // Parameter order is reversed for easy binding. | 264 // Parameter order is reversed for easy binding. |
270 void SetCdm(const CdmAttachedCB& cdm_attached_cb, CdmContext* cdm_context); | 265 void SetCdm(const CdmAttachedCB& cdm_attached_cb, CdmContext* cdm_context); |
271 | 266 |
272 // Called when a CDM has been attached to the |pipeline_|. | 267 // Called when a CDM has been attached to the |pipeline_|. |
273 void OnCdmAttached(bool success); | 268 void OnCdmAttached(bool success); |
274 | 269 |
275 // Updates |paused_time_| to the current media time with consideration for the | |
276 // |ended_| state by clamping current time to duration upon |ended_|. | |
277 void UpdatePausedTime(); | |
278 | |
279 // Notifies |delegate_| that playback has started or was paused; also starts | 270 // Notifies |delegate_| that playback has started or was paused; also starts |
280 // or stops the memory usage reporting timer respectively. | 271 // or stops the memory usage reporting timer respectively. |
281 void NotifyPlaybackStarted(); | 272 void NotifyPlaybackStarted(); |
282 void NotifyPlaybackPaused(); | 273 void NotifyPlaybackPaused(); |
283 | 274 |
284 // Called at low frequency to tell external observers how much memory we're | 275 // Called at low frequency to tell external observers how much memory we're |
285 // using for video playback. Called by |memory_usage_reporting_timer_|. | 276 // using for video playback. Called by |memory_usage_reporting_timer_|. |
286 // Memory usage reporting is done in two steps, because |demuxer_| must be | 277 // Memory usage reporting is done in two steps, because |demuxer_| must be |
287 // accessed on the media thread. | 278 // accessed on the media thread. |
288 void ReportMemoryUsage(); | 279 void ReportMemoryUsage(); |
(...skipping 12 matching lines...) Expand all Loading... |
301 // setBufferingStrategy(). | 292 // setBufferingStrategy(). |
302 BufferedDataSource::BufferingStrategy buffering_strategy_; | 293 BufferedDataSource::BufferingStrategy buffering_strategy_; |
303 | 294 |
304 // Task runner for posting tasks on Chrome's main thread. Also used | 295 // Task runner for posting tasks on Chrome's main thread. Also used |
305 // for DCHECKs so methods calls won't execute in the wrong thread. | 296 // for DCHECKs so methods calls won't execute in the wrong thread. |
306 const scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 297 const scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
307 | 298 |
308 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_; | 299 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_; |
309 scoped_refptr<base::TaskRunner> worker_task_runner_; | 300 scoped_refptr<base::TaskRunner> worker_task_runner_; |
310 scoped_refptr<MediaLog> media_log_; | 301 scoped_refptr<MediaLog> media_log_; |
| 302 |
| 303 // |pipeline_controller_| references |pipeline_| and therefore must be |
| 304 // constructed after and destructed before |pipeline_|. |
311 PipelineImpl pipeline_; | 305 PipelineImpl pipeline_; |
| 306 PipelineController pipeline_controller_; |
312 | 307 |
313 // 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. |
314 LoadType load_type_; | 309 LoadType load_type_; |
315 | 310 |
316 // Cache of metadata for answering hasAudio(), hasVideo(), and naturalSize(). | 311 // Cache of metadata for answering hasAudio(), hasVideo(), and naturalSize(). |
317 PipelineMetadata pipeline_metadata_; | 312 PipelineMetadata pipeline_metadata_; |
318 | 313 |
319 // Whether the video is known to be opaque or not. | 314 // Whether the video is known to be opaque or not. |
320 bool opaque_; | 315 bool opaque_; |
321 | 316 |
322 // Playback state. | 317 // Playback state. |
323 // | 318 // |
324 // 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 |
325 // single "playback rate" over worrying about paused/stopped etc... It forces | 320 // single "playback rate" over worrying about paused/stopped etc... It forces |
326 // 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 |
327 // really a bad thing? | 322 // really a bad thing? |
328 // | 323 // |
329 // 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 |
330 // 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 |
331 // 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 |
332 // clock can creep forward a little bit while the asynchronous | 327 // clock can creep forward a little bit while the asynchronous |
333 // SetPlaybackRate(0) is being executed. | 328 // SetPlaybackRate(0) is being executed. |
334 double playback_rate_; | 329 double playback_rate_; |
| 330 |
| 331 // Set while paused. |paused_time_| is only valid when |paused_| is true. |
335 bool paused_; | 332 bool paused_; |
336 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. |
337 bool seeking_; | 337 bool seeking_; |
338 | |
339 // Set when seeking (|seeking_| is true) or resuming. | |
340 base::TimeDelta seek_time_; | 338 base::TimeDelta seek_time_; |
341 | 339 |
342 // Set when a suspend is required but another suspend or seek is in progress. | |
343 bool pending_suspend_; | |
344 | |
345 // Set when suspending immediately after a seek. The time change will happen | |
346 // after Resume(). | |
347 bool pending_time_change_; | |
348 | |
349 // Set when a resume is required but suspending is in progress. | |
350 bool pending_resume_; | |
351 | |
352 // Set for the entire period between suspend starting and resume completing. | |
353 bool suspending_; | |
354 | |
355 // Set while suspending to detect double-suspend. | |
356 bool suspended_; | |
357 | |
358 // Set while resuming to detect double-resume. | |
359 bool resuming_; | |
360 | |
361 // Set when doing a restart (a suspend and resume in sequence) of the pipeline | 340 // Set when doing a restart (a suspend and resume in sequence) of the pipeline |
362 // in order to destruct and reinitialize the decoders. This is separate from | 341 // in order to destruct and reinitialize the decoders. This is separate from |
363 // |pending_resume_| and |pending_suspend_| because they can be elided in | 342 // |pending_resume_| and |pending_suspend_| because they can be elided in |
364 // certain cases, whereas for a restart they must happen. | 343 // certain cases, whereas for a restart they must happen. |
365 // TODO(sandersd,watk): Create a simpler interface for a pipeline restart. | 344 // TODO(sandersd,watk): Create a simpler interface for a pipeline restart. |
366 bool pending_suspend_resume_cycle_; | 345 bool pending_suspend_resume_cycle_; |
367 | 346 |
368 // TODO(scherkus): Replace with an explicit ended signal to HTMLMediaElement, | 347 // TODO(scherkus): Replace with an explicit ended signal to HTMLMediaElement, |
369 // see http://crbug.com/409280 | 348 // see http://crbug.com/409280 |
370 bool ended_; | 349 bool ended_; |
371 | 350 |
372 // Indicates that a seek is queued after the current seek completes or, if the | |
373 // pipeline is suspended, after it resumes. Only the last queued seek will | |
374 // have any effect. | |
375 bool pending_seek_; | |
376 | |
377 // |pending_seek_time_| is meaningless when |pending_seek_| is false. | |
378 base::TimeDelta pending_seek_time_; | |
379 | |
380 // Tracks whether to issue time changed notifications during buffering state | 351 // Tracks whether to issue time changed notifications during buffering state |
381 // changes. | 352 // changes. |
382 bool should_notify_time_changed_; | 353 bool should_notify_time_changed_; |
383 | 354 |
384 bool fullscreen_; | 355 bool fullscreen_; |
385 | 356 |
386 // Whether the current decoder requires a restart on fullscreen transitions. | 357 // Whether the current decoder requires a restart on fullscreen transitions. |
387 bool decoder_requires_restart_for_fullscreen_; | 358 bool decoder_requires_restart_for_fullscreen_; |
388 | 359 |
389 blink::WebMediaPlayerClient* client_; | 360 blink::WebMediaPlayerClient* client_; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 // started; prevents us from spuriously logging errors that are transient or | 429 // started; prevents us from spuriously logging errors that are transient or |
459 // unimportant. | 430 // unimportant. |
460 bool suppress_destruction_errors_; | 431 bool suppress_destruction_errors_; |
461 | 432 |
462 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerImpl); | 433 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerImpl); |
463 }; | 434 }; |
464 | 435 |
465 } // namespace media | 436 } // namespace media |
466 | 437 |
467 #endif // MEDIA_BLINK_WEBMEDIAPLAYER_IMPL_H_ | 438 #endif // MEDIA_BLINK_WEBMEDIAPLAYER_IMPL_H_ |
OLD | NEW |