Chromium Code Reviews| Index: media/blink/webmediaplayer_impl.cc |
| diff --git a/media/blink/webmediaplayer_impl.cc b/media/blink/webmediaplayer_impl.cc |
| index 84dd78fc2d15342eabb71b203dfa18494b8d7b74..92d1227db9645b04b44dd78c006f3b503596ccfa 100644 |
| --- a/media/blink/webmediaplayer_impl.cc |
| +++ b/media/blink/webmediaplayer_impl.cc |
| @@ -37,6 +37,7 @@ |
| #include "media/base/timestamp_constants.h" |
| #include "media/base/video_frame.h" |
| #include "media/blink/texttrack_impl.h" |
| +#include "media/blink/watch_time_reporter.h" |
| #include "media/blink/webaudiosourceprovider_impl.h" |
| #include "media/blink/webcontentdecryptionmodule_impl.h" |
| #include "media/blink/webinbandtexttrack_impl.h" |
| @@ -129,6 +130,12 @@ gfx::Size GetRotatedVideoSize(VideoRotation rotation, gfx::Size natural_size) { |
| return natural_size; |
| } |
| +base::TimeDelta GetCurrentTimeInternal(WebMediaPlayerImpl* p_this) { |
| + // We wrap currentTime() instead of using pipeline_.GetMediaTime() since there |
| + // are a variety of cases in which that time is not accurate. |
|
sandersd (OOO until July 31)
2016/08/03 22:45:59
Can you expand on those cases here? (That said, cu
DaleCurtis
2016/08/04 19:14:59
Done.
|
| + return base::TimeDelta::FromSecondsD(p_this->currentTime()); |
| +} |
| + |
| } // namespace |
| class BufferedDataSourceHostImpl; |
| @@ -213,7 +220,8 @@ WebMediaPlayerImpl::WebMediaPlayerImpl( |
| surface_manager_(params.surface_manager()), |
| overlay_surface_id_(SurfaceManager::kNoSurfaceID), |
| suppress_destruction_errors_(false), |
| - can_suspend_state_(CanSuspendState::UNKNOWN) { |
| + can_suspend_state_(CanSuspendState::UNKNOWN), |
| + is_encrypted_(false) { |
| DCHECK(!adjust_allocated_memory_cb_.is_null()); |
| DCHECK(renderer_factory_); |
| DCHECK(client_); |
| @@ -394,6 +402,7 @@ void WebMediaPlayerImpl::play() { |
| if (data_source_) |
| data_source_->MediaIsPlaying(); |
| + watch_time_reporter_->OnPlaying(); |
| media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::PLAY)); |
| UpdatePlayState(); |
| } |
| @@ -423,6 +432,7 @@ void WebMediaPlayerImpl::pause() { |
| paused_time_ = |
| ended_ ? pipeline_.GetMediaDuration() : pipeline_.GetMediaTime(); |
| + watch_time_reporter_->OnPaused(); |
| media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::PAUSE)); |
| UpdatePlayState(); |
| } |
| @@ -473,6 +483,10 @@ void WebMediaPlayerImpl::DoSeek(base::TimeDelta time, bool time_updated) { |
| return; |
| } |
| + // Call this before setting |seeking_| so that the current media time can be |
| + // recorded by the reporter. |
| + watch_time_reporter_->OnSeeking(time); |
| + |
| // TODO(sandersd): Ideally we would not clear the idle state if |
| // |pipeline_controller_| can elide the seek. |
| is_idle_ = false; |
| @@ -519,6 +533,8 @@ void WebMediaPlayerImpl::setVolume(double volume) { |
| DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| volume_ = volume; |
| pipeline_.SetVolume(volume_ * volume_multiplier_); |
| + if (watch_time_reporter_) |
| + watch_time_reporter_->OnVolumeChange(volume); |
| } |
| void WebMediaPlayerImpl::setSinkId( |
| @@ -871,6 +887,7 @@ void WebMediaPlayerImpl::OnEncryptedMediaInitData( |
| // TODO(xhwang): Update this UMA name. https://crbug.com/589251 |
| UMA_HISTOGRAM_COUNTS("Media.EME.NeedKey", 1); |
| + is_encrypted_ = true; |
| encrypted_client_->encrypted( |
| ConvertToWebInitDataType(init_data_type), init_data.data(), |
| base::saturated_cast<unsigned int>(init_data.size())); |
| @@ -1023,9 +1040,9 @@ void WebMediaPlayerImpl::OnMetadata(PipelineMetadata metadata) { |
| pipeline_metadata_ = metadata; |
| + SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); |
| UMA_HISTOGRAM_ENUMERATION("Media.VideoRotation", metadata.video_rotation, |
| VIDEO_ROTATION_MAX + 1); |
| - SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); |
| if (hasVideo()) { |
| pipeline_metadata_.natural_size = GetRotatedVideoSize( |
| @@ -1042,6 +1059,17 @@ void WebMediaPlayerImpl::OnMetadata(PipelineMetadata metadata) { |
| client_->setWebLayer(video_weblayer_.get()); |
| } |
| + // Create the watch time reporter and synchronize its initial state. |
| + watch_time_reporter_.reset( |
| + new WatchTimeReporter(hasAudio(), hasVideo(), !!chunk_demuxer_, |
| + is_encrypted_, pipeline_metadata_.natural_size, |
| + base::Bind(&GetCurrentTimeInternal, this))); |
|
sandersd (OOO until July 31)
2016/08/03 22:45:59
What's the reason to not just directly bind curren
DaleCurtis
2016/08/04 19:14:59
The detail of currentTime returning a double is sp
|
| + watch_time_reporter_->OnVolumeChange(volume_); |
| + if (delegate_ && delegate_->IsHidden()) |
| + watch_time_reporter_->OnHidden(); |
| + else |
| + watch_time_reporter_->OnShown(); |
| + |
| UpdatePlayState(); |
| } |
| @@ -1160,6 +1188,9 @@ void WebMediaPlayerImpl::OnVideoOpacityChange(bool opaque) { |
| void WebMediaPlayerImpl::OnHidden() { |
| DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| + if (watch_time_reporter_) |
| + watch_time_reporter_->OnHidden(); |
| + |
| UpdatePlayState(); |
| // Schedule suspended playing media to be paused if the user doesn't come back |
| @@ -1169,6 +1200,9 @@ void WebMediaPlayerImpl::OnHidden() { |
| void WebMediaPlayerImpl::OnShown() { |
| DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| + if (watch_time_reporter_) |
| + watch_time_reporter_->OnShown(); |
| + |
| must_suspend_ = false; |
| background_pause_timer_.Stop(); |
| UpdatePlayState(); |