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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 media_task_runner_(params.media_task_runner()), | 193 media_task_runner_(params.media_task_runner()), |
194 worker_task_runner_(params.worker_task_runner()), | 194 worker_task_runner_(params.worker_task_runner()), |
195 media_log_(params.media_log()), | 195 media_log_(params.media_log()), |
196 pipeline_(media_task_runner_, media_log_.get()), | 196 pipeline_(media_task_runner_, media_log_.get()), |
197 pipeline_controller_( | 197 pipeline_controller_( |
198 &pipeline_, | 198 &pipeline_, |
199 base::Bind(&WebMediaPlayerImpl::CreateRenderer, | 199 base::Bind(&WebMediaPlayerImpl::CreateRenderer, |
200 base::Unretained(this)), | 200 base::Unretained(this)), |
201 base::Bind(&WebMediaPlayerImpl::OnPipelineSeeked, AsWeakPtr()), | 201 base::Bind(&WebMediaPlayerImpl::OnPipelineSeeked, AsWeakPtr()), |
202 base::Bind(&WebMediaPlayerImpl::OnPipelineSuspended, AsWeakPtr()), | 202 base::Bind(&WebMediaPlayerImpl::OnPipelineSuspended, AsWeakPtr()), |
203 base::Bind(&WebMediaPlayerImpl::OnPipelineResumed, AsWeakPtr()), | |
203 base::Bind(&WebMediaPlayerImpl::OnError, AsWeakPtr())), | 204 base::Bind(&WebMediaPlayerImpl::OnError, AsWeakPtr())), |
204 load_type_(LoadTypeURL), | 205 load_type_(LoadTypeURL), |
205 opaque_(false), | 206 opaque_(false), |
206 playback_rate_(0.0), | 207 playback_rate_(0.0), |
207 paused_(true), | 208 paused_(true), |
208 paused_when_hidden_(false), | 209 paused_when_hidden_(false), |
209 seeking_(false), | 210 seeking_(false), |
210 pending_suspend_resume_cycle_(false), | 211 pending_suspend_resume_cycle_(false), |
211 ended_(false), | 212 ended_(false), |
212 should_notify_time_changed_(false), | 213 should_notify_time_changed_(false), |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
467 // incorrectly discard what it thinks is a seek to the existing time. | 468 // incorrectly discard what it thinks is a seek to the existing time. |
468 paused_time_ = | 469 paused_time_ = |
469 ended_ ? pipeline_.GetMediaDuration() : pipeline_.GetMediaTime(); | 470 ended_ ? pipeline_.GetMediaDuration() : pipeline_.GetMediaTime(); |
470 | 471 |
471 if (observer_) | 472 if (observer_) |
472 observer_->OnPaused(); | 473 observer_->OnPaused(); |
473 | 474 |
474 DCHECK(watch_time_reporter_); | 475 DCHECK(watch_time_reporter_); |
475 watch_time_reporter_->OnPaused(); | 476 watch_time_reporter_->OnPaused(); |
476 media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::PAUSE)); | 477 media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::PAUSE)); |
478 | |
479 // Enable the background video track back so that when the new renderer is | |
480 // initialized upon resume, it registers itself with the video track. | |
481 // TODO(avayvod): Remove when disabling video tracks works correctly. See | |
482 // https://crbug.com/678374. | |
483 if (video_track_disabled_) { | |
sandersd (OOO until July 31)
2017/01/09 20:12:49
I think this would be better in an OnBeforeResume(
whywhat
2017/01/10 01:04:48
Sure. I guess the fix would be reduced to enabling
| |
484 video_track_disabled_ = false; | |
485 if (client_->hasSelectedVideoTrack()) { | |
486 WebMediaPlayer::TrackId trackId = client_->getSelectedVideoTrackId(); | |
487 selectedVideoTrackChanged(&trackId); | |
488 } | |
489 } | |
490 | |
477 UpdatePlayState(); | 491 UpdatePlayState(); |
478 } | 492 } |
479 | 493 |
480 bool WebMediaPlayerImpl::supportsSave() const { | 494 bool WebMediaPlayerImpl::supportsSave() const { |
481 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 495 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
482 return supports_save_; | 496 return supports_save_; |
483 } | 497 } |
484 | 498 |
485 void WebMediaPlayerImpl::seek(double seconds) { | 499 void WebMediaPlayerImpl::seek(double seconds) { |
486 DVLOG(1) << __func__ << "(" << seconds << "s)"; | 500 DVLOG(1) << __func__ << "(" << seconds << "s)"; |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
664 << "]"; | 678 << "]"; |
665 pipeline_.OnEnabledAudioTracksChanged(enabledMediaTrackIds); | 679 pipeline_.OnEnabledAudioTracksChanged(enabledMediaTrackIds); |
666 } | 680 } |
667 | 681 |
668 void WebMediaPlayerImpl::selectedVideoTrackChanged( | 682 void WebMediaPlayerImpl::selectedVideoTrackChanged( |
669 blink::WebMediaPlayer::TrackId* selectedTrackId) { | 683 blink::WebMediaPlayer::TrackId* selectedTrackId) { |
670 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 684 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
671 | 685 |
672 std::ostringstream logstr; | 686 std::ostringstream logstr; |
673 std::vector<MediaTrack::Id> selectedVideoMediaTrackId; | 687 std::vector<MediaTrack::Id> selectedVideoMediaTrackId; |
674 bool canAddVideoTrack = | 688 if (selectedTrackId && !video_track_disabled_) { |
675 !IsBackgroundVideoTrackOptimizationEnabled() || !IsHidden(); | |
676 if (selectedTrackId && canAddVideoTrack) { | |
677 selectedVideoMediaTrackId.push_back(selectedTrackId->utf8().data()); | 689 selectedVideoMediaTrackId.push_back(selectedTrackId->utf8().data()); |
678 logstr << selectedVideoMediaTrackId[0]; | 690 logstr << selectedVideoMediaTrackId[0]; |
679 } | 691 } |
680 MEDIA_LOG(INFO, media_log_) << "Selected video track: [" << logstr.str() | 692 MEDIA_LOG(INFO, media_log_) << "Selected video track: [" << logstr.str() |
681 << "]"; | 693 << "]"; |
682 pipeline_.OnSelectedVideoTrackChanged(selectedVideoMediaTrackId); | 694 pipeline_.OnSelectedVideoTrackChanged(selectedVideoMediaTrackId); |
683 } | 695 } |
684 | 696 |
685 blink::WebSize WebMediaPlayerImpl::naturalSize() const { | 697 blink::WebSize WebMediaPlayerImpl::naturalSize() const { |
686 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 698 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1053 set_cdm_result_->completeWithError( | 1065 set_cdm_result_->completeWithError( |
1054 blink::WebContentDecryptionModuleExceptionNotSupportedError, 0, | 1066 blink::WebContentDecryptionModuleExceptionNotSupportedError, 0, |
1055 "Unable to set ContentDecryptionModule object"); | 1067 "Unable to set ContentDecryptionModule object"); |
1056 set_cdm_result_.reset(); | 1068 set_cdm_result_.reset(); |
1057 } | 1069 } |
1058 } | 1070 } |
1059 | 1071 |
1060 void WebMediaPlayerImpl::OnPipelineSeeked(bool time_updated) { | 1072 void WebMediaPlayerImpl::OnPipelineSeeked(bool time_updated) { |
1061 seeking_ = false; | 1073 seeking_ = false; |
1062 seek_time_ = base::TimeDelta(); | 1074 seek_time_ = base::TimeDelta(); |
1075 | |
1063 if (paused_) { | 1076 if (paused_) { |
1064 #if defined(OS_ANDROID) // WMPI_CAST | 1077 #if defined(OS_ANDROID) // WMPI_CAST |
1065 if (isRemote()) { | 1078 if (isRemote()) { |
1066 paused_time_ = base::TimeDelta::FromSecondsD(cast_impl_.currentTime()); | 1079 paused_time_ = base::TimeDelta::FromSecondsD(cast_impl_.currentTime()); |
1067 } else { | 1080 } else { |
1068 paused_time_ = pipeline_.GetMediaTime(); | 1081 paused_time_ = pipeline_.GetMediaTime(); |
1069 } | 1082 } |
1070 #else | 1083 #else |
1071 paused_time_ = pipeline_.GetMediaTime(); | 1084 paused_time_ = pipeline_.GetMediaTime(); |
1072 #endif | 1085 #endif |
(...skipping 27 matching lines...) Expand all Loading... | |
1100 } | 1113 } |
1101 | 1114 |
1102 ReportMemoryUsage(); | 1115 ReportMemoryUsage(); |
1103 | 1116 |
1104 if (pending_suspend_resume_cycle_) { | 1117 if (pending_suspend_resume_cycle_) { |
1105 pending_suspend_resume_cycle_ = false; | 1118 pending_suspend_resume_cycle_ = false; |
1106 UpdatePlayState(); | 1119 UpdatePlayState(); |
1107 } | 1120 } |
1108 } | 1121 } |
1109 | 1122 |
1123 void WebMediaPlayerImpl::OnPipelineResumed() { | |
1124 // Disable video track if we start playing the video in the background and | |
1125 // haven't disabled the decoder yet. | |
1126 // TODO(avayvod): Remove this when disabling and enabling video tracks in | |
1127 // non-playing state works correctly. See https://crbug.com/678374. | |
1128 if (IsBackgroundVideoTrackOptimizationEnabled() && IsHidden() && | |
1129 !video_track_disabled_) { | |
1130 video_track_disabled_ = true; | |
1131 selectedVideoTrackChanged(nullptr); | |
1132 } | |
1133 } | |
1134 | |
1110 void WebMediaPlayerImpl::OnDemuxerOpened() { | 1135 void WebMediaPlayerImpl::OnDemuxerOpened() { |
1111 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1136 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1112 client_->mediaSourceOpened( | 1137 client_->mediaSourceOpened( |
1113 new WebMediaSourceImpl(chunk_demuxer_, media_log_)); | 1138 new WebMediaSourceImpl(chunk_demuxer_, media_log_)); |
1114 } | 1139 } |
1115 | 1140 |
1116 void WebMediaPlayerImpl::OnError(PipelineStatus status) { | 1141 void WebMediaPlayerImpl::OnError(PipelineStatus status) { |
1117 DVLOG(1) << __func__; | 1142 DVLOG(1) << __func__; |
1118 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1143 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1119 DCHECK_NE(status, PIPELINE_OK); | 1144 DCHECK_NE(status, PIPELINE_OK); |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1350 watch_time_reporter_->OnHidden(); | 1375 watch_time_reporter_->OnHidden(); |
1351 | 1376 |
1352 if (IsBackgroundVideoTrackOptimizationEnabled()) { | 1377 if (IsBackgroundVideoTrackOptimizationEnabled()) { |
1353 if (ShouldPauseWhenHidden()) { | 1378 if (ShouldPauseWhenHidden()) { |
1354 // OnPause() will set |paused_when_hidden_| to false and call | 1379 // OnPause() will set |paused_when_hidden_| to false and call |
1355 // UpdatePlayState(), so set the flag to true after and then return. | 1380 // UpdatePlayState(), so set the flag to true after and then return. |
1356 OnPause(); | 1381 OnPause(); |
1357 paused_when_hidden_ = true; | 1382 paused_when_hidden_ = true; |
1358 return; | 1383 return; |
1359 } | 1384 } |
1360 | |
1361 selectedVideoTrackChanged(nullptr); | |
1362 } | 1385 } |
1363 | 1386 |
1364 UpdatePlayState(); | 1387 UpdatePlayState(); |
1365 | 1388 |
1389 // Only disable video tracks for background videos when they're playing. | |
1390 // Otherwise the video track will get detached from the renderer. | |
1391 // TODO(avayvod): Remove extra check once this is no longer happening. | |
1392 // See https://crbug.com/678374. | |
1393 if (IsBackgroundVideoTrackOptimizationEnabled() && | |
1394 delegate_state_ == DelegateState::PLAYING) { | |
sandersd (OOO until July 31)
2017/01/09 20:12:49
Is |delegate_state_| the best thing to check for t
whywhat
2017/01/10 01:04:48
Will try. I saw this member is gone in your refact
| |
1395 video_track_disabled_ = true; | |
1396 selectedVideoTrackChanged(nullptr); | |
1397 } | |
1398 | |
1366 // Schedule suspended playing media to be paused if the user doesn't come back | 1399 // Schedule suspended playing media to be paused if the user doesn't come back |
1367 // to it within some timeout period to avoid any autoplay surprises. | 1400 // to it within some timeout period to avoid any autoplay surprises. |
1368 ScheduleIdlePauseTimer(); | 1401 ScheduleIdlePauseTimer(); |
1369 } | 1402 } |
1370 | 1403 |
1371 void WebMediaPlayerImpl::OnShown() { | 1404 void WebMediaPlayerImpl::OnShown() { |
1372 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1405 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1373 if (watch_time_reporter_) | 1406 if (watch_time_reporter_) |
1374 watch_time_reporter_->OnShown(); | 1407 watch_time_reporter_->OnShown(); |
1375 | 1408 |
1376 compositor_task_runner_->PostTask( | 1409 compositor_task_runner_->PostTask( |
1377 FROM_HERE, | 1410 FROM_HERE, |
1378 base::Bind(&VideoFrameCompositor::SetForegroundTime, | 1411 base::Bind(&VideoFrameCompositor::SetForegroundTime, |
1379 base::Unretained(compositor_), base::TimeTicks::Now())); | 1412 base::Unretained(compositor_), base::TimeTicks::Now())); |
1380 | 1413 |
1381 if (IsBackgroundVideoTrackOptimizationEnabled()) { | 1414 must_suspend_ = false; |
1382 if (paused_when_hidden_) { | 1415 background_pause_timer_.Stop(); |
1383 paused_when_hidden_ = false; | |
1384 OnPlay(); // Calls UpdatePlayState() so return afterwards. | |
1385 return; | |
1386 } | |
1387 | 1416 |
1417 if (paused_when_hidden_) { | |
1418 paused_when_hidden_ = false; | |
1419 OnPlay(); // Calls UpdatePlayState() so return afterwards. | |
1420 return; | |
1421 } | |
1422 | |
1423 if (video_track_disabled_) { | |
1424 video_track_disabled_ = false; | |
1388 if (client_->hasSelectedVideoTrack()) { | 1425 if (client_->hasSelectedVideoTrack()) { |
1389 WebMediaPlayer::TrackId trackId = client_->getSelectedVideoTrackId(); | 1426 WebMediaPlayer::TrackId trackId = client_->getSelectedVideoTrackId(); |
1390 selectedVideoTrackChanged(&trackId); | 1427 selectedVideoTrackChanged(&trackId); |
1391 } | 1428 } |
1392 } | 1429 } |
1393 | 1430 |
1394 must_suspend_ = false; | |
1395 background_pause_timer_.Stop(); | |
1396 | |
1397 UpdatePlayState(); | 1431 UpdatePlayState(); |
1398 } | 1432 } |
1399 | 1433 |
1400 bool WebMediaPlayerImpl::OnSuspendRequested(bool must_suspend) { | 1434 bool WebMediaPlayerImpl::OnSuspendRequested(bool must_suspend) { |
1401 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1435 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1402 | 1436 |
1403 if (must_suspend) { | 1437 if (must_suspend) { |
1404 must_suspend_ = true; | 1438 must_suspend_ = true; |
1405 UpdatePlayState(); | 1439 UpdatePlayState(); |
1406 return true; | 1440 return true; |
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2074 bool WebMediaPlayerImpl::ShouldPauseWhenHidden() const { | 2108 bool WebMediaPlayerImpl::ShouldPauseWhenHidden() const { |
2075 #if defined(OS_ANDROID) // WMPI_CAST | 2109 #if defined(OS_ANDROID) // WMPI_CAST |
2076 if (isRemote()) | 2110 if (isRemote()) |
2077 return false; | 2111 return false; |
2078 #endif // defined(OS_ANDROID) // WMPI_CAST | 2112 #endif // defined(OS_ANDROID) // WMPI_CAST |
2079 | 2113 |
2080 return hasVideo() && !hasAudio(); | 2114 return hasVideo() && !hasAudio(); |
2081 } | 2115 } |
2082 | 2116 |
2083 } // namespace media | 2117 } // namespace media |
OLD | NEW |