Index: media/blink/webmediaplayer_impl.cc |
diff --git a/media/blink/webmediaplayer_impl.cc b/media/blink/webmediaplayer_impl.cc |
index c9b8f8a465bd5590c4dca4fb7af1538961b429bd..3055c3dcb62d107e2190474c0b1f20b8064813ef 100644 |
--- a/media/blink/webmediaplayer_impl.cc |
+++ b/media/blink/webmediaplayer_impl.cc |
@@ -200,6 +200,7 @@ WebMediaPlayerImpl::WebMediaPlayerImpl( |
base::Unretained(this)), |
base::Bind(&WebMediaPlayerImpl::OnPipelineSeeked, AsWeakPtr()), |
base::Bind(&WebMediaPlayerImpl::OnPipelineSuspended, AsWeakPtr()), |
+ base::Bind(&WebMediaPlayerImpl::OnPipelineResumed, AsWeakPtr()), |
base::Bind(&WebMediaPlayerImpl::OnError, AsWeakPtr())), |
load_type_(LoadTypeURL), |
opaque_(false), |
@@ -470,6 +471,19 @@ void WebMediaPlayerImpl::pause() { |
DCHECK(watch_time_reporter_); |
watch_time_reporter_->OnPaused(); |
media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::PAUSE)); |
+ |
+ // Enable the background video track back so that when the new renderer is |
+ // initialized upon resume, it registers itself with the video track. |
+ // TODO(avayvod): Remove when disabling video tracks works correctly. See |
+ // https://crbug.com/678374. |
+ if (video_track_disabled_) { |
+ video_track_disabled_ = false; |
+ if (client_->hasSelectedVideoTrack()) { |
+ WebMediaPlayer::TrackId trackId = client_->getSelectedVideoTrackId(); |
+ selectedVideoTrackChanged(&trackId); |
+ } |
+ } |
+ |
UpdatePlayState(); |
} |
@@ -667,9 +681,7 @@ void WebMediaPlayerImpl::selectedVideoTrackChanged( |
std::ostringstream logstr; |
std::vector<MediaTrack::Id> selectedVideoMediaTrackId; |
- bool canAddVideoTrack = |
- !IsBackgroundVideoTrackOptimizationEnabled() || !IsHidden(); |
- if (selectedTrackId && canAddVideoTrack) { |
+ if (selectedTrackId && !video_track_disabled_) { |
selectedVideoMediaTrackId.push_back(selectedTrackId->utf8().data()); |
logstr << selectedVideoMediaTrackId[0]; |
} |
@@ -1054,8 +1066,11 @@ void WebMediaPlayerImpl::OnCdmAttached(bool success) { |
} |
void WebMediaPlayerImpl::OnPipelineSeeked(bool time_updated) { |
- seeking_ = false; |
- seek_time_ = base::TimeDelta(); |
+ if (seeking_) { |
sandersd (OOO until July 31)
2017/01/07 00:56:17
Shouldn't be needed anymore?
whywhat
2017/01/07 02:02:35
Done.
|
+ seeking_ = false; |
+ seek_time_ = base::TimeDelta(); |
+ } |
+ |
if (paused_) { |
#if defined(OS_ANDROID) // WMPI_CAST |
if (isRemote()) { |
@@ -1103,6 +1118,18 @@ void WebMediaPlayerImpl::OnPipelineSuspended() { |
} |
} |
+void WebMediaPlayerImpl::OnPipelineResumed() { |
+ // Disable video track if we start playing the video in the background and |
+ // haven't disabled the decoder yet. |
+ // TODO(avayvod): Remove this when disabling and enabling video tracks in |
+ // non-playing state works correctly. See https://crbug.com/678374. |
+ if (IsBackgroundVideoTrackOptimizationEnabled() && IsHidden() && |
+ !video_track_disabled_) { |
+ video_track_disabled_ = true; |
+ selectedVideoTrackChanged(nullptr); |
+ } |
+} |
+ |
void WebMediaPlayerImpl::OnDemuxerOpened() { |
DCHECK(main_task_runner_->BelongsToCurrentThread()); |
client_->mediaSourceOpened( |
@@ -1336,14 +1363,21 @@ void WebMediaPlayerImpl::OnVideoOpacityChange(bool opaque) { |
void WebMediaPlayerImpl::OnHidden() { |
DCHECK(main_task_runner_->BelongsToCurrentThread()); |
- if (IsBackgroundVideoTrackOptimizationEnabled()) |
- selectedVideoTrackChanged(nullptr); |
- |
if (watch_time_reporter_) |
watch_time_reporter_->OnHidden(); |
UpdatePlayState(); |
+ // Only disable video tracks for background videos when they're playing. |
+ // Otherwise the video track will get detached from the renderer. |
+ // TODO(avayvod): Remove extra check once this is no longer happening. |
+ // See https://crbug.com/678374. |
+ if (IsBackgroundVideoTrackOptimizationEnabled() && |
+ delegate_state_ == DelegateState::PLAYING) { |
+ video_track_disabled_ = true; |
+ selectedVideoTrackChanged(nullptr); |
+ } |
+ |
// Schedule suspended playing media to be paused if the user doesn't come back |
// to it within some timeout period to avoid any autoplay surprises. |
ScheduleIdlePauseTimer(); |
@@ -1359,15 +1393,17 @@ void WebMediaPlayerImpl::OnShown() { |
base::Bind(&VideoFrameCompositor::SetForegroundTime, |
base::Unretained(compositor_), base::TimeTicks::Now())); |
- if (IsBackgroundVideoTrackOptimizationEnabled() && |
- client_->hasSelectedVideoTrack()) { |
- WebMediaPlayer::TrackId trackId = client_->getSelectedVideoTrackId(); |
- selectedVideoTrackChanged(&trackId); |
- } |
- |
must_suspend_ = false; |
background_pause_timer_.Stop(); |
+ if (video_track_disabled_) { |
+ video_track_disabled_ = false; |
+ if (client_->hasSelectedVideoTrack()) { |
+ WebMediaPlayer::TrackId trackId = client_->getSelectedVideoTrackId(); |
+ selectedVideoTrackChanged(&trackId); |
+ } |
+ } |
+ |
UpdatePlayState(); |
} |