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

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

Issue 2810333007: [Video] Record the results of background video optimization checks.
Patch Set: Created 3 years, 8 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') | tools/metrics/histograms/histograms.xml » ('j') | 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 2177 matching lines...) Expand 10 before | Expand all | Expand 10 after
2188 } 2188 }
2189 2189
2190 bool WebMediaPlayerImpl::ShouldPauseVideoWhenHidden() const { 2190 bool WebMediaPlayerImpl::ShouldPauseVideoWhenHidden() const {
2191 // If suspending background video, pause any video that's not remoted or 2191 // If suspending background video, pause any video that's not remoted or
2192 // not unlocked to play in the background. 2192 // not unlocked to play in the background.
2193 if (IsBackgroundedSuspendEnabled()) { 2193 if (IsBackgroundedSuspendEnabled()) {
2194 if (!HasVideo()) 2194 if (!HasVideo())
2195 return false; 2195 return false;
2196 2196
2197 #if defined(OS_ANDROID) 2197 #if defined(OS_ANDROID)
2198 if (IsRemote()) 2198 if (IsRemote()) {
2199 UMA_HISTOGRAM_ENUMERATION("Media.Video.ShouldPauseVideoWhenHiddenResult",
2200 BackgroundOptimizationResult::FAIL_FOR_REMOTE,
2201 BackgroundOptimizationResult::RESULT_MAX + 1);
2199 return false; 2202 return false;
2203 }
2200 #endif 2204 #endif
2201 2205
2202 return !HasAudio() || (IsResumeBackgroundVideosEnabled() && 2206 if (!HasAudio()) {
2203 video_locked_when_paused_when_hidden_); 2207 ReportBackgroundOptimizationResult(
2208 BackgroundOptimizationResult::SUCCESS_FOR_VIDEO_ONLY);
2209 return true;
2210 }
2211
2212 // Non an optimization so don't record the result.
2213 return IsResumeBackgroundVideosEnabled() &&
2214 video_locked_when_paused_when_hidden_;
2204 } 2215 }
2205 2216
2206 // Otherwise only pause if the optimization is on and it's a video-only 2217 // Otherwise only pause if the optimization is on and it's a video-only
2207 // optimization candidate. 2218 // optimization candidate.
2208 return IsBackgroundVideoPauseOptimizationEnabled() && !HasAudio() && 2219 return IsBackgroundVideoPauseOptimizationEnabled() && !HasAudio() &&
2209 IsBackgroundOptimizationCandidate(); 2220 IsBackgroundOptimizationCandidate();
2210 } 2221 }
2211 2222
2212 bool WebMediaPlayerImpl::ShouldDisableVideoWhenHidden() const { 2223 bool WebMediaPlayerImpl::ShouldDisableVideoWhenHidden() const {
2213 // This optimization is behind the flag on all platforms. 2224 // This optimization is behind the flag on all platforms.
2214 if (!IsBackgroundVideoTrackOptimizationEnabled()) 2225 if (!IsBackgroundVideoTrackOptimizationEnabled())
2215 return false; 2226 return false;
2216 2227
2217 // Disable video track only for players with audio that match the criteria for 2228 // Disable video track only for players with audio that match the criteria for
2218 // being optimized. 2229 // being optimized.
2219 return HasAudio() && IsBackgroundOptimizationCandidate(); 2230 return HasAudio() && IsBackgroundOptimizationCandidate();
2220 } 2231 }
2221 2232
2222 bool WebMediaPlayerImpl::IsBackgroundOptimizationCandidate() const { 2233 bool WebMediaPlayerImpl::IsBackgroundOptimizationCandidate() const {
2223 DCHECK(main_task_runner_->BelongsToCurrentThread()); 2234 DCHECK(main_task_runner_->BelongsToCurrentThread());
2224 2235
2236 // Never optimize audio-only players.
2237 if (!HasVideo())
2238 return false;
2239
2225 #if defined(OS_ANDROID) // WMPI_CAST 2240 #if defined(OS_ANDROID) // WMPI_CAST
2226 // Don't optimize players being Cast. 2241 // Don't optimize players being Cast.
2227 if (IsRemote()) 2242 if (IsRemote()) {
2243 ReportBackgroundOptimizationResult(
2244 BackgroundOptimizationResult::FAIL_FOR_REMOTE);
2228 return false; 2245 return false;
2246 }
2229 2247
2230 // Video-only players are always optimized (paused) on Android. 2248 // Video-only players are always optimized (paused) on Android.
2231 // Don't check the keyframe distance and duration. 2249 // Don't check the keyframe distance and duration.
2232 if (!HasAudio() && HasVideo()) 2250 if (!HasAudio()) {
2251 ReportBackgroundOptimizationResult(
2252 BackgroundOptimizationResult::SUCCESS_FOR_VIDEO_ONLY);
2233 return true; 2253 return true;
2254 }
2234 #endif // defined(OS_ANDROID) 2255 #endif // defined(OS_ANDROID)
2235 2256
2236 // Don't optimize audio-only or streaming players. 2257 // Don't optimize audio-only or streaming players.
2237 if (!HasVideo() || IsStreaming()) 2258 if (IsStreaming()) {
2259 ReportBackgroundOptimizationResult(
2260 BackgroundOptimizationResult::FAIL_FOR_STREAMING);
2238 return false; 2261 return false;
2262 }
2239 2263
2240 // Videos shorter than the maximum allowed keyframe distance can be optimized. 2264 // Videos shorter than the maximum allowed keyframe distance can be optimized.
2241 base::TimeDelta duration = GetPipelineMediaDuration(); 2265 base::TimeDelta duration = GetPipelineMediaDuration();
2242 base::TimeDelta max_keyframe_distance = 2266 base::TimeDelta max_keyframe_distance =
2243 (load_type_ == kLoadTypeMediaSource) 2267 (load_type_ == kLoadTypeMediaSource)
2244 ? max_keyframe_distance_to_disable_background_video_mse_ 2268 ? max_keyframe_distance_to_disable_background_video_mse_
2245 : max_keyframe_distance_to_disable_background_video_; 2269 : max_keyframe_distance_to_disable_background_video_;
2246 if (duration < max_keyframe_distance) 2270 if (duration < max_keyframe_distance) {
2271 ReportBackgroundOptimizationResult(
2272 BackgroundOptimizationResult::SUCCESS_FOR_DURATION);
2247 return true; 2273 return true;
2274 }
2248 2275
2249 // Otherwise, only optimize videos with shorter average keyframe distance. 2276 // Otherwise, only optimize videos with shorter average keyframe distance.
2250 PipelineStatistics stats = GetPipelineStatistics(); 2277 PipelineStatistics stats = GetPipelineStatistics();
2251 return stats.video_keyframe_distance_average < max_keyframe_distance; 2278 bool is_candidate =
2279 stats.video_keyframe_distance_average < max_keyframe_distance;
2280 ReportBackgroundOptimizationResult(
2281 is_candidate ? BackgroundOptimizationResult::SUCCESS_FOR_KEYFRAME_DISTANCE
2282 : BackgroundOptimizationResult::FAIL_FOR_KEYFRAME_DISTANCE);
2283 return is_candidate;
2284 }
2285
2286 void WebMediaPlayerImpl::ReportBackgroundOptimizationResult(
2287 BackgroundOptimizationResult result) const {
2288 if (HasAudio()) {
2289 UMA_HISTOGRAM_ENUMERATION("Media.Video.ShouldDisableVideoWhenHiddenResult",
2290 result,
2291 BackgroundOptimizationResult::RESULT_MAX + 1);
2292 } else {
2293 UMA_HISTOGRAM_ENUMERATION("Media.Video.ShouldPauseVideoWhenHiddenResult",
2294 result,
2295 BackgroundOptimizationResult::RESULT_MAX + 1);
2296 }
2252 } 2297 }
2253 2298
2254 void WebMediaPlayerImpl::UpdateBackgroundVideoOptimizationState() { 2299 void WebMediaPlayerImpl::UpdateBackgroundVideoOptimizationState() {
2255 if (IsHidden()) { 2300 if (IsHidden()) {
2256 if (ShouldPauseVideoWhenHidden()) 2301 if (ShouldPauseVideoWhenHidden())
2257 PauseVideoIfNeeded(); 2302 PauseVideoIfNeeded();
2258 else 2303 else
2259 DisableVideoTrackIfNeeded(); 2304 DisableVideoTrackIfNeeded();
2260 } else { 2305 } else {
2261 EnableVideoTrackIfNeeded(); 2306 EnableVideoTrackIfNeeded();
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
2351 2396
2352 void WebMediaPlayerImpl::RecordUnderflowDuration(base::TimeDelta duration) { 2397 void WebMediaPlayerImpl::RecordUnderflowDuration(base::TimeDelta duration) {
2353 DCHECK(data_source_ || chunk_demuxer_); 2398 DCHECK(data_source_ || chunk_demuxer_);
2354 if (data_source_) 2399 if (data_source_)
2355 UMA_HISTOGRAM_TIMES("Media.UnderflowDuration", duration); 2400 UMA_HISTOGRAM_TIMES("Media.UnderflowDuration", duration);
2356 else 2401 else
2357 UMA_HISTOGRAM_TIMES("Media.UnderflowDuration.MSE", duration); 2402 UMA_HISTOGRAM_TIMES("Media.UnderflowDuration.MSE", duration);
2358 } 2403 }
2359 2404
2360 } // namespace media 2405 } // namespace media
OLDNEW
« no previous file with comments | « media/blink/webmediaplayer_impl.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698