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 seeking_(false), | 209 seeking_(false), |
209 pending_suspend_resume_cycle_(false), | 210 pending_suspend_resume_cycle_(false), |
210 ended_(false), | 211 ended_(false), |
211 should_notify_time_changed_(false), | 212 should_notify_time_changed_(false), |
212 overlay_enabled_(false), | 213 overlay_enabled_(false), |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
463 // incorrectly discard what it thinks is a seek to the existing time. | 464 // incorrectly discard what it thinks is a seek to the existing time. |
464 paused_time_ = | 465 paused_time_ = |
465 ended_ ? pipeline_.GetMediaDuration() : pipeline_.GetMediaTime(); | 466 ended_ ? pipeline_.GetMediaDuration() : pipeline_.GetMediaTime(); |
466 | 467 |
467 if (observer_) | 468 if (observer_) |
468 observer_->OnPaused(); | 469 observer_->OnPaused(); |
469 | 470 |
470 DCHECK(watch_time_reporter_); | 471 DCHECK(watch_time_reporter_); |
471 watch_time_reporter_->OnPaused(); | 472 watch_time_reporter_->OnPaused(); |
472 media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::PAUSE)); | 473 media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::PAUSE)); |
474 | |
475 // Enable the background video track back so that when the new renderer is | |
476 // initialized upon resume, it registers itself with the video track. | |
477 // TODO(avayvod): Remove when disabling video tracks works correctly. See | |
478 // https://crbug.com/678374. | |
479 if (video_track_disabled_) { | |
480 video_track_disabled_ = false; | |
481 if (client_->hasSelectedVideoTrack()) { | |
482 WebMediaPlayer::TrackId trackId = client_->getSelectedVideoTrackId(); | |
483 selectedVideoTrackChanged(&trackId); | |
484 } | |
485 } | |
486 | |
473 UpdatePlayState(); | 487 UpdatePlayState(); |
474 } | 488 } |
475 | 489 |
476 bool WebMediaPlayerImpl::supportsSave() const { | 490 bool WebMediaPlayerImpl::supportsSave() const { |
477 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 491 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
478 return supports_save_; | 492 return supports_save_; |
479 } | 493 } |
480 | 494 |
481 void WebMediaPlayerImpl::seek(double seconds) { | 495 void WebMediaPlayerImpl::seek(double seconds) { |
482 DVLOG(1) << __func__ << "(" << seconds << "s)"; | 496 DVLOG(1) << __func__ << "(" << seconds << "s)"; |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
660 << "]"; | 674 << "]"; |
661 pipeline_.OnEnabledAudioTracksChanged(enabledMediaTrackIds); | 675 pipeline_.OnEnabledAudioTracksChanged(enabledMediaTrackIds); |
662 } | 676 } |
663 | 677 |
664 void WebMediaPlayerImpl::selectedVideoTrackChanged( | 678 void WebMediaPlayerImpl::selectedVideoTrackChanged( |
665 blink::WebMediaPlayer::TrackId* selectedTrackId) { | 679 blink::WebMediaPlayer::TrackId* selectedTrackId) { |
666 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 680 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
667 | 681 |
668 std::ostringstream logstr; | 682 std::ostringstream logstr; |
669 std::vector<MediaTrack::Id> selectedVideoMediaTrackId; | 683 std::vector<MediaTrack::Id> selectedVideoMediaTrackId; |
670 bool canAddVideoTrack = | 684 if (selectedTrackId && !video_track_disabled_) { |
671 !IsBackgroundVideoTrackOptimizationEnabled() || !IsHidden(); | |
672 if (selectedTrackId && canAddVideoTrack) { | |
673 selectedVideoMediaTrackId.push_back(selectedTrackId->utf8().data()); | 685 selectedVideoMediaTrackId.push_back(selectedTrackId->utf8().data()); |
674 logstr << selectedVideoMediaTrackId[0]; | 686 logstr << selectedVideoMediaTrackId[0]; |
675 } | 687 } |
676 MEDIA_LOG(INFO, media_log_) << "Selected video track: [" << logstr.str() | 688 MEDIA_LOG(INFO, media_log_) << "Selected video track: [" << logstr.str() |
677 << "]"; | 689 << "]"; |
678 pipeline_.OnSelectedVideoTrackChanged(selectedVideoMediaTrackId); | 690 pipeline_.OnSelectedVideoTrackChanged(selectedVideoMediaTrackId); |
679 } | 691 } |
680 | 692 |
681 blink::WebSize WebMediaPlayerImpl::naturalSize() const { | 693 blink::WebSize WebMediaPlayerImpl::naturalSize() const { |
682 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 694 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1047 pending_cdm_ = nullptr; | 1059 pending_cdm_ = nullptr; |
1048 if (set_cdm_result_) { | 1060 if (set_cdm_result_) { |
1049 set_cdm_result_->completeWithError( | 1061 set_cdm_result_->completeWithError( |
1050 blink::WebContentDecryptionModuleExceptionNotSupportedError, 0, | 1062 blink::WebContentDecryptionModuleExceptionNotSupportedError, 0, |
1051 "Unable to set ContentDecryptionModule object"); | 1063 "Unable to set ContentDecryptionModule object"); |
1052 set_cdm_result_.reset(); | 1064 set_cdm_result_.reset(); |
1053 } | 1065 } |
1054 } | 1066 } |
1055 | 1067 |
1056 void WebMediaPlayerImpl::OnPipelineSeeked(bool time_updated) { | 1068 void WebMediaPlayerImpl::OnPipelineSeeked(bool time_updated) { |
1057 seeking_ = false; | 1069 if (seeking_) { |
sandersd (OOO until July 31)
2017/01/07 00:56:17
Shouldn't be needed anymore?
whywhat
2017/01/07 02:02:35
Done.
| |
1058 seek_time_ = base::TimeDelta(); | 1070 seeking_ = false; |
1071 seek_time_ = base::TimeDelta(); | |
1072 } | |
1073 | |
1059 if (paused_) { | 1074 if (paused_) { |
1060 #if defined(OS_ANDROID) // WMPI_CAST | 1075 #if defined(OS_ANDROID) // WMPI_CAST |
1061 if (isRemote()) { | 1076 if (isRemote()) { |
1062 paused_time_ = base::TimeDelta::FromSecondsD(cast_impl_.currentTime()); | 1077 paused_time_ = base::TimeDelta::FromSecondsD(cast_impl_.currentTime()); |
1063 } else { | 1078 } else { |
1064 paused_time_ = pipeline_.GetMediaTime(); | 1079 paused_time_ = pipeline_.GetMediaTime(); |
1065 } | 1080 } |
1066 #else | 1081 #else |
1067 paused_time_ = pipeline_.GetMediaTime(); | 1082 paused_time_ = pipeline_.GetMediaTime(); |
1068 #endif | 1083 #endif |
(...skipping 27 matching lines...) Expand all Loading... | |
1096 } | 1111 } |
1097 | 1112 |
1098 ReportMemoryUsage(); | 1113 ReportMemoryUsage(); |
1099 | 1114 |
1100 if (pending_suspend_resume_cycle_) { | 1115 if (pending_suspend_resume_cycle_) { |
1101 pending_suspend_resume_cycle_ = false; | 1116 pending_suspend_resume_cycle_ = false; |
1102 UpdatePlayState(); | 1117 UpdatePlayState(); |
1103 } | 1118 } |
1104 } | 1119 } |
1105 | 1120 |
1121 void WebMediaPlayerImpl::OnPipelineResumed() { | |
1122 // Disable video track if we start playing the video in the background and | |
1123 // haven't disabled the decoder yet. | |
1124 // TODO(avayvod): Remove this when disabling and enabling video tracks in | |
1125 // non-playing state works correctly. See https://crbug.com/678374. | |
1126 if (IsBackgroundVideoTrackOptimizationEnabled() && IsHidden() && | |
1127 !video_track_disabled_) { | |
1128 video_track_disabled_ = true; | |
1129 selectedVideoTrackChanged(nullptr); | |
1130 } | |
1131 } | |
1132 | |
1106 void WebMediaPlayerImpl::OnDemuxerOpened() { | 1133 void WebMediaPlayerImpl::OnDemuxerOpened() { |
1107 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1134 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1108 client_->mediaSourceOpened( | 1135 client_->mediaSourceOpened( |
1109 new WebMediaSourceImpl(chunk_demuxer_, media_log_)); | 1136 new WebMediaSourceImpl(chunk_demuxer_, media_log_)); |
1110 } | 1137 } |
1111 | 1138 |
1112 void WebMediaPlayerImpl::OnError(PipelineStatus status) { | 1139 void WebMediaPlayerImpl::OnError(PipelineStatus status) { |
1113 DVLOG(1) << __func__; | 1140 DVLOG(1) << __func__; |
1114 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1141 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1115 DCHECK_NE(status, PIPELINE_OK); | 1142 DCHECK_NE(status, PIPELINE_OK); |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1329 opaque_ = opaque; | 1356 opaque_ = opaque; |
1330 // Modify content opaqueness of cc::Layer directly so that | 1357 // Modify content opaqueness of cc::Layer directly so that |
1331 // SetContentsOpaqueIsFixed is ignored. | 1358 // SetContentsOpaqueIsFixed is ignored. |
1332 if (video_weblayer_) | 1359 if (video_weblayer_) |
1333 video_weblayer_->layer()->SetContentsOpaque(opaque_); | 1360 video_weblayer_->layer()->SetContentsOpaque(opaque_); |
1334 } | 1361 } |
1335 | 1362 |
1336 void WebMediaPlayerImpl::OnHidden() { | 1363 void WebMediaPlayerImpl::OnHidden() { |
1337 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1364 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1338 | 1365 |
1339 if (IsBackgroundVideoTrackOptimizationEnabled()) | |
1340 selectedVideoTrackChanged(nullptr); | |
1341 | |
1342 if (watch_time_reporter_) | 1366 if (watch_time_reporter_) |
1343 watch_time_reporter_->OnHidden(); | 1367 watch_time_reporter_->OnHidden(); |
1344 | 1368 |
1345 UpdatePlayState(); | 1369 UpdatePlayState(); |
1346 | 1370 |
1371 // Only disable video tracks for background videos when they're playing. | |
1372 // Otherwise the video track will get detached from the renderer. | |
1373 // TODO(avayvod): Remove extra check once this is no longer happening. | |
1374 // See https://crbug.com/678374. | |
1375 if (IsBackgroundVideoTrackOptimizationEnabled() && | |
1376 delegate_state_ == DelegateState::PLAYING) { | |
1377 video_track_disabled_ = true; | |
1378 selectedVideoTrackChanged(nullptr); | |
1379 } | |
1380 | |
1347 // Schedule suspended playing media to be paused if the user doesn't come back | 1381 // Schedule suspended playing media to be paused if the user doesn't come back |
1348 // to it within some timeout period to avoid any autoplay surprises. | 1382 // to it within some timeout period to avoid any autoplay surprises. |
1349 ScheduleIdlePauseTimer(); | 1383 ScheduleIdlePauseTimer(); |
1350 } | 1384 } |
1351 | 1385 |
1352 void WebMediaPlayerImpl::OnShown() { | 1386 void WebMediaPlayerImpl::OnShown() { |
1353 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1387 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1354 if (watch_time_reporter_) | 1388 if (watch_time_reporter_) |
1355 watch_time_reporter_->OnShown(); | 1389 watch_time_reporter_->OnShown(); |
1356 | 1390 |
1357 compositor_task_runner_->PostTask( | 1391 compositor_task_runner_->PostTask( |
1358 FROM_HERE, | 1392 FROM_HERE, |
1359 base::Bind(&VideoFrameCompositor::SetForegroundTime, | 1393 base::Bind(&VideoFrameCompositor::SetForegroundTime, |
1360 base::Unretained(compositor_), base::TimeTicks::Now())); | 1394 base::Unretained(compositor_), base::TimeTicks::Now())); |
1361 | 1395 |
1362 if (IsBackgroundVideoTrackOptimizationEnabled() && | |
1363 client_->hasSelectedVideoTrack()) { | |
1364 WebMediaPlayer::TrackId trackId = client_->getSelectedVideoTrackId(); | |
1365 selectedVideoTrackChanged(&trackId); | |
1366 } | |
1367 | |
1368 must_suspend_ = false; | 1396 must_suspend_ = false; |
1369 background_pause_timer_.Stop(); | 1397 background_pause_timer_.Stop(); |
1370 | 1398 |
1399 if (video_track_disabled_) { | |
1400 video_track_disabled_ = false; | |
1401 if (client_->hasSelectedVideoTrack()) { | |
1402 WebMediaPlayer::TrackId trackId = client_->getSelectedVideoTrackId(); | |
1403 selectedVideoTrackChanged(&trackId); | |
1404 } | |
1405 } | |
1406 | |
1371 UpdatePlayState(); | 1407 UpdatePlayState(); |
1372 } | 1408 } |
1373 | 1409 |
1374 bool WebMediaPlayerImpl::OnSuspendRequested(bool must_suspend) { | 1410 bool WebMediaPlayerImpl::OnSuspendRequested(bool must_suspend) { |
1375 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1411 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1376 | 1412 |
1377 if (must_suspend) { | 1413 if (must_suspend) { |
1378 must_suspend_ = true; | 1414 must_suspend_ = true; |
1379 UpdatePlayState(); | 1415 UpdatePlayState(); |
1380 return true; | 1416 return true; |
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2039 return pipeline_metadata_.video_rotation == VIDEO_ROTATION_0; | 2075 return pipeline_metadata_.video_rotation == VIDEO_ROTATION_0; |
2040 } | 2076 } |
2041 | 2077 |
2042 void WebMediaPlayerImpl::ActivateViewportIntersectionMonitoring(bool activate) { | 2078 void WebMediaPlayerImpl::ActivateViewportIntersectionMonitoring(bool activate) { |
2043 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 2079 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
2044 | 2080 |
2045 client_->activateViewportIntersectionMonitoring(activate); | 2081 client_->activateViewportIntersectionMonitoring(activate); |
2046 } | 2082 } |
2047 | 2083 |
2048 } // namespace media | 2084 } // namespace media |
OLD | NEW |