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

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

Issue 2487373003: Disable background video track behind a feature flag (Closed)
Patch Set: Rebase + comment fix Created 4 years 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_impl.h ('k') | media/blink/webmediaplayer_impl_unittest.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 #include "media/blink/webmediaplayer_impl.h" 5 #include "media/blink/webmediaplayer_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <limits> 9 #include <limits>
10 #include <string> 10 #include <string>
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 #else 117 #else
118 return !base::CommandLine::ForCurrentProcess()->HasSwitch( 118 return !base::CommandLine::ForCurrentProcess()->HasSwitch(
119 switches::kDisableMediaSuspend); 119 switches::kDisableMediaSuspend);
120 #endif 120 #endif
121 } 121 }
122 122
123 bool IsResumeBackgroundVideosEnabled() { 123 bool IsResumeBackgroundVideosEnabled() {
124 return base::FeatureList::IsEnabled(kResumeBackgroundVideo); 124 return base::FeatureList::IsEnabled(kResumeBackgroundVideo);
125 } 125 }
126 126
127 bool IsBackgroundVideoTrackOptimizationEnabled() {
128 return base::FeatureList::IsEnabled(kBackgroundVideoTrackOptimization);
129 }
130
127 bool IsNetworkStateError(blink::WebMediaPlayer::NetworkState state) { 131 bool IsNetworkStateError(blink::WebMediaPlayer::NetworkState state) {
128 bool result = state == blink::WebMediaPlayer::NetworkStateFormatError || 132 bool result = state == blink::WebMediaPlayer::NetworkStateFormatError ||
129 state == blink::WebMediaPlayer::NetworkStateNetworkError || 133 state == blink::WebMediaPlayer::NetworkStateNetworkError ||
130 state == blink::WebMediaPlayer::NetworkStateDecodeError; 134 state == blink::WebMediaPlayer::NetworkStateDecodeError;
131 DCHECK_EQ(state > blink::WebMediaPlayer::NetworkStateLoaded, result); 135 DCHECK_EQ(state > blink::WebMediaPlayer::NetworkStateLoaded, result);
132 return result; 136 return result;
133 } 137 }
134 138
135 gfx::Size GetRotatedVideoSize(VideoRotation rotation, gfx::Size natural_size) { 139 gfx::Size GetRotatedVideoSize(VideoRotation rotation, gfx::Size natural_size) {
136 if (rotation == VIDEO_ROTATION_90 || rotation == VIDEO_ROTATION_270) 140 if (rotation == VIDEO_ROTATION_90 || rotation == VIDEO_ROTATION_270)
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 << "]"; 648 << "]";
645 pipeline_.OnEnabledAudioTracksChanged(enabledMediaTrackIds); 649 pipeline_.OnEnabledAudioTracksChanged(enabledMediaTrackIds);
646 } 650 }
647 651
648 void WebMediaPlayerImpl::selectedVideoTrackChanged( 652 void WebMediaPlayerImpl::selectedVideoTrackChanged(
649 blink::WebMediaPlayer::TrackId* selectedTrackId) { 653 blink::WebMediaPlayer::TrackId* selectedTrackId) {
650 DCHECK(main_task_runner_->BelongsToCurrentThread()); 654 DCHECK(main_task_runner_->BelongsToCurrentThread());
651 655
652 std::ostringstream logstr; 656 std::ostringstream logstr;
653 std::vector<MediaTrack::Id> selectedVideoMediaTrackId; 657 std::vector<MediaTrack::Id> selectedVideoMediaTrackId;
654 if (selectedTrackId) { 658 bool canAddVideoTrack =
659 !IsBackgroundVideoTrackOptimizationEnabled() || !IsHidden();
660 if (selectedTrackId && canAddVideoTrack) {
655 selectedVideoMediaTrackId.push_back(selectedTrackId->utf8().data()); 661 selectedVideoMediaTrackId.push_back(selectedTrackId->utf8().data());
656 logstr << selectedVideoMediaTrackId[0]; 662 logstr << selectedVideoMediaTrackId[0];
657 } 663 }
658 MEDIA_LOG(INFO, media_log_) << "Selected video track: [" << logstr.str() 664 MEDIA_LOG(INFO, media_log_) << "Selected video track: [" << logstr.str()
659 << "]"; 665 << "]";
660 pipeline_.OnSelectedVideoTrackChanged(selectedVideoMediaTrackId); 666 pipeline_.OnSelectedVideoTrackChanged(selectedVideoMediaTrackId);
661 } 667 }
662 668
663 blink::WebSize WebMediaPlayerImpl::naturalSize() const { 669 blink::WebSize WebMediaPlayerImpl::naturalSize() const {
664 DCHECK(main_task_runner_->BelongsToCurrentThread()); 670 DCHECK(main_task_runner_->BelongsToCurrentThread());
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after
1302 1308
1303 opaque_ = opaque; 1309 opaque_ = opaque;
1304 // Modify content opaqueness of cc::Layer directly so that 1310 // Modify content opaqueness of cc::Layer directly so that
1305 // SetContentsOpaqueIsFixed is ignored. 1311 // SetContentsOpaqueIsFixed is ignored.
1306 if (video_weblayer_) 1312 if (video_weblayer_)
1307 video_weblayer_->layer()->SetContentsOpaque(opaque_); 1313 video_weblayer_->layer()->SetContentsOpaque(opaque_);
1308 } 1314 }
1309 1315
1310 void WebMediaPlayerImpl::OnHidden() { 1316 void WebMediaPlayerImpl::OnHidden() {
1311 DCHECK(main_task_runner_->BelongsToCurrentThread()); 1317 DCHECK(main_task_runner_->BelongsToCurrentThread());
1318
1319 if (IsBackgroundVideoTrackOptimizationEnabled())
1320 selectedVideoTrackChanged(nullptr);
1321
1312 if (watch_time_reporter_) 1322 if (watch_time_reporter_)
1313 watch_time_reporter_->OnHidden(); 1323 watch_time_reporter_->OnHidden();
1314 1324
1315 UpdatePlayState(); 1325 UpdatePlayState();
1316 1326
1317 // Schedule suspended playing media to be paused if the user doesn't come back 1327 // Schedule suspended playing media to be paused if the user doesn't come back
1318 // to it within some timeout period to avoid any autoplay surprises. 1328 // to it within some timeout period to avoid any autoplay surprises.
1319 ScheduleIdlePauseTimer(); 1329 ScheduleIdlePauseTimer();
1320 } 1330 }
1321 1331
1322 void WebMediaPlayerImpl::OnShown() { 1332 void WebMediaPlayerImpl::OnShown() {
1323 DCHECK(main_task_runner_->BelongsToCurrentThread()); 1333 DCHECK(main_task_runner_->BelongsToCurrentThread());
1324 if (watch_time_reporter_) 1334 if (watch_time_reporter_)
1325 watch_time_reporter_->OnShown(); 1335 watch_time_reporter_->OnShown();
1326 1336
1337 if (IsBackgroundVideoTrackOptimizationEnabled() &&
1338 client_->hasSelectedVideoTrack()) {
1339 WebMediaPlayer::TrackId trackId = client_->getSelectedVideoTrackId();
1340 selectedVideoTrackChanged(&trackId);
1341 }
1342
1327 must_suspend_ = false; 1343 must_suspend_ = false;
1328 background_pause_timer_.Stop(); 1344 background_pause_timer_.Stop();
1329 1345
1330 UpdatePlayState(); 1346 UpdatePlayState();
1331 } 1347 }
1332 1348
1333 bool WebMediaPlayerImpl::OnSuspendRequested(bool must_suspend) { 1349 bool WebMediaPlayerImpl::OnSuspendRequested(bool must_suspend) {
1334 DCHECK(main_task_runner_->BelongsToCurrentThread()); 1350 DCHECK(main_task_runner_->BelongsToCurrentThread());
1335 1351
1336 if (must_suspend) { 1352 if (must_suspend) {
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
1693 1709
1694 #if defined(OS_ANDROID) // WMPI_CAST 1710 #if defined(OS_ANDROID) // WMPI_CAST
1695 bool is_remote = isRemote(); 1711 bool is_remote = isRemote();
1696 bool is_streaming = false; 1712 bool is_streaming = false;
1697 #else 1713 #else
1698 bool is_remote = false; 1714 bool is_remote = false;
1699 bool is_streaming = data_source_ && data_source_->IsStreaming(); 1715 bool is_streaming = data_source_ && data_source_->IsStreaming();
1700 #endif 1716 #endif
1701 1717
1702 bool is_suspended = pipeline_controller_.IsSuspended(); 1718 bool is_suspended = pipeline_controller_.IsSuspended();
1703 bool is_backgrounded = 1719 bool is_backgrounded = IsBackgroundedSuspendEnabled() && IsHidden();
1704 IsBackgroundedSuspendEnabled() && delegate_ && delegate_->IsHidden();
1705 PlayState state = UpdatePlayState_ComputePlayState( 1720 PlayState state = UpdatePlayState_ComputePlayState(
1706 is_remote, is_streaming, is_suspended, is_backgrounded); 1721 is_remote, is_streaming, is_suspended, is_backgrounded);
1707 SetDelegateState(state.delegate_state); 1722 SetDelegateState(state.delegate_state);
1708 SetMemoryReportingState(state.is_memory_reporting_enabled); 1723 SetMemoryReportingState(state.is_memory_reporting_enabled);
1709 SetSuspendState(state.is_suspended || pending_suspend_resume_cycle_); 1724 SetSuspendState(state.is_suspended || pending_suspend_resume_cycle_);
1710 } 1725 }
1711 1726
1712 void WebMediaPlayerImpl::SetDelegateState(DelegateState new_state) { 1727 void WebMediaPlayerImpl::SetDelegateState(DelegateState new_state) {
1713 if (!delegate_) 1728 if (!delegate_)
1714 return; 1729 return;
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
1953 this, &WebMediaPlayerImpl::OnPause); 1968 this, &WebMediaPlayerImpl::OnPause);
1954 } 1969 }
1955 1970
1956 void WebMediaPlayerImpl::CreateWatchTimeReporter() { 1971 void WebMediaPlayerImpl::CreateWatchTimeReporter() {
1957 // Create the watch time reporter and synchronize its initial state. 1972 // Create the watch time reporter and synchronize its initial state.
1958 watch_time_reporter_.reset(new WatchTimeReporter( 1973 watch_time_reporter_.reset(new WatchTimeReporter(
1959 hasAudio(), hasVideo(), !!chunk_demuxer_, is_encrypted_, media_log_, 1974 hasAudio(), hasVideo(), !!chunk_demuxer_, is_encrypted_, media_log_,
1960 pipeline_metadata_.natural_size, 1975 pipeline_metadata_.natural_size,
1961 base::Bind(&GetCurrentTimeInternal, this))); 1976 base::Bind(&GetCurrentTimeInternal, this)));
1962 watch_time_reporter_->OnVolumeChange(volume_); 1977 watch_time_reporter_->OnVolumeChange(volume_);
1963 if (delegate_ && delegate_->IsHidden()) 1978 if (IsHidden())
1964 watch_time_reporter_->OnHidden(); 1979 watch_time_reporter_->OnHidden();
1965 else 1980 else
1966 watch_time_reporter_->OnShown(); 1981 watch_time_reporter_->OnShown();
1967 } 1982 }
1968 1983
1984 bool WebMediaPlayerImpl::IsHidden() const {
1985 DCHECK(main_task_runner_->BelongsToCurrentThread());
1986
1987 return delegate_ && delegate_->IsHidden();
1988 }
1989
1969 } // namespace media 1990 } // namespace media
OLDNEW
« no previous file with comments | « media/blink/webmediaplayer_impl.h ('k') | media/blink/webmediaplayer_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698