| 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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 base::Unretained(this)), | 199 base::Unretained(this)), |
| 200 base::Bind(&WebMediaPlayerImpl::OnPipelineSeeked, AsWeakPtr()), | 200 base::Bind(&WebMediaPlayerImpl::OnPipelineSeeked, AsWeakPtr()), |
| 201 base::Bind(&WebMediaPlayerImpl::OnPipelineSuspended, AsWeakPtr()), | 201 base::Bind(&WebMediaPlayerImpl::OnPipelineSuspended, AsWeakPtr()), |
| 202 base::Bind(&WebMediaPlayerImpl::OnBeforePipelineResume, AsWeakPtr()), | 202 base::Bind(&WebMediaPlayerImpl::OnBeforePipelineResume, AsWeakPtr()), |
| 203 base::Bind(&WebMediaPlayerImpl::OnPipelineResumed, AsWeakPtr()), | 203 base::Bind(&WebMediaPlayerImpl::OnPipelineResumed, AsWeakPtr()), |
| 204 base::Bind(&WebMediaPlayerImpl::OnError, AsWeakPtr())), | 204 base::Bind(&WebMediaPlayerImpl::OnError, AsWeakPtr())), |
| 205 load_type_(LoadTypeURL), | 205 load_type_(LoadTypeURL), |
| 206 opaque_(false), | 206 opaque_(false), |
| 207 playback_rate_(0.0), | 207 playback_rate_(0.0), |
| 208 paused_(true), | 208 paused_(true), |
| 209 paused_when_hidden_(false), | 209 paused_when_background_(false), |
| 210 seeking_(false), | 210 seeking_(false), |
| 211 pending_suspend_resume_cycle_(false), | 211 pending_suspend_resume_cycle_(false), |
| 212 ended_(false), | 212 ended_(false), |
| 213 should_notify_time_changed_(false), | 213 should_notify_time_changed_(false), |
| 214 overlay_enabled_(false), | 214 overlay_enabled_(false), |
| 215 decoder_requires_restart_for_overlay_(false), | 215 decoder_requires_restart_for_overlay_(false), |
| 216 client_(client), | 216 client_(client), |
| 217 encrypted_client_(encrypted_client), | 217 encrypted_client_(encrypted_client), |
| 218 delegate_(delegate), | 218 delegate_(delegate), |
| 219 delegate_id_(0), | 219 delegate_id_(0), |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 | 446 |
| 447 void WebMediaPlayerImpl::pause() { | 447 void WebMediaPlayerImpl::pause() { |
| 448 DVLOG(1) << __func__; | 448 DVLOG(1) << __func__; |
| 449 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 449 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 450 | 450 |
| 451 // We update the paused state even when casting, since we expect pause() to be | 451 // We update the paused state even when casting, since we expect pause() to be |
| 452 // called when casting begins, and when we exit casting we should end up in a | 452 // called when casting begins, and when we exit casting we should end up in a |
| 453 // paused state. | 453 // paused state. |
| 454 paused_ = true; | 454 paused_ = true; |
| 455 | 455 |
| 456 // No longer paused because it was hidden. | 456 // No longer paused because it was backgrounded. |
| 457 paused_when_hidden_ = false; | 457 paused_when_background_ = false; |
| 458 | 458 |
| 459 #if defined(OS_ANDROID) // WMPI_CAST | 459 #if defined(OS_ANDROID) // WMPI_CAST |
| 460 if (isRemote()) { | 460 if (isRemote()) { |
| 461 cast_impl_.pause(); | 461 cast_impl_.pause(); |
| 462 return; | 462 return; |
| 463 } | 463 } |
| 464 #endif | 464 #endif |
| 465 | 465 |
| 466 pipeline_.SetPlaybackRate(0.0); | 466 pipeline_.SetPlaybackRate(0.0); |
| 467 | 467 |
| (...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1110 DCHECK(watch_time_reporter_); | 1110 DCHECK(watch_time_reporter_); |
| 1111 watch_time_reporter_->OnPlaying(); | 1111 watch_time_reporter_->OnPlaying(); |
| 1112 } | 1112 } |
| 1113 if (time_updated) | 1113 if (time_updated) |
| 1114 should_notify_time_changed_ = true; | 1114 should_notify_time_changed_ = true; |
| 1115 | 1115 |
| 1116 // Reset underflow count upon seek; this prevents looping videos and user | 1116 // Reset underflow count upon seek; this prevents looping videos and user |
| 1117 // actions from artificially inflating the underflow count. | 1117 // actions from artificially inflating the underflow count. |
| 1118 underflow_count_ = 0; | 1118 underflow_count_ = 0; |
| 1119 | 1119 |
| 1120 // Background video optimizations are delayed when shown/hidden if pipeline | 1120 // Background video optimizations are delayed when if pipeline |
| 1121 // is seeking. | 1121 // is seeking when the video goes to the background or the foreground. |
| 1122 UpdateBackgroundVideoOptimizationState(); | 1122 UpdateBackgroundVideoOptimizationState(); |
| 1123 } | 1123 } |
| 1124 | 1124 |
| 1125 void WebMediaPlayerImpl::OnPipelineSuspended() { | 1125 void WebMediaPlayerImpl::OnPipelineSuspended() { |
| 1126 #if defined(OS_ANDROID) | 1126 #if defined(OS_ANDROID) |
| 1127 if (isRemote()) { | 1127 if (isRemote()) { |
| 1128 scoped_refptr<VideoFrame> frame = cast_impl_.GetCastingBanner(); | 1128 scoped_refptr<VideoFrame> frame = cast_impl_.GetCastingBanner(); |
| 1129 if (frame) | 1129 if (frame) |
| 1130 compositor_->PaintSingleFrame(frame); | 1130 compositor_->PaintSingleFrame(frame); |
| 1131 } | 1131 } |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1398 if (video_weblayer_) | 1398 if (video_weblayer_) |
| 1399 video_weblayer_->layer()->SetContentsOpaque(opaque_); | 1399 video_weblayer_->layer()->SetContentsOpaque(opaque_); |
| 1400 } | 1400 } |
| 1401 | 1401 |
| 1402 void WebMediaPlayerImpl::OnFrameHidden() { | 1402 void WebMediaPlayerImpl::OnFrameHidden() { |
| 1403 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1403 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1404 | 1404 |
| 1405 if (watch_time_reporter_) | 1405 if (watch_time_reporter_) |
| 1406 watch_time_reporter_->OnHidden(); | 1406 watch_time_reporter_->OnHidden(); |
| 1407 | 1407 |
| 1408 // OnFrameHidden() can be called when frame is closed, then IsHidden() will | 1408 if (IsBackgrounded()) { |
| 1409 // return false, so check explicitly. | 1409 if (ShouldPauseVideoWhenBackground()) { |
| 1410 if (IsHidden()) { | |
| 1411 if (ShouldPauseVideoWhenHidden()) { | |
| 1412 PauseVideoIfNeeded(); | 1410 PauseVideoIfNeeded(); |
| 1413 return; | 1411 return; |
| 1414 } else { | 1412 } else { |
| 1415 DisableVideoTrackIfNeeded(); | 1413 DisableVideoTrackIfNeeded(); |
| 1416 } | 1414 } |
| 1417 } | 1415 } |
| 1418 | 1416 |
| 1419 UpdatePlayState(); | 1417 UpdatePlayState(); |
| 1420 | 1418 |
| 1421 // Schedule suspended playing media to be paused if the user doesn't come back | 1419 // Schedule suspended playing media to be paused if the user doesn't come back |
| 1422 // to it within some timeout period to avoid any autoplay surprises. | 1420 // to it within some timeout period to avoid any autoplay surprises. |
| 1423 ScheduleIdlePauseTimer(); | 1421 ScheduleIdlePauseTimer(); |
| 1424 } | 1422 } |
| 1425 | 1423 |
| 1426 void WebMediaPlayerImpl::OnFrameClosed() { | 1424 void WebMediaPlayerImpl::OnFrameClosed() { |
| 1427 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1425 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1428 UpdatePlayState(); | 1426 UpdatePlayState(); |
| 1429 } | 1427 } |
| 1430 | 1428 |
| 1431 void WebMediaPlayerImpl::OnFrameShown() { | 1429 void WebMediaPlayerImpl::OnFrameShown() { |
| 1432 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1430 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1433 background_pause_timer_.Stop(); | 1431 background_pause_timer_.Stop(); |
| 1434 | 1432 |
| 1435 if (watch_time_reporter_) | 1433 if (watch_time_reporter_) |
| 1436 watch_time_reporter_->OnShown(); | 1434 watch_time_reporter_->OnShown(); |
| 1437 | 1435 |
| 1438 // Only track the time to the first frame if playing or about to play because | 1436 // Only track the time to the first frame if playing or about to play because |
| 1439 // of being shown and only for videos we would optimize background playback | 1437 // of being foregrounded and only for videos we would optimize background |
| 1440 // for. | 1438 // playback for. |
| 1441 if ((!paused_ && IsBackgroundOptimizationCandidate()) || | 1439 if ((!paused_ && IsBackgroundOptimizationCandidate()) || |
| 1442 paused_when_hidden_) { | 1440 paused_when_background_) { |
| 1443 VideoFrameCompositor::OnNewProcessedFrameCB new_processed_frame_cb = | 1441 VideoFrameCompositor::OnNewProcessedFrameCB new_processed_frame_cb = |
| 1444 BIND_TO_RENDER_LOOP1( | 1442 BIND_TO_RENDER_LOOP1( |
| 1445 &WebMediaPlayerImpl::ReportTimeFromForegroundToFirstFrame, | 1443 &WebMediaPlayerImpl::ReportTimeFromForegroundToFirstFrame, |
| 1446 base::TimeTicks::Now()); | 1444 base::TimeTicks::Now()); |
| 1447 compositor_task_runner_->PostTask( | 1445 compositor_task_runner_->PostTask( |
| 1448 FROM_HERE, | 1446 FROM_HERE, |
| 1449 base::Bind(&VideoFrameCompositor::SetOnNewProcessedFrameCallback, | 1447 base::Bind(&VideoFrameCompositor::SetOnNewProcessedFrameCallback, |
| 1450 base::Unretained(compositor_), new_processed_frame_cb)); | 1448 base::Unretained(compositor_), new_processed_frame_cb)); |
| 1451 } | 1449 } |
| 1452 | 1450 |
| 1453 if (paused_when_hidden_) { | 1451 if (paused_when_background_) { |
| 1454 paused_when_hidden_ = false; | 1452 paused_when_background_ = false; |
| 1455 OnPlay(); // Calls UpdatePlayState() so return afterwards. | 1453 OnPlay(); // Calls UpdatePlayState() so return afterwards. |
| 1456 return; | 1454 return; |
| 1457 } | 1455 } |
| 1458 | 1456 |
| 1459 EnableVideoTrackIfNeeded(); | 1457 EnableVideoTrackIfNeeded(); |
| 1460 | 1458 |
| 1461 UpdatePlayState(); | 1459 UpdatePlayState(); |
| 1462 } | 1460 } |
| 1463 | 1461 |
| 1464 void WebMediaPlayerImpl::OnIdleTimeout() { | 1462 void WebMediaPlayerImpl::OnIdleTimeout() { |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1797 | 1795 |
| 1798 #if defined(OS_ANDROID) // WMPI_CAST | 1796 #if defined(OS_ANDROID) // WMPI_CAST |
| 1799 bool is_remote = isRemote(); | 1797 bool is_remote = isRemote(); |
| 1800 bool is_streaming = false; | 1798 bool is_streaming = false; |
| 1801 #else | 1799 #else |
| 1802 bool is_remote = false; | 1800 bool is_remote = false; |
| 1803 bool is_streaming = IsStreaming(); | 1801 bool is_streaming = IsStreaming(); |
| 1804 #endif | 1802 #endif |
| 1805 | 1803 |
| 1806 bool is_suspended = pipeline_controller_.IsSuspended(); | 1804 bool is_suspended = pipeline_controller_.IsSuspended(); |
| 1807 bool is_backgrounded = IsBackgroundedSuspendEnabled() && IsHidden(); | 1805 bool is_backgrounded = IsBackgroundedSuspendEnabled() && IsBackgrounded(); |
| 1808 PlayState state = UpdatePlayState_ComputePlayState( | 1806 PlayState state = UpdatePlayState_ComputePlayState( |
| 1809 is_remote, is_streaming, is_suspended, is_backgrounded); | 1807 is_remote, is_streaming, is_suspended, is_backgrounded); |
| 1810 SetDelegateState(state.delegate_state, state.is_idle); | 1808 SetDelegateState(state.delegate_state, state.is_idle); |
| 1811 SetMemoryReportingState(state.is_memory_reporting_enabled); | 1809 SetMemoryReportingState(state.is_memory_reporting_enabled); |
| 1812 SetSuspendState(state.is_suspended || pending_suspend_resume_cycle_); | 1810 SetSuspendState(state.is_suspended || pending_suspend_resume_cycle_); |
| 1813 } | 1811 } |
| 1814 | 1812 |
| 1815 void WebMediaPlayerImpl::SetDelegateState(DelegateState new_state, | 1813 void WebMediaPlayerImpl::SetDelegateState(DelegateState new_state, |
| 1816 bool is_idle) { | 1814 bool is_idle) { |
| 1817 DCHECK(delegate_); | 1815 DCHECK(delegate_); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1942 bool background_suspended = !is_streaming && is_backgrounded_video && | 1940 bool background_suspended = !is_streaming && is_backgrounded_video && |
| 1943 !(can_play_backgrounded && is_background_playing); | 1941 !(can_play_backgrounded && is_background_playing); |
| 1944 bool background_pause_suspended = | 1942 bool background_pause_suspended = |
| 1945 !is_streaming && is_backgrounded && paused_ && have_future_data; | 1943 !is_streaming && is_backgrounded && paused_ && have_future_data; |
| 1946 | 1944 |
| 1947 // Idle suspension is allowed prior to have future data since there exist | 1945 // Idle suspension is allowed prior to have future data since there exist |
| 1948 // mechanisms to exit the idle state when the player is capable of reaching | 1946 // mechanisms to exit the idle state when the player is capable of reaching |
| 1949 // the have future data state; see didLoadingProgress(). | 1947 // the have future data state; see didLoadingProgress(). |
| 1950 // | 1948 // |
| 1951 // TODO(sandersd): Make the delegate suspend idle players immediately when | 1949 // TODO(sandersd): Make the delegate suspend idle players immediately when |
| 1952 // hidden. | 1950 // in the background. |
| 1953 bool idle_suspended = | 1951 bool idle_suspended = |
| 1954 !is_streaming && is_stale && paused_ && !seeking_ && !overlay_enabled_; | 1952 !is_streaming && is_stale && paused_ && !seeking_ && !overlay_enabled_; |
| 1955 | 1953 |
| 1956 // If we're already suspended, see if we can wait for user interaction. Prior | 1954 // If we're already suspended, see if we can wait for user interaction. Prior |
| 1957 // to HaveFutureData, we require |is_stale| to remain suspended. |is_stale| | 1955 // to HaveFutureData, we require |is_stale| to remain suspended. |is_stale| |
| 1958 // will be cleared when we receive data which may take us to HaveFutureData. | 1956 // will be cleared when we receive data which may take us to HaveFutureData. |
| 1959 bool can_stay_suspended = | 1957 bool can_stay_suspended = |
| 1960 (is_stale || have_future_data) && is_suspended && paused_ && !seeking_; | 1958 (is_stale || have_future_data) && is_suspended && paused_ && !seeking_; |
| 1961 | 1959 |
| 1962 // Combined suspend state. | 1960 // Combined suspend state. |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2096 hasAudio(), hasVideo(), !!chunk_demuxer_, is_encrypted_, media_log_, | 2094 hasAudio(), hasVideo(), !!chunk_demuxer_, is_encrypted_, media_log_, |
| 2097 pipeline_metadata_.natural_size, | 2095 pipeline_metadata_.natural_size, |
| 2098 base::Bind(&GetCurrentTimeInternal, this))); | 2096 base::Bind(&GetCurrentTimeInternal, this))); |
| 2099 watch_time_reporter_->OnVolumeChange(volume_); | 2097 watch_time_reporter_->OnVolumeChange(volume_); |
| 2100 if (delegate_->IsFrameHidden()) | 2098 if (delegate_->IsFrameHidden()) |
| 2101 watch_time_reporter_->OnHidden(); | 2099 watch_time_reporter_->OnHidden(); |
| 2102 else | 2100 else |
| 2103 watch_time_reporter_->OnShown(); | 2101 watch_time_reporter_->OnShown(); |
| 2104 } | 2102 } |
| 2105 | 2103 |
| 2106 bool WebMediaPlayerImpl::IsHidden() const { | 2104 bool WebMediaPlayerImpl::IsBackgrounded() const { |
| 2107 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 2105 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 2108 | 2106 |
| 2107 // Nothing related to the media being in the background should matter if the |
| 2108 // frame is closed. However, the delegate might call OnFrameHidden() when |
| 2109 // closed so specifically exclude this case. |
| 2109 return delegate_->IsFrameHidden() && !delegate_->IsFrameClosed(); | 2110 return delegate_->IsFrameHidden() && !delegate_->IsFrameClosed(); |
| 2110 } | 2111 } |
| 2111 | 2112 |
| 2112 bool WebMediaPlayerImpl::IsStreaming() const { | 2113 bool WebMediaPlayerImpl::IsStreaming() const { |
| 2113 return data_source_ && data_source_->IsStreaming(); | 2114 return data_source_ && data_source_->IsStreaming(); |
| 2114 } | 2115 } |
| 2115 | 2116 |
| 2116 bool WebMediaPlayerImpl::DoesOverlaySupportMetadata() const { | 2117 bool WebMediaPlayerImpl::DoesOverlaySupportMetadata() const { |
| 2117 return pipeline_metadata_.video_rotation == VIDEO_ROTATION_0; | 2118 return pipeline_metadata_.video_rotation == VIDEO_ROTATION_0; |
| 2118 } | 2119 } |
| 2119 | 2120 |
| 2120 void WebMediaPlayerImpl::ActivateViewportIntersectionMonitoring(bool activate) { | 2121 void WebMediaPlayerImpl::ActivateViewportIntersectionMonitoring(bool activate) { |
| 2121 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 2122 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 2122 | 2123 |
| 2123 client_->activateViewportIntersectionMonitoring(activate); | 2124 client_->activateViewportIntersectionMonitoring(activate); |
| 2124 } | 2125 } |
| 2125 | 2126 |
| 2126 bool WebMediaPlayerImpl::ShouldPauseVideoWhenHidden() const { | 2127 bool WebMediaPlayerImpl::ShouldPauseVideoWhenBackground() const { |
| 2127 #if !defined(OS_ANDROID) | 2128 #if !defined(OS_ANDROID) |
| 2128 // On desktop, this behavior is behind the feature flag. | 2129 // On desktop, this behavior is behind the feature flag. |
| 2129 if (!IsBackgroundVideoTrackOptimizationEnabled()) | 2130 if (!IsBackgroundVideoTrackOptimizationEnabled()) |
| 2130 return false; | 2131 return false; |
| 2131 #endif | 2132 #endif |
| 2132 | 2133 |
| 2133 // Pause video-only players that match the criteria for being optimized. | 2134 // Pause video-only players that match the criteria for being optimized. |
| 2134 return !hasAudio() && IsBackgroundOptimizationCandidate(); | 2135 return !hasAudio() && IsBackgroundOptimizationCandidate(); |
| 2135 } | 2136 } |
| 2136 | 2137 |
| 2137 bool WebMediaPlayerImpl::ShouldDisableVideoWhenHidden() const { | 2138 bool WebMediaPlayerImpl::ShouldDisableVideoWhenBackground() const { |
| 2138 // This optimization is behind the flag on all platforms. | 2139 // This optimization is behind the flag on all platforms. |
| 2139 if (!IsBackgroundVideoTrackOptimizationEnabled()) | 2140 if (!IsBackgroundVideoTrackOptimizationEnabled()) |
| 2140 return false; | 2141 return false; |
| 2141 | 2142 |
| 2142 // Disable video track only for players with audio that match the criteria for | 2143 // Disable video track only for players with audio that match the criteria for |
| 2143 // being optimized. | 2144 // being optimized. |
| 2144 return hasAudio() && IsBackgroundOptimizationCandidate(); | 2145 return hasAudio() && IsBackgroundOptimizationCandidate(); |
| 2145 } | 2146 } |
| 2146 | 2147 |
| 2147 bool WebMediaPlayerImpl::IsBackgroundOptimizationCandidate() const { | 2148 bool WebMediaPlayerImpl::IsBackgroundOptimizationCandidate() const { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2167 if (duration < max_keyframe_distance_to_disable_background_video_) | 2168 if (duration < max_keyframe_distance_to_disable_background_video_) |
| 2168 return true; | 2169 return true; |
| 2169 | 2170 |
| 2170 // Otherwise, only optimize videos with shorter average keyframe distance. | 2171 // Otherwise, only optimize videos with shorter average keyframe distance. |
| 2171 PipelineStatistics stats = GetPipelineStatistics(); | 2172 PipelineStatistics stats = GetPipelineStatistics(); |
| 2172 return stats.video_keyframe_distance_average < | 2173 return stats.video_keyframe_distance_average < |
| 2173 max_keyframe_distance_to_disable_background_video_; | 2174 max_keyframe_distance_to_disable_background_video_; |
| 2174 } | 2175 } |
| 2175 | 2176 |
| 2176 void WebMediaPlayerImpl::UpdateBackgroundVideoOptimizationState() { | 2177 void WebMediaPlayerImpl::UpdateBackgroundVideoOptimizationState() { |
| 2177 if (IsHidden()) { | 2178 if (IsBackgrounded()) { |
| 2178 if (ShouldPauseVideoWhenHidden()) | 2179 if (ShouldPauseVideoWhenBackground()) |
| 2179 PauseVideoIfNeeded(); | 2180 PauseVideoIfNeeded(); |
| 2180 else | 2181 else |
| 2181 DisableVideoTrackIfNeeded(); | 2182 DisableVideoTrackIfNeeded(); |
| 2182 } else { | 2183 } else { |
| 2183 EnableVideoTrackIfNeeded(); | 2184 EnableVideoTrackIfNeeded(); |
| 2184 } | 2185 } |
| 2185 } | 2186 } |
| 2186 | 2187 |
| 2187 void WebMediaPlayerImpl::PauseVideoIfNeeded() { | 2188 void WebMediaPlayerImpl::PauseVideoIfNeeded() { |
| 2188 DCHECK(IsHidden()); | 2189 DCHECK(IsBackgrounded()); |
| 2189 | 2190 |
| 2190 // Don't pause video while the pipeline is stopped, resuming or seeking. | 2191 // Don't pause video while the pipeline is stopped, resuming or seeking. |
| 2191 // Also if the video is paused already. | 2192 // Also if the video is paused already. |
| 2192 if (!pipeline_.IsRunning() || is_pipeline_resuming_ || seeking_ || paused_) | 2193 if (!pipeline_.IsRunning() || is_pipeline_resuming_ || seeking_ || paused_) |
| 2193 return; | 2194 return; |
| 2194 | 2195 |
| 2195 // OnPause() will set |paused_when_hidden_| to false and call | 2196 // OnPause() will set |paused_when_background_| to false and call |
| 2196 // UpdatePlayState(), so set the flag to true after and then return. | 2197 // UpdatePlayState(), so set the flag to true after and then return. |
| 2197 OnPause(); | 2198 OnPause(); |
| 2198 paused_when_hidden_ = true; | 2199 paused_when_background_ = true; |
| 2199 } | 2200 } |
| 2200 | 2201 |
| 2201 void WebMediaPlayerImpl::EnableVideoTrackIfNeeded() { | 2202 void WebMediaPlayerImpl::EnableVideoTrackIfNeeded() { |
| 2202 // Don't change video track while the pipeline is stopped, resuming or | 2203 // Don't change video track while the pipeline is stopped, resuming or |
| 2203 // seeking. | 2204 // seeking. |
| 2204 if (!pipeline_.IsRunning() || is_pipeline_resuming_ || seeking_) | 2205 if (!pipeline_.IsRunning() || is_pipeline_resuming_ || seeking_) |
| 2205 return; | 2206 return; |
| 2206 | 2207 |
| 2207 if (video_track_disabled_) { | 2208 if (video_track_disabled_) { |
| 2208 video_track_disabled_ = false; | 2209 video_track_disabled_ = false; |
| 2209 if (client_->hasSelectedVideoTrack()) { | 2210 if (client_->hasSelectedVideoTrack()) { |
| 2210 WebMediaPlayer::TrackId trackId = client_->getSelectedVideoTrackId(); | 2211 WebMediaPlayer::TrackId trackId = client_->getSelectedVideoTrackId(); |
| 2211 selectedVideoTrackChanged(&trackId); | 2212 selectedVideoTrackChanged(&trackId); |
| 2212 } | 2213 } |
| 2213 } | 2214 } |
| 2214 } | 2215 } |
| 2215 | 2216 |
| 2216 void WebMediaPlayerImpl::DisableVideoTrackIfNeeded() { | 2217 void WebMediaPlayerImpl::DisableVideoTrackIfNeeded() { |
| 2217 DCHECK(IsHidden()); | 2218 DCHECK(IsBackgrounded()); |
| 2218 | 2219 |
| 2219 // Don't change video track while the pipeline is resuming or seeking. | 2220 // Don't change video track while the pipeline is resuming or seeking. |
| 2220 if (is_pipeline_resuming_ || seeking_) | 2221 if (is_pipeline_resuming_ || seeking_) |
| 2221 return; | 2222 return; |
| 2222 | 2223 |
| 2223 if (!video_track_disabled_ && ShouldDisableVideoWhenHidden()) { | 2224 if (!video_track_disabled_ && ShouldDisableVideoWhenBackground()) { |
| 2224 video_track_disabled_ = true; | 2225 video_track_disabled_ = true; |
| 2225 selectedVideoTrackChanged(nullptr); | 2226 selectedVideoTrackChanged(nullptr); |
| 2226 } | 2227 } |
| 2227 } | 2228 } |
| 2228 | 2229 |
| 2229 void WebMediaPlayerImpl::SetPipelineStatisticsForTest( | 2230 void WebMediaPlayerImpl::SetPipelineStatisticsForTest( |
| 2230 const PipelineStatistics& stats) { | 2231 const PipelineStatistics& stats) { |
| 2231 pipeline_statistics_for_test_ = base::make_optional(stats); | 2232 pipeline_statistics_for_test_ = base::make_optional(stats); |
| 2232 } | 2233 } |
| 2233 | 2234 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 2257 UMA_HISTOGRAM_TIMES( | 2258 UMA_HISTOGRAM_TIMES( |
| 2258 "Media.Video.TimeFromForegroundToFirstFrame.DisableTrack", | 2259 "Media.Video.TimeFromForegroundToFirstFrame.DisableTrack", |
| 2259 time_to_first_frame); | 2260 time_to_first_frame); |
| 2260 } else { | 2261 } else { |
| 2261 UMA_HISTOGRAM_TIMES("Media.Video.TimeFromForegroundToFirstFrame.Paused", | 2262 UMA_HISTOGRAM_TIMES("Media.Video.TimeFromForegroundToFirstFrame.Paused", |
| 2262 time_to_first_frame); | 2263 time_to_first_frame); |
| 2263 } | 2264 } |
| 2264 } | 2265 } |
| 2265 | 2266 |
| 2266 } // namespace media | 2267 } // namespace media |
| OLD | NEW |