| 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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 surface_manager_(params.surface_manager()), | 230 surface_manager_(params.surface_manager()), |
| 231 overlay_surface_id_(SurfaceManager::kNoSurfaceID), | 231 overlay_surface_id_(SurfaceManager::kNoSurfaceID), |
| 232 suppress_destruction_errors_(false), | 232 suppress_destruction_errors_(false), |
| 233 suspend_enabled_(params.allow_suspend()), | 233 suspend_enabled_(params.allow_suspend()), |
| 234 use_fallback_path_(false), | 234 use_fallback_path_(false), |
| 235 is_encrypted_(false), | 235 is_encrypted_(false), |
| 236 preroll_attempt_pending_(false), | 236 preroll_attempt_pending_(false), |
| 237 observer_(params.media_observer()), | 237 observer_(params.media_observer()), |
| 238 max_keyframe_distance_to_disable_background_video_( | 238 max_keyframe_distance_to_disable_background_video_( |
| 239 params.max_keyframe_distance_to_disable_background_video()), | 239 params.max_keyframe_distance_to_disable_background_video()), |
| 240 max_keyframe_distance_to_disable_background_video_mse_( |
| 241 params.max_keyframe_distance_to_disable_background_video_mse()), |
| 240 enable_instant_source_buffer_gc_( | 242 enable_instant_source_buffer_gc_( |
| 241 params.enable_instant_source_buffer_gc()), | 243 params.enable_instant_source_buffer_gc()), |
| 242 embedded_media_experience_enabled_( | 244 embedded_media_experience_enabled_( |
| 243 params.embedded_media_experience_enabled()) { | 245 params.embedded_media_experience_enabled()) { |
| 244 DVLOG(1) << __func__; | 246 DVLOG(1) << __func__; |
| 245 DCHECK(!adjust_allocated_memory_cb_.is_null()); | 247 DCHECK(!adjust_allocated_memory_cb_.is_null()); |
| 246 DCHECK(renderer_factory_); | 248 DCHECK(renderer_factory_); |
| 247 DCHECK(client_); | 249 DCHECK(client_); |
| 248 DCHECK(delegate_); | 250 DCHECK(delegate_); |
| 249 | 251 |
| (...skipping 1976 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2226 if (!HasAudio() && HasVideo()) | 2228 if (!HasAudio() && HasVideo()) |
| 2227 return true; | 2229 return true; |
| 2228 #endif // defined(OS_ANDROID) | 2230 #endif // defined(OS_ANDROID) |
| 2229 | 2231 |
| 2230 // Don't optimize audio-only or streaming players. | 2232 // Don't optimize audio-only or streaming players. |
| 2231 if (!HasVideo() || IsStreaming()) | 2233 if (!HasVideo() || IsStreaming()) |
| 2232 return false; | 2234 return false; |
| 2233 | 2235 |
| 2234 // Videos shorter than the maximum allowed keyframe distance can be optimized. | 2236 // Videos shorter than the maximum allowed keyframe distance can be optimized. |
| 2235 base::TimeDelta duration = GetPipelineMediaDuration(); | 2237 base::TimeDelta duration = GetPipelineMediaDuration(); |
| 2236 if (duration < max_keyframe_distance_to_disable_background_video_) | 2238 base::TimeDelta max_keyframe_distance = |
| 2239 (load_type_ == kLoadTypeMediaSource) |
| 2240 ? max_keyframe_distance_to_disable_background_video_mse_ |
| 2241 : max_keyframe_distance_to_disable_background_video_; |
| 2242 if (duration < max_keyframe_distance) |
| 2237 return true; | 2243 return true; |
| 2238 | 2244 |
| 2239 // Otherwise, only optimize videos with shorter average keyframe distance. | 2245 // Otherwise, only optimize videos with shorter average keyframe distance. |
| 2240 PipelineStatistics stats = GetPipelineStatistics(); | 2246 PipelineStatistics stats = GetPipelineStatistics(); |
| 2241 return stats.video_keyframe_distance_average < | 2247 return stats.video_keyframe_distance_average < max_keyframe_distance; |
| 2242 max_keyframe_distance_to_disable_background_video_; | |
| 2243 } | 2248 } |
| 2244 | 2249 |
| 2245 void WebMediaPlayerImpl::UpdateBackgroundVideoOptimizationState() { | 2250 void WebMediaPlayerImpl::UpdateBackgroundVideoOptimizationState() { |
| 2246 if (IsHidden()) { | 2251 if (IsHidden()) { |
| 2247 if (ShouldPauseVideoWhenHidden()) | 2252 if (ShouldPauseVideoWhenHidden()) |
| 2248 PauseVideoIfNeeded(); | 2253 PauseVideoIfNeeded(); |
| 2249 else | 2254 else |
| 2250 DisableVideoTrackIfNeeded(); | 2255 DisableVideoTrackIfNeeded(); |
| 2251 } else { | 2256 } else { |
| 2252 EnableVideoTrackIfNeeded(); | 2257 EnableVideoTrackIfNeeded(); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2342 | 2347 |
| 2343 void WebMediaPlayerImpl::RecordUnderflowDuration(base::TimeDelta duration) { | 2348 void WebMediaPlayerImpl::RecordUnderflowDuration(base::TimeDelta duration) { |
| 2344 DCHECK(data_source_ || chunk_demuxer_); | 2349 DCHECK(data_source_ || chunk_demuxer_); |
| 2345 if (data_source_) | 2350 if (data_source_) |
| 2346 UMA_HISTOGRAM_TIMES("Media.UnderflowDuration", duration); | 2351 UMA_HISTOGRAM_TIMES("Media.UnderflowDuration", duration); |
| 2347 else | 2352 else |
| 2348 UMA_HISTOGRAM_TIMES("Media.UnderflowDuration.MSE", duration); | 2353 UMA_HISTOGRAM_TIMES("Media.UnderflowDuration.MSE", duration); |
| 2349 } | 2354 } |
| 2350 | 2355 |
| 2351 } // namespace media | 2356 } // namespace media |
| OLD | NEW |