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 renderer_factory_(std::move(renderer_factory)) { | 184 renderer_factory_(std::move(renderer_factory)) |
185 #if defined(OS_ANDROID) // WMPI_CAST | |
186 ,cast_impl_(this, client_, params.context_3d_cb()) | |
187 #endif | |
188 { | |
185 DCHECK(!adjust_allocated_memory_cb_.is_null()); | 189 DCHECK(!adjust_allocated_memory_cb_.is_null()); |
186 | 190 |
187 if (delegate) | 191 if (delegate) |
188 delegate->AddObserver(this); | 192 delegate->AddObserver(this); |
189 | 193 |
190 media_log_->AddEvent( | 194 media_log_->AddEvent( |
191 media_log_->CreateEvent(MediaLogEvent::WEBMEDIAPLAYER_CREATED)); | 195 media_log_->CreateEvent(MediaLogEvent::WEBMEDIAPLAYER_CREATED)); |
192 | 196 |
193 if (params.initial_cdm()) { | 197 if (params.initial_cdm()) { |
194 SetCdm(base::Bind(&IgnoreCdmAttached), | 198 SetCdm(base::Bind(&IgnoreCdmAttached), |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
293 data_source_.reset(new BufferedDataSource( | 297 data_source_.reset(new BufferedDataSource( |
294 url, static_cast<BufferedResourceLoader::CORSMode>(cors_mode), | 298 url, static_cast<BufferedResourceLoader::CORSMode>(cors_mode), |
295 main_task_runner_, frame_, media_log_.get(), | 299 main_task_runner_, frame_, media_log_.get(), |
296 &buffered_data_source_host_, | 300 &buffered_data_source_host_, |
297 base::Bind(&WebMediaPlayerImpl::NotifyDownloading, AsWeakPtr()))); | 301 base::Bind(&WebMediaPlayerImpl::NotifyDownloading, AsWeakPtr()))); |
298 } | 302 } |
299 data_source_->SetPreload(preload_); | 303 data_source_->SetPreload(preload_); |
300 data_source_->SetBufferingStrategy(buffering_strategy_); | 304 data_source_->SetBufferingStrategy(buffering_strategy_); |
301 data_source_->Initialize( | 305 data_source_->Initialize( |
302 base::Bind(&WebMediaPlayerImpl::DataSourceInitialized, AsWeakPtr())); | 306 base::Bind(&WebMediaPlayerImpl::DataSourceInitialized, AsWeakPtr())); |
307 | |
308 #if defined(OS_ANDROID) // WMPI_CAST | |
309 cast_impl_.Initialize(url, frame_); | |
310 #endif | |
303 } | 311 } |
304 | 312 |
305 void WebMediaPlayerImpl::play() { | 313 void WebMediaPlayerImpl::play() { |
306 DVLOG(1) << __FUNCTION__; | 314 DVLOG(1) << __FUNCTION__; |
307 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 315 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
308 | 316 |
317 #if defined(OS_ANDROID) // WMPI_CAST | |
318 if (cast_impl_.isRemote()) { | |
319 cast_impl_.play(); | |
320 return; | |
321 } | |
322 #endif | |
323 | |
309 paused_ = false; | 324 paused_ = false; |
325 | |
310 pipeline_.SetPlaybackRate(playback_rate_); | 326 pipeline_.SetPlaybackRate(playback_rate_); |
311 if (data_source_) | 327 if (data_source_) |
312 data_source_->MediaIsPlaying(); | 328 data_source_->MediaIsPlaying(); |
313 | 329 |
314 media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::PLAY)); | 330 media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::PLAY)); |
315 | 331 |
316 if (delegate_ && playback_rate_ > 0) | 332 if (delegate_ && playback_rate_ > 0) |
317 NotifyPlaybackStarted(); | 333 NotifyPlaybackStarted(); |
318 } | 334 } |
319 | 335 |
320 void WebMediaPlayerImpl::pause() { | 336 void WebMediaPlayerImpl::pause() { |
321 DVLOG(1) << __FUNCTION__; | 337 DVLOG(1) << __FUNCTION__; |
322 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 338 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
323 | 339 |
324 const bool was_already_paused = paused_ || playback_rate_ == 0; | 340 const bool was_already_paused = paused_ || playback_rate_ == 0; |
325 paused_ = true; | 341 paused_ = true; |
342 | |
343 #if defined(OS_ANDROID) // WMPI_CAST | |
344 if (cast_impl_.isRemote()) { | |
345 cast_impl_.pause(); | |
346 return; | |
347 } | |
348 #endif | |
349 | |
326 pipeline_.SetPlaybackRate(0.0); | 350 pipeline_.SetPlaybackRate(0.0); |
327 UpdatePausedTime(); | 351 UpdatePausedTime(); |
328 | 352 |
329 media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::PAUSE)); | 353 media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::PAUSE)); |
330 | 354 |
331 if (!was_already_paused && delegate_) | 355 if (!was_already_paused && delegate_) |
332 NotifyPlaybackPaused(); | 356 NotifyPlaybackPaused(); |
333 } | 357 } |
334 | 358 |
335 bool WebMediaPlayerImpl::supportsSave() const { | 359 bool WebMediaPlayerImpl::supportsSave() const { |
336 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 360 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
337 return supports_save_; | 361 return supports_save_; |
338 } | 362 } |
339 | 363 |
340 void WebMediaPlayerImpl::seek(double seconds) { | 364 void WebMediaPlayerImpl::seek(double seconds) { |
341 DVLOG(1) << __FUNCTION__ << "(" << seconds << "s)"; | 365 DVLOG(1) << __FUNCTION__ << "(" << seconds << "s)"; |
342 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 366 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
343 | 367 |
344 ended_ = false; | 368 ended_ = false; |
345 | 369 |
370 base::TimeDelta new_seek_time = base::TimeDelta::FromSecondsD(seconds); | |
371 | |
372 #if defined(OS_ANDROID) // WMPI_CAST | |
373 if (cast_impl_.isRemote()) { | |
374 cast_impl_.seek(new_seek_time); | |
375 return; | |
376 } | |
377 #endif | |
378 | |
346 ReadyState old_state = ready_state_; | 379 ReadyState old_state = ready_state_; |
347 if (ready_state_ > WebMediaPlayer::ReadyStateHaveMetadata) | 380 if (ready_state_ > WebMediaPlayer::ReadyStateHaveMetadata) |
348 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); | 381 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); |
349 | 382 |
350 base::TimeDelta new_seek_time = base::TimeDelta::FromSecondsD(seconds); | |
351 | |
352 if (seeking_ || suspended_) { | 383 if (seeking_ || suspended_) { |
353 // Once resuming, it's too late to change the resume time and so the | 384 // Once resuming, it's too late to change the resume time and so the |
354 // implementation is a little different. | 385 // implementation is a little different. |
355 bool is_suspended = suspended_ && !resuming_; | 386 bool is_suspended = suspended_ && !resuming_; |
356 | 387 |
357 // If we are currently seeking or resuming to |new_seek_time|, skip the | 388 // If we are currently seeking or resuming to |new_seek_time|, skip the |
358 // seek (except for MSE, which always seeks). | 389 // seek (except for MSE, which always seeks). |
359 if (!is_suspended && new_seek_time == seek_time_) { | 390 if (!is_suspended && new_seek_time == seek_time_) { |
360 if (chunk_demuxer_) { | 391 if (chunk_demuxer_) { |
361 // Don't suppress any redundant in-progress MSE seek. There could have | 392 // 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; | 446 return; |
416 } | 447 } |
417 } | 448 } |
418 | 449 |
419 seeking_ = true; | 450 seeking_ = true; |
420 seek_time_ = new_seek_time; | 451 seek_time_ = new_seek_time; |
421 | 452 |
422 if (chunk_demuxer_) | 453 if (chunk_demuxer_) |
423 chunk_demuxer_->StartWaitingForSeek(seek_time_); | 454 chunk_demuxer_->StartWaitingForSeek(seek_time_); |
424 | 455 |
425 // Kick off the asynchronous seek! | |
426 pipeline_.Seek(seek_time_, BIND_TO_RENDER_LOOP1( | 456 pipeline_.Seek(seek_time_, BIND_TO_RENDER_LOOP1( |
427 &WebMediaPlayerImpl::OnPipelineSeeked, true)); | 457 &WebMediaPlayerImpl::OnPipelineSeeked, true)); |
428 } | 458 } |
429 | 459 |
430 void WebMediaPlayerImpl::setRate(double rate) { | 460 void WebMediaPlayerImpl::setRate(double rate) { |
431 DVLOG(1) << __FUNCTION__ << "(" << rate << ")"; | 461 DVLOG(1) << __FUNCTION__ << "(" << rate << ")"; |
432 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 462 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
433 | 463 |
434 // TODO(kylep): Remove when support for negatives is added. Also, modify the | 464 // TODO(kylep): Remove when support for negatives is added. Also, modify the |
435 // following checks so rewind uses reasonable values also. | 465 // following checks so rewind uses reasonable values also. |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
532 | 562 |
533 blink::WebSize WebMediaPlayerImpl::naturalSize() const { | 563 blink::WebSize WebMediaPlayerImpl::naturalSize() const { |
534 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 564 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
535 | 565 |
536 return blink::WebSize(pipeline_metadata_.natural_size); | 566 return blink::WebSize(pipeline_metadata_.natural_size); |
537 } | 567 } |
538 | 568 |
539 bool WebMediaPlayerImpl::paused() const { | 569 bool WebMediaPlayerImpl::paused() const { |
540 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 570 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
541 | 571 |
572 #if defined(OS_ANDROID) // WMPI_CAST | |
573 if (cast_impl_.isRemote()) | |
574 return cast_impl_.paused(); | |
575 #endif | |
542 return pipeline_.GetPlaybackRate() == 0.0f; | 576 return pipeline_.GetPlaybackRate() == 0.0f; |
543 } | 577 } |
544 | 578 |
545 bool WebMediaPlayerImpl::seeking() const { | 579 bool WebMediaPlayerImpl::seeking() const { |
546 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 580 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
547 | 581 |
548 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing) | 582 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing) |
549 return false; | 583 return false; |
550 | 584 |
551 return seeking_; | 585 return seeking_; |
(...skipping 27 matching lines...) Expand all Loading... | |
579 return duration(); | 613 return duration(); |
580 | 614 |
581 // We know the current seek time better than pipeline: pipeline may processing | 615 // 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 | 616 // an earlier seek before a pending seek has been started, or it might not yet |
583 // have the current seek time returnable via GetMediaTime(). | 617 // have the current seek time returnable via GetMediaTime(). |
584 if (seeking()) { | 618 if (seeking()) { |
585 return pending_seek_ ? pending_seek_time_.InSecondsF() | 619 return pending_seek_ ? pending_seek_time_.InSecondsF() |
586 : seek_time_.InSecondsF(); | 620 : seek_time_.InSecondsF(); |
587 } | 621 } |
588 | 622 |
589 return (paused_ ? paused_time_ : pipeline_.GetMediaTime()).InSecondsF(); | 623 #if defined(OS_ANDROID) // WMPI_CAST |
624 if (cast_impl_.isRemote()) { | |
625 return cast_impl_.currentTime(); | |
626 } | |
627 #endif | |
628 | |
629 if (paused_) { | |
630 return paused_time_.InSecondsF(); | |
631 } | |
632 | |
633 return pipeline_.GetMediaTime().InSecondsF(); | |
590 } | 634 } |
591 | 635 |
592 WebMediaPlayer::NetworkState WebMediaPlayerImpl::networkState() const { | 636 WebMediaPlayer::NetworkState WebMediaPlayerImpl::networkState() const { |
593 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 637 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
594 return network_state_; | 638 return network_state_; |
595 } | 639 } |
596 | 640 |
597 WebMediaPlayer::ReadyState WebMediaPlayerImpl::readyState() const { | 641 WebMediaPlayer::ReadyState WebMediaPlayerImpl::readyState() const { |
598 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 642 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
599 return ready_state_; | 643 return ready_state_; |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1041 #endif // !defined(OS_ANDROID) | 1085 #endif // !defined(OS_ANDROID) |
1042 | 1086 |
1043 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1087 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
1044 switches::kDisableMediaSuspend)) { | 1088 switches::kDisableMediaSuspend)) { |
1045 return; | 1089 return; |
1046 } | 1090 } |
1047 | 1091 |
1048 if (!pipeline_.IsRunning()) | 1092 if (!pipeline_.IsRunning()) |
1049 return; | 1093 return; |
1050 | 1094 |
1095 if (suspended_) | |
sandersd (OOO until July 31)
2016/01/13 00:23:08
This is not the right place because while suspende
hubbe
2016/01/13 19:21:55
Better?
| |
1096 return; | |
1097 | |
1051 if (resuming_ || seeking_) { | 1098 if (resuming_ || seeking_) { |
1052 pending_suspend_ = true; | 1099 pending_suspend_ = true; |
1053 return; | 1100 return; |
1054 } | 1101 } |
1055 | 1102 |
1056 if (pending_resume_) { | 1103 if (pending_resume_) { |
1057 pending_resume_ = false; | 1104 pending_resume_ = false; |
1058 return; | 1105 return; |
1059 } | 1106 } |
1060 | 1107 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1094 return; | 1141 return; |
1095 } | 1142 } |
1096 | 1143 |
1097 if (pending_suspend_) { | 1144 if (pending_suspend_) { |
1098 pending_suspend_ = false; | 1145 pending_suspend_ = false; |
1099 return; | 1146 return; |
1100 } | 1147 } |
1101 | 1148 |
1102 // We may not be suspended if we were not yet subscribed or the pipeline was | 1149 // We may not be suspended if we were not yet subscribed or the pipeline was |
1103 // not yet started when OnHidden() fired. | 1150 // not yet started when OnHidden() fired. |
1104 if (!suspended_) | 1151 if (!suspended_ || resuming_) |
sandersd (OOO until July 31)
2016/01/13 00:23:08
Without cast changes, it's not possible to be resu
hubbe
2016/01/13 19:21:55
Done.
| |
1105 return; | 1152 return; |
1106 | 1153 |
1107 Resume(); | 1154 Resume(); |
1108 } | 1155 } |
1109 | 1156 |
1110 void WebMediaPlayerImpl::Resume() { | 1157 void WebMediaPlayerImpl::Resume() { |
1111 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1158 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1112 CHECK(suspended_); | 1159 CHECK(suspended_); |
1113 CHECK(!resuming_); | 1160 CHECK(!resuming_); |
1114 | 1161 |
(...skipping 18 matching lines...) Expand all Loading... | |
1133 | 1180 |
1134 if (chunk_demuxer_) | 1181 if (chunk_demuxer_) |
1135 chunk_demuxer_->StartWaitingForSeek(seek_time_); | 1182 chunk_demuxer_->StartWaitingForSeek(seek_time_); |
1136 | 1183 |
1137 resuming_ = true; | 1184 resuming_ = true; |
1138 pipeline_.Resume(CreateRenderer(), seek_time_, | 1185 pipeline_.Resume(CreateRenderer(), seek_time_, |
1139 BIND_TO_RENDER_LOOP1(&WebMediaPlayerImpl::OnPipelineSeeked, | 1186 BIND_TO_RENDER_LOOP1(&WebMediaPlayerImpl::OnPipelineSeeked, |
1140 time_changed)); | 1187 time_changed)); |
1141 } | 1188 } |
1142 | 1189 |
1190 #if defined(OS_ANDROID) // WMPI_CAST | |
1191 void WebMediaPlayerImpl::set_media_player_manager( | |
1192 RendererMediaPlayerManagerInterface* media_player_manager) { | |
1193 cast_impl_.set_media_player_manager(media_player_manager); | |
1194 } | |
1195 | |
1196 void WebMediaPlayerImpl::requestRemotePlayback() { | |
1197 cast_impl_.requestRemotePlayback(); | |
1198 } | |
1199 | |
1200 void WebMediaPlayerImpl::requestRemotePlaybackControl() { | |
1201 cast_impl_.requestRemotePlaybackControl(); | |
1202 } | |
1203 | |
1204 void WebMediaPlayerImpl::OnRemotePlaybackEnded() { | |
1205 DVLOG(1) << __FUNCTION__; | |
1206 DCHECK(main_task_runner_->BelongsToCurrentThread()); | |
1207 | |
1208 ended_ = true; | |
1209 client_->timeChanged(); | |
1210 } | |
1211 | |
1212 void WebMediaPlayerImpl::OnDisconnectedFromRemoteDevice(double t) { | |
1213 pipeline_.SetPlaybackRate(0.0); | |
sandersd (OOO until July 31)
2016/01/13 00:23:08
Here we want to make sure that Blink finds out tha
hubbe
2016/01/13 19:21:55
We don't want to call DidPause(), and WebMediaPlay
| |
1214 paused_time_ = base::TimeDelta::FromSecondsD(t); | |
1215 pending_seek_ = true; | |
1216 pending_seek_time_ = paused_time_; | |
1217 | |
1218 if (suspended_ && !resuming_) | |
sandersd (OOO until July 31)
2016/01/13 00:23:08
Here again what we really want is to factor out th
hubbe
2016/01/13 19:21:55
Done.
| |
1219 Resume(); | |
1220 | |
1221 // We already told the delegate we're paused when remoting started. | |
1222 client_->disconnectedFromRemoteDevice(); | |
1223 if (!paused_) { | |
1224 paused_ = true; | |
1225 client_->playbackStateChanged(); | |
1226 } | |
1227 if (paused_time_ == pipeline_.GetMediaDuration()) { | |
1228 ended_ = true; | |
1229 } | |
1230 } | |
1231 | |
1232 void WebMediaPlayerImpl::SuspendForRemote( | |
1233 const scoped_refptr<VideoFrame>& new_frame) { | |
1234 if (!suspended_ && !suspending_) { | |
sandersd (OOO until July 31)
2016/01/13 00:23:08
|suspending_| is a subset of |suspended_|.
In gen
hubbe
2016/01/13 19:21:55
Done.
| |
1235 suspended_ = true; | |
1236 suspending_ = true; | |
1237 pipeline_.Suspend( | |
1238 BIND_TO_RENDER_LOOP1(&WebMediaPlayerImpl::DisplayCastFrameAfterSuspend, | |
1239 new_frame)); | |
1240 } else { | |
1241 compositor_->PaintFrameUsingOldRenderingPath(new_frame); | |
1242 } | |
1243 } | |
1244 | |
1245 void WebMediaPlayerImpl::DisplayCastFrameAfterSuspend( | |
1246 const scoped_refptr<VideoFrame>& new_frame, | |
1247 PipelineStatus status) { | |
1248 compositor_->PaintFrameUsingOldRenderingPath(new_frame); | |
1249 OnPipelineSuspended(status); | |
1250 } | |
1251 | |
1252 gfx::Size WebMediaPlayerImpl::GetCanvasSize() const { | |
1253 if (!video_weblayer_) | |
1254 return gfx::Size(0, 0); | |
1255 | |
1256 gfx::Size video_size_css_px = video_weblayer_->bounds(); | |
1257 float device_scale_factor = frame_->view()->deviceScaleFactor(); | |
1258 // canvas_size will be the size in device pixels when pageScaleFactor == 1 | |
1259 gfx::Size canvas_size( | |
1260 static_cast<int>(video_size_css_px.width() * device_scale_factor), | |
1261 static_cast<int>(video_size_css_px.height() * device_scale_factor)); | |
1262 return canvas_size; | |
1263 } | |
1264 #endif // defined(OS_ANDROID) // WMPI_CAST | |
1265 | |
1143 void WebMediaPlayerImpl::DataSourceInitialized(bool success) { | 1266 void WebMediaPlayerImpl::DataSourceInitialized(bool success) { |
1144 DVLOG(1) << __FUNCTION__; | 1267 DVLOG(1) << __FUNCTION__; |
1145 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1268 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1146 | 1269 |
1147 if (!success) { | 1270 if (!success) { |
1148 SetNetworkState(WebMediaPlayer::NetworkStateFormatError); | 1271 SetNetworkState(WebMediaPlayer::NetworkStateFormatError); |
1149 return; | 1272 return; |
1150 } | 1273 } |
1151 | 1274 |
1152 StartPipeline(); | 1275 StartPipeline(); |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1314 | 1437 |
1315 // pause() may be called after playback has ended and the HTMLMediaElement | 1438 // pause() may be called after playback has ended and the HTMLMediaElement |
1316 // requires that currentTime() == duration() after ending. We want to ensure | 1439 // requires that currentTime() == duration() after ending. We want to ensure |
1317 // |paused_time_| matches currentTime() in this case or a future seek() may | 1440 // |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. | 1441 // incorrectly discard what it thinks is a seek to the existing time. |
1319 paused_time_ = | 1442 paused_time_ = |
1320 ended_ ? pipeline_.GetMediaDuration() : pipeline_.GetMediaTime(); | 1443 ended_ ? pipeline_.GetMediaDuration() : pipeline_.GetMediaTime(); |
1321 } | 1444 } |
1322 | 1445 |
1323 void WebMediaPlayerImpl::NotifyPlaybackStarted() { | 1446 void WebMediaPlayerImpl::NotifyPlaybackStarted() { |
1447 #if defined(OS_ANDROID) // WMPI_CAST | |
1448 // We do not tell our delegates about remote playback, becuase that would | |
1449 // keep the device awake, which is not what we want. | |
1450 if (cast_impl_.isRemote()) | |
1451 return; | |
1452 #endif | |
1324 if (delegate_) | 1453 if (delegate_) |
1325 delegate_->DidPlay(this); | 1454 delegate_->DidPlay(this); |
1326 if (!memory_usage_reporting_timer_.IsRunning()) { | 1455 if (!memory_usage_reporting_timer_.IsRunning()) { |
1327 memory_usage_reporting_timer_.Start(FROM_HERE, | 1456 memory_usage_reporting_timer_.Start(FROM_HERE, |
1328 base::TimeDelta::FromSeconds(2), this, | 1457 base::TimeDelta::FromSeconds(2), this, |
1329 &WebMediaPlayerImpl::ReportMemoryUsage); | 1458 &WebMediaPlayerImpl::ReportMemoryUsage); |
1330 } | 1459 } |
1331 } | 1460 } |
1332 | 1461 |
1333 void WebMediaPlayerImpl::NotifyPlaybackPaused() { | 1462 void WebMediaPlayerImpl::NotifyPlaybackPaused() { |
1463 #if defined(OS_ANDROID) // WMPI_CAST | |
1464 if (cast_impl_.isRemote()) | |
1465 return; | |
1466 #endif | |
1334 if (delegate_) | 1467 if (delegate_) |
1335 delegate_->DidPause(this); | 1468 delegate_->DidPause(this); |
1336 memory_usage_reporting_timer_.Stop(); | 1469 memory_usage_reporting_timer_.Stop(); |
1337 ReportMemoryUsage(); | 1470 ReportMemoryUsage(); |
1338 } | 1471 } |
1339 | 1472 |
1340 void WebMediaPlayerImpl::ReportMemoryUsage() { | 1473 void WebMediaPlayerImpl::ReportMemoryUsage() { |
1341 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1474 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1342 | 1475 |
1343 // About base::Unretained() usage below: We destroy |demuxer_| on the main | 1476 // 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: " | 1501 << ", Video: " << stats.video_memory_usage << ", DataSource: " |
1369 << (data_source_ ? data_source_->GetMemoryUsage() : 0) | 1502 << (data_source_ ? data_source_->GetMemoryUsage() : 0) |
1370 << ", Demuxer: " << demuxer_memory_usage; | 1503 << ", Demuxer: " << demuxer_memory_usage; |
1371 | 1504 |
1372 const int64_t delta = current_memory_usage - last_reported_memory_usage_; | 1505 const int64_t delta = current_memory_usage - last_reported_memory_usage_; |
1373 last_reported_memory_usage_ = current_memory_usage; | 1506 last_reported_memory_usage_ = current_memory_usage; |
1374 adjust_allocated_memory_cb_.Run(delta); | 1507 adjust_allocated_memory_cb_.Run(delta); |
1375 } | 1508 } |
1376 | 1509 |
1377 } // namespace media | 1510 } // namespace media |
OLD | NEW |