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

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

Issue 1409123005: Add methods for telling V8 how much memory audio/video is using. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix html viewer. Created 5 years, 1 month 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') | media/blink/webmediaplayer_params.h » ('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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
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),
160 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnOpacityChanged))), 162 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnOpacityChanged))),
161 encrypted_media_support_(cdm_factory, 163 encrypted_media_support_(cdm_factory,
162 encrypted_client, 164 encrypted_client,
163 params.media_permission(), 165 params.media_permission(),
164 base::Bind(&WebMediaPlayerImpl::SetCdm, 166 base::Bind(&WebMediaPlayerImpl::SetCdm,
165 AsWeakPtr(), 167 AsWeakPtr(),
166 base::Bind(&IgnoreCdmAttached))), 168 base::Bind(&IgnoreCdmAttached))),
167 renderer_factory_(renderer_factory.Pass()) { 169 renderer_factory_(renderer_factory.Pass()) {
170 DCHECK(!adjust_allocated_memory_cb_.is_null());
171
168 media_log_->AddEvent( 172 media_log_->AddEvent(
169 media_log_->CreateEvent(MediaLogEvent::WEBMEDIAPLAYER_CREATED)); 173 media_log_->CreateEvent(MediaLogEvent::WEBMEDIAPLAYER_CREATED));
170 174
171 if (params.initial_cdm()) { 175 if (params.initial_cdm()) {
172 SetCdm(base::Bind(&IgnoreCdmAttached), 176 SetCdm(base::Bind(&IgnoreCdmAttached),
173 ToWebContentDecryptionModuleImpl(params.initial_cdm()) 177 ToWebContentDecryptionModuleImpl(params.initial_cdm())
174 ->GetCdmContext()); 178 ->GetCdmContext());
175 } 179 }
176 180
177 // TODO(xhwang): When we use an external Renderer, many methods won't work, 181 // TODO(xhwang): When we use an external Renderer, many methods won't work,
(...skipping 24 matching lines...) Expand all
202 206
203 renderer_factory_.reset(); 207 renderer_factory_.reset();
204 208
205 // Make sure to kill the pipeline so there's no more media threads running. 209 // 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. 210 // Note: stopping the pipeline might block for a long time.
207 base::WaitableEvent waiter(false, false); 211 base::WaitableEvent waiter(false, false);
208 pipeline_.Stop( 212 pipeline_.Stop(
209 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&waiter))); 213 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&waiter)));
210 waiter.Wait(); 214 waiter.Wait();
211 215
216 if (last_reported_memory_usage_)
217 adjust_allocated_memory_cb_.Run(-last_reported_memory_usage_);
218
212 compositor_task_runner_->DeleteSoon(FROM_HERE, compositor_); 219 compositor_task_runner_->DeleteSoon(FROM_HERE, compositor_);
213 220
214 media_log_->AddEvent( 221 media_log_->AddEvent(
215 media_log_->CreateEvent(MediaLogEvent::WEBMEDIAPLAYER_DESTROYED)); 222 media_log_->CreateEvent(MediaLogEvent::WEBMEDIAPLAYER_DESTROYED));
216 } 223 }
217 224
218 void WebMediaPlayerImpl::load(LoadType load_type, const blink::WebURL& url, 225 void WebMediaPlayerImpl::load(LoadType load_type, const blink::WebURL& url,
219 CORSMode cors_mode) { 226 CORSMode cors_mode) {
220 DVLOG(1) << __FUNCTION__ << "(" << load_type << ", " << url << ", " 227 DVLOG(1) << __FUNCTION__ << "(" << load_type << ", " << url << ", "
221 << cors_mode << ")"; 228 << cors_mode << ")";
(...skipping 15 matching lines...) Expand all
237 GURL(frame_->document().securityOrigin().toString())); 244 GURL(frame_->document().securityOrigin().toString()));
238 245
239 // Set subresource URL for crash reporting. 246 // Set subresource URL for crash reporting.
240 base::debug::SetCrashKeyValue("subresource_url", gurl.spec()); 247 base::debug::SetCrashKeyValue("subresource_url", gurl.spec());
241 248
242 load_type_ = load_type; 249 load_type_ = load_type;
243 250
244 SetNetworkState(WebMediaPlayer::NetworkStateLoading); 251 SetNetworkState(WebMediaPlayer::NetworkStateLoading);
245 SetReadyState(WebMediaPlayer::ReadyStateHaveNothing); 252 SetReadyState(WebMediaPlayer::ReadyStateHaveNothing);
246 media_log_->AddEvent(media_log_->CreateLoadEvent(url.spec())); 253 media_log_->AddEvent(media_log_->CreateLoadEvent(url.spec()));
254 memory_usage_reporting_timer_.Start(
255 FROM_HERE, base::TimeDelta::FromMilliseconds(500), this,
256 &WebMediaPlayerImpl::ReportMemoryUsage);
247 257
248 // Media source pipelines can start immediately. 258 // Media source pipelines can start immediately.
249 if (load_type == LoadTypeMediaSource) { 259 if (load_type == LoadTypeMediaSource) {
250 supports_save_ = false; 260 supports_save_ = false;
251 StartPipeline(); 261 StartPipeline();
252 return; 262 return;
253 } 263 }
254 264
255 // Otherwise it's a regular request which requires resolving the URL first. 265 // Otherwise it's a regular request which requires resolving the URL first.
256 data_source_.reset(new BufferedDataSource( 266 data_source_.reset(new BufferedDataSource(
(...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 DCHECK(main_task_runner_->BelongsToCurrentThread()); 1086 DCHECK(main_task_runner_->BelongsToCurrentThread());
1077 1087
1078 // pause() may be called after playback has ended and the HTMLMediaElement 1088 // pause() may be called after playback has ended and the HTMLMediaElement
1079 // requires that currentTime() == duration() after ending. We want to ensure 1089 // requires that currentTime() == duration() after ending. We want to ensure
1080 // |paused_time_| matches currentTime() in this case or a future seek() may 1090 // |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. 1091 // incorrectly discard what it thinks is a seek to the existing time.
1082 paused_time_ = 1092 paused_time_ =
1083 ended_ ? pipeline_.GetMediaDuration() : pipeline_.GetMediaTime(); 1093 ended_ ? pipeline_.GetMediaDuration() : pipeline_.GetMediaTime();
1084 } 1094 }
1085 1095
1096 void WebMediaPlayerImpl::ReportMemoryUsage() {
1097 DCHECK(main_task_runner_->BelongsToCurrentThread());
1098
1099 const PipelineStatistics stats = pipeline_.GetStatistics();
1100 const int64_t current_memory_usage =
1101 stats.audio_memory_usage + stats.video_memory_usage +
1102 (data_source_ ? data_source_->GetMemoryUsage() : 0) +
1103 (demuxer_ ? demuxer_->GetMemoryUsage() : 0);
1104
1105 DVLOG(2) << "Memory Usage -- Audio: " << stats.audio_memory_usage
1106 << ", Video: " << stats.video_memory_usage << ", DataSource: "
1107 << (data_source_ ? data_source_->GetMemoryUsage() : 0)
1108 << ", Demuxer: " << (demuxer_ ? demuxer_->GetMemoryUsage() : 0);
1109
1110 const int64_t delta = current_memory_usage - last_reported_memory_usage_;
1111 last_reported_memory_usage_ = current_memory_usage;
1112 adjust_allocated_memory_cb_.Run(delta);
1113 }
1114
1086 } // namespace media 1115 } // namespace media
OLDNEW
« no previous file with comments | « media/blink/webmediaplayer_impl.h ('k') | media/blink/webmediaplayer_params.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698