| 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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 paused_(true), | 140 paused_(true), |
| 141 seeking_(false), | 141 seeking_(false), |
| 142 ended_(false), | 142 ended_(false), |
| 143 pending_seek_(false), | 143 pending_seek_(false), |
| 144 should_notify_time_changed_(false), | 144 should_notify_time_changed_(false), |
| 145 client_(client), | 145 client_(client), |
| 146 encrypted_client_(encrypted_client), | 146 encrypted_client_(encrypted_client), |
| 147 delegate_(delegate), | 147 delegate_(delegate), |
| 148 defer_load_cb_(params.defer_load_cb()), | 148 defer_load_cb_(params.defer_load_cb()), |
| 149 context_3d_cb_(params.context_3d_cb()), | 149 context_3d_cb_(params.context_3d_cb()), |
| 150 adjust_allocated_memory_cb_(params.adjust_allocated_memory_cb()), |
| 151 last_reported_memory_usage_(0), |
| 150 supports_save_(true), | 152 supports_save_(true), |
| 151 chunk_demuxer_(NULL), | 153 chunk_demuxer_(NULL), |
| 152 // Threaded compositing isn't enabled universally yet. | 154 // Threaded compositing isn't enabled universally yet. |
| 153 compositor_task_runner_( | 155 compositor_task_runner_( |
| 154 params.compositor_task_runner() | 156 params.compositor_task_runner() |
| 155 ? params.compositor_task_runner() | 157 ? params.compositor_task_runner() |
| 156 : base::MessageLoop::current()->task_runner()), | 158 : base::MessageLoop::current()->task_runner()), |
| 157 compositor_(new VideoFrameCompositor( | 159 compositor_(new VideoFrameCompositor( |
| 158 compositor_task_runner_, | 160 compositor_task_runner_, |
| 159 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNaturalSizeChanged), | 161 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNaturalSizeChanged), |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 | 204 |
| 203 renderer_factory_.reset(); | 205 renderer_factory_.reset(); |
| 204 | 206 |
| 205 // Make sure to kill the pipeline so there's no more media threads running. | 207 // Make sure to kill the pipeline so there's no more media threads running. |
| 206 // Note: stopping the pipeline might block for a long time. | 208 // Note: stopping the pipeline might block for a long time. |
| 207 base::WaitableEvent waiter(false, false); | 209 base::WaitableEvent waiter(false, false); |
| 208 pipeline_.Stop( | 210 pipeline_.Stop( |
| 209 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&waiter))); | 211 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&waiter))); |
| 210 waiter.Wait(); | 212 waiter.Wait(); |
| 211 | 213 |
| 214 if (last_reported_memory_usage_) |
| 215 adjust_allocated_memory_cb_.Run(-last_reported_memory_usage_); |
| 216 |
| 212 compositor_task_runner_->DeleteSoon(FROM_HERE, compositor_); | 217 compositor_task_runner_->DeleteSoon(FROM_HERE, compositor_); |
| 213 | 218 |
| 214 media_log_->AddEvent( | 219 media_log_->AddEvent( |
| 215 media_log_->CreateEvent(MediaLogEvent::WEBMEDIAPLAYER_DESTROYED)); | 220 media_log_->CreateEvent(MediaLogEvent::WEBMEDIAPLAYER_DESTROYED)); |
| 216 } | 221 } |
| 217 | 222 |
| 218 void WebMediaPlayerImpl::load(LoadType load_type, const blink::WebURL& url, | 223 void WebMediaPlayerImpl::load(LoadType load_type, const blink::WebURL& url, |
| 219 CORSMode cors_mode) { | 224 CORSMode cors_mode) { |
| 220 DVLOG(1) << __FUNCTION__ << "(" << load_type << ", " << url << ", " | 225 DVLOG(1) << __FUNCTION__ << "(" << load_type << ", " << url << ", " |
| 221 << cors_mode << ")"; | 226 << cors_mode << ")"; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 237 GURL(frame_->document().securityOrigin().toString())); | 242 GURL(frame_->document().securityOrigin().toString())); |
| 238 | 243 |
| 239 // Set subresource URL for crash reporting. | 244 // Set subresource URL for crash reporting. |
| 240 base::debug::SetCrashKeyValue("subresource_url", gurl.spec()); | 245 base::debug::SetCrashKeyValue("subresource_url", gurl.spec()); |
| 241 | 246 |
| 242 load_type_ = load_type; | 247 load_type_ = load_type; |
| 243 | 248 |
| 244 SetNetworkState(WebMediaPlayer::NetworkStateLoading); | 249 SetNetworkState(WebMediaPlayer::NetworkStateLoading); |
| 245 SetReadyState(WebMediaPlayer::ReadyStateHaveNothing); | 250 SetReadyState(WebMediaPlayer::ReadyStateHaveNothing); |
| 246 media_log_->AddEvent(media_log_->CreateLoadEvent(url.spec())); | 251 media_log_->AddEvent(media_log_->CreateLoadEvent(url.spec())); |
| 252 memory_usage_reporting_timer_.Start( |
| 253 FROM_HERE, base::TimeDelta::FromMilliseconds(500), this, |
| 254 &WebMediaPlayerImpl::ReportMemoryUsage); |
| 247 | 255 |
| 248 // Media source pipelines can start immediately. | 256 // Media source pipelines can start immediately. |
| 249 if (load_type == LoadTypeMediaSource) { | 257 if (load_type == LoadTypeMediaSource) { |
| 250 supports_save_ = false; | 258 supports_save_ = false; |
| 251 StartPipeline(); | 259 StartPipeline(); |
| 252 return; | 260 return; |
| 253 } | 261 } |
| 254 | 262 |
| 255 // Otherwise it's a regular request which requires resolving the URL first. | 263 // Otherwise it's a regular request which requires resolving the URL first. |
| 256 data_source_.reset(new BufferedDataSource( | 264 data_source_.reset(new BufferedDataSource( |
| (...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1076 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1084 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1077 | 1085 |
| 1078 // pause() may be called after playback has ended and the HTMLMediaElement | 1086 // pause() may be called after playback has ended and the HTMLMediaElement |
| 1079 // requires that currentTime() == duration() after ending. We want to ensure | 1087 // requires that currentTime() == duration() after ending. We want to ensure |
| 1080 // |paused_time_| matches currentTime() in this case or a future seek() may | 1088 // |paused_time_| matches currentTime() in this case or a future seek() may |
| 1081 // incorrectly discard what it thinks is a seek to the existing time. | 1089 // incorrectly discard what it thinks is a seek to the existing time. |
| 1082 paused_time_ = | 1090 paused_time_ = |
| 1083 ended_ ? pipeline_.GetMediaDuration() : pipeline_.GetMediaTime(); | 1091 ended_ ? pipeline_.GetMediaDuration() : pipeline_.GetMediaTime(); |
| 1084 } | 1092 } |
| 1085 | 1093 |
| 1094 void WebMediaPlayerImpl::ReportMemoryUsage() { |
| 1095 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1096 |
| 1097 const PipelineStatistics stats = pipeline_.GetStatistics(); |
| 1098 const int64_t current_memory_usage = |
| 1099 stats.audio_memory_usage + stats.video_memory_usage + |
| 1100 (data_source_ ? data_source_->GetMemoryUsage() : 0) + |
| 1101 (demuxer_ ? demuxer_->GetMemoryUsage() : 0); |
| 1102 |
| 1103 DVLOG(2) << "Memory Usage -- Audio: " << stats.audio_memory_usage |
| 1104 << ", Video: " << stats.video_memory_usage << ", DataSource: " |
| 1105 << (data_source_ ? data_source_->GetMemoryUsage() : 0) |
| 1106 << ", Demuxer: " << (demuxer_ ? demuxer_->GetMemoryUsage() : 0); |
| 1107 |
| 1108 const int64_t delta = current_memory_usage - last_reported_memory_usage_; |
| 1109 last_reported_memory_usage_ = current_memory_usage; |
| 1110 adjust_allocated_memory_cb_.Run(delta); |
| 1111 } |
| 1112 |
| 1086 } // namespace media | 1113 } // namespace media |
| OLD | NEW |