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 1143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1154 // TODO(avayvod): Remove this when disabling and enabling video tracks in | 1154 // TODO(avayvod): Remove this when disabling and enabling video tracks in |
1155 // non-playing state works correctly. See https://crbug.com/678374. | 1155 // non-playing state works correctly. See https://crbug.com/678374. |
1156 EnableVideoTrackIfNeeded(); | 1156 EnableVideoTrackIfNeeded(); |
1157 is_pipeline_resuming_ = true; | 1157 is_pipeline_resuming_ = true; |
1158 } | 1158 } |
1159 | 1159 |
1160 void WebMediaPlayerImpl::OnPipelineResumed() { | 1160 void WebMediaPlayerImpl::OnPipelineResumed() { |
1161 is_pipeline_resuming_ = false; | 1161 is_pipeline_resuming_ = false; |
1162 | 1162 |
1163 if (IsHidden()) { | 1163 if (IsHidden()) { |
1164 DisableVideoTrackIfNeeded(); | 1164 if (ShouldPauseVideoWhenHidden()) |
1165 PauseVideoIfNeeded(); | |
1166 else | |
1167 DisableVideoTrackIfNeeded(); | |
1165 } else { | 1168 } else { |
1166 EnableVideoTrackIfNeeded(); | 1169 EnableVideoTrackIfNeeded(); |
1167 } | 1170 } |
1168 } | 1171 } |
1169 | 1172 |
1170 void WebMediaPlayerImpl::OnDemuxerOpened() { | 1173 void WebMediaPlayerImpl::OnDemuxerOpened() { |
1171 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1174 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1172 client_->mediaSourceOpened( | 1175 client_->mediaSourceOpened( |
1173 new WebMediaSourceImpl(chunk_demuxer_, media_log_)); | 1176 new WebMediaSourceImpl(chunk_demuxer_, media_log_)); |
1174 } | 1177 } |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1404 video_weblayer_->layer()->SetContentsOpaque(opaque_); | 1407 video_weblayer_->layer()->SetContentsOpaque(opaque_); |
1405 } | 1408 } |
1406 | 1409 |
1407 void WebMediaPlayerImpl::OnFrameHidden() { | 1410 void WebMediaPlayerImpl::OnFrameHidden() { |
1408 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1411 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1409 | 1412 |
1410 if (watch_time_reporter_) | 1413 if (watch_time_reporter_) |
1411 watch_time_reporter_->OnHidden(); | 1414 watch_time_reporter_->OnHidden(); |
1412 | 1415 |
1413 if (ShouldPauseVideoWhenHidden()) { | 1416 if (ShouldPauseVideoWhenHidden()) { |
1414 if (!paused_when_hidden_) { | 1417 PauseVideoIfNeeded(); |
1415 // OnPause() will set |paused_when_hidden_| to false and call | 1418 return; |
1416 // UpdatePlayState(), so set the flag to true after and then return. | |
1417 OnPause(); | |
1418 paused_when_hidden_ = true; | |
1419 return; | |
1420 } | |
1421 } else { | 1419 } else { |
1422 DisableVideoTrackIfNeeded(); | 1420 DisableVideoTrackIfNeeded(); |
1423 } | 1421 } |
1424 | 1422 |
1425 UpdatePlayState(); | 1423 UpdatePlayState(); |
1426 | 1424 |
1427 // Schedule suspended playing media to be paused if the user doesn't come back | 1425 // Schedule suspended playing media to be paused if the user doesn't come back |
1428 // to it within some timeout period to avoid any autoplay surprises. | 1426 // to it within some timeout period to avoid any autoplay surprises. |
1429 ScheduleIdlePauseTimer(); | 1427 ScheduleIdlePauseTimer(); |
1430 } | 1428 } |
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2175 base::TimeDelta duration = GetPipelineMediaDuration(); | 2173 base::TimeDelta duration = GetPipelineMediaDuration(); |
2176 if (duration < max_keyframe_distance_to_disable_background_video_) | 2174 if (duration < max_keyframe_distance_to_disable_background_video_) |
2177 return true; | 2175 return true; |
2178 | 2176 |
2179 // Otherwise, only optimize videos with shorter average keyframe distance. | 2177 // Otherwise, only optimize videos with shorter average keyframe distance. |
2180 PipelineStatistics stats = GetPipelineStatistics(); | 2178 PipelineStatistics stats = GetPipelineStatistics(); |
2181 return stats.video_keyframe_distance_average < | 2179 return stats.video_keyframe_distance_average < |
2182 max_keyframe_distance_to_disable_background_video_; | 2180 max_keyframe_distance_to_disable_background_video_; |
2183 } | 2181 } |
2184 | 2182 |
2183 void WebMediaPlayerImpl::PauseVideoIfNeeded() { | |
2184 if (is_pipeline_resuming_ || seeking_ || paused_ || paused_when_hidden_) | |
sandersd (OOO until July 31)
2017/01/20 21:24:19
Require or DCHECK IsHidden?
Do we need to also ch
| |
2185 return; | |
2186 | |
2187 // OnPause() will set |paused_when_hidden_| to false and call | |
2188 // UpdatePlayState(), so set the flag to true after and then return. | |
2189 OnPause(); | |
2190 paused_when_hidden_ = true; | |
2191 } | |
2192 | |
2185 void WebMediaPlayerImpl::EnableVideoTrackIfNeeded() { | 2193 void WebMediaPlayerImpl::EnableVideoTrackIfNeeded() { |
2186 DCHECK(!IsHidden()); | 2194 DCHECK(!IsHidden()); |
2187 | 2195 |
2188 // Don't change video track while the pipeline is resuming or seeking. | 2196 // Don't change video track while the pipeline is resuming or seeking. |
2189 if (is_pipeline_resuming_ || seeking_) | 2197 if (is_pipeline_resuming_ || seeking_) |
2190 return; | 2198 return; |
2191 | 2199 |
2192 if (video_track_disabled_) { | 2200 if (video_track_disabled_) { |
2193 video_track_disabled_ = false; | 2201 video_track_disabled_ = false; |
2194 if (client_->hasSelectedVideoTrack()) { | 2202 if (client_->hasSelectedVideoTrack()) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2242 UMA_HISTOGRAM_TIMES( | 2250 UMA_HISTOGRAM_TIMES( |
2243 "Media.Video.TimeFromForegroundToFirstFrame.DisableTrack", | 2251 "Media.Video.TimeFromForegroundToFirstFrame.DisableTrack", |
2244 time_to_first_frame); | 2252 time_to_first_frame); |
2245 } else { | 2253 } else { |
2246 UMA_HISTOGRAM_TIMES("Media.Video.TimeFromForegroundToFirstFrame.Paused", | 2254 UMA_HISTOGRAM_TIMES("Media.Video.TimeFromForegroundToFirstFrame.Paused", |
2247 time_to_first_frame); | 2255 time_to_first_frame); |
2248 } | 2256 } |
2249 } | 2257 } |
2250 | 2258 |
2251 } // namespace media | 2259 } // namespace media |
OLD | NEW |