| 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 pending_resume_(false), | 153 pending_resume_(false), |
| 154 suspending_(false), | 154 suspending_(false), |
| 155 suspended_(false), | 155 suspended_(false), |
| 156 resuming_(false), | 156 resuming_(false), |
| 157 ended_(false), | 157 ended_(false), |
| 158 pending_seek_(false), | 158 pending_seek_(false), |
| 159 should_notify_time_changed_(false), | 159 should_notify_time_changed_(false), |
| 160 client_(client), | 160 client_(client), |
| 161 encrypted_client_(encrypted_client), | 161 encrypted_client_(encrypted_client), |
| 162 delegate_(delegate), | 162 delegate_(delegate), |
| 163 delegate_id_(0), |
| 163 defer_load_cb_(params.defer_load_cb()), | 164 defer_load_cb_(params.defer_load_cb()), |
| 164 context_3d_cb_(params.context_3d_cb()), | 165 context_3d_cb_(params.context_3d_cb()), |
| 165 adjust_allocated_memory_cb_(params.adjust_allocated_memory_cb()), | 166 adjust_allocated_memory_cb_(params.adjust_allocated_memory_cb()), |
| 166 last_reported_memory_usage_(0), | 167 last_reported_memory_usage_(0), |
| 167 supports_save_(true), | 168 supports_save_(true), |
| 168 chunk_demuxer_(NULL), | 169 chunk_demuxer_(NULL), |
| 169 url_index_(url_index), | 170 url_index_(url_index), |
| 170 // Threaded compositing isn't enabled universally yet. | 171 // Threaded compositing isn't enabled universally yet. |
| 171 compositor_task_runner_( | 172 compositor_task_runner_( |
| 172 params.compositor_task_runner() | 173 params.compositor_task_runner() |
| 173 ? params.compositor_task_runner() | 174 ? params.compositor_task_runner() |
| 174 : base::MessageLoop::current()->task_runner()), | 175 : base::MessageLoop::current()->task_runner()), |
| 175 compositor_(new VideoFrameCompositor( | 176 compositor_(new VideoFrameCompositor( |
| 176 compositor_task_runner_, | 177 compositor_task_runner_, |
| 177 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNaturalSizeChanged), | 178 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNaturalSizeChanged), |
| 178 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnOpacityChanged))), | 179 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnOpacityChanged))), |
| 179 encrypted_media_support_(cdm_factory, | 180 encrypted_media_support_(cdm_factory, |
| 180 encrypted_client, | 181 encrypted_client, |
| 181 params.media_permission(), | 182 params.media_permission(), |
| 182 base::Bind(&WebMediaPlayerImpl::SetCdm, | 183 base::Bind(&WebMediaPlayerImpl::SetCdm, |
| 183 AsWeakPtr(), | 184 AsWeakPtr(), |
| 184 base::Bind(&IgnoreCdmAttached))), | 185 base::Bind(&IgnoreCdmAttached))), |
| 185 is_cdm_attached_(false), | 186 is_cdm_attached_(false), |
| 186 #if defined(OS_ANDROID) // WMPI_CAST | 187 #if defined(OS_ANDROID) // WMPI_CAST |
| 187 cast_impl_(this, client_, params.context_3d_cb(), delegate), | 188 cast_impl_(this, client_, params.context_3d_cb()), |
| 188 #endif | 189 #endif |
| 190 volume_(1.0), |
| 191 volume_multiplier_(1.0), |
| 189 renderer_factory_(std::move(renderer_factory)) { | 192 renderer_factory_(std::move(renderer_factory)) { |
| 190 DCHECK(!adjust_allocated_memory_cb_.is_null()); | 193 DCHECK(!adjust_allocated_memory_cb_.is_null()); |
| 191 DCHECK(renderer_factory_); | 194 DCHECK(renderer_factory_); |
| 192 | 195 |
| 193 if (delegate) | 196 if (delegate_) |
| 194 delegate->AddObserver(this); | 197 delegate_id_ = delegate_->AddObserver(this); |
| 195 | 198 |
| 196 media_log_->AddEvent( | 199 media_log_->AddEvent( |
| 197 media_log_->CreateEvent(MediaLogEvent::WEBMEDIAPLAYER_CREATED)); | 200 media_log_->CreateEvent(MediaLogEvent::WEBMEDIAPLAYER_CREATED)); |
| 198 | 201 |
| 199 if (params.initial_cdm()) { | 202 if (params.initial_cdm()) { |
| 200 SetCdm(base::Bind(&IgnoreCdmAttached), | 203 SetCdm(base::Bind(&IgnoreCdmAttached), |
| 201 ToWebContentDecryptionModuleImpl(params.initial_cdm()) | 204 ToWebContentDecryptionModuleImpl(params.initial_cdm()) |
| 202 ->GetCdmContext()); | 205 ->GetCdmContext()); |
| 203 } | 206 } |
| 204 | 207 |
| 205 // TODO(xhwang): When we use an external Renderer, many methods won't work, | 208 // TODO(xhwang): When we use an external Renderer, many methods won't work, |
| 206 // e.g. GetCurrentFrameFromCompositor(). See http://crbug.com/434861 | 209 // e.g. GetCurrentFrameFromCompositor(). See http://crbug.com/434861 |
| 207 | 210 |
| 208 // Use the null sink if no sink was provided. | 211 // Use the null sink if no sink was provided. |
| 209 audio_source_provider_ = new WebAudioSourceProviderImpl( | 212 audio_source_provider_ = new WebAudioSourceProviderImpl( |
| 210 params.audio_renderer_sink().get() | 213 params.audio_renderer_sink().get() |
| 211 ? params.audio_renderer_sink() | 214 ? params.audio_renderer_sink() |
| 212 : new NullAudioSink(media_task_runner_)); | 215 : new NullAudioSink(media_task_runner_)); |
| 213 } | 216 } |
| 214 | 217 |
| 215 WebMediaPlayerImpl::~WebMediaPlayerImpl() { | 218 WebMediaPlayerImpl::~WebMediaPlayerImpl() { |
| 216 client_->setWebLayer(NULL); | 219 client_->setWebLayer(NULL); |
| 217 | 220 |
| 218 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 221 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 219 | 222 |
| 220 if (delegate_) { | 223 if (delegate_) { |
| 221 delegate_->RemoveObserver(this); | 224 delegate_->PlayerGone(delegate_id_); |
| 222 delegate_->PlayerGone(this); | 225 delegate_->RemoveObserver(delegate_id_); |
| 223 } | 226 } |
| 224 | 227 |
| 225 // Abort any pending IO so stopping the pipeline doesn't get blocked. | 228 // Abort any pending IO so stopping the pipeline doesn't get blocked. |
| 226 if (data_source_) | 229 if (data_source_) |
| 227 data_source_->Abort(); | 230 data_source_->Abort(); |
| 228 if (chunk_demuxer_) { | 231 if (chunk_demuxer_) { |
| 229 chunk_demuxer_->Shutdown(); | 232 chunk_demuxer_->Shutdown(); |
| 230 chunk_demuxer_ = NULL; | 233 chunk_demuxer_ = NULL; |
| 231 } | 234 } |
| 232 | 235 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 main_task_runner_, frame_, media_log_.get(), | 305 main_task_runner_, frame_, media_log_.get(), |
| 303 &buffered_data_source_host_, | 306 &buffered_data_source_host_, |
| 304 base::Bind(&WebMediaPlayerImpl::NotifyDownloading, AsWeakPtr()))); | 307 base::Bind(&WebMediaPlayerImpl::NotifyDownloading, AsWeakPtr()))); |
| 305 } | 308 } |
| 306 data_source_->SetPreload(preload_); | 309 data_source_->SetPreload(preload_); |
| 307 data_source_->SetBufferingStrategy(buffering_strategy_); | 310 data_source_->SetBufferingStrategy(buffering_strategy_); |
| 308 data_source_->Initialize( | 311 data_source_->Initialize( |
| 309 base::Bind(&WebMediaPlayerImpl::DataSourceInitialized, AsWeakPtr())); | 312 base::Bind(&WebMediaPlayerImpl::DataSourceInitialized, AsWeakPtr())); |
| 310 | 313 |
| 311 #if defined(OS_ANDROID) // WMPI_CAST | 314 #if defined(OS_ANDROID) // WMPI_CAST |
| 312 cast_impl_.Initialize(url, frame_); | 315 cast_impl_.Initialize(url, frame_, delegate_id_); |
| 313 #endif | 316 #endif |
| 314 } | 317 } |
| 315 | 318 |
| 316 void WebMediaPlayerImpl::play() { | 319 void WebMediaPlayerImpl::play() { |
| 317 DVLOG(1) << __FUNCTION__; | 320 DVLOG(1) << __FUNCTION__; |
| 318 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 321 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 319 | 322 |
| 320 #if defined(OS_ANDROID) // WMPI_CAST | 323 #if defined(OS_ANDROID) // WMPI_CAST |
| 321 if (isRemote()) { | 324 if (isRemote()) { |
| 322 cast_impl_.play(); | 325 cast_impl_.play(); |
| 323 return; | 326 return; |
| 324 } | 327 } |
| 325 #endif | 328 #endif |
| 326 | 329 |
| 327 paused_ = false; | 330 paused_ = false; |
| 328 | 331 |
| 329 pipeline_.SetPlaybackRate(playback_rate_); | 332 pipeline_.SetPlaybackRate(playback_rate_); |
| 330 if (data_source_) | 333 if (data_source_) |
| 331 data_source_->MediaIsPlaying(); | 334 data_source_->MediaIsPlaying(); |
| 332 | 335 |
| 333 media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::PLAY)); | 336 media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::PLAY)); |
| 334 | 337 |
| 335 if (delegate_ && playback_rate_ > 0) | 338 if (playback_rate_ > 0) |
| 336 NotifyPlaybackStarted(); | 339 NotifyPlaybackStarted(); |
| 337 } | 340 } |
| 338 | 341 |
| 339 void WebMediaPlayerImpl::pause() { | 342 void WebMediaPlayerImpl::pause() { |
| 340 DVLOG(1) << __FUNCTION__; | 343 DVLOG(1) << __FUNCTION__; |
| 341 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 344 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 342 | 345 |
| 343 const bool was_already_paused = paused_ || playback_rate_ == 0; | 346 const bool was_already_paused = paused_ || playback_rate_ == 0; |
| 344 paused_ = true; | 347 paused_ = true; |
| 345 | 348 |
| 346 #if defined(OS_ANDROID) // WMPI_CAST | 349 #if defined(OS_ANDROID) // WMPI_CAST |
| 347 if (isRemote()) { | 350 if (isRemote()) { |
| 348 cast_impl_.pause(); | 351 cast_impl_.pause(); |
| 349 return; | 352 return; |
| 350 } | 353 } |
| 351 #endif | 354 #endif |
| 352 | 355 |
| 353 pipeline_.SetPlaybackRate(0.0); | 356 pipeline_.SetPlaybackRate(0.0); |
| 354 UpdatePausedTime(); | 357 UpdatePausedTime(); |
| 355 | 358 |
| 356 media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::PAUSE)); | 359 media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::PAUSE)); |
| 357 | 360 |
| 358 if (!was_already_paused && delegate_) | 361 if (!was_already_paused) |
| 359 NotifyPlaybackPaused(); | 362 NotifyPlaybackPaused(); |
| 360 } | 363 } |
| 361 | 364 |
| 362 bool WebMediaPlayerImpl::supportsSave() const { | 365 bool WebMediaPlayerImpl::supportsSave() const { |
| 363 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 366 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 364 return supports_save_; | 367 return supports_save_; |
| 365 } | 368 } |
| 366 | 369 |
| 367 void WebMediaPlayerImpl::seek(double seconds) { | 370 void WebMediaPlayerImpl::seek(double seconds) { |
| 368 DVLOG(1) << __FUNCTION__ << "(" << seconds << "s)"; | 371 DVLOG(1) << __FUNCTION__ << "(" << seconds << "s)"; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 // following checks so rewind uses reasonable values also. | 471 // following checks so rewind uses reasonable values also. |
| 469 if (rate < 0.0) | 472 if (rate < 0.0) |
| 470 return; | 473 return; |
| 471 | 474 |
| 472 // Limit rates to reasonable values by clamping. | 475 // Limit rates to reasonable values by clamping. |
| 473 if (rate != 0.0) { | 476 if (rate != 0.0) { |
| 474 if (rate < kMinRate) | 477 if (rate < kMinRate) |
| 475 rate = kMinRate; | 478 rate = kMinRate; |
| 476 else if (rate > kMaxRate) | 479 else if (rate > kMaxRate) |
| 477 rate = kMaxRate; | 480 rate = kMaxRate; |
| 478 if (playback_rate_ == 0 && !paused_ && delegate_) | 481 if (playback_rate_ == 0 && !paused_) |
| 479 NotifyPlaybackStarted(); | 482 NotifyPlaybackStarted(); |
| 480 } else if (playback_rate_ != 0 && !paused_ && delegate_) { | 483 } else if (playback_rate_ != 0 && !paused_) { |
| 481 NotifyPlaybackPaused(); | 484 NotifyPlaybackPaused(); |
| 482 } | 485 } |
| 483 | 486 |
| 484 playback_rate_ = rate; | 487 playback_rate_ = rate; |
| 485 if (!paused_) { | 488 if (!paused_) { |
| 486 pipeline_.SetPlaybackRate(rate); | 489 pipeline_.SetPlaybackRate(rate); |
| 487 if (data_source_) | 490 if (data_source_) |
| 488 data_source_->MediaPlaybackRateChanged(rate); | 491 data_source_->MediaPlaybackRateChanged(rate); |
| 489 } | 492 } |
| 490 } | 493 } |
| 491 | 494 |
| 492 void WebMediaPlayerImpl::setVolume(double volume) { | 495 void WebMediaPlayerImpl::setVolume(double volume) { |
| 493 DVLOG(1) << __FUNCTION__ << "(" << volume << ")"; | 496 DVLOG(1) << __FUNCTION__ << "(" << volume << ")"; |
| 494 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 497 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 495 | 498 volume_ = volume; |
| 496 pipeline_.SetVolume(volume); | 499 pipeline_.SetVolume(volume_ * volume_multiplier_); |
| 497 } | 500 } |
| 498 | 501 |
| 499 void WebMediaPlayerImpl::setSinkId( | 502 void WebMediaPlayerImpl::setSinkId( |
| 500 const blink::WebString& sink_id, | 503 const blink::WebString& sink_id, |
| 501 const blink::WebSecurityOrigin& security_origin, | 504 const blink::WebSecurityOrigin& security_origin, |
| 502 blink::WebSetSinkIdCallbacks* web_callback) { | 505 blink::WebSetSinkIdCallbacks* web_callback) { |
| 503 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 506 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 504 DVLOG(1) << __FUNCTION__; | 507 DVLOG(1) << __FUNCTION__; |
| 505 | 508 |
| 506 media::SwitchOutputDeviceCB callback = | 509 media::SwitchOutputDeviceCB callback = |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 908 void WebMediaPlayerImpl::OnPipelineSeeked(bool time_changed, | 911 void WebMediaPlayerImpl::OnPipelineSeeked(bool time_changed, |
| 909 PipelineStatus status) { | 912 PipelineStatus status) { |
| 910 DVLOG(1) << __FUNCTION__ << "(" << time_changed << ", " << status << ")"; | 913 DVLOG(1) << __FUNCTION__ << "(" << time_changed << ", " << status << ")"; |
| 911 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 914 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 912 | 915 |
| 913 if (status != PIPELINE_OK) { | 916 if (status != PIPELINE_OK) { |
| 914 OnPipelineError(status); | 917 OnPipelineError(status); |
| 915 return; | 918 return; |
| 916 } | 919 } |
| 917 | 920 |
| 921 // If we we're resuming into the playing state, notify the delegate. |
| 922 if (resuming_ && playback_rate_ > 0 && !paused_) |
| 923 NotifyPlaybackStarted(); |
| 924 |
| 918 // Whether or not the seek was caused by a resume, we're not suspended now. | 925 // Whether or not the seek was caused by a resume, we're not suspended now. |
| 919 resuming_ = false; | 926 resuming_ = false; |
| 920 suspended_ = false; | 927 suspended_ = false; |
| 921 | 928 |
| 922 // If there is a pending suspend, the seek does not complete until after the | 929 // If there is a pending suspend, the seek does not complete until after the |
| 923 // next resume. | 930 // next resume. |
| 924 if (pending_suspend_) { | 931 if (pending_suspend_) { |
| 925 pending_suspend_ = false; | 932 pending_suspend_ = false; |
| 926 pending_time_change_ = time_changed; | 933 pending_time_change_ = time_changed; |
| 927 Suspend(); | 934 Suspend(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 952 void WebMediaPlayerImpl::OnPipelineSuspended(PipelineStatus status) { | 959 void WebMediaPlayerImpl::OnPipelineSuspended(PipelineStatus status) { |
| 953 DVLOG(1) << __FUNCTION__ << "(" << status << ")"; | 960 DVLOG(1) << __FUNCTION__ << "(" << status << ")"; |
| 954 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 961 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 955 | 962 |
| 956 if (status != PIPELINE_OK) { | 963 if (status != PIPELINE_OK) { |
| 957 OnPipelineError(status); | 964 OnPipelineError(status); |
| 958 return; | 965 return; |
| 959 } | 966 } |
| 960 | 967 |
| 961 suspending_ = false; | 968 suspending_ = false; |
| 969 if (delegate_) |
| 970 delegate_->PlayerGone(delegate_id_); |
| 962 | 971 |
| 963 #if defined(OS_ANDROID) | 972 #if defined(OS_ANDROID) |
| 964 if (isRemote()) { | 973 if (isRemote()) { |
| 965 scoped_refptr<VideoFrame> frame = cast_impl_.GetCastingBanner(); | 974 scoped_refptr<VideoFrame> frame = cast_impl_.GetCastingBanner(); |
| 966 if (frame) { | 975 if (frame) { |
| 967 compositor_->PaintFrameUsingOldRenderingPath(frame); | 976 compositor_->PaintFrameUsingOldRenderingPath(frame); |
| 968 } | 977 } |
| 969 } | 978 } |
| 970 #endif | 979 #endif |
| 971 | 980 |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1181 if (pending_suspend_) { | 1190 if (pending_suspend_) { |
| 1182 pending_suspend_ = false; | 1191 pending_suspend_ = false; |
| 1183 return; | 1192 return; |
| 1184 } | 1193 } |
| 1185 | 1194 |
| 1186 // Might already be resuming iff we came back from remote playback recently. | 1195 // Might already be resuming iff we came back from remote playback recently. |
| 1187 if (suspended_ && !resuming_) | 1196 if (suspended_ && !resuming_) |
| 1188 Resume(); | 1197 Resume(); |
| 1189 } | 1198 } |
| 1190 | 1199 |
| 1200 void WebMediaPlayerImpl::OnPlay() { |
| 1201 play(); |
| 1202 client_->playbackStateChanged(); |
| 1203 } |
| 1204 |
| 1205 void WebMediaPlayerImpl::OnPause() { |
| 1206 pause(); |
| 1207 client_->playbackStateChanged(); |
| 1208 } |
| 1209 |
| 1210 void WebMediaPlayerImpl::OnVolumeMultiplierUpdate(double multiplier) { |
| 1211 volume_multiplier_ = multiplier; |
| 1212 setVolume(volume_); |
| 1213 } |
| 1214 |
| 1191 void WebMediaPlayerImpl::Resume() { | 1215 void WebMediaPlayerImpl::Resume() { |
| 1192 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1216 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1193 CHECK(suspended_); | 1217 CHECK(suspended_); |
| 1194 CHECK(!resuming_); | 1218 CHECK(!resuming_); |
| 1195 | 1219 |
| 1196 // If there was a time change pending when we suspended (which can happen when | 1220 // If there was a time change pending when we suspended (which can happen when |
| 1197 // we suspend immediately after a seek), surface it after resuming. | 1221 // we suspend immediately after a seek), surface it after resuming. |
| 1198 bool time_changed = pending_time_change_; | 1222 bool time_changed = pending_time_change_; |
| 1199 pending_time_change_ = false; | 1223 pending_time_change_ = false; |
| 1200 | 1224 |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1465 ended_ ? pipeline_.GetMediaDuration() : pipeline_.GetMediaTime(); | 1489 ended_ ? pipeline_.GetMediaDuration() : pipeline_.GetMediaTime(); |
| 1466 } | 1490 } |
| 1467 | 1491 |
| 1468 void WebMediaPlayerImpl::NotifyPlaybackStarted() { | 1492 void WebMediaPlayerImpl::NotifyPlaybackStarted() { |
| 1469 #if defined(OS_ANDROID) // WMPI_CAST | 1493 #if defined(OS_ANDROID) // WMPI_CAST |
| 1470 // We do not tell our delegates about remote playback, becuase that would | 1494 // We do not tell our delegates about remote playback, becuase that would |
| 1471 // keep the device awake, which is not what we want. | 1495 // keep the device awake, which is not what we want. |
| 1472 if (isRemote()) | 1496 if (isRemote()) |
| 1473 return; | 1497 return; |
| 1474 #endif | 1498 #endif |
| 1475 if (delegate_) | 1499 if (delegate_) { |
| 1476 delegate_->DidPlay(this); | 1500 delegate_->DidPlay(delegate_id_, hasVideo(), hasAudio(), false, |
| 1501 pipeline_.GetMediaDuration()); |
| 1502 } |
| 1477 if (!memory_usage_reporting_timer_.IsRunning()) { | 1503 if (!memory_usage_reporting_timer_.IsRunning()) { |
| 1478 memory_usage_reporting_timer_.Start(FROM_HERE, | 1504 memory_usage_reporting_timer_.Start(FROM_HERE, |
| 1479 base::TimeDelta::FromSeconds(2), this, | 1505 base::TimeDelta::FromSeconds(2), this, |
| 1480 &WebMediaPlayerImpl::ReportMemoryUsage); | 1506 &WebMediaPlayerImpl::ReportMemoryUsage); |
| 1481 } | 1507 } |
| 1482 } | 1508 } |
| 1483 | 1509 |
| 1484 void WebMediaPlayerImpl::NotifyPlaybackPaused() { | 1510 void WebMediaPlayerImpl::NotifyPlaybackPaused() { |
| 1485 #if defined(OS_ANDROID) // WMPI_CAST | 1511 #if defined(OS_ANDROID) // WMPI_CAST |
| 1486 if (isRemote()) | 1512 if (isRemote()) |
| 1487 return; | 1513 return; |
| 1488 #endif | 1514 #endif |
| 1489 if (delegate_) | 1515 if (delegate_) |
| 1490 delegate_->DidPause(this); | 1516 delegate_->DidPause(delegate_id_, ended_); |
| 1491 memory_usage_reporting_timer_.Stop(); | 1517 memory_usage_reporting_timer_.Stop(); |
| 1492 ReportMemoryUsage(); | 1518 ReportMemoryUsage(); |
| 1493 } | 1519 } |
| 1494 | 1520 |
| 1495 void WebMediaPlayerImpl::ReportMemoryUsage() { | 1521 void WebMediaPlayerImpl::ReportMemoryUsage() { |
| 1496 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1522 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1497 | 1523 |
| 1498 // About base::Unretained() usage below: We destroy |demuxer_| on the main | 1524 // About base::Unretained() usage below: We destroy |demuxer_| on the main |
| 1499 // thread. Before that, however, ~WebMediaPlayerImpl() posts a task to the | 1525 // thread. Before that, however, ~WebMediaPlayerImpl() posts a task to the |
| 1500 // media thread and waits for it to finish. Hence, the GetMemoryUsage() task | 1526 // media thread and waits for it to finish. Hence, the GetMemoryUsage() task |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1523 << ", Video: " << stats.video_memory_usage << ", DataSource: " | 1549 << ", Video: " << stats.video_memory_usage << ", DataSource: " |
| 1524 << (data_source_ ? data_source_->GetMemoryUsage() : 0) | 1550 << (data_source_ ? data_source_->GetMemoryUsage() : 0) |
| 1525 << ", Demuxer: " << demuxer_memory_usage; | 1551 << ", Demuxer: " << demuxer_memory_usage; |
| 1526 | 1552 |
| 1527 const int64_t delta = current_memory_usage - last_reported_memory_usage_; | 1553 const int64_t delta = current_memory_usage - last_reported_memory_usage_; |
| 1528 last_reported_memory_usage_ = current_memory_usage; | 1554 last_reported_memory_usage_ = current_memory_usage; |
| 1529 adjust_allocated_memory_cb_.Run(delta); | 1555 adjust_allocated_memory_cb_.Run(delta); |
| 1530 } | 1556 } |
| 1531 | 1557 |
| 1532 } // namespace media | 1558 } // namespace media |
| OLD | NEW |