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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 | 180 |
181 void SetEnableFullscreenOverlays(bool enable_overlays); | 181 void SetEnableFullscreenOverlays(bool enable_overlays); |
182 bool supportsOverlayFullscreenVideo() override; | 182 bool supportsOverlayFullscreenVideo() override; |
183 void enteredFullscreen() override; | 183 void enteredFullscreen() override; |
184 void exitedFullscreen() override; | 184 void exitedFullscreen() override; |
185 void becameDominantVisibleContent(bool isDominant) override; | 185 void becameDominantVisibleContent(bool isDominant) override; |
186 | 186 |
187 void setPoster(const blink::WebURL& poster) override; | 187 void setPoster(const blink::WebURL& poster) override; |
188 | 188 |
189 // WebMediaPlayerDelegate::Observer implementation. | 189 // WebMediaPlayerDelegate::Observer implementation. |
190 void OnHidden() override; | 190 void OnFrameHidden() override; |
191 void OnShown() override; | 191 void OnFrameClosed() override; |
192 bool OnSuspendRequested(bool must_suspend) override; | 192 void OnFrameShown() override; |
| 193 void OnIdleTimeout() override; |
193 void OnPlay() override; | 194 void OnPlay() override; |
194 void OnPause() override; | 195 void OnPause() override; |
195 void OnVolumeMultiplierUpdate(double multiplier) override; | 196 void OnVolumeMultiplierUpdate(double multiplier) override; |
196 | 197 |
197 void requestRemotePlaybackDisabled(bool disabled) override; | 198 void requestRemotePlaybackDisabled(bool disabled) override; |
198 #if defined(OS_ANDROID) // WMPI_CAST | 199 #if defined(OS_ANDROID) // WMPI_CAST |
199 bool isRemote() const override; | 200 bool isRemote() const override; |
200 void requestRemotePlayback() override; | 201 void requestRemotePlayback() override; |
201 void requestRemotePlaybackControl() override; | 202 void requestRemotePlaybackControl() override; |
202 void requestRemotePlaybackStop() override; | 203 void requestRemotePlaybackStop() override; |
(...skipping 16 matching lines...) Expand all Loading... |
219 | 220 |
220 // Restart the player/pipeline as soon as possible. This will destroy the | 221 // Restart the player/pipeline as soon as possible. This will destroy the |
221 // current renderer, if any, and create a new one via the RendererFactory; and | 222 // current renderer, if any, and create a new one via the RendererFactory; and |
222 // then seek to resume playback at the current position. | 223 // then seek to resume playback at the current position. |
223 void ScheduleRestart(); | 224 void ScheduleRestart(); |
224 | 225 |
225 // Called when requests to activate monitoring changes on viewport | 226 // Called when requests to activate monitoring changes on viewport |
226 // intersection. | 227 // intersection. |
227 void ActivateViewportIntersectionMonitoring(bool activate); | 228 void ActivateViewportIntersectionMonitoring(bool activate); |
228 | 229 |
229 // Distinct states that |delegate_| can be in. | 230 // Distinct states that |delegate_| can be in. (Public for testing.) |
230 // TODO(sandersd): This should move into WebMediaPlayerDelegate. | |
231 // (Public for testing.) | |
232 enum class DelegateState { | 231 enum class DelegateState { |
233 GONE, | 232 GONE, |
234 PLAYING, | 233 PLAYING, |
235 PAUSED, | 234 PAUSED, |
236 ENDED, | |
237 }; | 235 }; |
238 | 236 |
239 // Playback state variables computed together in UpdatePlayState(). | 237 // Playback state variables computed together in UpdatePlayState(). |
240 // (Public for testing.) | 238 // (Public for testing.) |
241 struct PlayState { | 239 struct PlayState { |
242 DelegateState delegate_state; | 240 DelegateState delegate_state; |
| 241 bool is_idle; |
243 bool is_memory_reporting_enabled; | 242 bool is_memory_reporting_enabled; |
244 bool is_suspended; | 243 bool is_suspended; |
245 }; | 244 }; |
246 | 245 |
247 private: | 246 private: |
248 friend class WebMediaPlayerImplTest; | 247 friend class WebMediaPlayerImplTest; |
249 | 248 |
250 void EnableOverlay(); | 249 void EnableOverlay(); |
251 void DisableOverlay(); | 250 void DisableOverlay(); |
252 | 251 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 // - is_idle_, must_suspend_, | 336 // - is_idle_, must_suspend_, |
338 // - paused_, ended_, | 337 // - paused_, ended_, |
339 // - pending_suspend_resume_cycle_, | 338 // - pending_suspend_resume_cycle_, |
340 void UpdatePlayState(); | 339 void UpdatePlayState(); |
341 | 340 |
342 // Methods internal to UpdatePlayState(). | 341 // Methods internal to UpdatePlayState(). |
343 PlayState UpdatePlayState_ComputePlayState(bool is_remote, | 342 PlayState UpdatePlayState_ComputePlayState(bool is_remote, |
344 bool is_streaming, | 343 bool is_streaming, |
345 bool is_suspended, | 344 bool is_suspended, |
346 bool is_backgrounded); | 345 bool is_backgrounded); |
347 void SetDelegateState(DelegateState new_state); | 346 void SetDelegateState(DelegateState new_state, bool is_idle); |
348 void SetMemoryReportingState(bool is_memory_reporting_enabled); | 347 void SetMemoryReportingState(bool is_memory_reporting_enabled); |
349 void SetSuspendState(bool is_suspended); | 348 void SetSuspendState(bool is_suspended); |
350 | 349 |
351 // 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 |
352 // using for video playback. Called by |memory_usage_reporting_timer_|. | 351 // using for video playback. Called by |memory_usage_reporting_timer_|. |
353 // 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 |
354 // accessed on the media thread. | 353 // accessed on the media thread. |
355 void ReportMemoryUsage(); | 354 void ReportMemoryUsage(); |
356 void FinishMemoryUsageReport(int64_t demuxer_memory_usage); | 355 void FinishMemoryUsageReport(int64_t demuxer_memory_usage); |
357 | 356 |
358 // Called during OnHidden() when we want a suspended player to enter the | 357 // Called during OnHidden() when we want a suspended player to enter the |
359 // paused state after some idle timeout. | 358 // paused state after some idle timeout. |
360 void ScheduleIdlePauseTimer(); | 359 void ScheduleIdlePauseTimer(); |
361 | 360 |
| 361 // Returns |true| before HaveFutureData whenever there has been loading |
| 362 // progress and we have not been resumed for at least kLoadingToIdleTimeout |
| 363 // since then. |
| 364 // |
| 365 // This is used to delay suspension long enough for preroll to complete, which |
| 366 // is necessay because play() will not be called before HaveFutureData (and |
| 367 // thus we think we are idle forever). |
| 368 bool IsPrerollAttemptNeeded(); |
| 369 |
362 void CreateWatchTimeReporter(); | 370 void CreateWatchTimeReporter(); |
363 | 371 |
364 // Returns true if the player is hidden. | 372 // Returns true if the player is hidden. |
365 bool IsHidden() const; | 373 bool IsHidden() const; |
366 | 374 |
367 // Return whether |pipeline_metadata_| is compatible with an overlay. This | 375 // Return whether |pipeline_metadata_| is compatible with an overlay. This |
368 // is intended for android. | 376 // is intended for android. |
369 bool DoesOverlaySupportMetadata() const; | 377 bool DoesOverlaySupportMetadata() const; |
370 | 378 |
371 blink::WebLocalFrame* frame_; | 379 blink::WebLocalFrame* frame_; |
372 | 380 |
373 // The playback state last reported to |delegate_|, to avoid setting duplicate | |
374 // states. (Which can have undesired effects like resetting the idle timer.) | |
375 DelegateState delegate_state_; | |
376 | |
377 // Set when OnSuspendRequested() is called with |must_suspend| unset. | |
378 bool is_idle_; | |
379 | |
380 // Set when OnSuspendRequested() is called with |must_suspend| set. | |
381 bool must_suspend_; | |
382 | |
383 blink::WebMediaPlayer::NetworkState network_state_; | 381 blink::WebMediaPlayer::NetworkState network_state_; |
384 blink::WebMediaPlayer::ReadyState ready_state_; | 382 blink::WebMediaPlayer::ReadyState ready_state_; |
385 blink::WebMediaPlayer::ReadyState highest_ready_state_; | 383 blink::WebMediaPlayer::ReadyState highest_ready_state_; |
386 | 384 |
387 // Preload state for when |data_source_| is created after setPreload(). | 385 // Preload state for when |data_source_| is created after setPreload(). |
388 MultibufferDataSource::Preload preload_; | 386 MultibufferDataSource::Preload preload_; |
389 | 387 |
390 // Buffering strategy for when |data_source_| is created after | 388 // Buffering strategy for when |data_source_| is created after |
391 // setBufferingStrategy(). | 389 // setBufferingStrategy(). |
392 MultibufferDataSource::BufferingStrategy buffering_strategy_; | 390 MultibufferDataSource::BufferingStrategy buffering_strategy_; |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 // from the compositor will be queried to see if suspend is supported; the | 560 // from the compositor will be queried to see if suspend is supported; the |
563 // state will be set to YES or NO respectively if a frame is available. | 561 // state will be set to YES or NO respectively if a frame is available. |
564 enum class CanSuspendState { UNKNOWN, YES, NO }; | 562 enum class CanSuspendState { UNKNOWN, YES, NO }; |
565 CanSuspendState can_suspend_state_; | 563 CanSuspendState can_suspend_state_; |
566 | 564 |
567 // Used for HLS playback and in certain fallback paths (e.g. on older devices | 565 // Used for HLS playback and in certain fallback paths (e.g. on older devices |
568 // that can't support the unified media pipeline). | 566 // that can't support the unified media pipeline). |
569 GURL fallback_url_; | 567 GURL fallback_url_; |
570 bool use_fallback_path_; | 568 bool use_fallback_path_; |
571 | 569 |
572 // Called some-time after OnHidden() if the media was suspended in a playing | 570 // Called sometime after the media is suspended in a playing state in |
573 // state as part of the call to OnHidden(). | 571 // OnFrameHidden(), causing the state to change to paused. |
574 base::OneShotTimer background_pause_timer_; | 572 base::OneShotTimer background_pause_timer_; |
575 | 573 |
576 // Monitors the watch time of the played content. | 574 // Monitors the watch time of the played content. |
577 std::unique_ptr<WatchTimeReporter> watch_time_reporter_; | 575 std::unique_ptr<WatchTimeReporter> watch_time_reporter_; |
578 bool is_encrypted_; | 576 bool is_encrypted_; |
579 | 577 |
580 // Number of times we've reached BUFFERING_HAVE_NOTHING during playback. | 578 // Number of times we've reached BUFFERING_HAVE_NOTHING during playback. |
581 int underflow_count_; | 579 int underflow_count_; |
582 std::unique_ptr<base::ElapsedTimer> underflow_timer_; | 580 std::unique_ptr<base::ElapsedTimer> underflow_timer_; |
583 | 581 |
584 // The last time didLoadingProgress() returned true. | 582 // Used to track loading progress, used by IsPrerollAttemptNeeded(). |
585 base::TimeTicks last_time_loading_progressed_; | 583 // |preroll_attempt_pending_| indicates that the clock has been reset |
| 584 // (awaiting a resume to start), while |preroll_attempt_start_time_| tracks |
| 585 // when a preroll attempt began. |
| 586 bool preroll_attempt_pending_; |
| 587 base::TimeTicks preroll_attempt_start_time_; |
586 | 588 |
587 std::unique_ptr<base::TickClock> tick_clock_; | 589 std::unique_ptr<base::TickClock> tick_clock_; |
588 | 590 |
589 // Monitors the player events. | 591 // Monitors the player events. |
590 base::WeakPtr<MediaObserver> observer_; | 592 base::WeakPtr<MediaObserver> observer_; |
591 | 593 |
592 // Whether the player is currently in autoplay muted state. | |
593 bool autoplay_muted_ = false; | |
594 | |
595 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerImpl); | 594 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerImpl); |
596 }; | 595 }; |
597 | 596 |
598 } // namespace media | 597 } // namespace media |
599 | 598 |
600 #endif // MEDIA_BLINK_WEBMEDIAPLAYER_IMPL_H_ | 599 #endif // MEDIA_BLINK_WEBMEDIAPLAYER_IMPL_H_ |
OLD | NEW |