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 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 << "]"; | 642 << "]"; |
643 pipeline_.OnEnabledAudioTracksChanged(enabledMediaTrackIds); | 643 pipeline_.OnEnabledAudioTracksChanged(enabledMediaTrackIds); |
644 } | 644 } |
645 | 645 |
646 void WebMediaPlayerImpl::selectedVideoTrackChanged( | 646 void WebMediaPlayerImpl::selectedVideoTrackChanged( |
647 blink::WebMediaPlayer::TrackId* selectedTrackId) { | 647 blink::WebMediaPlayer::TrackId* selectedTrackId) { |
648 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 648 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
649 | 649 |
650 std::ostringstream logstr; | 650 std::ostringstream logstr; |
651 std::vector<MediaTrack::Id> selectedVideoMediaTrackId; | 651 std::vector<MediaTrack::Id> selectedVideoMediaTrackId; |
652 if (selectedTrackId) { | 652 bool canAddVideoTrack = |
| 653 !base::FeatureList::IsEnabled(kBackgroundVideoTrackOptimization) || |
| 654 !IsHidden(); |
| 655 if (selectedTrackId && canAddVideoTrack) { |
653 selectedVideoMediaTrackId.push_back(selectedTrackId->utf8().data()); | 656 selectedVideoMediaTrackId.push_back(selectedTrackId->utf8().data()); |
654 logstr << selectedVideoMediaTrackId[0]; | 657 logstr << selectedVideoMediaTrackId[0]; |
655 } | 658 } |
656 MEDIA_LOG(INFO, media_log_) << "Selected video track: [" << logstr.str() | 659 MEDIA_LOG(INFO, media_log_) << "Selected video track: [" << logstr.str() |
657 << "]"; | 660 << "]"; |
658 pipeline_.OnSelectedVideoTrackChanged(selectedVideoMediaTrackId); | 661 pipeline_.OnSelectedVideoTrackChanged(selectedVideoMediaTrackId); |
659 } | 662 } |
660 | 663 |
661 blink::WebSize WebMediaPlayerImpl::naturalSize() const { | 664 blink::WebSize WebMediaPlayerImpl::naturalSize() const { |
662 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 665 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1300 | 1303 |
1301 opaque_ = opaque; | 1304 opaque_ = opaque; |
1302 // Modify content opaqueness of cc::Layer directly so that | 1305 // Modify content opaqueness of cc::Layer directly so that |
1303 // SetContentsOpaqueIsFixed is ignored. | 1306 // SetContentsOpaqueIsFixed is ignored. |
1304 if (video_weblayer_) | 1307 if (video_weblayer_) |
1305 video_weblayer_->layer()->SetContentsOpaque(opaque_); | 1308 video_weblayer_->layer()->SetContentsOpaque(opaque_); |
1306 } | 1309 } |
1307 | 1310 |
1308 void WebMediaPlayerImpl::OnHidden() { | 1311 void WebMediaPlayerImpl::OnHidden() { |
1309 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1312 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1313 |
| 1314 client_->hidden(); |
| 1315 |
1310 if (watch_time_reporter_) | 1316 if (watch_time_reporter_) |
1311 watch_time_reporter_->OnHidden(); | 1317 watch_time_reporter_->OnHidden(); |
1312 | 1318 |
1313 UpdatePlayState(); | 1319 UpdatePlayState(); |
1314 | 1320 |
1315 // Schedule suspended playing media to be paused if the user doesn't come back | 1321 // Schedule suspended playing media to be paused if the user doesn't come back |
1316 // to it within some timeout period to avoid any autoplay surprises. | 1322 // to it within some timeout period to avoid any autoplay surprises. |
1317 ScheduleIdlePauseTimer(); | 1323 ScheduleIdlePauseTimer(); |
1318 } | 1324 } |
1319 | 1325 |
1320 void WebMediaPlayerImpl::OnShown() { | 1326 void WebMediaPlayerImpl::OnShown() { |
1321 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1327 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1322 if (watch_time_reporter_) | 1328 if (watch_time_reporter_) |
1323 watch_time_reporter_->OnShown(); | 1329 watch_time_reporter_->OnShown(); |
1324 | 1330 |
| 1331 client_->shown(); |
| 1332 |
1325 must_suspend_ = false; | 1333 must_suspend_ = false; |
1326 background_pause_timer_.Stop(); | 1334 background_pause_timer_.Stop(); |
1327 | 1335 |
1328 UpdatePlayState(); | 1336 UpdatePlayState(); |
1329 } | 1337 } |
1330 | 1338 |
1331 bool WebMediaPlayerImpl::OnSuspendRequested(bool must_suspend) { | 1339 bool WebMediaPlayerImpl::OnSuspendRequested(bool must_suspend) { |
1332 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1340 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1333 | 1341 |
1334 if (must_suspend) { | 1342 if (must_suspend) { |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1683 void WebMediaPlayerImpl::UpdatePlayState() { | 1691 void WebMediaPlayerImpl::UpdatePlayState() { |
1684 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1692 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1685 | 1693 |
1686 #if defined(OS_ANDROID) // WMPI_CAST | 1694 #if defined(OS_ANDROID) // WMPI_CAST |
1687 bool is_remote = isRemote(); | 1695 bool is_remote = isRemote(); |
1688 #else | 1696 #else |
1689 bool is_remote = false; | 1697 bool is_remote = false; |
1690 #endif | 1698 #endif |
1691 | 1699 |
1692 bool is_suspended = pipeline_controller_.IsSuspended(); | 1700 bool is_suspended = pipeline_controller_.IsSuspended(); |
1693 bool is_backgrounded = | 1701 bool is_backgrounded = IsBackgroundedSuspendEnabled() && IsHidden(); |
1694 IsBackgroundedSuspendEnabled() && delegate_ && delegate_->IsHidden(); | |
1695 PlayState state = UpdatePlayState_ComputePlayState(is_remote, is_suspended, | 1702 PlayState state = UpdatePlayState_ComputePlayState(is_remote, is_suspended, |
1696 is_backgrounded); | 1703 is_backgrounded); |
1697 SetDelegateState(state.delegate_state); | 1704 SetDelegateState(state.delegate_state); |
1698 SetMemoryReportingState(state.is_memory_reporting_enabled); | 1705 SetMemoryReportingState(state.is_memory_reporting_enabled); |
1699 SetSuspendState(state.is_suspended || pending_suspend_resume_cycle_); | 1706 SetSuspendState(state.is_suspended || pending_suspend_resume_cycle_); |
1700 } | 1707 } |
1701 | 1708 |
1702 void WebMediaPlayerImpl::SetDelegateState(DelegateState new_state) { | 1709 void WebMediaPlayerImpl::SetDelegateState(DelegateState new_state) { |
1703 if (!delegate_) | 1710 if (!delegate_) |
1704 return; | 1711 return; |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1942 this, &WebMediaPlayerImpl::OnPause); | 1949 this, &WebMediaPlayerImpl::OnPause); |
1943 } | 1950 } |
1944 | 1951 |
1945 void WebMediaPlayerImpl::CreateWatchTimeReporter() { | 1952 void WebMediaPlayerImpl::CreateWatchTimeReporter() { |
1946 // Create the watch time reporter and synchronize its initial state. | 1953 // Create the watch time reporter and synchronize its initial state. |
1947 watch_time_reporter_.reset(new WatchTimeReporter( | 1954 watch_time_reporter_.reset(new WatchTimeReporter( |
1948 hasAudio(), hasVideo(), !!chunk_demuxer_, is_encrypted_, media_log_, | 1955 hasAudio(), hasVideo(), !!chunk_demuxer_, is_encrypted_, media_log_, |
1949 pipeline_metadata_.natural_size, | 1956 pipeline_metadata_.natural_size, |
1950 base::Bind(&GetCurrentTimeInternal, this))); | 1957 base::Bind(&GetCurrentTimeInternal, this))); |
1951 watch_time_reporter_->OnVolumeChange(volume_); | 1958 watch_time_reporter_->OnVolumeChange(volume_); |
1952 if (delegate_ && delegate_->IsHidden()) | 1959 if (IsHidden()) |
1953 watch_time_reporter_->OnHidden(); | 1960 watch_time_reporter_->OnHidden(); |
1954 else | 1961 else |
1955 watch_time_reporter_->OnShown(); | 1962 watch_time_reporter_->OnShown(); |
1956 } | 1963 } |
1957 | 1964 |
| 1965 bool WebMediaPlayerImpl::IsHidden() const { |
| 1966 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1967 |
| 1968 return delegate_ && delegate_->IsHidden(); |
| 1969 } |
| 1970 |
1958 } // namespace media | 1971 } // namespace media |
OLD | NEW |