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

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

Issue 2610893004: [Media] Disable background video optimization for streaming videos (Closed)
Patch Set: Rebase 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_impl.h ('k') | no next file » | 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 1331 matching lines...) Expand 10 before | Expand all | Expand 10 after
1342 if (video_weblayer_) 1342 if (video_weblayer_)
1343 video_weblayer_->layer()->SetContentsOpaque(opaque_); 1343 video_weblayer_->layer()->SetContentsOpaque(opaque_);
1344 } 1344 }
1345 1345
1346 void WebMediaPlayerImpl::OnHidden() { 1346 void WebMediaPlayerImpl::OnHidden() {
1347 DCHECK(main_task_runner_->BelongsToCurrentThread()); 1347 DCHECK(main_task_runner_->BelongsToCurrentThread());
1348 1348
1349 if (watch_time_reporter_) 1349 if (watch_time_reporter_)
1350 watch_time_reporter_->OnHidden(); 1350 watch_time_reporter_->OnHidden();
1351 1351
1352 if (IsBackgroundVideoTrackOptimizationEnabled()) { 1352 if (!IsStreaming() && IsBackgroundVideoTrackOptimizationEnabled()) {
1353 if (ShouldPauseWhenHidden()) { 1353 if (ShouldPauseWhenHidden()) {
1354 // OnPause() will set |paused_when_hidden_| to false and call 1354 // OnPause() will set |paused_when_hidden_| to false and call
1355 // UpdatePlayState(), so set the flag to true after and then return. 1355 // UpdatePlayState(), so set the flag to true after and then return.
1356 OnPause(); 1356 OnPause();
1357 paused_when_hidden_ = true; 1357 paused_when_hidden_ = true;
1358 return; 1358 return;
1359 } 1359 }
1360 1360
1361 selectedVideoTrackChanged(nullptr); 1361 selectedVideoTrackChanged(nullptr);
1362 } 1362 }
1363 1363
1364 UpdatePlayState(); 1364 UpdatePlayState();
1365 1365
1366 // Schedule suspended playing media to be paused if the user doesn't come back 1366 // Schedule suspended playing media to be paused if the user doesn't come back
1367 // to it within some timeout period to avoid any autoplay surprises. 1367 // to it within some timeout period to avoid any autoplay surprises.
1368 ScheduleIdlePauseTimer(); 1368 ScheduleIdlePauseTimer();
1369 } 1369 }
1370 1370
1371 void WebMediaPlayerImpl::OnShown() { 1371 void WebMediaPlayerImpl::OnShown() {
1372 DCHECK(main_task_runner_->BelongsToCurrentThread()); 1372 DCHECK(main_task_runner_->BelongsToCurrentThread());
1373 if (watch_time_reporter_) 1373 if (watch_time_reporter_)
1374 watch_time_reporter_->OnShown(); 1374 watch_time_reporter_->OnShown();
1375 1375
1376 compositor_task_runner_->PostTask( 1376 compositor_task_runner_->PostTask(
1377 FROM_HERE, 1377 FROM_HERE,
1378 base::Bind(&VideoFrameCompositor::SetForegroundTime, 1378 base::Bind(&VideoFrameCompositor::SetForegroundTime,
1379 base::Unretained(compositor_), base::TimeTicks::Now())); 1379 base::Unretained(compositor_), base::TimeTicks::Now()));
1380 1380
1381 if (IsBackgroundVideoTrackOptimizationEnabled()) { 1381 if (!IsStreaming() && IsBackgroundVideoTrackOptimizationEnabled()) {
1382 if (paused_when_hidden_) { 1382 if (paused_when_hidden_) {
1383 paused_when_hidden_ = false; 1383 paused_when_hidden_ = false;
1384 OnPlay(); // Calls UpdatePlayState() so return afterwards. 1384 OnPlay(); // Calls UpdatePlayState() so return afterwards.
1385 return; 1385 return;
1386 } 1386 }
1387 1387
1388 if (client_->hasSelectedVideoTrack()) { 1388 if (client_->hasSelectedVideoTrack()) {
1389 WebMediaPlayer::TrackId trackId = client_->getSelectedVideoTrackId(); 1389 WebMediaPlayer::TrackId trackId = client_->getSelectedVideoTrackId();
1390 selectedVideoTrackChanged(&trackId); 1390 selectedVideoTrackChanged(&trackId);
1391 } 1391 }
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
1672 1672
1673 chunk_demuxer_ = new ChunkDemuxer( 1673 chunk_demuxer_ = new ChunkDemuxer(
1674 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnDemuxerOpened), 1674 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnDemuxerOpened),
1675 encrypted_media_init_data_cb, media_log_); 1675 encrypted_media_init_data_cb, media_log_);
1676 demuxer_.reset(chunk_demuxer_); 1676 demuxer_.reset(chunk_demuxer_);
1677 } 1677 }
1678 1678
1679 // TODO(sandersd): FileSystem objects may also be non-static, but due to our 1679 // TODO(sandersd): FileSystem objects may also be non-static, but due to our
1680 // caching layer such situations are broken already. http://crbug.com/593159 1680 // caching layer such situations are broken already. http://crbug.com/593159
1681 bool is_static = !chunk_demuxer_; 1681 bool is_static = !chunk_demuxer_;
1682 bool is_streaming = data_source_ && data_source_->IsStreaming(); 1682 bool is_streaming = IsStreaming();
1683 UMA_HISTOGRAM_BOOLEAN("Media.IsStreaming", is_streaming); 1683 UMA_HISTOGRAM_BOOLEAN("Media.IsStreaming", is_streaming);
1684 1684
1685 // ... and we're ready to go! 1685 // ... and we're ready to go!
1686 // TODO(sandersd): On Android, defer Start() if the tab is not visible. 1686 // TODO(sandersd): On Android, defer Start() if the tab is not visible.
1687 seeking_ = true; 1687 seeking_ = true;
1688 pipeline_controller_.Start(demuxer_.get(), this, is_streaming, is_static); 1688 pipeline_controller_.Start(demuxer_.get(), this, is_streaming, is_static);
1689 } 1689 }
1690 1690
1691 void WebMediaPlayerImpl::SetNetworkState(WebMediaPlayer::NetworkState state) { 1691 void WebMediaPlayerImpl::SetNetworkState(WebMediaPlayer::NetworkState state) {
1692 DVLOG(1) << __func__ << "(" << state << ")"; 1692 DVLOG(1) << __func__ << "(" << state << ")";
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1761 } 1761 }
1762 1762
1763 void WebMediaPlayerImpl::UpdatePlayState() { 1763 void WebMediaPlayerImpl::UpdatePlayState() {
1764 DCHECK(main_task_runner_->BelongsToCurrentThread()); 1764 DCHECK(main_task_runner_->BelongsToCurrentThread());
1765 1765
1766 #if defined(OS_ANDROID) // WMPI_CAST 1766 #if defined(OS_ANDROID) // WMPI_CAST
1767 bool is_remote = isRemote(); 1767 bool is_remote = isRemote();
1768 bool is_streaming = false; 1768 bool is_streaming = false;
1769 #else 1769 #else
1770 bool is_remote = false; 1770 bool is_remote = false;
1771 bool is_streaming = data_source_ && data_source_->IsStreaming(); 1771 bool is_streaming = IsStreaming();
1772 #endif 1772 #endif
1773 1773
1774 bool is_suspended = pipeline_controller_.IsSuspended(); 1774 bool is_suspended = pipeline_controller_.IsSuspended();
1775 bool is_backgrounded = IsBackgroundedSuspendEnabled() && IsHidden(); 1775 bool is_backgrounded = IsBackgroundedSuspendEnabled() && IsHidden();
1776 PlayState state = UpdatePlayState_ComputePlayState( 1776 PlayState state = UpdatePlayState_ComputePlayState(
1777 is_remote, is_streaming, is_suspended, is_backgrounded); 1777 is_remote, is_streaming, is_suspended, is_backgrounded);
1778 SetDelegateState(state.delegate_state); 1778 SetDelegateState(state.delegate_state);
1779 SetMemoryReportingState(state.is_memory_reporting_enabled); 1779 SetMemoryReportingState(state.is_memory_reporting_enabled);
1780 SetSuspendState(state.is_suspended || pending_suspend_resume_cycle_); 1780 SetSuspendState(state.is_suspended || pending_suspend_resume_cycle_);
1781 } 1781 }
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
2054 else 2054 else
2055 watch_time_reporter_->OnShown(); 2055 watch_time_reporter_->OnShown();
2056 } 2056 }
2057 2057
2058 bool WebMediaPlayerImpl::IsHidden() const { 2058 bool WebMediaPlayerImpl::IsHidden() const {
2059 DCHECK(main_task_runner_->BelongsToCurrentThread()); 2059 DCHECK(main_task_runner_->BelongsToCurrentThread());
2060 2060
2061 return delegate_ && delegate_->IsHidden(); 2061 return delegate_ && delegate_->IsHidden();
2062 } 2062 }
2063 2063
2064 bool WebMediaPlayerImpl::IsStreaming() const {
2065 return data_source_ && data_source_->IsStreaming();
2066 }
2067
2064 bool WebMediaPlayerImpl::DoesOverlaySupportMetadata() const { 2068 bool WebMediaPlayerImpl::DoesOverlaySupportMetadata() const {
2065 return pipeline_metadata_.video_rotation == VIDEO_ROTATION_0; 2069 return pipeline_metadata_.video_rotation == VIDEO_ROTATION_0;
2066 } 2070 }
2067 2071
2068 void WebMediaPlayerImpl::ActivateViewportIntersectionMonitoring(bool activate) { 2072 void WebMediaPlayerImpl::ActivateViewportIntersectionMonitoring(bool activate) {
2069 DCHECK(main_task_runner_->BelongsToCurrentThread()); 2073 DCHECK(main_task_runner_->BelongsToCurrentThread());
2070 2074
2071 client_->activateViewportIntersectionMonitoring(activate); 2075 client_->activateViewportIntersectionMonitoring(activate);
2072 } 2076 }
2073 2077
2074 bool WebMediaPlayerImpl::ShouldPauseWhenHidden() const { 2078 bool WebMediaPlayerImpl::ShouldPauseWhenHidden() const {
2075 #if defined(OS_ANDROID) // WMPI_CAST 2079 #if defined(OS_ANDROID) // WMPI_CAST
2076 if (isRemote()) 2080 if (isRemote())
2077 return false; 2081 return false;
2078 #endif // defined(OS_ANDROID) // WMPI_CAST 2082 #endif // defined(OS_ANDROID) // WMPI_CAST
2079 2083
2080 return hasVideo() && !hasAudio(); 2084 return hasVideo() && !hasAudio();
2081 } 2085 }
2082 2086
2083 } // namespace media 2087 } // namespace media
OLDNEW
« no previous file with comments | « media/blink/webmediaplayer_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698