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 <memory> | 10 #include <memory> |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 class WebAudioSourceProviderImpl; | 81 class WebAudioSourceProviderImpl; |
82 class WebMediaPlayerDelegate; | 82 class WebMediaPlayerDelegate; |
83 | 83 |
84 // The canonical implementation of blink::WebMediaPlayer that's backed by | 84 // The canonical implementation of blink::WebMediaPlayer that's backed by |
85 // Pipeline. Handles normal resource loading, Media Source, and | 85 // Pipeline. Handles normal resource loading, Media Source, and |
86 // Encrypted Media. | 86 // Encrypted Media. |
87 class MEDIA_BLINK_EXPORT WebMediaPlayerImpl | 87 class MEDIA_BLINK_EXPORT WebMediaPlayerImpl |
88 : public NON_EXPORTED_BASE(blink::WebMediaPlayer), | 88 : public NON_EXPORTED_BASE(blink::WebMediaPlayer), |
89 public NON_EXPORTED_BASE(WebMediaPlayerDelegate::Observer), | 89 public NON_EXPORTED_BASE(WebMediaPlayerDelegate::Observer), |
90 public NON_EXPORTED_BASE(Pipeline::Client), | 90 public NON_EXPORTED_BASE(Pipeline::Client), |
| 91 public MediaObserverClient, |
91 public base::SupportsWeakPtr<WebMediaPlayerImpl> { | 92 public base::SupportsWeakPtr<WebMediaPlayerImpl> { |
92 public: | 93 public: |
93 // Constructs a WebMediaPlayer implementation using Chromium's media stack. | 94 // Constructs a WebMediaPlayer implementation using Chromium's media stack. |
94 // |delegate| and |renderer_factory| must not be null. | 95 // |delegate| and |renderer_factory| must not be null. |
95 WebMediaPlayerImpl( | 96 WebMediaPlayerImpl( |
96 blink::WebLocalFrame* frame, | 97 blink::WebLocalFrame* frame, |
97 blink::WebMediaPlayerClient* client, | 98 blink::WebMediaPlayerClient* client, |
98 blink::WebMediaPlayerEncryptedMediaClient* encrypted_client, | 99 blink::WebMediaPlayerEncryptedMediaClient* encrypted_client, |
99 WebMediaPlayerDelegate* delegate, | 100 WebMediaPlayerDelegate* delegate, |
100 std::unique_ptr<RendererFactory> renderer_factory, | 101 std::unique_ptr<RendererFactory> renderer_factory, |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 void OnRemotePlaybackEnded(); | 208 void OnRemotePlaybackEnded(); |
208 void OnDisconnectedFromRemoteDevice(double t); | 209 void OnDisconnectedFromRemoteDevice(double t); |
209 void SuspendForRemote(); | 210 void SuspendForRemote(); |
210 void DisplayCastFrameAfterSuspend(const scoped_refptr<VideoFrame>& new_frame, | 211 void DisplayCastFrameAfterSuspend(const scoped_refptr<VideoFrame>& new_frame, |
211 PipelineStatus status); | 212 PipelineStatus status); |
212 gfx::Size GetCanvasSize() const; | 213 gfx::Size GetCanvasSize() const; |
213 void SetDeviceScaleFactor(float scale_factor); | 214 void SetDeviceScaleFactor(float scale_factor); |
214 void SetUseFallbackPath(bool use_fallback_path); | 215 void SetUseFallbackPath(bool use_fallback_path); |
215 #endif | 216 #endif |
216 | 217 |
| 218 // MediaObserverClient implementation. |
| 219 void SwitchRenderer(bool disable_pipeline_auto_suspend) override; |
| 220 void ActivateViewportIntersectionMonitoring(bool activate) override; |
| 221 |
217 // Called from WebMediaPlayerCast. | 222 // Called from WebMediaPlayerCast. |
218 // TODO(hubbe): WMPI_CAST make private. | 223 // TODO(hubbe): WMPI_CAST make private. |
219 void OnPipelineSeeked(bool time_updated); | 224 void OnPipelineSeeked(bool time_updated); |
220 | 225 |
221 // Restart the player/pipeline as soon as possible. This will destroy the | |
222 // current renderer, if any, and create a new one via the RendererFactory; and | |
223 // then seek to resume playback at the current position. | |
224 void ScheduleRestart(); | |
225 | |
226 // Called when requests to activate monitoring changes on viewport | |
227 // intersection. | |
228 void ActivateViewportIntersectionMonitoring(bool activate); | |
229 | |
230 // Distinct states that |delegate_| can be in. (Public for testing.) | 226 // Distinct states that |delegate_| can be in. (Public for testing.) |
231 enum class DelegateState { | 227 enum class DelegateState { |
232 GONE, | 228 GONE, |
233 PLAYING, | 229 PLAYING, |
234 PAUSED, | 230 PAUSED, |
235 }; | 231 }; |
236 | 232 |
237 // Playback state variables computed together in UpdatePlayState(). | 233 // Playback state variables computed together in UpdatePlayState(). |
238 // (Public for testing.) | 234 // (Public for testing.) |
239 struct PlayState { | 235 struct PlayState { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 // necessary). | 285 // necessary). |
290 void OnSurfaceRequested(bool decoder_requires_restart_for_overlay, | 286 void OnSurfaceRequested(bool decoder_requires_restart_for_overlay, |
291 const SurfaceCreatedCB& surface_created_cb); | 287 const SurfaceCreatedCB& surface_created_cb); |
292 | 288 |
293 // Creates a Renderer via the |renderer_factory_|. | 289 // Creates a Renderer via the |renderer_factory_|. |
294 std::unique_ptr<Renderer> CreateRenderer(); | 290 std::unique_ptr<Renderer> CreateRenderer(); |
295 | 291 |
296 // Finishes starting the pipeline due to a call to load(). | 292 // Finishes starting the pipeline due to a call to load(). |
297 void StartPipeline(); | 293 void StartPipeline(); |
298 | 294 |
| 295 // Restart the player/pipeline as soon as possible. This will destroy the |
| 296 // current renderer, if any, and create a new one via the RendererFactory; and |
| 297 // then seek to resume playback at the current position. |
| 298 void ScheduleRestart(); |
| 299 |
299 // Helpers that set the network/ready state and notifies the client if | 300 // Helpers that set the network/ready state and notifies the client if |
300 // they've changed. | 301 // they've changed. |
301 void SetNetworkState(blink::WebMediaPlayer::NetworkState state); | 302 void SetNetworkState(blink::WebMediaPlayer::NetworkState state); |
302 void SetReadyState(blink::WebMediaPlayer::ReadyState state); | 303 void SetReadyState(blink::WebMediaPlayer::ReadyState state); |
303 | 304 |
304 // Returns the current video frame from |compositor_|. Blocks until the | 305 // Returns the current video frame from |compositor_|. Blocks until the |
305 // compositor can return the frame. | 306 // compositor can return the frame. |
306 scoped_refptr<VideoFrame> GetCurrentFrameFromCompositor(); | 307 scoped_refptr<VideoFrame> GetCurrentFrameFromCompositor(); |
307 | 308 |
308 // Called when the demuxer encounters encrypted streams. | 309 // Called when the demuxer encounters encrypted streams. |
(...skipping 23 matching lines...) Expand all Loading... |
332 // - hasVideo(), | 333 // - hasVideo(), |
333 // - delegate_->IsHidden(), | 334 // - delegate_->IsHidden(), |
334 // - network_state_, ready_state_, | 335 // - network_state_, ready_state_, |
335 // - is_idle_, must_suspend_, | 336 // - is_idle_, must_suspend_, |
336 // - paused_, ended_, | 337 // - paused_, ended_, |
337 // - pending_suspend_resume_cycle_, | 338 // - pending_suspend_resume_cycle_, |
338 void UpdatePlayState(); | 339 void UpdatePlayState(); |
339 | 340 |
340 // Methods internal to UpdatePlayState(). | 341 // Methods internal to UpdatePlayState(). |
341 PlayState UpdatePlayState_ComputePlayState(bool is_remote, | 342 PlayState UpdatePlayState_ComputePlayState(bool is_remote, |
342 bool is_streaming, | 343 bool can_auto_suspend, |
343 bool is_suspended, | 344 bool is_suspended, |
344 bool is_backgrounded); | 345 bool is_backgrounded); |
345 void SetDelegateState(DelegateState new_state, bool is_idle); | 346 void SetDelegateState(DelegateState new_state, bool is_idle); |
346 void SetMemoryReportingState(bool is_memory_reporting_enabled); | 347 void SetMemoryReportingState(bool is_memory_reporting_enabled); |
347 void SetSuspendState(bool is_suspended); | 348 void SetSuspendState(bool is_suspended); |
348 | 349 |
349 // Called at low frequency to tell external observers how much memory we're | 350 // Called at low frequency to tell external observers how much memory we're |
350 // using for video playback. Called by |memory_usage_reporting_timer_|. | 351 // using for video playback. Called by |memory_usage_reporting_timer_|. |
351 // Memory usage reporting is done in two steps, because |demuxer_| must be | 352 // Memory usage reporting is done in two steps, because |demuxer_| must be |
352 // accessed on the media thread. | 353 // accessed on the media thread. |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 // immediately on memory pressure notification or during the next SourceBuffer | 683 // immediately on memory pressure notification or during the next SourceBuffer |
683 // append (slower, but MSE spec compliant). | 684 // append (slower, but MSE spec compliant). |
684 bool enable_instant_source_buffer_gc_ = false; | 685 bool enable_instant_source_buffer_gc_ = false; |
685 | 686 |
686 // Whether disabled the video track as an optimization. | 687 // Whether disabled the video track as an optimization. |
687 bool video_track_disabled_ = false; | 688 bool video_track_disabled_ = false; |
688 | 689 |
689 // Whether the pipeline is being resumed at the moment. | 690 // Whether the pipeline is being resumed at the moment. |
690 bool is_pipeline_resuming_ = false; | 691 bool is_pipeline_resuming_ = false; |
691 | 692 |
| 693 // When this is true, pipeline will not be auto suspended. |
| 694 bool disable_pipeline_auto_suspend_ = false; |
| 695 |
692 // Pipeline statistics overridden by tests. | 696 // Pipeline statistics overridden by tests. |
693 base::Optional<PipelineStatistics> pipeline_statistics_for_test_; | 697 base::Optional<PipelineStatistics> pipeline_statistics_for_test_; |
694 | 698 |
695 // Pipeline media duration overridden by tests. | 699 // Pipeline media duration overridden by tests. |
696 base::Optional<base::TimeDelta> pipeline_media_duration_for_test_; | 700 base::Optional<base::TimeDelta> pipeline_media_duration_for_test_; |
697 | 701 |
698 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerImpl); | 702 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerImpl); |
699 }; | 703 }; |
700 | 704 |
701 } // namespace media | 705 } // namespace media |
702 | 706 |
703 #endif // MEDIA_BLINK_WEBMEDIAPLAYER_IMPL_H_ | 707 #endif // MEDIA_BLINK_WEBMEDIAPLAYER_IMPL_H_ |
OLD | NEW |