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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 void setContentDecryptionModule( | 177 void setContentDecryptionModule( |
178 blink::WebContentDecryptionModule* cdm, | 178 blink::WebContentDecryptionModule* cdm, |
179 blink::WebContentDecryptionModuleResult result) override; | 179 blink::WebContentDecryptionModuleResult result) override; |
180 | 180 |
181 bool supportsOverlayFullscreenVideo() override; | 181 bool supportsOverlayFullscreenVideo() override; |
182 void enteredFullscreen() override; | 182 void enteredFullscreen() override; |
183 void exitedFullscreen() override; | 183 void exitedFullscreen() override; |
184 void becameDominantVisibleContent(bool isDominant) override; | 184 void becameDominantVisibleContent(bool isDominant) override; |
185 | 185 |
186 // WebMediaPlayerDelegate::Observer implementation. | 186 // WebMediaPlayerDelegate::Observer implementation. |
187 void OnHidden() override; | 187 void OnFrameHidden() override; |
188 void OnShown() override; | 188 void OnFrameClosed() override; |
189 bool OnSuspendRequested(bool must_suspend) override; | 189 void OnFrameShown() override; |
190 bool OnIdleTimeout() override; | |
190 void OnPlay() override; | 191 void OnPlay() override; |
191 void OnPause() override; | 192 void OnPause() override; |
192 void OnVolumeMultiplierUpdate(double multiplier) override; | 193 void OnVolumeMultiplierUpdate(double multiplier) override; |
193 | 194 |
194 void requestRemotePlaybackDisabled(bool disabled) override; | 195 void requestRemotePlaybackDisabled(bool disabled) override; |
195 #if defined(OS_ANDROID) // WMPI_CAST | 196 #if defined(OS_ANDROID) // WMPI_CAST |
196 bool isRemote() const override; | 197 bool isRemote() const override; |
197 void requestRemotePlayback() override; | 198 void requestRemotePlayback() override; |
198 void requestRemotePlaybackControl() override; | 199 void requestRemotePlaybackControl() override; |
199 void requestRemotePlaybackStop() override; | 200 void requestRemotePlaybackStop() override; |
(...skipping 13 matching lines...) Expand all Loading... | |
213 | 214 |
214 // Called from WebMediaPlayerCast. | 215 // Called from WebMediaPlayerCast. |
215 // TODO(hubbe): WMPI_CAST make private. | 216 // TODO(hubbe): WMPI_CAST make private. |
216 void OnPipelineSeeked(bool time_updated); | 217 void OnPipelineSeeked(bool time_updated); |
217 | 218 |
218 // Restart the player/pipeline as soon as possible. This will destroy the | 219 // Restart the player/pipeline as soon as possible. This will destroy the |
219 // current renderer, if any, and create a new one via the RendererFactory; and | 220 // current renderer, if any, and create a new one via the RendererFactory; and |
220 // then seek to resume playback at the current position. | 221 // then seek to resume playback at the current position. |
221 void ScheduleRestart(); | 222 void ScheduleRestart(); |
222 | 223 |
223 // Distinct states that |delegate_| can be in. | 224 // Distinct states that |delegate_| can be in. (Public for testing.) |
224 // TODO(sandersd): This should move into WebMediaPlayerDelegate. | |
watk
2016/12/10 00:01:31
Can it not move in?
sandersd (OOO until July 31)
2017/01/05 23:12:21
It's not really necessary any more, separating the
| |
225 // (Public for testing.) | |
226 enum class DelegateState { | 225 enum class DelegateState { |
227 GONE, | 226 GONE, |
228 PLAYING, | 227 PLAYING, |
229 PAUSED, | 228 PAUSED, |
230 ENDED, | |
231 }; | 229 }; |
232 | 230 |
233 // Playback state variables computed together in UpdatePlayState(). | 231 // Playback state variables computed together in UpdatePlayState(). |
234 // (Public for testing.) | 232 // (Public for testing.) |
235 struct PlayState { | 233 struct PlayState { |
236 DelegateState delegate_state; | 234 DelegateState delegate_state; |
235 bool is_idle; | |
237 bool is_memory_reporting_enabled; | 236 bool is_memory_reporting_enabled; |
238 bool is_suspended; | 237 bool is_suspended; |
239 }; | 238 }; |
240 | 239 |
241 private: | 240 private: |
242 friend class WebMediaPlayerImplTest; | 241 friend class WebMediaPlayerImplTest; |
243 | 242 |
244 void EnableOverlay(); | 243 void EnableOverlay(); |
245 void DisableOverlay(); | 244 void DisableOverlay(); |
246 | 245 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
331 // - is_idle_, must_suspend_, | 330 // - is_idle_, must_suspend_, |
332 // - paused_, ended_, | 331 // - paused_, ended_, |
333 // - pending_suspend_resume_cycle_, | 332 // - pending_suspend_resume_cycle_, |
334 void UpdatePlayState(); | 333 void UpdatePlayState(); |
335 | 334 |
336 // Methods internal to UpdatePlayState(). | 335 // Methods internal to UpdatePlayState(). |
337 PlayState UpdatePlayState_ComputePlayState(bool is_remote, | 336 PlayState UpdatePlayState_ComputePlayState(bool is_remote, |
338 bool is_streaming, | 337 bool is_streaming, |
339 bool is_suspended, | 338 bool is_suspended, |
340 bool is_backgrounded); | 339 bool is_backgrounded); |
341 void SetDelegateState(DelegateState new_state); | 340 void SetDelegateState(DelegateState new_state, bool is_idle); |
342 void SetMemoryReportingState(bool is_memory_reporting_enabled); | 341 void SetMemoryReportingState(bool is_memory_reporting_enabled); |
343 void SetSuspendState(bool is_suspended); | 342 void SetSuspendState(bool is_suspended); |
344 | 343 |
345 // Called at low frequency to tell external observers how much memory we're | 344 // Called at low frequency to tell external observers how much memory we're |
346 // using for video playback. Called by |memory_usage_reporting_timer_|. | 345 // using for video playback. Called by |memory_usage_reporting_timer_|. |
347 // Memory usage reporting is done in two steps, because |demuxer_| must be | 346 // Memory usage reporting is done in two steps, because |demuxer_| must be |
348 // accessed on the media thread. | 347 // accessed on the media thread. |
349 void ReportMemoryUsage(); | 348 void ReportMemoryUsage(); |
350 void FinishMemoryUsageReport(int64_t demuxer_memory_usage); | 349 void FinishMemoryUsageReport(int64_t demuxer_memory_usage); |
351 | 350 |
352 // Called during OnHidden() when we want a suspended player to enter the | 351 // Called during OnHidden() when we want a suspended player to enter the |
353 // paused state after some idle timeout. | 352 // paused state after some idle timeout. |
354 void ScheduleIdlePauseTimer(); | 353 void ScheduleIdlePauseTimer(); |
355 | 354 |
355 // Returns |true| before HaveFutureData whenever there has been loading | |
356 // progress and we have not been resumed for at least kLoadingToIdleTimeout | |
357 // since then. | |
watk
2016/12/10 00:01:31
I don't think this is clear if you don't understan
sandersd (OOO until July 31)
2017/01/05 23:12:21
Done.
| |
358 bool IsPrerollAttemptNeeded(); | |
359 | |
356 void CreateWatchTimeReporter(); | 360 void CreateWatchTimeReporter(); |
357 | 361 |
358 // Returns true if the player is hidden. | 362 // Returns true if the player is hidden. |
359 bool IsHidden() const; | 363 bool IsHidden() const; |
360 | 364 |
361 blink::WebLocalFrame* frame_; | 365 blink::WebLocalFrame* frame_; |
362 | 366 |
363 // The playback state last reported to |delegate_|, to avoid setting duplicate | |
364 // states. (Which can have undesired effects like resetting the idle timer.) | |
365 DelegateState delegate_state_; | |
366 | |
367 // Set when OnSuspendRequested() is called with |must_suspend| unset. | |
368 bool is_idle_; | |
369 | |
370 // Set when OnSuspendRequested() is called with |must_suspend| set. | |
371 bool must_suspend_; | |
372 | |
373 blink::WebMediaPlayer::NetworkState network_state_; | 367 blink::WebMediaPlayer::NetworkState network_state_; |
374 blink::WebMediaPlayer::ReadyState ready_state_; | 368 blink::WebMediaPlayer::ReadyState ready_state_; |
375 blink::WebMediaPlayer::ReadyState highest_ready_state_; | 369 blink::WebMediaPlayer::ReadyState highest_ready_state_; |
376 | 370 |
377 // Preload state for when |data_source_| is created after setPreload(). | 371 // Preload state for when |data_source_| is created after setPreload(). |
378 MultibufferDataSource::Preload preload_; | 372 MultibufferDataSource::Preload preload_; |
379 | 373 |
380 // Buffering strategy for when |data_source_| is created after | 374 // Buffering strategy for when |data_source_| is created after |
381 // setBufferingStrategy(). | 375 // setBufferingStrategy(). |
382 MultibufferDataSource::BufferingStrategy buffering_strategy_; | 376 MultibufferDataSource::BufferingStrategy buffering_strategy_; |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
549 // from the compositor will be queried to see if suspend is supported; the | 543 // from the compositor will be queried to see if suspend is supported; the |
550 // state will be set to YES or NO respectively if a frame is available. | 544 // state will be set to YES or NO respectively if a frame is available. |
551 enum class CanSuspendState { UNKNOWN, YES, NO }; | 545 enum class CanSuspendState { UNKNOWN, YES, NO }; |
552 CanSuspendState can_suspend_state_; | 546 CanSuspendState can_suspend_state_; |
553 | 547 |
554 // Used for HLS playback and in certain fallback paths (e.g. on older devices | 548 // Used for HLS playback and in certain fallback paths (e.g. on older devices |
555 // that can't support the unified media pipeline). | 549 // that can't support the unified media pipeline). |
556 GURL fallback_url_; | 550 GURL fallback_url_; |
557 bool use_fallback_path_; | 551 bool use_fallback_path_; |
558 | 552 |
559 // Called some-time after OnHidden() if the media was suspended in a playing | 553 // Called sometime after the media is suspended in a playing state in |
560 // state as part of the call to OnHidden(). | 554 // OnFrameHidden(), causing the state to change to paused. |
561 base::OneShotTimer background_pause_timer_; | 555 base::OneShotTimer background_pause_timer_; |
562 | 556 |
563 // Monitors the watch time of the played content. | 557 // Monitors the watch time of the played content. |
564 std::unique_ptr<WatchTimeReporter> watch_time_reporter_; | 558 std::unique_ptr<WatchTimeReporter> watch_time_reporter_; |
565 bool is_encrypted_; | 559 bool is_encrypted_; |
566 | 560 |
567 // Number of times we've reached BUFFERING_HAVE_NOTHING during playback. | 561 // Number of times we've reached BUFFERING_HAVE_NOTHING during playback. |
568 int underflow_count_; | 562 int underflow_count_; |
569 std::unique_ptr<base::ElapsedTimer> underflow_timer_; | 563 std::unique_ptr<base::ElapsedTimer> underflow_timer_; |
570 | 564 |
571 // The last time didLoadingProgress() returned true. | 565 // Used to track loading progress, used by IsPrerollAttemptNeeded(). |
572 base::TimeTicks last_time_loading_progressed_; | 566 // |preroll_attempt_pending_| indicates that the clock has been reset |
567 // (awaiting a resume to start), while |preroll_attempt_start_time_| tracks | |
568 // when a preroll attempt began. | |
569 bool preroll_attempt_pending_; | |
570 base::TimeTicks preroll_attempt_start_time_; | |
573 | 571 |
574 std::unique_ptr<base::TickClock> tick_clock_; | 572 std::unique_ptr<base::TickClock> tick_clock_; |
575 | 573 |
576 // Monitors the player events. | 574 // Monitors the player events. |
577 base::WeakPtr<MediaObserver> observer_; | 575 base::WeakPtr<MediaObserver> observer_; |
578 | 576 |
579 // Whether the player is currently in autoplay muted state. | |
580 bool autoplay_muted_ = false; | |
581 | |
582 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerImpl); | 577 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerImpl); |
583 }; | 578 }; |
584 | 579 |
585 } // namespace media | 580 } // namespace media |
586 | 581 |
587 #endif // MEDIA_BLINK_WEBMEDIAPLAYER_IMPL_H_ | 582 #endif // MEDIA_BLINK_WEBMEDIAPLAYER_IMPL_H_ |
OLD | NEW |