Index: media/blink/webmediaplayer_impl.cc |
diff --git a/media/blink/webmediaplayer_impl.cc b/media/blink/webmediaplayer_impl.cc |
index 96ba8b569f4cc125fcd33c88f230e590f4ec849a..0bb3a568e59bef67d1eca4aa101e2c64bcbc2017 100644 |
--- a/media/blink/webmediaplayer_impl.cc |
+++ b/media/blink/webmediaplayer_impl.cc |
@@ -2195,12 +2195,23 @@ bool WebMediaPlayerImpl::ShouldPauseVideoWhenHidden() const { |
return false; |
#if defined(OS_ANDROID) |
- if (IsRemote()) |
+ if (IsRemote()) { |
+ UMA_HISTOGRAM_ENUMERATION("Media.Video.ShouldPauseVideoWhenHiddenResult", |
+ BackgroundOptimizationResult::FAIL_FOR_REMOTE, |
+ BackgroundOptimizationResult::RESULT_MAX + 1); |
return false; |
+ } |
#endif |
- return !HasAudio() || (IsResumeBackgroundVideosEnabled() && |
- video_locked_when_paused_when_hidden_); |
+ if (!HasAudio()) { |
+ ReportBackgroundOptimizationResult( |
+ BackgroundOptimizationResult::SUCCESS_FOR_VIDEO_ONLY); |
+ return true; |
+ } |
+ |
+ // Non an optimization so don't record the result. |
+ return IsResumeBackgroundVideosEnabled() && |
+ video_locked_when_paused_when_hidden_; |
} |
// Otherwise only pause if the optimization is on and it's a video-only |
@@ -2222,20 +2233,33 @@ bool WebMediaPlayerImpl::ShouldDisableVideoWhenHidden() const { |
bool WebMediaPlayerImpl::IsBackgroundOptimizationCandidate() const { |
DCHECK(main_task_runner_->BelongsToCurrentThread()); |
+ // Never optimize audio-only players. |
+ if (!HasVideo()) |
+ return false; |
+ |
#if defined(OS_ANDROID) // WMPI_CAST |
// Don't optimize players being Cast. |
- if (IsRemote()) |
+ if (IsRemote()) { |
+ ReportBackgroundOptimizationResult( |
+ BackgroundOptimizationResult::FAIL_FOR_REMOTE); |
return false; |
+ } |
// Video-only players are always optimized (paused) on Android. |
// Don't check the keyframe distance and duration. |
- if (!HasAudio() && HasVideo()) |
+ if (!HasAudio()) { |
+ ReportBackgroundOptimizationResult( |
+ BackgroundOptimizationResult::SUCCESS_FOR_VIDEO_ONLY); |
return true; |
+ } |
#endif // defined(OS_ANDROID) |
// Don't optimize audio-only or streaming players. |
- if (!HasVideo() || IsStreaming()) |
+ if (IsStreaming()) { |
+ ReportBackgroundOptimizationResult( |
+ BackgroundOptimizationResult::FAIL_FOR_STREAMING); |
return false; |
+ } |
// Videos shorter than the maximum allowed keyframe distance can be optimized. |
base::TimeDelta duration = GetPipelineMediaDuration(); |
@@ -2243,12 +2267,33 @@ bool WebMediaPlayerImpl::IsBackgroundOptimizationCandidate() const { |
(load_type_ == kLoadTypeMediaSource) |
? max_keyframe_distance_to_disable_background_video_mse_ |
: max_keyframe_distance_to_disable_background_video_; |
- if (duration < max_keyframe_distance) |
+ if (duration < max_keyframe_distance) { |
+ ReportBackgroundOptimizationResult( |
+ BackgroundOptimizationResult::SUCCESS_FOR_DURATION); |
return true; |
+ } |
// Otherwise, only optimize videos with shorter average keyframe distance. |
PipelineStatistics stats = GetPipelineStatistics(); |
- return stats.video_keyframe_distance_average < max_keyframe_distance; |
+ bool is_candidate = |
+ stats.video_keyframe_distance_average < max_keyframe_distance; |
+ ReportBackgroundOptimizationResult( |
+ is_candidate ? BackgroundOptimizationResult::SUCCESS_FOR_KEYFRAME_DISTANCE |
+ : BackgroundOptimizationResult::FAIL_FOR_KEYFRAME_DISTANCE); |
+ return is_candidate; |
+} |
+ |
+void WebMediaPlayerImpl::ReportBackgroundOptimizationResult( |
+ BackgroundOptimizationResult result) const { |
+ if (HasAudio()) { |
+ UMA_HISTOGRAM_ENUMERATION("Media.Video.ShouldDisableVideoWhenHiddenResult", |
+ result, |
+ BackgroundOptimizationResult::RESULT_MAX + 1); |
+ } else { |
+ UMA_HISTOGRAM_ENUMERATION("Media.Video.ShouldPauseVideoWhenHiddenResult", |
+ result, |
+ BackgroundOptimizationResult::RESULT_MAX + 1); |
+ } |
} |
void WebMediaPlayerImpl::UpdateBackgroundVideoOptimizationState() { |