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> |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 57 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 58 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | 58 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
| 59 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | 59 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
| 60 #include "third_party/WebKit/public/web/WebView.h" | 60 #include "third_party/WebKit/public/web/WebView.h" |
| 61 | 61 |
| 62 using blink::WebCanvas; | 62 using blink::WebCanvas; |
| 63 using blink::WebMediaPlayer; | 63 using blink::WebMediaPlayer; |
| 64 using blink::WebRect; | 64 using blink::WebRect; |
| 65 using blink::WebSize; | 65 using blink::WebSize; |
| 66 using blink::WebString; | 66 using blink::WebString; |
| 67 using gpu::gles2::GLES2Interface; | |
| 68 | |
| 69 namespace media { | |
| 67 | 70 |
| 68 namespace { | 71 namespace { |
| 69 | 72 |
| 70 // Limits the range of playback rate. | 73 // Limits the range of playback rate. |
| 71 // | 74 // |
| 72 // TODO(kylep): Revisit these. | 75 // TODO(kylep): Revisit these. |
| 73 // | 76 // |
| 74 // Vista has substantially lower performance than XP or Windows7. If you speed | 77 // Vista has substantially lower performance than XP or Windows7. If you speed |
| 75 // up a video too much, it can't keep up, and rendering stops updating except on | 78 // up a video too much, it can't keep up, and rendering stops updating except on |
| 76 // the time bar. For really high speeds, audio becomes a bottleneck and we just | 79 // the time bar. For really high speeds, audio becomes a bottleneck and we just |
| 77 // use up the data we have, which may not achieve the speed requested, but will | 80 // use up the data we have, which may not achieve the speed requested, but will |
| 78 // not crash the tab. | 81 // not crash the tab. |
| 79 // | 82 // |
| 80 // A very slow speed, ie 0.00000001x, causes the machine to lock up. (It seems | 83 // A very slow speed, ie 0.00000001x, causes the machine to lock up. (It seems |
| 81 // like a busy loop). It gets unresponsive, although its not completely dead. | 84 // like a busy loop). It gets unresponsive, although its not completely dead. |
| 82 // | 85 // |
| 83 // Also our timers are not very accurate (especially for ogg), which becomes | 86 // Also our timers are not very accurate (especially for ogg), which becomes |
| 84 // evident at low speeds and on Vista. Since other speeds are risky and outside | 87 // evident at low speeds and on Vista. Since other speeds are risky and outside |
| 85 // the norms, we think 1/16x to 16x is a safe and useful range for now. | 88 // the norms, we think 1/16x to 16x is a safe and useful range for now. |
| 86 const double kMinRate = 0.0625; | 89 const double kMinRate = 0.0625; |
| 87 const double kMaxRate = 16.0; | 90 const double kMaxRate = 16.0; |
| 88 | 91 |
| 89 void SetSinkIdOnMediaThread( | 92 void SetSinkIdOnMediaThread(scoped_refptr<WebAudioSourceProviderImpl> sink, |
| 90 scoped_refptr<media::WebAudioSourceProviderImpl> sink, | 93 const std::string& device_id, |
| 91 const std::string& device_id, | 94 const url::Origin& security_origin, |
| 92 const url::Origin& security_origin, | 95 const SwitchOutputDeviceCB& callback) { |
| 93 const media::SwitchOutputDeviceCB& callback) { | |
| 94 if (sink->GetOutputDevice()) { | 96 if (sink->GetOutputDevice()) { |
| 95 sink->GetOutputDevice()->SwitchOutputDevice(device_id, security_origin, | 97 sink->GetOutputDevice()->SwitchOutputDevice(device_id, security_origin, |
| 96 callback); | 98 callback); |
| 97 } else { | 99 } else { |
| 98 callback.Run(media::OUTPUT_DEVICE_STATUS_ERROR_INTERNAL); | 100 callback.Run(OUTPUT_DEVICE_STATUS_ERROR_INTERNAL); |
| 99 } | 101 } |
| 100 } | 102 } |
| 101 | 103 |
| 102 } // namespace | 104 } // namespace |
| 103 | 105 |
| 104 namespace media { | |
| 105 | |
| 106 class BufferedDataSourceHostImpl; | 106 class BufferedDataSourceHostImpl; |
| 107 | 107 |
| 108 #define STATIC_ASSERT_MATCHING_ENUM(name, name2) \ | 108 #define STATIC_ASSERT_MATCHING_ENUM(name, name2) \ |
| 109 static_assert(static_cast<int>(WebMediaPlayer::CORSMode##name) == \ | 109 static_assert(static_cast<int>(WebMediaPlayer::CORSMode##name) == \ |
| 110 static_cast<int>(UrlData::name2), \ | 110 static_cast<int>(UrlData::name2), \ |
| 111 "mismatching enum values: " #name) | 111 "mismatching enum values: " #name) |
| 112 STATIC_ASSERT_MATCHING_ENUM(Unspecified, CORS_UNSPECIFIED); | 112 STATIC_ASSERT_MATCHING_ENUM(Unspecified, CORS_UNSPECIFIED); |
| 113 STATIC_ASSERT_MATCHING_ENUM(Anonymous, CORS_ANONYMOUS); | 113 STATIC_ASSERT_MATCHING_ENUM(Anonymous, CORS_ANONYMOUS); |
| 114 STATIC_ASSERT_MATCHING_ENUM(UseCredentials, CORS_USE_CREDENTIALS); | 114 STATIC_ASSERT_MATCHING_ENUM(UseCredentials, CORS_USE_CREDENTIALS); |
| 115 #undef STATIC_ASSERT_MATCHING_ENUM | 115 #undef STATIC_ASSERT_MATCHING_ENUM |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 174 compositor_(new VideoFrameCompositor( | 174 compositor_(new VideoFrameCompositor( |
| 175 compositor_task_runner_, | 175 compositor_task_runner_, |
| 176 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNaturalSizeChanged), | 176 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNaturalSizeChanged), |
| 177 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnOpacityChanged))), | 177 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnOpacityChanged))), |
| 178 encrypted_media_support_(cdm_factory, | 178 encrypted_media_support_(cdm_factory, |
| 179 encrypted_client, | 179 encrypted_client, |
| 180 params.media_permission(), | 180 params.media_permission(), |
| 181 base::Bind(&WebMediaPlayerImpl::SetCdm, | 181 base::Bind(&WebMediaPlayerImpl::SetCdm, |
| 182 AsWeakPtr(), | 182 AsWeakPtr(), |
| 183 base::Bind(&IgnoreCdmAttached))), | 183 base::Bind(&IgnoreCdmAttached))), |
| 184 #if defined(OS_ANDROID) // WMPI_CAST | |
| 185 cast_impl_(this, client_, params.context_3d_cb()), | |
| 186 #endif | |
| 184 renderer_factory_(std::move(renderer_factory)) { | 187 renderer_factory_(std::move(renderer_factory)) { |
| 185 DCHECK(!adjust_allocated_memory_cb_.is_null()); | 188 DCHECK(!adjust_allocated_memory_cb_.is_null()); |
| 186 | 189 |
| 187 if (delegate) | 190 if (delegate) |
| 188 delegate->AddObserver(this); | 191 delegate->AddObserver(this); |
| 189 | 192 |
| 190 media_log_->AddEvent( | 193 media_log_->AddEvent( |
| 191 media_log_->CreateEvent(MediaLogEvent::WEBMEDIAPLAYER_CREATED)); | 194 media_log_->CreateEvent(MediaLogEvent::WEBMEDIAPLAYER_CREATED)); |
| 192 | 195 |
| 193 if (params.initial_cdm()) { | 196 if (params.initial_cdm()) { |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 293 data_source_.reset(new BufferedDataSource( | 296 data_source_.reset(new BufferedDataSource( |
| 294 url, static_cast<BufferedResourceLoader::CORSMode>(cors_mode), | 297 url, static_cast<BufferedResourceLoader::CORSMode>(cors_mode), |
| 295 main_task_runner_, frame_, media_log_.get(), | 298 main_task_runner_, frame_, media_log_.get(), |
| 296 &buffered_data_source_host_, | 299 &buffered_data_source_host_, |
| 297 base::Bind(&WebMediaPlayerImpl::NotifyDownloading, AsWeakPtr()))); | 300 base::Bind(&WebMediaPlayerImpl::NotifyDownloading, AsWeakPtr()))); |
| 298 } | 301 } |
| 299 data_source_->SetPreload(preload_); | 302 data_source_->SetPreload(preload_); |
| 300 data_source_->SetBufferingStrategy(buffering_strategy_); | 303 data_source_->SetBufferingStrategy(buffering_strategy_); |
| 301 data_source_->Initialize( | 304 data_source_->Initialize( |
| 302 base::Bind(&WebMediaPlayerImpl::DataSourceInitialized, AsWeakPtr())); | 305 base::Bind(&WebMediaPlayerImpl::DataSourceInitialized, AsWeakPtr())); |
| 306 | |
| 307 #if defined(OS_ANDROID) // WMPI_CAST | |
| 308 cast_impl_.Initialize(url, frame_); | |
| 309 #endif | |
| 303 } | 310 } |
| 304 | 311 |
| 305 void WebMediaPlayerImpl::play() { | 312 void WebMediaPlayerImpl::play() { |
| 306 DVLOG(1) << __FUNCTION__; | 313 DVLOG(1) << __FUNCTION__; |
| 307 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 314 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 308 | 315 |
| 316 #if defined(OS_ANDROID) // WMPI_CAST | |
| 317 if (cast_impl_.isRemote()) { | |
| 318 cast_impl_.play(); | |
| 319 return; | |
| 320 } | |
| 321 #endif | |
| 322 | |
| 309 paused_ = false; | 323 paused_ = false; |
| 324 | |
| 310 pipeline_.SetPlaybackRate(playback_rate_); | 325 pipeline_.SetPlaybackRate(playback_rate_); |
| 311 if (data_source_) | 326 if (data_source_) |
| 312 data_source_->MediaIsPlaying(); | 327 data_source_->MediaIsPlaying(); |
| 313 | 328 |
| 314 media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::PLAY)); | 329 media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::PLAY)); |
| 315 | 330 |
| 316 if (delegate_ && playback_rate_ > 0) | 331 if (delegate_ && playback_rate_ > 0) |
| 317 NotifyPlaybackStarted(); | 332 NotifyPlaybackStarted(); |
| 318 } | 333 } |
| 319 | 334 |
| 320 void WebMediaPlayerImpl::pause() { | 335 void WebMediaPlayerImpl::pause() { |
| 321 DVLOG(1) << __FUNCTION__; | 336 DVLOG(1) << __FUNCTION__; |
| 322 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 337 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 323 | 338 |
| 324 const bool was_already_paused = paused_ || playback_rate_ == 0; | 339 const bool was_already_paused = paused_ || playback_rate_ == 0; |
| 325 paused_ = true; | 340 paused_ = true; |
| 341 | |
| 342 #if defined(OS_ANDROID) // WMPI_CAST | |
| 343 if (cast_impl_.isRemote()) { | |
| 344 cast_impl_.pause(); | |
| 345 return; | |
| 346 } | |
| 347 #endif | |
| 348 | |
| 326 pipeline_.SetPlaybackRate(0.0); | 349 pipeline_.SetPlaybackRate(0.0); |
| 327 UpdatePausedTime(); | 350 UpdatePausedTime(); |
| 328 | 351 |
| 329 media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::PAUSE)); | 352 media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::PAUSE)); |
| 330 | 353 |
| 331 if (!was_already_paused && delegate_) | 354 if (!was_already_paused && delegate_) |
| 332 NotifyPlaybackPaused(); | 355 NotifyPlaybackPaused(); |
| 333 } | 356 } |
| 334 | 357 |
| 335 bool WebMediaPlayerImpl::supportsSave() const { | 358 bool WebMediaPlayerImpl::supportsSave() const { |
| 336 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 359 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 337 return supports_save_; | 360 return supports_save_; |
| 338 } | 361 } |
| 339 | 362 |
| 340 void WebMediaPlayerImpl::seek(double seconds) { | 363 void WebMediaPlayerImpl::seek(double seconds) { |
| 341 DVLOG(1) << __FUNCTION__ << "(" << seconds << "s)"; | 364 DVLOG(1) << __FUNCTION__ << "(" << seconds << "s)"; |
| 342 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 365 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 343 | 366 |
| 344 ended_ = false; | 367 ended_ = false; |
| 345 | 368 |
| 369 base::TimeDelta new_seek_time = base::TimeDelta::FromSecondsD(seconds); | |
| 370 | |
| 371 #if defined(OS_ANDROID) // WMPI_CAST | |
| 372 if (cast_impl_.isRemote()) { | |
| 373 cast_impl_.seek(new_seek_time); | |
| 374 return; | |
| 375 } | |
| 376 #endif | |
| 377 | |
| 346 ReadyState old_state = ready_state_; | 378 ReadyState old_state = ready_state_; |
| 347 if (ready_state_ > WebMediaPlayer::ReadyStateHaveMetadata) | 379 if (ready_state_ > WebMediaPlayer::ReadyStateHaveMetadata) |
| 348 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); | 380 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); |
| 349 | 381 |
| 350 base::TimeDelta new_seek_time = base::TimeDelta::FromSecondsD(seconds); | |
| 351 | |
| 352 if (seeking_ || suspended_) { | 382 if (seeking_ || suspended_) { |
| 353 // Once resuming, it's too late to change the resume time and so the | 383 // Once resuming, it's too late to change the resume time and so the |
| 354 // implementation is a little different. | 384 // implementation is a little different. |
| 355 bool is_suspended = suspended_ && !resuming_; | 385 bool is_suspended = suspended_ && !resuming_; |
| 356 | 386 |
| 357 // If we are currently seeking or resuming to |new_seek_time|, skip the | 387 // If we are currently seeking or resuming to |new_seek_time|, skip the |
| 358 // seek (except for MSE, which always seeks). | 388 // seek (except for MSE, which always seeks). |
| 359 if (!is_suspended && new_seek_time == seek_time_) { | 389 if (!is_suspended && new_seek_time == seek_time_) { |
| 360 if (chunk_demuxer_) { | 390 if (chunk_demuxer_) { |
| 361 // Don't suppress any redundant in-progress MSE seek. There could have | 391 // Don't suppress any redundant in-progress MSE seek. There could have |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 415 return; | 445 return; |
| 416 } | 446 } |
| 417 } | 447 } |
| 418 | 448 |
| 419 seeking_ = true; | 449 seeking_ = true; |
| 420 seek_time_ = new_seek_time; | 450 seek_time_ = new_seek_time; |
| 421 | 451 |
| 422 if (chunk_demuxer_) | 452 if (chunk_demuxer_) |
| 423 chunk_demuxer_->StartWaitingForSeek(seek_time_); | 453 chunk_demuxer_->StartWaitingForSeek(seek_time_); |
| 424 | 454 |
| 425 // Kick off the asynchronous seek! | |
| 426 pipeline_.Seek(seek_time_, BIND_TO_RENDER_LOOP1( | 455 pipeline_.Seek(seek_time_, BIND_TO_RENDER_LOOP1( |
| 427 &WebMediaPlayerImpl::OnPipelineSeeked, true)); | 456 &WebMediaPlayerImpl::OnPipelineSeeked, true)); |
| 428 } | 457 } |
| 429 | 458 |
| 430 void WebMediaPlayerImpl::setRate(double rate) { | 459 void WebMediaPlayerImpl::setRate(double rate) { |
| 431 DVLOG(1) << __FUNCTION__ << "(" << rate << ")"; | 460 DVLOG(1) << __FUNCTION__ << "(" << rate << ")"; |
| 432 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 461 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 433 | 462 |
| 434 // TODO(kylep): Remove when support for negatives is added. Also, modify the | 463 // TODO(kylep): Remove when support for negatives is added. Also, modify the |
| 435 // following checks so rewind uses reasonable values also. | 464 // following checks so rewind uses reasonable values also. |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 532 | 561 |
| 533 blink::WebSize WebMediaPlayerImpl::naturalSize() const { | 562 blink::WebSize WebMediaPlayerImpl::naturalSize() const { |
| 534 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 563 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 535 | 564 |
| 536 return blink::WebSize(pipeline_metadata_.natural_size); | 565 return blink::WebSize(pipeline_metadata_.natural_size); |
| 537 } | 566 } |
| 538 | 567 |
| 539 bool WebMediaPlayerImpl::paused() const { | 568 bool WebMediaPlayerImpl::paused() const { |
| 540 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 569 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 541 | 570 |
| 571 #if defined(OS_ANDROID) // WMPI_CAST | |
| 572 if (cast_impl_.isRemote()) | |
| 573 return cast_impl_.paused(); | |
| 574 #endif | |
| 542 return pipeline_.GetPlaybackRate() == 0.0f; | 575 return pipeline_.GetPlaybackRate() == 0.0f; |
| 543 } | 576 } |
| 544 | 577 |
| 545 bool WebMediaPlayerImpl::seeking() const { | 578 bool WebMediaPlayerImpl::seeking() const { |
| 546 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 579 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 547 | 580 |
| 548 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing) | 581 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing) |
| 549 return false; | 582 return false; |
| 550 | 583 |
| 551 return seeking_; | 584 return seeking_; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 579 return duration(); | 612 return duration(); |
| 580 | 613 |
| 581 // We know the current seek time better than pipeline: pipeline may processing | 614 // We know the current seek time better than pipeline: pipeline may processing |
| 582 // an earlier seek before a pending seek has been started, or it might not yet | 615 // an earlier seek before a pending seek has been started, or it might not yet |
| 583 // have the current seek time returnable via GetMediaTime(). | 616 // have the current seek time returnable via GetMediaTime(). |
| 584 if (seeking()) { | 617 if (seeking()) { |
| 585 return pending_seek_ ? pending_seek_time_.InSecondsF() | 618 return pending_seek_ ? pending_seek_time_.InSecondsF() |
| 586 : seek_time_.InSecondsF(); | 619 : seek_time_.InSecondsF(); |
| 587 } | 620 } |
| 588 | 621 |
| 589 return (paused_ ? paused_time_ : pipeline_.GetMediaTime()).InSecondsF(); | 622 #if defined(OS_ANDROID) // WMPI_CAST |
| 623 if (cast_impl_.isRemote()) { | |
| 624 return cast_impl_.currentTime(); | |
| 625 } | |
| 626 #endif | |
| 627 | |
| 628 if (paused_) { | |
| 629 return paused_time_.InSecondsF(); | |
| 630 } | |
| 631 | |
| 632 return pipeline_.GetMediaTime().InSecondsF(); | |
| 590 } | 633 } |
| 591 | 634 |
| 592 WebMediaPlayer::NetworkState WebMediaPlayerImpl::networkState() const { | 635 WebMediaPlayer::NetworkState WebMediaPlayerImpl::networkState() const { |
| 593 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 636 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 594 return network_state_; | 637 return network_state_; |
| 595 } | 638 } |
| 596 | 639 |
| 597 WebMediaPlayer::ReadyState WebMediaPlayerImpl::readyState() const { | 640 WebMediaPlayer::ReadyState WebMediaPlayerImpl::readyState() const { |
| 598 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 641 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 599 return ready_state_; | 642 return ready_state_; |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 903 DVLOG(1) << __FUNCTION__ << "(" << status << ")"; | 946 DVLOG(1) << __FUNCTION__ << "(" << status << ")"; |
| 904 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 947 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 905 | 948 |
| 906 if (status != PIPELINE_OK) { | 949 if (status != PIPELINE_OK) { |
| 907 OnPipelineError(status); | 950 OnPipelineError(status); |
| 908 return; | 951 return; |
| 909 } | 952 } |
| 910 | 953 |
| 911 suspending_ = false; | 954 suspending_ = false; |
| 912 | 955 |
| 956 #if defined(OS_ANDROID) | |
| 957 if (cast_impl_.isRemote()) { | |
| 958 scoped_refptr<VideoFrame> frame = cast_impl_.GetCastingBanner(); | |
| 959 if (frame) { | |
| 960 compositor_->PaintFrameUsingOldRenderingPath(frame); | |
| 961 } | |
| 962 } | |
| 963 #endif | |
| 964 | |
| 913 if (pending_resume_) { | 965 if (pending_resume_) { |
| 914 pending_resume_ = false; | 966 pending_resume_ = false; |
| 915 Resume(); | 967 Resume(); |
| 916 return; | 968 return; |
| 917 } | 969 } |
| 918 } | 970 } |
| 919 | 971 |
| 920 void WebMediaPlayerImpl::OnPipelineEnded() { | 972 void WebMediaPlayerImpl::OnPipelineEnded() { |
| 921 DVLOG(1) << __FUNCTION__; | 973 DVLOG(1) << __FUNCTION__; |
| 922 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 974 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1031 | 1083 |
| 1032 void WebMediaPlayerImpl::OnHidden() { | 1084 void WebMediaPlayerImpl::OnHidden() { |
| 1033 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1085 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1034 | 1086 |
| 1035 #if !defined(OS_ANDROID) | 1087 #if !defined(OS_ANDROID) |
| 1036 // Suspend/Resume is enabled by default on Android. | 1088 // Suspend/Resume is enabled by default on Android. |
| 1037 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 1089 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1038 switches::kEnableMediaSuspend)) { | 1090 switches::kEnableMediaSuspend)) { |
| 1039 return; | 1091 return; |
| 1040 } | 1092 } |
| 1093 #else | |
| 1094 // If we're remote, the pipeline should already be suspended. | |
| 1095 if (cast_impl_.isRemote()) | |
|
sandersd (OOO until July 31)
2016/01/13 22:11:10
Nit: This would be better as a separate condition,
hubbe
2016/01/13 22:28:25
Like this?
| |
| 1096 return; | |
| 1041 #endif // !defined(OS_ANDROID) | 1097 #endif // !defined(OS_ANDROID) |
| 1042 | 1098 |
| 1043 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1099 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1044 switches::kDisableMediaSuspend)) { | 1100 switches::kDisableMediaSuspend)) { |
| 1045 return; | 1101 return; |
| 1046 } | 1102 } |
| 1047 | 1103 |
| 1104 ScheduleSuspend(); | |
| 1105 } | |
| 1106 | |
| 1107 void WebMediaPlayerImpl::ScheduleSuspend() { | |
| 1048 if (!pipeline_.IsRunning()) | 1108 if (!pipeline_.IsRunning()) |
| 1049 return; | 1109 return; |
| 1050 | 1110 |
| 1051 if (resuming_ || seeking_) { | 1111 if (resuming_ || seeking_) { |
| 1052 pending_suspend_ = true; | 1112 pending_suspend_ = true; |
| 1053 return; | 1113 return; |
| 1054 } | 1114 } |
| 1055 | 1115 |
| 1056 if (pending_resume_) { | 1116 if (pending_resume_) { |
| 1057 pending_resume_ = false; | 1117 pending_resume_ = false; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1072 | 1132 |
| 1073 void WebMediaPlayerImpl::OnShown() { | 1133 void WebMediaPlayerImpl::OnShown() { |
| 1074 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1134 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1075 | 1135 |
| 1076 #if !defined(OS_ANDROID) | 1136 #if !defined(OS_ANDROID) |
| 1077 // Suspend/Resume is enabled by default on Android. | 1137 // Suspend/Resume is enabled by default on Android. |
| 1078 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 1138 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1079 switches::kEnableMediaSuspend)) { | 1139 switches::kEnableMediaSuspend)) { |
| 1080 return; | 1140 return; |
| 1081 } | 1141 } |
| 1142 #else | |
| 1143 // If we're remote, the pipeline should stay suspended. | |
| 1144 if (cast_impl_.isRemote()) | |
|
sandersd (OOO until July 31)
2016/01/13 22:11:10
Nit: Same here about grouping command line handlin
hubbe
2016/01/13 22:28:25
Done.
| |
| 1145 return; | |
| 1082 #endif // !defined(OS_ANDROID) | 1146 #endif // !defined(OS_ANDROID) |
| 1083 | 1147 |
| 1084 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1148 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1085 switches::kDisableMediaSuspend)) { | 1149 switches::kDisableMediaSuspend)) { |
| 1086 return; | 1150 return; |
| 1087 } | 1151 } |
| 1088 | 1152 |
| 1153 ScheduleResume(); | |
| 1154 } | |
| 1155 | |
| 1156 void WebMediaPlayerImpl::ScheduleResume() { | |
| 1089 if (!pipeline_.IsRunning()) | 1157 if (!pipeline_.IsRunning()) |
| 1090 return; | 1158 return; |
| 1091 | 1159 |
| 1092 if (suspending_) { | 1160 if (suspending_) { |
| 1093 pending_resume_ = true; | 1161 pending_resume_ = true; |
| 1094 return; | 1162 return; |
| 1095 } | 1163 } |
| 1096 | 1164 |
| 1097 if (pending_suspend_) { | 1165 if (pending_suspend_) { |
| 1098 pending_suspend_ = false; | 1166 pending_suspend_ = false; |
| 1099 return; | 1167 return; |
| 1100 } | 1168 } |
| 1101 | 1169 |
| 1102 // We may not be suspended if we were not yet subscribed or the pipeline was | 1170 // Might already be resuming iff we came back from remote playback recently. |
| 1103 // not yet started when OnHidden() fired. | 1171 if (suspended_ && !resuming_) |
| 1104 if (!suspended_) | 1172 Resume(); |
| 1105 return; | |
| 1106 | |
| 1107 Resume(); | |
| 1108 } | 1173 } |
| 1109 | 1174 |
| 1110 void WebMediaPlayerImpl::Resume() { | 1175 void WebMediaPlayerImpl::Resume() { |
| 1111 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1176 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1112 CHECK(suspended_); | 1177 CHECK(suspended_); |
| 1113 CHECK(!resuming_); | 1178 CHECK(!resuming_); |
| 1114 | 1179 |
| 1115 // If there was a time change pending when we suspended (which can happen when | 1180 // If there was a time change pending when we suspended (which can happen when |
| 1116 // we suspend immediately after a seek), surface it after resuming. | 1181 // we suspend immediately after a seek), surface it after resuming. |
| 1117 bool time_changed = pending_time_change_; | 1182 bool time_changed = pending_time_change_; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1133 | 1198 |
| 1134 if (chunk_demuxer_) | 1199 if (chunk_demuxer_) |
| 1135 chunk_demuxer_->StartWaitingForSeek(seek_time_); | 1200 chunk_demuxer_->StartWaitingForSeek(seek_time_); |
| 1136 | 1201 |
| 1137 resuming_ = true; | 1202 resuming_ = true; |
| 1138 pipeline_.Resume(CreateRenderer(), seek_time_, | 1203 pipeline_.Resume(CreateRenderer(), seek_time_, |
| 1139 BIND_TO_RENDER_LOOP1(&WebMediaPlayerImpl::OnPipelineSeeked, | 1204 BIND_TO_RENDER_LOOP1(&WebMediaPlayerImpl::OnPipelineSeeked, |
| 1140 time_changed)); | 1205 time_changed)); |
| 1141 } | 1206 } |
| 1142 | 1207 |
| 1208 #if defined(OS_ANDROID) // WMPI_CAST | |
| 1209 void WebMediaPlayerImpl::set_media_player_manager( | |
| 1210 RendererMediaPlayerManagerInterface* media_player_manager) { | |
| 1211 cast_impl_.set_media_player_manager(media_player_manager); | |
| 1212 } | |
| 1213 | |
| 1214 void WebMediaPlayerImpl::requestRemotePlayback() { | |
| 1215 cast_impl_.requestRemotePlayback(); | |
| 1216 } | |
| 1217 | |
| 1218 void WebMediaPlayerImpl::requestRemotePlaybackControl() { | |
| 1219 cast_impl_.requestRemotePlaybackControl(); | |
| 1220 } | |
| 1221 | |
| 1222 void WebMediaPlayerImpl::OnRemotePlaybackEnded() { | |
| 1223 DVLOG(1) << __FUNCTION__; | |
| 1224 DCHECK(main_task_runner_->BelongsToCurrentThread()); | |
| 1225 | |
| 1226 ended_ = true; | |
| 1227 client_->timeChanged(); | |
| 1228 } | |
| 1229 | |
| 1230 void WebMediaPlayerImpl::OnDisconnectedFromRemoteDevice(double t) { | |
| 1231 paused_time_ = base::TimeDelta::FromSecondsD(t); | |
| 1232 pending_seek_ = true; | |
| 1233 pending_seek_time_ = paused_time_; | |
|
sandersd (OOO until July 31)
2016/01/13 22:11:10
One thing to consider is that there may have been
hubbe
2016/01/13 22:28:25
Wouldn't currentTime() return the right time if a
| |
| 1234 | |
| 1235 ScheduleResume(); | |
| 1236 | |
| 1237 if (paused_time_ == pipeline_.GetMediaDuration()) { | |
| 1238 ended_ = true; | |
| 1239 } | |
| 1240 // We already told the delegate we're paused when remoting started. | |
| 1241 client_->playbackStateChanged(); | |
| 1242 client_->disconnectedFromRemoteDevice(); | |
| 1243 } | |
| 1244 | |
| 1245 void WebMediaPlayerImpl::SuspendForRemote() { | |
| 1246 if (suspended_ && !suspending_) { | |
| 1247 scoped_refptr<VideoFrame> frame = cast_impl_.GetCastingBanner(); | |
| 1248 if (frame) { | |
| 1249 compositor_->PaintFrameUsingOldRenderingPath(frame); | |
| 1250 } | |
| 1251 return; | |
|
sandersd (OOO until July 31)
2016/01/13 22:11:10
Early return here could be in a bad state if there
hubbe
2016/01/13 22:28:25
Done.
| |
| 1252 } | |
| 1253 ScheduleSuspend(); | |
| 1254 } | |
| 1255 | |
| 1256 gfx::Size WebMediaPlayerImpl::GetCanvasSize() const { | |
| 1257 if (!video_weblayer_) | |
| 1258 return gfx::Size(0, 0); | |
| 1259 | |
| 1260 gfx::Size video_size_css_px = video_weblayer_->bounds(); | |
| 1261 float device_scale_factor = frame_->view()->deviceScaleFactor(); | |
| 1262 // canvas_size will be the size in device pixels when pageScaleFactor == 1 | |
| 1263 gfx::Size canvas_size( | |
| 1264 static_cast<int>(video_size_css_px.width() * device_scale_factor), | |
| 1265 static_cast<int>(video_size_css_px.height() * device_scale_factor)); | |
| 1266 return canvas_size; | |
| 1267 } | |
| 1268 #endif // defined(OS_ANDROID) // WMPI_CAST | |
| 1269 | |
| 1143 void WebMediaPlayerImpl::DataSourceInitialized(bool success) { | 1270 void WebMediaPlayerImpl::DataSourceInitialized(bool success) { |
| 1144 DVLOG(1) << __FUNCTION__; | 1271 DVLOG(1) << __FUNCTION__; |
| 1145 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1272 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1146 | 1273 |
| 1147 if (!success) { | 1274 if (!success) { |
| 1148 SetNetworkState(WebMediaPlayer::NetworkStateFormatError); | 1275 SetNetworkState(WebMediaPlayer::NetworkStateFormatError); |
| 1149 return; | 1276 return; |
| 1150 } | 1277 } |
| 1151 | 1278 |
| 1152 StartPipeline(); | 1279 StartPipeline(); |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1314 | 1441 |
| 1315 // pause() may be called after playback has ended and the HTMLMediaElement | 1442 // pause() may be called after playback has ended and the HTMLMediaElement |
| 1316 // requires that currentTime() == duration() after ending. We want to ensure | 1443 // requires that currentTime() == duration() after ending. We want to ensure |
| 1317 // |paused_time_| matches currentTime() in this case or a future seek() may | 1444 // |paused_time_| matches currentTime() in this case or a future seek() may |
| 1318 // incorrectly discard what it thinks is a seek to the existing time. | 1445 // incorrectly discard what it thinks is a seek to the existing time. |
| 1319 paused_time_ = | 1446 paused_time_ = |
| 1320 ended_ ? pipeline_.GetMediaDuration() : pipeline_.GetMediaTime(); | 1447 ended_ ? pipeline_.GetMediaDuration() : pipeline_.GetMediaTime(); |
| 1321 } | 1448 } |
| 1322 | 1449 |
| 1323 void WebMediaPlayerImpl::NotifyPlaybackStarted() { | 1450 void WebMediaPlayerImpl::NotifyPlaybackStarted() { |
| 1451 #if defined(OS_ANDROID) // WMPI_CAST | |
| 1452 // We do not tell our delegates about remote playback, becuase that would | |
| 1453 // keep the device awake, which is not what we want. | |
| 1454 if (cast_impl_.isRemote()) | |
| 1455 return; | |
| 1456 #endif | |
| 1324 if (delegate_) | 1457 if (delegate_) |
| 1325 delegate_->DidPlay(this); | 1458 delegate_->DidPlay(this); |
| 1326 if (!memory_usage_reporting_timer_.IsRunning()) { | 1459 if (!memory_usage_reporting_timer_.IsRunning()) { |
| 1327 memory_usage_reporting_timer_.Start(FROM_HERE, | 1460 memory_usage_reporting_timer_.Start(FROM_HERE, |
| 1328 base::TimeDelta::FromSeconds(2), this, | 1461 base::TimeDelta::FromSeconds(2), this, |
| 1329 &WebMediaPlayerImpl::ReportMemoryUsage); | 1462 &WebMediaPlayerImpl::ReportMemoryUsage); |
| 1330 } | 1463 } |
| 1331 } | 1464 } |
| 1332 | 1465 |
| 1333 void WebMediaPlayerImpl::NotifyPlaybackPaused() { | 1466 void WebMediaPlayerImpl::NotifyPlaybackPaused() { |
| 1467 #if defined(OS_ANDROID) // WMPI_CAST | |
| 1468 if (cast_impl_.isRemote()) | |
| 1469 return; | |
| 1470 #endif | |
| 1334 if (delegate_) | 1471 if (delegate_) |
| 1335 delegate_->DidPause(this); | 1472 delegate_->DidPause(this); |
| 1336 memory_usage_reporting_timer_.Stop(); | 1473 memory_usage_reporting_timer_.Stop(); |
| 1337 ReportMemoryUsage(); | 1474 ReportMemoryUsage(); |
| 1338 } | 1475 } |
| 1339 | 1476 |
| 1340 void WebMediaPlayerImpl::ReportMemoryUsage() { | 1477 void WebMediaPlayerImpl::ReportMemoryUsage() { |
| 1341 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1478 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1342 | 1479 |
| 1343 // About base::Unretained() usage below: We destroy |demuxer_| on the main | 1480 // About base::Unretained() usage below: We destroy |demuxer_| on the main |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 1368 << ", Video: " << stats.video_memory_usage << ", DataSource: " | 1505 << ", Video: " << stats.video_memory_usage << ", DataSource: " |
| 1369 << (data_source_ ? data_source_->GetMemoryUsage() : 0) | 1506 << (data_source_ ? data_source_->GetMemoryUsage() : 0) |
| 1370 << ", Demuxer: " << demuxer_memory_usage; | 1507 << ", Demuxer: " << demuxer_memory_usage; |
| 1371 | 1508 |
| 1372 const int64_t delta = current_memory_usage - last_reported_memory_usage_; | 1509 const int64_t delta = current_memory_usage - last_reported_memory_usage_; |
| 1373 last_reported_memory_usage_ = current_memory_usage; | 1510 last_reported_memory_usage_ = current_memory_usage; |
| 1374 adjust_allocated_memory_cb_.Run(delta); | 1511 adjust_allocated_memory_cb_.Run(delta); |
| 1375 } | 1512 } |
| 1376 | 1513 |
| 1377 } // namespace media | 1514 } // namespace media |
| OLD | NEW |