Chromium Code Reviews| 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> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
| 15 #include "base/callback.h" | 15 #include "base/callback.h" |
| 16 #include "base/callback_helpers.h" | 16 #include "base/callback_helpers.h" |
| 17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
| 18 #include "base/debug/alias.h" | 18 #include "base/debug/alias.h" |
| 19 #include "base/debug/crash_logging.h" | 19 #include "base/debug/crash_logging.h" |
| 20 #include "base/location.h" | 20 #include "base/location.h" |
| 21 #include "base/memory/ptr_util.h" | |
| 21 #include "base/metrics/histogram_macros.h" | 22 #include "base/metrics/histogram_macros.h" |
| 22 #include "base/single_thread_task_runner.h" | 23 #include "base/single_thread_task_runner.h" |
| 23 #include "base/strings/string_number_conversions.h" | 24 #include "base/strings/string_number_conversions.h" |
| 24 #include "base/task_runner_util.h" | 25 #include "base/task_runner_util.h" |
| 25 #include "base/threading/thread_task_runner_handle.h" | 26 #include "base/threading/thread_task_runner_handle.h" |
| 26 #include "base/trace_event/trace_event.h" | 27 #include "base/trace_event/trace_event.h" |
| 27 #include "build/build_config.h" | 28 #include "build/build_config.h" |
| 28 #include "cc/blink/web_layer_impl.h" | 29 #include "cc/blink/web_layer_impl.h" |
| 29 #include "cc/layers/video_layer.h" | 30 #include "cc/layers/video_layer.h" |
| 30 #include "media/audio/null_audio_sink.h" | 31 #include "media/audio/null_audio_sink.h" |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 surface_manager_(params.surface_manager()), | 239 surface_manager_(params.surface_manager()), |
| 239 overlay_surface_id_(SurfaceManager::kNoSurfaceID), | 240 overlay_surface_id_(SurfaceManager::kNoSurfaceID), |
| 240 suppress_destruction_errors_(false), | 241 suppress_destruction_errors_(false), |
| 241 can_suspend_state_(CanSuspendState::UNKNOWN), | 242 can_suspend_state_(CanSuspendState::UNKNOWN), |
| 242 use_fallback_path_(false), | 243 use_fallback_path_(false), |
| 243 is_encrypted_(false), | 244 is_encrypted_(false), |
| 244 underflow_count_(0), | 245 underflow_count_(0), |
| 245 preroll_attempt_pending_(false), | 246 preroll_attempt_pending_(false), |
| 246 observer_(params.media_observer()), | 247 observer_(params.media_observer()), |
| 247 max_keyframe_distance_to_disable_background_video_( | 248 max_keyframe_distance_to_disable_background_video_( |
| 248 params.max_keyframe_distance_to_disable_background_video()) { | 249 params.max_keyframe_distance_to_disable_background_video()), |
| 250 mse_force_gc_on_memory_pressure_( | |
| 251 params.mse_force_gc_on_memory_pressure()) { | |
| 249 DCHECK(!adjust_allocated_memory_cb_.is_null()); | 252 DCHECK(!adjust_allocated_memory_cb_.is_null()); |
| 250 DCHECK(renderer_factory_); | 253 DCHECK(renderer_factory_); |
| 251 DCHECK(client_); | 254 DCHECK(client_); |
| 252 DCHECK(delegate_); | 255 DCHECK(delegate_); |
| 253 | 256 |
| 254 tick_clock_.reset(new base::DefaultTickClock()); | 257 tick_clock_.reset(new base::DefaultTickClock()); |
| 255 | 258 |
| 256 force_video_overlays_ = base::CommandLine::ForCurrentProcess()->HasSwitch( | 259 force_video_overlays_ = base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 257 switches::kForceVideoOverlays); | 260 switches::kForceVideoOverlays); |
| 258 | 261 |
| (...skipping 902 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1161 | 1164 |
| 1162 UpdateBackgroundVideoOptimizationState(); | 1165 UpdateBackgroundVideoOptimizationState(); |
| 1163 } | 1166 } |
| 1164 | 1167 |
| 1165 void WebMediaPlayerImpl::OnDemuxerOpened() { | 1168 void WebMediaPlayerImpl::OnDemuxerOpened() { |
| 1166 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1169 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1167 client_->mediaSourceOpened( | 1170 client_->mediaSourceOpened( |
| 1168 new WebMediaSourceImpl(chunk_demuxer_, media_log_)); | 1171 new WebMediaSourceImpl(chunk_demuxer_, media_log_)); |
| 1169 } | 1172 } |
| 1170 | 1173 |
| 1174 void WebMediaPlayerImpl::OnMemoryPressure( | |
| 1175 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { | |
| 1176 DVLOG(2) << __func__ << " memory_pressure_level=" << memory_pressure_level; | |
| 1177 DCHECK(main_task_runner_->BelongsToCurrentThread()); | |
| 1178 DCHECK(base::FeatureList::IsEnabled(kReduceMSEBuffersOnMemoryPressure)); | |
| 1179 if (chunk_demuxer_) { | |
|
DaleCurtis
2017/01/26 23:07:37
DCHECK(chunk_demuxer_) and just don't register the
servolk
2017/01/27 00:52:13
Done.
| |
| 1180 // base::Unretained is safe, since chunk_demuxer_ is actually owned by | |
| 1181 // |this| via this->demuxer_. | |
| 1182 media_task_runner_->PostTask( | |
|
DaleCurtis
2017/01/26 23:07:37
I'm still not convinced why you need to provide th
servolk
2017/01/27 00:52:13
The last read pts is not guaranteed to be close en
| |
| 1183 FROM_HERE, | |
| 1184 base::Bind(&ChunkDemuxer::OnMemoryPressure, | |
| 1185 base::Unretained(chunk_demuxer_), | |
| 1186 base::TimeDelta::FromSecondsD(currentTime()), | |
| 1187 memory_pressure_level, mse_force_gc_on_memory_pressure_)); | |
| 1188 } | |
| 1189 } | |
| 1190 | |
| 1171 void WebMediaPlayerImpl::OnError(PipelineStatus status) { | 1191 void WebMediaPlayerImpl::OnError(PipelineStatus status) { |
| 1172 DVLOG(1) << __func__; | 1192 DVLOG(1) << __func__; |
| 1173 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1193 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1174 DCHECK_NE(status, PIPELINE_OK); | 1194 DCHECK_NE(status, PIPELINE_OK); |
| 1175 | 1195 |
| 1176 if (suppress_destruction_errors_) | 1196 if (suppress_destruction_errors_) |
| 1177 return; | 1197 return; |
| 1178 | 1198 |
| 1179 ReportPipelineError(load_type_, frame_->getSecurityOrigin(), status); | 1199 ReportPipelineError(load_type_, frame_->getSecurityOrigin(), status); |
| 1180 media_log_->AddEvent(media_log_->CreatePipelineErrorEvent(status)); | 1200 media_log_->AddEvent(media_log_->CreatePipelineErrorEvent(status)); |
| (...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1710 return; | 1730 return; |
| 1711 #endif | 1731 #endif |
| 1712 } else { | 1732 } else { |
| 1713 DCHECK(!chunk_demuxer_); | 1733 DCHECK(!chunk_demuxer_); |
| 1714 DCHECK(!data_source_); | 1734 DCHECK(!data_source_); |
| 1715 | 1735 |
| 1716 chunk_demuxer_ = new ChunkDemuxer( | 1736 chunk_demuxer_ = new ChunkDemuxer( |
| 1717 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnDemuxerOpened), | 1737 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnDemuxerOpened), |
| 1718 encrypted_media_init_data_cb, media_log_); | 1738 encrypted_media_init_data_cb, media_log_); |
| 1719 demuxer_.reset(chunk_demuxer_); | 1739 demuxer_.reset(chunk_demuxer_); |
| 1740 | |
| 1741 if (base::FeatureList::IsEnabled(kReduceMSEBuffersOnMemoryPressure)) { | |
| 1742 // base::Unretained is safe because |this| owns memory_pressure_listener_. | |
| 1743 memory_pressure_listener_ = | |
| 1744 base::MakeUnique<base::MemoryPressureListener>(base::Bind( | |
| 1745 &WebMediaPlayerImpl::OnMemoryPressure, base::Unretained(this))); | |
| 1746 } | |
| 1720 } | 1747 } |
| 1721 | 1748 |
| 1722 // TODO(sandersd): FileSystem objects may also be non-static, but due to our | 1749 // TODO(sandersd): FileSystem objects may also be non-static, but due to our |
| 1723 // caching layer such situations are broken already. http://crbug.com/593159 | 1750 // caching layer such situations are broken already. http://crbug.com/593159 |
| 1724 bool is_static = !chunk_demuxer_; | 1751 bool is_static = !chunk_demuxer_; |
| 1725 bool is_streaming = IsStreaming(); | 1752 bool is_streaming = IsStreaming(); |
| 1726 UMA_HISTOGRAM_BOOLEAN("Media.IsStreaming", is_streaming); | 1753 UMA_HISTOGRAM_BOOLEAN("Media.IsStreaming", is_streaming); |
| 1727 | 1754 |
| 1728 // ... and we're ready to go! | 1755 // ... and we're ready to go! |
| 1729 // TODO(sandersd): On Android, defer Start() if the tab is not visible. | 1756 // TODO(sandersd): On Android, defer Start() if the tab is not visible. |
| (...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2257 UMA_HISTOGRAM_TIMES( | 2284 UMA_HISTOGRAM_TIMES( |
| 2258 "Media.Video.TimeFromForegroundToFirstFrame.DisableTrack", | 2285 "Media.Video.TimeFromForegroundToFirstFrame.DisableTrack", |
| 2259 time_to_first_frame); | 2286 time_to_first_frame); |
| 2260 } else { | 2287 } else { |
| 2261 UMA_HISTOGRAM_TIMES("Media.Video.TimeFromForegroundToFirstFrame.Paused", | 2288 UMA_HISTOGRAM_TIMES("Media.Video.TimeFromForegroundToFirstFrame.Paused", |
| 2262 time_to_first_frame); | 2289 time_to_first_frame); |
| 2263 } | 2290 } |
| 2264 } | 2291 } |
| 2265 | 2292 |
| 2266 } // namespace media | 2293 } // namespace media |
| OLD | NEW |