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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
212 client_(client), | 212 client_(client), |
213 encrypted_client_(encrypted_client), | 213 encrypted_client_(encrypted_client), |
214 delegate_(delegate), | 214 delegate_(delegate), |
215 delegate_id_(0), | 215 delegate_id_(0), |
216 defer_load_cb_(params->defer_load_cb()), | 216 defer_load_cb_(params->defer_load_cb()), |
217 context_3d_cb_(params->context_3d_cb()), | 217 context_3d_cb_(params->context_3d_cb()), |
218 adjust_allocated_memory_cb_(params->adjust_allocated_memory_cb()), | 218 adjust_allocated_memory_cb_(params->adjust_allocated_memory_cb()), |
219 last_reported_memory_usage_(0), | 219 last_reported_memory_usage_(0), |
220 supports_save_(true), | 220 supports_save_(true), |
221 chunk_demuxer_(NULL), | 221 chunk_demuxer_(NULL), |
222 buffered_data_source_host_( | |
223 base::Bind(&WebMediaPlayerImpl::OnProgress, AsWeakPtr())), | |
222 url_index_(url_index), | 224 url_index_(url_index), |
223 // Threaded compositing isn't enabled universally yet. | 225 // Threaded compositing isn't enabled universally yet. |
224 compositor_task_runner_(params->compositor_task_runner() | 226 compositor_task_runner_(params->compositor_task_runner() |
225 ? params->compositor_task_runner() | 227 ? params->compositor_task_runner() |
226 : base::ThreadTaskRunnerHandle::Get()), | 228 : base::ThreadTaskRunnerHandle::Get()), |
227 compositor_(new VideoFrameCompositor(compositor_task_runner_)), | 229 compositor_(new VideoFrameCompositor(compositor_task_runner_)), |
228 #if defined(OS_ANDROID) // WMPI_CAST | 230 #if defined(OS_ANDROID) // WMPI_CAST |
229 cast_impl_(this, client_, params->context_3d_cb()), | 231 cast_impl_(this, client_, params->context_3d_cb()), |
230 #endif | 232 #endif |
231 volume_(1.0), | 233 volume_(1.0), |
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
847 tick_clock_->NowTicks() - preroll_attempt_start_time_; | 849 tick_clock_->NowTicks() - preroll_attempt_start_time_; |
848 return preroll_attempt_duration < kPrerollAttemptTimeout; | 850 return preroll_attempt_duration < kPrerollAttemptTimeout; |
849 } | 851 } |
850 | 852 |
851 bool WebMediaPlayerImpl::DidLoadingProgress() { | 853 bool WebMediaPlayerImpl::DidLoadingProgress() { |
852 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 854 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
853 | 855 |
854 // Note: Separate variables used to ensure both methods are called every time. | 856 // Note: Separate variables used to ensure both methods are called every time. |
855 const bool pipeline_progress = pipeline_controller_.DidLoadingProgress(); | 857 const bool pipeline_progress = pipeline_controller_.DidLoadingProgress(); |
856 const bool data_progress = buffered_data_source_host_.DidLoadingProgress(); | 858 const bool data_progress = buffered_data_source_host_.DidLoadingProgress(); |
857 const bool did_loading_progress = pipeline_progress || data_progress; | 859 return pipeline_progress || data_progress; |
858 | |
859 if (did_loading_progress && | |
860 highest_ready_state_ < ReadyState::kReadyStateHaveFutureData) { | |
861 // Reset the preroll attempt clock. | |
862 preroll_attempt_pending_ = true; | |
863 preroll_attempt_start_time_ = base::TimeTicks(); | |
864 | |
865 // Clear any 'stale' flag and give the pipeline a chance to resume. If we | |
866 // are already resumed, this will cause |preroll_attempt_start_time_| to be | |
867 // set. | |
868 // TODO(sandersd): Should this be on the same stack? It might be surprising | |
869 // that didLoadingProgress() can synchronously change state. | |
870 delegate_->ClearStaleFlag(delegate_id_); | |
871 UpdatePlayState(); | |
872 } | |
873 | |
874 return did_loading_progress; | |
875 } | 860 } |
876 | 861 |
877 void WebMediaPlayerImpl::Paint(blink::WebCanvas* canvas, | 862 void WebMediaPlayerImpl::Paint(blink::WebCanvas* canvas, |
878 const blink::WebRect& rect, | 863 const blink::WebRect& rect, |
879 cc::PaintFlags& flags) { | 864 cc::PaintFlags& flags) { |
880 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 865 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
881 TRACE_EVENT0("media", "WebMediaPlayerImpl:paint"); | 866 TRACE_EVENT0("media", "WebMediaPlayerImpl:paint"); |
882 | 867 |
883 // TODO(sandersd): Move this check into GetCurrentFrameFromCompositor() when | 868 // TODO(sandersd): Move this check into GetCurrentFrameFromCompositor() when |
884 // we have other ways to check if decoder owns video frame. | 869 // we have other ways to check if decoder owns video frame. |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1292 client_->SetWebLayer(video_weblayer_.get()); | 1277 client_->SetWebLayer(video_weblayer_.get()); |
1293 } | 1278 } |
1294 | 1279 |
1295 if (observer_) | 1280 if (observer_) |
1296 observer_->OnMetadataChanged(pipeline_metadata_); | 1281 observer_->OnMetadataChanged(pipeline_metadata_); |
1297 | 1282 |
1298 CreateWatchTimeReporter(); | 1283 CreateWatchTimeReporter(); |
1299 UpdatePlayState(); | 1284 UpdatePlayState(); |
1300 } | 1285 } |
1301 | 1286 |
1287 void WebMediaPlayerImpl::OnProgress() { | |
1288 DVLOG(1) << __func__; | |
1289 if (highest_ready_state_ < ReadyState::kReadyStateHaveFutureData) { | |
1290 // Reset the preroll attempt clock. | |
1291 preroll_attempt_pending_ = true; | |
1292 preroll_attempt_start_time_ = base::TimeTicks(); | |
1293 | |
1294 // Clear any 'stale' flag and give the pipeline a chance to resume. If we | |
1295 // are already resumed, this will cause |preroll_attempt_start_time_| to | |
1296 // be set. | |
1297 // TODO(sandersd): Should this be on the same stack? It might be | |
DaleCurtis
2017/04/25 21:45:28
Delete todo now.
hubbe
2017/04/25 23:47:03
Done.
| |
1298 // surprising that didLoadingProgress() can synchronously change state. | |
1299 delegate_->ClearStaleFlag(delegate_id_); | |
1300 UpdatePlayState(); | |
1301 } | |
DaleCurtis
2017/04/25 21:45:28
else if?
hubbe
2017/04/25 23:47:03
Done.
| |
1302 if (ready_state_ == ReadyState::kReadyStateHaveFutureData && | |
1303 CanPlayThrough()) { | |
1304 SetReadyState(WebMediaPlayer::kReadyStateHaveEnoughData); | |
1305 } | |
1306 } | |
1307 | |
1308 bool WebMediaPlayerImpl::CanPlayThrough() { | |
1309 if (chunk_demuxer_) | |
1310 return true; | |
1311 if (data_source_ && data_source_->assume_fully_buffered()) | |
1312 return true; | |
1313 // If we're not currently downloading, we have as much buffer as | |
1314 // we're ever going to get, which means we say we can play through. | |
1315 if (network_state_ == WebMediaPlayer::kNetworkStateIdle) | |
1316 return true; | |
1317 return buffered_data_source_host_.CanPlayThrough( | |
1318 base::TimeDelta::FromSecondsD(CurrentTime()), | |
1319 base::TimeDelta::FromSecondsD(Duration()), | |
1320 playback_rate_ == 0.0 ? 1.0 : playback_rate_); | |
1321 } | |
1322 | |
1302 void WebMediaPlayerImpl::OnBufferingStateChange(BufferingState state) { | 1323 void WebMediaPlayerImpl::OnBufferingStateChange(BufferingState state) { |
1303 DVLOG(1) << __func__ << "(" << state << ")"; | 1324 DVLOG(1) << __func__ << "(" << state << ")"; |
1304 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1325 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1305 | 1326 |
1306 // Ignore buffering state changes until we've completed all outstanding | 1327 // Ignore buffering state changes until we've completed all outstanding |
1307 // operations. | 1328 // operations. |
1308 if (!pipeline_controller_.IsStable()) | 1329 if (!pipeline_controller_.IsStable()) |
1309 return; | 1330 return; |
1310 | 1331 |
1311 media_log_->AddEvent(media_log_->CreateBufferingStateChangedEvent( | 1332 media_log_->AddEvent(media_log_->CreateBufferingStateChangedEvent( |
1312 "pipeline_buffering_state", state)); | 1333 "pipeline_buffering_state", state)); |
1313 | 1334 |
1314 if (state == BUFFERING_HAVE_ENOUGH) { | 1335 if (state == BUFFERING_HAVE_ENOUGH) { |
1315 if (highest_ready_state_ < WebMediaPlayer::kReadyStateHaveEnoughData) { | 1336 if (highest_ready_state_ < WebMediaPlayer::kReadyStateHaveEnoughData) { |
1316 // Record a zero value for underflow histogram so that the histogram | 1337 // Record a zero value for underflow histogram so that the histogram |
1317 // includes playbacks which never encounter an underflow event. | 1338 // includes playbacks which never encounter an underflow event. |
1318 RecordUnderflowDuration(base::TimeDelta()); | 1339 RecordUnderflowDuration(base::TimeDelta()); |
1319 } | 1340 } |
1320 | 1341 |
1321 // TODO(chcunningham): Monitor playback position vs buffered. Potentially | 1342 SetReadyState(CanPlayThrough() ? WebMediaPlayer::kReadyStateHaveEnoughData |
1322 // transition to HAVE_FUTURE_DATA here if not enough is buffered. | 1343 : WebMediaPlayer::kReadyStateHaveFutureData); |
1323 SetReadyState(WebMediaPlayer::kReadyStateHaveEnoughData); | |
1324 | 1344 |
1325 // Let the DataSource know we have enough data. It may use this information | 1345 // Let the DataSource know we have enough data. It may use this information |
1326 // to release unused network connections. | 1346 // to release unused network connections. |
1327 if (data_source_) | 1347 if (data_source_) |
1328 data_source_->OnBufferingHaveEnough(false); | 1348 data_source_->OnBufferingHaveEnough(false); |
1329 | 1349 |
1330 // Blink expects a timeChanged() in response to a seek(). | 1350 // Blink expects a timeChanged() in response to a seek(). |
1331 if (should_notify_time_changed_) { | 1351 if (should_notify_time_changed_) { |
1332 should_notify_time_changed_ = false; | 1352 should_notify_time_changed_ = false; |
1333 client_->TimeChanged(); | 1353 client_->TimeChanged(); |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1653 // least this makes sure that the error handling code is in sync. | 1673 // least this makes sure that the error handling code is in sync. |
1654 UpdatePlayState(); | 1674 UpdatePlayState(); |
1655 | 1675 |
1656 return; | 1676 return; |
1657 } | 1677 } |
1658 | 1678 |
1659 StartPipeline(); | 1679 StartPipeline(); |
1660 } | 1680 } |
1661 | 1681 |
1662 void WebMediaPlayerImpl::NotifyDownloading(bool is_downloading) { | 1682 void WebMediaPlayerImpl::NotifyDownloading(bool is_downloading) { |
1663 DVLOG(1) << __func__; | 1683 DVLOG(1) << __func__ << "(" << is_downloading << ")"; |
1664 if (!is_downloading && network_state_ == WebMediaPlayer::kNetworkStateLoading) | 1684 if (!is_downloading && network_state_ == WebMediaPlayer::kNetworkStateLoading) |
1665 SetNetworkState(WebMediaPlayer::kNetworkStateIdle); | 1685 SetNetworkState(WebMediaPlayer::kNetworkStateIdle); |
1666 else if (is_downloading && | 1686 else if (is_downloading && |
1667 network_state_ == WebMediaPlayer::kNetworkStateIdle) | 1687 network_state_ == WebMediaPlayer::kNetworkStateIdle) |
1668 SetNetworkState(WebMediaPlayer::kNetworkStateLoading); | 1688 SetNetworkState(WebMediaPlayer::kNetworkStateLoading); |
1689 if (ready_state_ == ReadyState::kReadyStateHaveFutureData && !is_downloading) | |
1690 SetReadyState(WebMediaPlayer::kReadyStateHaveEnoughData); | |
1669 media_log_->AddEvent( | 1691 media_log_->AddEvent( |
1670 media_log_->CreateBooleanEvent(MediaLogEvent::NETWORK_ACTIVITY_SET, | 1692 media_log_->CreateBooleanEvent(MediaLogEvent::NETWORK_ACTIVITY_SET, |
1671 "is_downloading_data", is_downloading)); | 1693 "is_downloading_data", is_downloading)); |
1672 } | 1694 } |
1673 | 1695 |
1674 void WebMediaPlayerImpl::OnSurfaceCreated(int surface_id) { | 1696 void WebMediaPlayerImpl::OnSurfaceCreated(int surface_id) { |
1675 overlay_surface_id_ = surface_id; | 1697 overlay_surface_id_ = surface_id; |
1676 if (!set_surface_cb_.is_null()) { | 1698 if (!set_surface_cb_.is_null()) { |
1677 // If restart is required, the callback is one-shot only. | 1699 // If restart is required, the callback is one-shot only. |
1678 if (decoder_requires_restart_for_overlay_) | 1700 if (decoder_requires_restart_for_overlay_) |
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2395 | 2417 |
2396 if (is_encrypted_) | 2418 if (is_encrypted_) |
2397 UMA_HISTOGRAM_VIDEO_HEIGHT("Media.VideoHeight.Initial.EME", height); | 2419 UMA_HISTOGRAM_VIDEO_HEIGHT("Media.VideoHeight.Initial.EME", height); |
2398 | 2420 |
2399 UMA_HISTOGRAM_VIDEO_HEIGHT("Media.VideoHeight.Initial.All", height); | 2421 UMA_HISTOGRAM_VIDEO_HEIGHT("Media.VideoHeight.Initial.All", height); |
2400 } | 2422 } |
2401 | 2423 |
2402 #undef UMA_HISTOGRAM_VIDEO_HEIGHT | 2424 #undef UMA_HISTOGRAM_VIDEO_HEIGHT |
2403 | 2425 |
2404 } // namespace media | 2426 } // namespace media |
OLD | NEW |