Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: media/blink/webmediaplayer_impl.h

Issue 2490783002: Refactor WebMediaPlayerDelegate interface. (Closed)
Patch Set: Unit tests found a real bug! Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/blink/webmediaplayer_delegate.h ('k') | media/blink/webmediaplayer_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 // - is_idle_, must_suspend_, 338 // - is_idle_, must_suspend_,
340 // - paused_, ended_, 339 // - paused_, ended_,
341 // - pending_suspend_resume_cycle_, 340 // - pending_suspend_resume_cycle_,
342 void UpdatePlayState(); 341 void UpdatePlayState();
343 342
344 // Methods internal to UpdatePlayState(). 343 // Methods internal to UpdatePlayState().
345 PlayState UpdatePlayState_ComputePlayState(bool is_remote, 344 PlayState UpdatePlayState_ComputePlayState(bool is_remote,
346 bool is_streaming, 345 bool is_streaming,
347 bool is_suspended, 346 bool is_suspended,
348 bool is_backgrounded); 347 bool is_backgrounded);
349 void SetDelegateState(DelegateState new_state); 348 void SetDelegateState(DelegateState new_state, bool is_idle);
350 void SetMemoryReportingState(bool is_memory_reporting_enabled); 349 void SetMemoryReportingState(bool is_memory_reporting_enabled);
351 void SetSuspendState(bool is_suspended); 350 void SetSuspendState(bool is_suspended);
352 351
353 // Called at low frequency to tell external observers how much memory we're 352 // Called at low frequency to tell external observers how much memory we're
354 // using for video playback. Called by |memory_usage_reporting_timer_|. 353 // using for video playback. Called by |memory_usage_reporting_timer_|.
355 // Memory usage reporting is done in two steps, because |demuxer_| must be 354 // Memory usage reporting is done in two steps, because |demuxer_| must be
356 // accessed on the media thread. 355 // accessed on the media thread.
357 void ReportMemoryUsage(); 356 void ReportMemoryUsage();
358 void FinishMemoryUsageReport(int64_t demuxer_memory_usage); 357 void FinishMemoryUsageReport(int64_t demuxer_memory_usage);
359 358
360 // Called during OnHidden() when we want a suspended player to enter the 359 // Called during OnHidden() when we want a suspended player to enter the
361 // paused state after some idle timeout. 360 // paused state after some idle timeout.
362 void ScheduleIdlePauseTimer(); 361 void ScheduleIdlePauseTimer();
363 362
363 // Returns |true| before HaveFutureData whenever there has been loading
364 // progress and we have not been resumed for at least kLoadingToIdleTimeout
365 // since then.
366 //
367 // This is used to delay suspension long enough for preroll to complete, which
368 // is necessay because play() will not be called before HaveFutureData (and
369 // thus we think we are idle forever).
370 bool IsPrerollAttemptNeeded();
371
364 void CreateWatchTimeReporter(); 372 void CreateWatchTimeReporter();
365 373
366 // Returns true if the player is hidden. 374 // Returns true if the player is hidden.
367 bool IsHidden() const; 375 bool IsHidden() const;
368 376
369 // Returns true if the player's source is streaming. 377 // Returns true if the player's source is streaming.
370 bool IsStreaming() const; 378 bool IsStreaming() const;
371 379
372 // Return whether |pipeline_metadata_| is compatible with an overlay. This 380 // Return whether |pipeline_metadata_| is compatible with an overlay. This
373 // is intended for android. 381 // is intended for android.
(...skipping 25 matching lines...) Expand all
399 407
400 // Overrides the pipeline statistics returned by GetStatistics() for tests. 408 // Overrides the pipeline statistics returned by GetStatistics() for tests.
401 void SetPipelineStatisticsForTest(const PipelineStatistics& stats); 409 void SetPipelineStatisticsForTest(const PipelineStatistics& stats);
402 410
403 // Returns the pipeline statistics or the value overridden by tests. 411 // Returns the pipeline statistics or the value overridden by tests.
404 PipelineStatistics GetPipelineStatistics() const; 412 PipelineStatistics GetPipelineStatistics() const;
405 413
406 blink::WebLocalFrame* frame_; 414 blink::WebLocalFrame* frame_;
407 415
408 // The playback state last reported to |delegate_|, to avoid setting duplicate 416 // The playback state last reported to |delegate_|, to avoid setting duplicate
409 // states. (Which can have undesired effects like resetting the idle timer.) 417 // states.
418 // TODO(sandersd): The delegate should be implementing deduplication.
410 DelegateState delegate_state_; 419 DelegateState delegate_state_;
411 420 bool delegate_has_audio_;
412 // Set when OnSuspendRequested() is called with |must_suspend| unset.
413 bool is_idle_;
414
415 // Set when OnSuspendRequested() is called with |must_suspend| set.
416 bool must_suspend_;
417 421
418 blink::WebMediaPlayer::NetworkState network_state_; 422 blink::WebMediaPlayer::NetworkState network_state_;
419 blink::WebMediaPlayer::ReadyState ready_state_; 423 blink::WebMediaPlayer::ReadyState ready_state_;
420 blink::WebMediaPlayer::ReadyState highest_ready_state_; 424 blink::WebMediaPlayer::ReadyState highest_ready_state_;
421 425
422 // Preload state for when |data_source_| is created after setPreload(). 426 // Preload state for when |data_source_| is created after setPreload().
423 MultibufferDataSource::Preload preload_; 427 MultibufferDataSource::Preload preload_;
424 428
425 // Buffering strategy for when |data_source_| is created after 429 // Buffering strategy for when |data_source_| is created after
426 // setBufferingStrategy(). 430 // setBufferingStrategy().
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 // from the compositor will be queried to see if suspend is supported; the 605 // from the compositor will be queried to see if suspend is supported; the
602 // state will be set to YES or NO respectively if a frame is available. 606 // state will be set to YES or NO respectively if a frame is available.
603 enum class CanSuspendState { UNKNOWN, YES, NO }; 607 enum class CanSuspendState { UNKNOWN, YES, NO };
604 CanSuspendState can_suspend_state_; 608 CanSuspendState can_suspend_state_;
605 609
606 // Used for HLS playback and in certain fallback paths (e.g. on older devices 610 // Used for HLS playback and in certain fallback paths (e.g. on older devices
607 // that can't support the unified media pipeline). 611 // that can't support the unified media pipeline).
608 GURL fallback_url_; 612 GURL fallback_url_;
609 bool use_fallback_path_; 613 bool use_fallback_path_;
610 614
611 // Called some-time after OnHidden() if the media was suspended in a playing 615 // Called sometime after the media is suspended in a playing state in
612 // state as part of the call to OnHidden(). 616 // OnFrameHidden(), causing the state to change to paused.
613 base::OneShotTimer background_pause_timer_; 617 base::OneShotTimer background_pause_timer_;
614 618
615 // Monitors the watch time of the played content. 619 // Monitors the watch time of the played content.
616 std::unique_ptr<WatchTimeReporter> watch_time_reporter_; 620 std::unique_ptr<WatchTimeReporter> watch_time_reporter_;
617 bool is_encrypted_; 621 bool is_encrypted_;
618 622
619 // Number of times we've reached BUFFERING_HAVE_NOTHING during playback. 623 // Number of times we've reached BUFFERING_HAVE_NOTHING during playback.
620 int underflow_count_; 624 int underflow_count_;
621 std::unique_ptr<base::ElapsedTimer> underflow_timer_; 625 std::unique_ptr<base::ElapsedTimer> underflow_timer_;
622 626
623 // The last time didLoadingProgress() returned true. 627 // Used to track loading progress, used by IsPrerollAttemptNeeded().
624 base::TimeTicks last_time_loading_progressed_; 628 // |preroll_attempt_pending_| indicates that the clock has been reset
629 // (awaiting a resume to start), while |preroll_attempt_start_time_| tracks
630 // when a preroll attempt began.
631 bool preroll_attempt_pending_;
632 base::TimeTicks preroll_attempt_start_time_;
625 633
626 std::unique_ptr<base::TickClock> tick_clock_; 634 std::unique_ptr<base::TickClock> tick_clock_;
627 635
628 // Monitors the player events. 636 // Monitors the player events.
629 base::WeakPtr<MediaObserver> observer_; 637 base::WeakPtr<MediaObserver> observer_;
630 638
631 // Whether the player is currently in autoplay muted state.
632 bool autoplay_muted_ = false;
633
634 // The maximum video keyframe distance that allows triggering background 639 // The maximum video keyframe distance that allows triggering background
635 // playback optimizations. 640 // playback optimizations.
636 // 10 seconds by default but can be overridden by a Finch experiment. 641 // 10 seconds by default but can be overridden by a Finch experiment.
637 base::TimeDelta max_keyframe_distance_to_disable_background_video_ = 642 base::TimeDelta max_keyframe_distance_to_disable_background_video_ =
638 base::TimeDelta::FromSeconds(10); 643 base::TimeDelta::FromSeconds(10);
639 644
640 // Whether disabled the video track as an optimization. 645 // Whether disabled the video track as an optimization.
641 bool video_track_disabled_ = false; 646 bool video_track_disabled_ = false;
642 647
643 // Whether the pipeline is being resumed at the moment. 648 // Whether the pipeline is being resumed at the moment.
644 bool is_pipeline_resuming_ = false; 649 bool is_pipeline_resuming_ = false;
645 650
646 // Pipeline statistics overridden by tests. 651 // Pipeline statistics overridden by tests.
647 base::Optional<PipelineStatistics> pipeline_statistics_for_test_; 652 base::Optional<PipelineStatistics> pipeline_statistics_for_test_;
648 653
649 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerImpl); 654 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerImpl);
650 }; 655 };
651 656
652 } // namespace media 657 } // namespace media
653 658
654 #endif // MEDIA_BLINK_WEBMEDIAPLAYER_IMPL_H_ 659 #endif // MEDIA_BLINK_WEBMEDIAPLAYER_IMPL_H_
OLDNEW
« no previous file with comments | « media/blink/webmediaplayer_delegate.h ('k') | media/blink/webmediaplayer_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698