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

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

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

Powered by Google App Engine
This is Rietveld 408576698