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 19 matching lines...) Expand all Loading... | |
30 #include "media/audio/null_audio_sink.h" | 30 #include "media/audio/null_audio_sink.h" |
31 #include "media/base/bind_to_current_loop.h" | 31 #include "media/base/bind_to_current_loop.h" |
32 #include "media/base/cdm_context.h" | 32 #include "media/base/cdm_context.h" |
33 #include "media/base/limits.h" | 33 #include "media/base/limits.h" |
34 #include "media/base/media_log.h" | 34 #include "media/base/media_log.h" |
35 #include "media/base/media_switches.h" | 35 #include "media/base/media_switches.h" |
36 #include "media/base/text_renderer.h" | 36 #include "media/base/text_renderer.h" |
37 #include "media/base/timestamp_constants.h" | 37 #include "media/base/timestamp_constants.h" |
38 #include "media/base/video_frame.h" | 38 #include "media/base/video_frame.h" |
39 #include "media/blink/texttrack_impl.h" | 39 #include "media/blink/texttrack_impl.h" |
40 #include "media/blink/watch_time_reporter.h" | |
40 #include "media/blink/webaudiosourceprovider_impl.h" | 41 #include "media/blink/webaudiosourceprovider_impl.h" |
41 #include "media/blink/webcontentdecryptionmodule_impl.h" | 42 #include "media/blink/webcontentdecryptionmodule_impl.h" |
42 #include "media/blink/webinbandtexttrack_impl.h" | 43 #include "media/blink/webinbandtexttrack_impl.h" |
43 #include "media/blink/webmediaplayer_delegate.h" | 44 #include "media/blink/webmediaplayer_delegate.h" |
44 #include "media/blink/webmediaplayer_util.h" | 45 #include "media/blink/webmediaplayer_util.h" |
45 #include "media/blink/webmediasource_impl.h" | 46 #include "media/blink/webmediasource_impl.h" |
46 #include "media/filters/chunk_demuxer.h" | 47 #include "media/filters/chunk_demuxer.h" |
47 #include "media/filters/ffmpeg_demuxer.h" | 48 #include "media/filters/ffmpeg_demuxer.h" |
48 #include "third_party/WebKit/public/platform/WebEncryptedMediaTypes.h" | 49 #include "third_party/WebKit/public/platform/WebEncryptedMediaTypes.h" |
49 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" | 50 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 DCHECK_EQ(state > blink::WebMediaPlayer::NetworkStateLoaded, result); | 127 DCHECK_EQ(state > blink::WebMediaPlayer::NetworkStateLoaded, result); |
127 return result; | 128 return result; |
128 } | 129 } |
129 | 130 |
130 gfx::Size GetRotatedVideoSize(VideoRotation rotation, gfx::Size natural_size) { | 131 gfx::Size GetRotatedVideoSize(VideoRotation rotation, gfx::Size natural_size) { |
131 if (rotation == VIDEO_ROTATION_90 || rotation == VIDEO_ROTATION_270) | 132 if (rotation == VIDEO_ROTATION_90 || rotation == VIDEO_ROTATION_270) |
132 return gfx::Size(natural_size.height(), natural_size.width()); | 133 return gfx::Size(natural_size.height(), natural_size.width()); |
133 return natural_size; | 134 return natural_size; |
134 } | 135 } |
135 | 136 |
137 base::TimeDelta GetCurrentTimeInternal(WebMediaPlayerImpl* p_this) { | |
138 // We wrap currentTime() instead of using pipeline_.GetMediaTime() since there | |
139 // are a variety of cases in which that time is not accurate; e.g., while | |
140 // remoting and during a pause or seek. | |
141 return base::TimeDelta::FromSecondsD(p_this->currentTime()); | |
142 } | |
143 | |
136 } // namespace | 144 } // namespace |
137 | 145 |
138 class BufferedDataSourceHostImpl; | 146 class BufferedDataSourceHostImpl; |
139 | 147 |
140 STATIC_ASSERT_ENUM(WebMediaPlayer::CORSModeUnspecified, | 148 STATIC_ASSERT_ENUM(WebMediaPlayer::CORSModeUnspecified, |
141 UrlData::CORS_UNSPECIFIED); | 149 UrlData::CORS_UNSPECIFIED); |
142 STATIC_ASSERT_ENUM(WebMediaPlayer::CORSModeAnonymous, UrlData::CORS_ANONYMOUS); | 150 STATIC_ASSERT_ENUM(WebMediaPlayer::CORSModeAnonymous, UrlData::CORS_ANONYMOUS); |
143 STATIC_ASSERT_ENUM(WebMediaPlayer::CORSModeUseCredentials, | 151 STATIC_ASSERT_ENUM(WebMediaPlayer::CORSModeUseCredentials, |
144 UrlData::CORS_USE_CREDENTIALS); | 152 UrlData::CORS_USE_CREDENTIALS); |
145 | 153 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
210 is_cdm_attached_(false), | 218 is_cdm_attached_(false), |
211 #if defined(OS_ANDROID) // WMPI_CAST | 219 #if defined(OS_ANDROID) // WMPI_CAST |
212 cast_impl_(this, client_, params.context_3d_cb()), | 220 cast_impl_(this, client_, params.context_3d_cb()), |
213 #endif | 221 #endif |
214 volume_(1.0), | 222 volume_(1.0), |
215 volume_multiplier_(1.0), | 223 volume_multiplier_(1.0), |
216 renderer_factory_(std::move(renderer_factory)), | 224 renderer_factory_(std::move(renderer_factory)), |
217 surface_manager_(params.surface_manager()), | 225 surface_manager_(params.surface_manager()), |
218 overlay_surface_id_(SurfaceManager::kNoSurfaceID), | 226 overlay_surface_id_(SurfaceManager::kNoSurfaceID), |
219 suppress_destruction_errors_(false), | 227 suppress_destruction_errors_(false), |
220 can_suspend_state_(CanSuspendState::UNKNOWN) { | 228 can_suspend_state_(CanSuspendState::UNKNOWN), |
229 is_encrypted_(false) { | |
221 DCHECK(!adjust_allocated_memory_cb_.is_null()); | 230 DCHECK(!adjust_allocated_memory_cb_.is_null()); |
222 DCHECK(renderer_factory_); | 231 DCHECK(renderer_factory_); |
223 DCHECK(client_); | 232 DCHECK(client_); |
224 | 233 |
225 force_video_overlays_ = base::CommandLine::ForCurrentProcess()->HasSwitch( | 234 force_video_overlays_ = base::CommandLine::ForCurrentProcess()->HasSwitch( |
226 switches::kForceVideoOverlays); | 235 switches::kForceVideoOverlays); |
227 | 236 |
228 if (delegate_) | 237 if (delegate_) |
229 delegate_id_ = delegate_->AddObserver(this); | 238 delegate_id_ = delegate_->AddObserver(this); |
230 | 239 |
(...skipping 18 matching lines...) Expand all Loading... | |
249 | 258 |
250 WebMediaPlayerImpl::~WebMediaPlayerImpl() { | 259 WebMediaPlayerImpl::~WebMediaPlayerImpl() { |
251 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 260 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
252 | 261 |
253 suppress_destruction_errors_ = true; | 262 suppress_destruction_errors_ = true; |
254 if (delegate_) { | 263 if (delegate_) { |
255 delegate_->PlayerGone(delegate_id_); | 264 delegate_->PlayerGone(delegate_id_); |
256 delegate_->RemoveObserver(delegate_id_); | 265 delegate_->RemoveObserver(delegate_id_); |
257 } | 266 } |
258 | 267 |
268 // Finalize any watch time metrics before destroying the pipeline. | |
269 watch_time_reporter_.reset(); | |
270 | |
259 // Pipeline must be stopped before it is destroyed. | 271 // Pipeline must be stopped before it is destroyed. |
260 pipeline_.Stop(); | 272 pipeline_.Stop(); |
261 | 273 |
262 if (last_reported_memory_usage_) | 274 if (last_reported_memory_usage_) |
263 adjust_allocated_memory_cb_.Run(-last_reported_memory_usage_); | 275 adjust_allocated_memory_cb_.Run(-last_reported_memory_usage_); |
264 | 276 |
265 // Destruct compositor resources in the proper order. | 277 // Destruct compositor resources in the proper order. |
266 client_->setWebLayer(nullptr); | 278 client_->setWebLayer(nullptr); |
267 if (video_weblayer_) | 279 if (video_weblayer_) |
268 static_cast<cc::VideoLayer*>(video_weblayer_->layer())->StopUsingProvider(); | 280 static_cast<cc::VideoLayer*>(video_weblayer_->layer())->StopUsingProvider(); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
390 return; | 402 return; |
391 } | 403 } |
392 #endif | 404 #endif |
393 paused_ = false; | 405 paused_ = false; |
394 is_idle_ = false; | 406 is_idle_ = false; |
395 pipeline_.SetPlaybackRate(playback_rate_); | 407 pipeline_.SetPlaybackRate(playback_rate_); |
396 | 408 |
397 if (data_source_) | 409 if (data_source_) |
398 data_source_->MediaIsPlaying(); | 410 data_source_->MediaIsPlaying(); |
399 | 411 |
412 watch_time_reporter_->OnPlaying(); | |
sandersd (OOO until July 31)
2016/08/17 01:11:25
Perhaps add conditions (or at least DCHECKs) that
DaleCurtis
2016/08/17 20:30:44
We don't typically DCHECK() prior to dereferences,
| |
400 media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::PLAY)); | 413 media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::PLAY)); |
401 UpdatePlayState(); | 414 UpdatePlayState(); |
402 } | 415 } |
403 | 416 |
404 void WebMediaPlayerImpl::pause() { | 417 void WebMediaPlayerImpl::pause() { |
405 DVLOG(1) << __func__; | 418 DVLOG(1) << __func__; |
406 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 419 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
407 | 420 |
408 // We update the paused state even when casting, since we expect pause() to be | 421 // We update the paused state even when casting, since we expect pause() to be |
409 // called when casting begins, and when we exit casting we should end up in a | 422 // called when casting begins, and when we exit casting we should end up in a |
410 // paused state. | 423 // paused state. |
411 paused_ = true; | 424 paused_ = true; |
412 | 425 |
413 #if defined(OS_ANDROID) // WMPI_CAST | 426 #if defined(OS_ANDROID) // WMPI_CAST |
414 if (isRemote()) { | 427 if (isRemote()) { |
415 cast_impl_.pause(); | 428 cast_impl_.pause(); |
416 return; | 429 return; |
417 } | 430 } |
418 #endif | 431 #endif |
419 | 432 |
420 pipeline_.SetPlaybackRate(0.0); | 433 pipeline_.SetPlaybackRate(0.0); |
421 | 434 |
422 // pause() may be called after playback has ended and the HTMLMediaElement | 435 // pause() may be called after playback has ended and the HTMLMediaElement |
423 // requires that currentTime() == duration() after ending. We want to ensure | 436 // requires that currentTime() == duration() after ending. We want to ensure |
424 // |paused_time_| matches currentTime() in this case or a future seek() may | 437 // |paused_time_| matches currentTime() in this case or a future seek() may |
425 // incorrectly discard what it thinks is a seek to the existing time. | 438 // incorrectly discard what it thinks is a seek to the existing time. |
426 paused_time_ = | 439 paused_time_ = |
427 ended_ ? pipeline_.GetMediaDuration() : pipeline_.GetMediaTime(); | 440 ended_ ? pipeline_.GetMediaDuration() : pipeline_.GetMediaTime(); |
428 | 441 |
442 watch_time_reporter_->OnPaused(); | |
429 media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::PAUSE)); | 443 media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::PAUSE)); |
430 UpdatePlayState(); | 444 UpdatePlayState(); |
431 } | 445 } |
432 | 446 |
433 bool WebMediaPlayerImpl::supportsSave() const { | 447 bool WebMediaPlayerImpl::supportsSave() const { |
434 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 448 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
435 return supports_save_; | 449 return supports_save_; |
436 } | 450 } |
437 | 451 |
438 void WebMediaPlayerImpl::seek(double seconds) { | 452 void WebMediaPlayerImpl::seek(double seconds) { |
(...skipping 30 matching lines...) Expand all Loading... | |
469 // completed just by restoring it. Otherwise we will just wait for the real | 483 // completed just by restoring it. Otherwise we will just wait for the real |
470 // ready state change to eventually happen. | 484 // ready state change to eventually happen. |
471 if (old_state == ReadyStateHaveEnoughData) { | 485 if (old_state == ReadyStateHaveEnoughData) { |
472 main_task_runner_->PostTask( | 486 main_task_runner_->PostTask( |
473 FROM_HERE, base::Bind(&WebMediaPlayerImpl::OnBufferingStateChange, | 487 FROM_HERE, base::Bind(&WebMediaPlayerImpl::OnBufferingStateChange, |
474 AsWeakPtr(), BUFFERING_HAVE_ENOUGH)); | 488 AsWeakPtr(), BUFFERING_HAVE_ENOUGH)); |
475 } | 489 } |
476 return; | 490 return; |
477 } | 491 } |
478 | 492 |
493 // Call this before setting |seeking_| so that the current media time can be | |
494 // recorded by the reporter. | |
495 if (watch_time_reporter_) | |
496 watch_time_reporter_->OnSeeking(); | |
497 | |
479 // TODO(sandersd): Ideally we would not clear the idle state if | 498 // TODO(sandersd): Ideally we would not clear the idle state if |
480 // |pipeline_controller_| can elide the seek. | 499 // |pipeline_controller_| can elide the seek. |
481 is_idle_ = false; | 500 is_idle_ = false; |
482 ended_ = false; | 501 ended_ = false; |
483 | 502 |
484 seeking_ = true; | 503 seeking_ = true; |
485 seek_time_ = time; | 504 seek_time_ = time; |
486 if (paused_) | 505 if (paused_) |
487 paused_time_ = time; | 506 paused_time_ = time; |
488 pipeline_controller_.Seek(time, time_updated); | 507 pipeline_controller_.Seek(time, time_updated); |
(...skipping 26 matching lines...) Expand all Loading... | |
515 if (data_source_) | 534 if (data_source_) |
516 data_source_->MediaPlaybackRateChanged(rate); | 535 data_source_->MediaPlaybackRateChanged(rate); |
517 } | 536 } |
518 } | 537 } |
519 | 538 |
520 void WebMediaPlayerImpl::setVolume(double volume) { | 539 void WebMediaPlayerImpl::setVolume(double volume) { |
521 DVLOG(1) << __func__ << "(" << volume << ")"; | 540 DVLOG(1) << __func__ << "(" << volume << ")"; |
522 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 541 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
523 volume_ = volume; | 542 volume_ = volume; |
524 pipeline_.SetVolume(volume_ * volume_multiplier_); | 543 pipeline_.SetVolume(volume_ * volume_multiplier_); |
544 if (watch_time_reporter_) | |
545 watch_time_reporter_->OnVolumeChange(volume); | |
525 } | 546 } |
526 | 547 |
527 void WebMediaPlayerImpl::setSinkId( | 548 void WebMediaPlayerImpl::setSinkId( |
528 const blink::WebString& sink_id, | 549 const blink::WebString& sink_id, |
529 const blink::WebSecurityOrigin& security_origin, | 550 const blink::WebSecurityOrigin& security_origin, |
530 blink::WebSetSinkIdCallbacks* web_callback) { | 551 blink::WebSetSinkIdCallbacks* web_callback) { |
531 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 552 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
532 DVLOG(1) << __func__; | 553 DVLOG(1) << __func__; |
533 | 554 |
534 media::OutputDeviceStatusCB callback = | 555 media::OutputDeviceStatusCB callback = |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
855 return; | 876 return; |
856 } | 877 } |
857 | 878 |
858 // Create a local copy of |result| to avoid problems with the callback | 879 // Create a local copy of |result| to avoid problems with the callback |
859 // getting passed to the media thread and causing |result| to be destructed | 880 // getting passed to the media thread and causing |result| to be destructed |
860 // on the wrong thread in some failure conditions. Blink should prevent | 881 // on the wrong thread in some failure conditions. Blink should prevent |
861 // multiple simultaneous calls. | 882 // multiple simultaneous calls. |
862 DCHECK(!set_cdm_result_); | 883 DCHECK(!set_cdm_result_); |
863 set_cdm_result_.reset(new blink::WebContentDecryptionModuleResult(result)); | 884 set_cdm_result_.reset(new blink::WebContentDecryptionModuleResult(result)); |
864 | 885 |
886 // Recreate the watch time reporter if necessary. | |
887 const bool was_encrypted = is_encrypted_; | |
888 is_encrypted_ = true; | |
889 if (!was_encrypted && watch_time_reporter_) | |
890 CreateWatchTimeReporter(); | |
891 | |
865 SetCdm(BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnCdmAttached), | 892 SetCdm(BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnCdmAttached), |
866 ToWebContentDecryptionModuleImpl(cdm)->GetCdmContext()); | 893 ToWebContentDecryptionModuleImpl(cdm)->GetCdmContext()); |
867 } | 894 } |
868 | 895 |
869 void WebMediaPlayerImpl::OnEncryptedMediaInitData( | 896 void WebMediaPlayerImpl::OnEncryptedMediaInitData( |
870 EmeInitDataType init_data_type, | 897 EmeInitDataType init_data_type, |
871 const std::vector<uint8_t>& init_data) { | 898 const std::vector<uint8_t>& init_data) { |
872 DCHECK(init_data_type != EmeInitDataType::UNKNOWN); | 899 DCHECK(init_data_type != EmeInitDataType::UNKNOWN); |
873 | 900 |
874 // TODO(xhwang): Update this UMA name. https://crbug.com/589251 | 901 // TODO(xhwang): Update this UMA name. https://crbug.com/589251 |
875 UMA_HISTOGRAM_COUNTS("Media.EME.NeedKey", 1); | 902 UMA_HISTOGRAM_COUNTS("Media.EME.NeedKey", 1); |
876 | 903 |
904 // Recreate the watch time reporter if necessary. | |
905 const bool was_encrypted = is_encrypted_; | |
906 is_encrypted_ = true; | |
907 if (!was_encrypted && watch_time_reporter_) | |
908 CreateWatchTimeReporter(); | |
909 | |
877 encrypted_client_->encrypted( | 910 encrypted_client_->encrypted( |
878 ConvertToWebInitDataType(init_data_type), init_data.data(), | 911 ConvertToWebInitDataType(init_data_type), init_data.data(), |
879 base::saturated_cast<unsigned int>(init_data.size())); | 912 base::saturated_cast<unsigned int>(init_data.size())); |
880 } | 913 } |
881 | 914 |
882 void WebMediaPlayerImpl::OnFFmpegMediaTracksUpdated( | 915 void WebMediaPlayerImpl::OnFFmpegMediaTracksUpdated( |
883 std::unique_ptr<MediaTracks> tracks) { | 916 std::unique_ptr<MediaTracks> tracks) { |
884 // For MSE/chunk_demuxer case the media track updates are handled by | 917 // For MSE/chunk_demuxer case the media track updates are handled by |
885 // WebSourceBufferImpl. | 918 // WebSourceBufferImpl. |
886 DCHECK(demuxer_.get()); | 919 DCHECK(demuxer_.get()); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
938 if (paused_) { | 971 if (paused_) { |
939 #if defined(OS_ANDROID) // WMPI_CAST | 972 #if defined(OS_ANDROID) // WMPI_CAST |
940 if (isRemote()) { | 973 if (isRemote()) { |
941 paused_time_ = base::TimeDelta::FromSecondsD(cast_impl_.currentTime()); | 974 paused_time_ = base::TimeDelta::FromSecondsD(cast_impl_.currentTime()); |
942 } else { | 975 } else { |
943 paused_time_ = pipeline_.GetMediaTime(); | 976 paused_time_ = pipeline_.GetMediaTime(); |
944 } | 977 } |
945 #else | 978 #else |
946 paused_time_ = pipeline_.GetMediaTime(); | 979 paused_time_ = pipeline_.GetMediaTime(); |
947 #endif | 980 #endif |
981 } else { | |
982 watch_time_reporter_->OnPlaying(); | |
948 } | 983 } |
949 if (time_updated) | 984 if (time_updated) |
950 should_notify_time_changed_ = true; | 985 should_notify_time_changed_ = true; |
951 } | 986 } |
952 | 987 |
953 void WebMediaPlayerImpl::OnPipelineSuspended() { | 988 void WebMediaPlayerImpl::OnPipelineSuspended() { |
954 #if defined(OS_ANDROID) | 989 #if defined(OS_ANDROID) |
955 if (isRemote()) { | 990 if (isRemote()) { |
956 scoped_refptr<VideoFrame> frame = cast_impl_.GetCastingBanner(); | 991 scoped_refptr<VideoFrame> frame = cast_impl_.GetCastingBanner(); |
957 if (frame) | 992 if (frame) |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1019 // expected to be a no-op. | 1054 // expected to be a no-op. |
1020 UpdatePlayState(); | 1055 UpdatePlayState(); |
1021 } | 1056 } |
1022 | 1057 |
1023 void WebMediaPlayerImpl::OnMetadata(PipelineMetadata metadata) { | 1058 void WebMediaPlayerImpl::OnMetadata(PipelineMetadata metadata) { |
1024 DVLOG(1) << __func__; | 1059 DVLOG(1) << __func__; |
1025 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1060 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1026 | 1061 |
1027 pipeline_metadata_ = metadata; | 1062 pipeline_metadata_ = metadata; |
1028 | 1063 |
1064 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); | |
1029 UMA_HISTOGRAM_ENUMERATION("Media.VideoRotation", metadata.video_rotation, | 1065 UMA_HISTOGRAM_ENUMERATION("Media.VideoRotation", metadata.video_rotation, |
1030 VIDEO_ROTATION_MAX + 1); | 1066 VIDEO_ROTATION_MAX + 1); |
1031 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); | |
1032 | 1067 |
1033 if (hasVideo()) { | 1068 if (hasVideo()) { |
1034 pipeline_metadata_.natural_size = GetRotatedVideoSize( | 1069 pipeline_metadata_.natural_size = GetRotatedVideoSize( |
1035 pipeline_metadata_.video_rotation, pipeline_metadata_.natural_size); | 1070 pipeline_metadata_.video_rotation, pipeline_metadata_.natural_size); |
1036 | 1071 |
1037 if (overlay_enabled_ && surface_manager_) | 1072 if (overlay_enabled_ && surface_manager_) |
1038 surface_manager_->NaturalSizeChanged(pipeline_metadata_.natural_size); | 1073 surface_manager_->NaturalSizeChanged(pipeline_metadata_.natural_size); |
1039 | 1074 |
1040 DCHECK(!video_weblayer_); | 1075 DCHECK(!video_weblayer_); |
1041 video_weblayer_.reset(new cc_blink::WebLayerImpl(cc::VideoLayer::Create( | 1076 video_weblayer_.reset(new cc_blink::WebLayerImpl(cc::VideoLayer::Create( |
1042 compositor_, pipeline_metadata_.video_rotation))); | 1077 compositor_, pipeline_metadata_.video_rotation))); |
1043 video_weblayer_->layer()->SetContentsOpaque(opaque_); | 1078 video_weblayer_->layer()->SetContentsOpaque(opaque_); |
1044 video_weblayer_->SetContentsOpaqueIsFixed(true); | 1079 video_weblayer_->SetContentsOpaqueIsFixed(true); |
1045 client_->setWebLayer(video_weblayer_.get()); | 1080 client_->setWebLayer(video_weblayer_.get()); |
1046 } | 1081 } |
1047 | 1082 |
1083 CreateWatchTimeReporter(); | |
1048 UpdatePlayState(); | 1084 UpdatePlayState(); |
1049 } | 1085 } |
1050 | 1086 |
1051 void WebMediaPlayerImpl::OnBufferingStateChange(BufferingState state) { | 1087 void WebMediaPlayerImpl::OnBufferingStateChange(BufferingState state) { |
1052 DVLOG(1) << __func__ << "(" << state << ")"; | 1088 DVLOG(1) << __func__ << "(" << state << ")"; |
1053 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1089 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1054 | 1090 |
1055 // Ignore buffering state changes until we've completed all outstanding | 1091 // Ignore buffering state changes until we've completed all outstanding |
1056 // operations. | 1092 // operations. |
1057 if (!pipeline_controller_.IsStable()) | 1093 if (!pipeline_controller_.IsStable()) |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1156 | 1192 |
1157 opaque_ = opaque; | 1193 opaque_ = opaque; |
1158 // Modify content opaqueness of cc::Layer directly so that | 1194 // Modify content opaqueness of cc::Layer directly so that |
1159 // SetContentsOpaqueIsFixed is ignored. | 1195 // SetContentsOpaqueIsFixed is ignored. |
1160 if (video_weblayer_) | 1196 if (video_weblayer_) |
1161 video_weblayer_->layer()->SetContentsOpaque(opaque_); | 1197 video_weblayer_->layer()->SetContentsOpaque(opaque_); |
1162 } | 1198 } |
1163 | 1199 |
1164 void WebMediaPlayerImpl::OnHidden() { | 1200 void WebMediaPlayerImpl::OnHidden() { |
1165 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1201 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1202 if (watch_time_reporter_) | |
1203 watch_time_reporter_->OnHidden(); | |
1166 | 1204 |
1167 UpdatePlayState(); | 1205 UpdatePlayState(); |
1168 | 1206 |
1169 // Schedule suspended playing media to be paused if the user doesn't come back | 1207 // Schedule suspended playing media to be paused if the user doesn't come back |
1170 // to it within some timeout period to avoid any autoplay surprises. | 1208 // to it within some timeout period to avoid any autoplay surprises. |
1171 ScheduleIdlePauseTimer(); | 1209 ScheduleIdlePauseTimer(); |
1172 } | 1210 } |
1173 | 1211 |
1174 void WebMediaPlayerImpl::OnShown() { | 1212 void WebMediaPlayerImpl::OnShown() { |
1175 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1213 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1214 if (watch_time_reporter_) | |
1215 watch_time_reporter_->OnShown(); | |
1216 | |
1176 must_suspend_ = false; | 1217 must_suspend_ = false; |
1177 background_pause_timer_.Stop(); | 1218 background_pause_timer_.Stop(); |
1178 | 1219 |
1179 UpdatePlayState(); | 1220 UpdatePlayState(); |
1180 } | 1221 } |
1181 | 1222 |
1182 void WebMediaPlayerImpl::OnSuspendRequested(bool must_suspend) { | 1223 void WebMediaPlayerImpl::OnSuspendRequested(bool must_suspend) { |
1183 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1224 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1184 | 1225 |
1185 if (must_suspend) { | 1226 if (must_suspend) { |
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1747 // Remote players will be suspended and locally paused. | 1788 // Remote players will be suspended and locally paused. |
1748 if (isRemote()) | 1789 if (isRemote()) |
1749 return; | 1790 return; |
1750 #endif | 1791 #endif |
1751 | 1792 |
1752 // Idle timeout chosen arbitrarily. | 1793 // Idle timeout chosen arbitrarily. |
1753 background_pause_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(5), | 1794 background_pause_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(5), |
1754 this, &WebMediaPlayerImpl::OnPause); | 1795 this, &WebMediaPlayerImpl::OnPause); |
1755 } | 1796 } |
1756 | 1797 |
1798 void WebMediaPlayerImpl::CreateWatchTimeReporter() { | |
1799 // Create the watch time reporter and synchronize its initial state. | |
1800 watch_time_reporter_.reset(new WatchTimeReporter( | |
1801 hasAudio(), hasVideo(), !!chunk_demuxer_, is_encrypted_, media_log_, | |
1802 pipeline_metadata_.natural_size, | |
1803 base::Bind(&GetCurrentTimeInternal, this))); | |
1804 watch_time_reporter_->OnVolumeChange(volume_); | |
1805 if (delegate_ && delegate_->IsHidden()) | |
1806 watch_time_reporter_->OnHidden(); | |
1807 else | |
1808 watch_time_reporter_->OnShown(); | |
1809 } | |
1810 | |
1757 } // namespace media | 1811 } // namespace media |
OLD | NEW |