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 #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 Loading... | |
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 (IsBackgroundVideoTrackOptimizationEnabled() && |
1353 ShouldDecodeFastWhenShown()) { | |
1353 if (ShouldPauseWhenHidden()) { | 1354 if (ShouldPauseWhenHidden()) { |
1354 // OnPause() will set |paused_when_hidden_| to false and call | 1355 // OnPause() will set |paused_when_hidden_| to false and call |
1355 // UpdatePlayState(), so set the flag to true after and then return. | 1356 // UpdatePlayState(), so set the flag to true after and then return. |
1356 OnPause(); | 1357 OnPause(); |
1357 paused_when_hidden_ = true; | 1358 paused_when_hidden_ = true; |
1358 return; | 1359 return; |
1359 } | 1360 } |
1360 | 1361 |
1361 selectedVideoTrackChanged(nullptr); | 1362 selectedVideoTrackChanged(nullptr); |
1362 } | 1363 } |
1363 | 1364 |
1364 UpdatePlayState(); | 1365 UpdatePlayState(); |
1365 | 1366 |
1366 // Schedule suspended playing media to be paused if the user doesn't come back | 1367 // 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. | 1368 // to it within some timeout period to avoid any autoplay surprises. |
1368 ScheduleIdlePauseTimer(); | 1369 ScheduleIdlePauseTimer(); |
1369 } | 1370 } |
1370 | 1371 |
1371 void WebMediaPlayerImpl::OnShown() { | 1372 void WebMediaPlayerImpl::OnShown() { |
1372 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1373 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1373 if (watch_time_reporter_) | 1374 if (watch_time_reporter_) |
1374 watch_time_reporter_->OnShown(); | 1375 watch_time_reporter_->OnShown(); |
1375 | 1376 |
1376 compositor_task_runner_->PostTask( | 1377 compositor_task_runner_->PostTask( |
1377 FROM_HERE, | 1378 FROM_HERE, |
1378 base::Bind(&VideoFrameCompositor::SetForegroundTime, | 1379 base::Bind(&VideoFrameCompositor::SetForegroundTime, |
1379 base::Unretained(compositor_), base::TimeTicks::Now())); | 1380 base::Unretained(compositor_), base::TimeTicks::Now())); |
1380 | 1381 |
1381 if (IsBackgroundVideoTrackOptimizationEnabled()) { | 1382 if (IsBackgroundVideoTrackOptimizationEnabled() && |
1383 ShouldDecodeFastWhenShown()) { | |
1382 if (paused_when_hidden_) { | 1384 if (paused_when_hidden_) { |
1383 paused_when_hidden_ = false; | 1385 paused_when_hidden_ = false; |
1384 OnPlay(); // Calls UpdatePlayState() so return afterwards. | 1386 OnPlay(); // Calls UpdatePlayState() so return afterwards. |
1385 return; | 1387 return; |
1386 } | 1388 } |
1387 | 1389 |
1388 if (client_->hasSelectedVideoTrack()) { | 1390 if (client_->hasSelectedVideoTrack()) { |
1389 WebMediaPlayer::TrackId trackId = client_->getSelectedVideoTrackId(); | 1391 WebMediaPlayer::TrackId trackId = client_->getSelectedVideoTrackId(); |
1390 selectedVideoTrackChanged(&trackId); | 1392 selectedVideoTrackChanged(&trackId); |
1391 } | 1393 } |
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2073 | 2075 |
2074 bool WebMediaPlayerImpl::ShouldPauseWhenHidden() const { | 2076 bool WebMediaPlayerImpl::ShouldPauseWhenHidden() const { |
2075 #if defined(OS_ANDROID) // WMPI_CAST | 2077 #if defined(OS_ANDROID) // WMPI_CAST |
2076 if (isRemote()) | 2078 if (isRemote()) |
2077 return false; | 2079 return false; |
2078 #endif // defined(OS_ANDROID) // WMPI_CAST | 2080 #endif // defined(OS_ANDROID) // WMPI_CAST |
2079 | 2081 |
2080 return hasVideo() && !hasAudio(); | 2082 return hasVideo() && !hasAudio(); |
2081 } | 2083 } |
2082 | 2084 |
2085 bool WebMediaPlayerImpl::ShouldDecodeFastWhenShown() const { | |
DaleCurtis
2017/01/09 20:29:54
This name is very strange. Something like IsVideoS
| |
2086 DCHECK(main_task_runner_->BelongsToCurrentThread()); | |
2087 | |
2088 PipelineStatistics stats = pipeline_.GetStatistics(); | |
2089 return stats.video_keyframe_distance_average_ms < | |
2090 max_keyframe_distance_for_fast_decode_.InMilliseconds(); | |
2091 } | |
2092 | |
2083 } // namespace media | 2093 } // namespace media |
OLD | NEW |