Chromium Code Reviews| 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 1318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1329 opaque_ = opaque; | 1329 opaque_ = opaque; |
| 1330 // Modify content opaqueness of cc::Layer directly so that | 1330 // Modify content opaqueness of cc::Layer directly so that |
| 1331 // SetContentsOpaqueIsFixed is ignored. | 1331 // SetContentsOpaqueIsFixed is ignored. |
| 1332 if (video_weblayer_) | 1332 if (video_weblayer_) |
| 1333 video_weblayer_->layer()->SetContentsOpaque(opaque_); | 1333 video_weblayer_->layer()->SetContentsOpaque(opaque_); |
| 1334 } | 1334 } |
| 1335 | 1335 |
| 1336 void WebMediaPlayerImpl::OnHidden() { | 1336 void WebMediaPlayerImpl::OnHidden() { |
| 1337 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1337 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1338 | 1338 |
| 1339 if (IsBackgroundVideoTrackOptimizationEnabled()) | 1339 if (!IsStreaming() && IsBackgroundVideoTrackOptimizationEnabled()) |
| 1340 selectedVideoTrackChanged(nullptr); | 1340 selectedVideoTrackChanged(nullptr); |
| 1341 | 1341 |
| 1342 if (watch_time_reporter_) | 1342 if (watch_time_reporter_) |
| 1343 watch_time_reporter_->OnHidden(); | 1343 watch_time_reporter_->OnHidden(); |
| 1344 | 1344 |
| 1345 UpdatePlayState(); | 1345 UpdatePlayState(); |
| 1346 | 1346 |
| 1347 // Schedule suspended playing media to be paused if the user doesn't come back | 1347 // 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. | 1348 // to it within some timeout period to avoid any autoplay surprises. |
| 1349 ScheduleIdlePauseTimer(); | 1349 ScheduleIdlePauseTimer(); |
| 1350 } | 1350 } |
| 1351 | 1351 |
| 1352 void WebMediaPlayerImpl::OnShown() { | 1352 void WebMediaPlayerImpl::OnShown() { |
| 1353 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1353 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1354 if (watch_time_reporter_) | 1354 if (watch_time_reporter_) |
| 1355 watch_time_reporter_->OnShown(); | 1355 watch_time_reporter_->OnShown(); |
| 1356 | 1356 |
| 1357 if (IsBackgroundVideoTrackOptimizationEnabled() && | 1357 if (!IsStreaming() && IsBackgroundVideoTrackOptimizationEnabled() && |
| 1358 client_->hasSelectedVideoTrack()) { | 1358 client_->hasSelectedVideoTrack()) { |
| 1359 WebMediaPlayer::TrackId trackId = client_->getSelectedVideoTrackId(); | 1359 WebMediaPlayer::TrackId trackId = client_->getSelectedVideoTrackId(); |
| 1360 selectedVideoTrackChanged(&trackId); | 1360 selectedVideoTrackChanged(&trackId); |
| 1361 } | 1361 } |
| 1362 | 1362 |
| 1363 must_suspend_ = false; | 1363 must_suspend_ = false; |
| 1364 background_pause_timer_.Stop(); | 1364 background_pause_timer_.Stop(); |
| 1365 | 1365 |
| 1366 UpdatePlayState(); | 1366 UpdatePlayState(); |
| 1367 } | 1367 } |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1641 | 1641 |
| 1642 chunk_demuxer_ = new ChunkDemuxer( | 1642 chunk_demuxer_ = new ChunkDemuxer( |
| 1643 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnDemuxerOpened), | 1643 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnDemuxerOpened), |
| 1644 encrypted_media_init_data_cb, media_log_); | 1644 encrypted_media_init_data_cb, media_log_); |
| 1645 demuxer_.reset(chunk_demuxer_); | 1645 demuxer_.reset(chunk_demuxer_); |
| 1646 } | 1646 } |
| 1647 | 1647 |
| 1648 // TODO(sandersd): FileSystem objects may also be non-static, but due to our | 1648 // TODO(sandersd): FileSystem objects may also be non-static, but due to our |
| 1649 // caching layer such situations are broken already. http://crbug.com/593159 | 1649 // caching layer such situations are broken already. http://crbug.com/593159 |
| 1650 bool is_static = !chunk_demuxer_; | 1650 bool is_static = !chunk_demuxer_; |
| 1651 bool is_streaming = data_source_ && data_source_->IsStreaming(); | 1651 bool is_streaming = IsStreaming(); |
| 1652 UMA_HISTOGRAM_BOOLEAN("Media.IsStreaming", is_streaming); | 1652 UMA_HISTOGRAM_BOOLEAN("Media.IsStreaming", is_streaming); |
| 1653 | 1653 |
| 1654 // ... and we're ready to go! | 1654 // ... and we're ready to go! |
| 1655 // TODO(sandersd): On Android, defer Start() if the tab is not visible. | 1655 // TODO(sandersd): On Android, defer Start() if the tab is not visible. |
| 1656 seeking_ = true; | 1656 seeking_ = true; |
| 1657 pipeline_controller_.Start(demuxer_.get(), this, is_streaming, is_static); | 1657 pipeline_controller_.Start(demuxer_.get(), this, is_streaming, is_static); |
| 1658 } | 1658 } |
| 1659 | 1659 |
| 1660 void WebMediaPlayerImpl::SetNetworkState(WebMediaPlayer::NetworkState state) { | 1660 void WebMediaPlayerImpl::SetNetworkState(WebMediaPlayer::NetworkState state) { |
| 1661 DVLOG(1) << __func__ << "(" << state << ")"; | 1661 DVLOG(1) << __func__ << "(" << state << ")"; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1730 } | 1730 } |
| 1731 | 1731 |
| 1732 void WebMediaPlayerImpl::UpdatePlayState() { | 1732 void WebMediaPlayerImpl::UpdatePlayState() { |
| 1733 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1733 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1734 | 1734 |
| 1735 #if defined(OS_ANDROID) // WMPI_CAST | 1735 #if defined(OS_ANDROID) // WMPI_CAST |
| 1736 bool is_remote = isRemote(); | 1736 bool is_remote = isRemote(); |
| 1737 bool is_streaming = false; | 1737 bool is_streaming = false; |
| 1738 #else | 1738 #else |
| 1739 bool is_remote = false; | 1739 bool is_remote = false; |
| 1740 bool is_streaming = data_source_ && data_source_->IsStreaming(); | 1740 bool is_streaming = IsStreaming(); |
| 1741 #endif | 1741 #endif |
| 1742 | 1742 |
| 1743 bool is_suspended = pipeline_controller_.IsSuspended(); | 1743 bool is_suspended = pipeline_controller_.IsSuspended(); |
| 1744 bool is_backgrounded = IsBackgroundedSuspendEnabled() && IsHidden(); | 1744 bool is_backgrounded = IsBackgroundedSuspendEnabled() && IsHidden(); |
| 1745 PlayState state = UpdatePlayState_ComputePlayState( | 1745 PlayState state = UpdatePlayState_ComputePlayState( |
| 1746 is_remote, is_streaming, is_suspended, is_backgrounded); | 1746 is_remote, is_streaming, is_suspended, is_backgrounded); |
| 1747 SetDelegateState(state.delegate_state); | 1747 SetDelegateState(state.delegate_state); |
| 1748 SetMemoryReportingState(state.is_memory_reporting_enabled); | 1748 SetMemoryReportingState(state.is_memory_reporting_enabled); |
| 1749 SetSuspendState(state.is_suspended || pending_suspend_resume_cycle_); | 1749 SetSuspendState(state.is_suspended || pending_suspend_resume_cycle_); |
| 1750 } | 1750 } |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2023 else | 2023 else |
| 2024 watch_time_reporter_->OnShown(); | 2024 watch_time_reporter_->OnShown(); |
| 2025 } | 2025 } |
| 2026 | 2026 |
| 2027 bool WebMediaPlayerImpl::IsHidden() const { | 2027 bool WebMediaPlayerImpl::IsHidden() const { |
| 2028 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 2028 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 2029 | 2029 |
| 2030 return delegate_ && delegate_->IsHidden(); | 2030 return delegate_ && delegate_->IsHidden(); |
| 2031 } | 2031 } |
| 2032 | 2032 |
| 2033 bool WebMediaPlayerImpl::IsStreaming() const { | |
| 2034 return !std::isfinite(duration()) || | |
|
sandersd (OOO until July 31)
2017/01/06 21:20:28
FYI: I was just looking through this code, and eve
whywhat
2017/01/06 22:19:57
Hm, liveness seems to depend on the stream parser:
| |
| 2035 (data_source_ && data_source_->IsStreaming()); | |
| 2036 } | |
| 2037 | |
| 2033 bool WebMediaPlayerImpl::DoesOverlaySupportMetadata() const { | 2038 bool WebMediaPlayerImpl::DoesOverlaySupportMetadata() const { |
| 2034 return pipeline_metadata_.video_rotation == VIDEO_ROTATION_0; | 2039 return pipeline_metadata_.video_rotation == VIDEO_ROTATION_0; |
| 2035 } | 2040 } |
| 2036 | 2041 |
| 2037 void WebMediaPlayerImpl::ActivateViewportIntersectionMonitoring(bool activate) { | 2042 void WebMediaPlayerImpl::ActivateViewportIntersectionMonitoring(bool activate) { |
| 2038 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 2043 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 2039 | 2044 |
| 2040 client_->activateViewportIntersectionMonitoring(activate); | 2045 client_->activateViewportIntersectionMonitoring(activate); |
| 2041 } | 2046 } |
| 2042 | 2047 |
| 2043 } // namespace media | 2048 } // namespace media |
| OLD | NEW |