Chromium Code Reviews| Index: media/base/android/media_source_player.cc |
| diff --git a/media/base/android/media_source_player.cc b/media/base/android/media_source_player.cc |
| index 85ffd545d87877f787ca8d3a13fc55c1408460bd..155fd081d0af33f958f1cd5e42f7045802aad3e3 100644 |
| --- a/media/base/android/media_source_player.cc |
| +++ b/media/base/android/media_source_player.cc |
| @@ -61,6 +61,7 @@ MediaSourcePlayer::MediaSourcePlayer( |
| weak_factory_.GetWeakPtr()))); |
| demuxer_->Initialize(this); |
| interpolator_.SetUpperBound(base::TimeDelta()); |
| + audible_state_idle_period_ = base::TimeDelta::FromMilliseconds(1000); |
| weak_this_ = weak_factory_.GetWeakPtr(); |
| } |
| @@ -194,6 +195,9 @@ void MediaSourcePlayer::Release() { |
| playing_ = false; |
| decoder_starvation_callback_.Cancel(); |
| + audible_audio_stopped_callback_.Cancel(); |
| + |
| + SetAudible(false); |
| DetachListener(); |
| } |
| @@ -238,6 +242,7 @@ void MediaSourcePlayer::OnDemuxerConfigsAvailable( |
| const DemuxerConfigs& configs) { |
| DVLOG(1) << __FUNCTION__; |
| DCHECK(!HasAudio() && !HasVideo()); |
| + |
| duration_ = configs.duration; |
| audio_decoder_job_->SetDemuxerConfigs(configs); |
| @@ -399,6 +404,7 @@ void MediaSourcePlayer::ProcessPendingEvents() { |
| if (IsEventPending(PREFETCH_REQUEST_EVENT_PENDING)) { |
| DVLOG(1) << __FUNCTION__ << " : Handling PREFETCH_REQUEST_EVENT."; |
| + |
| int count = (AudioFinished() ? 0 : 1) + (VideoFinished() ? 0 : 1); |
| // It is possible that all streams have finished decode, yet starvation |
| @@ -574,6 +580,7 @@ void MediaSourcePlayer::DecodeMoreAudio() { |
| case MediaDecoderJob::STATUS_SUCCESS: |
| TRACE_EVENT_ASYNC_BEGIN0("media", "MediaSourcePlayer::DecodeMoreAudio", |
| audio_decoder_job_.get()); |
| + UpdateAudibleStatus(); |
| break; |
| case MediaDecoderJob::STATUS_KEY_FRAME_REQUIRED: |
| NOTREACHED(); |
| @@ -586,6 +593,24 @@ void MediaSourcePlayer::DecodeMoreAudio() { |
| } |
| } |
| +void MediaSourcePlayer::SetAudibleStateIdlePeriod(base::TimeDelta duration) { |
| + audible_state_idle_period_ = duration; |
| +} |
| + |
| +void MediaSourcePlayer::UpdateAudibleStatus() { |
|
qinmin
2015/03/19 23:34:23
I don't think we really need a timer for this. We
|
| + SetAudible(audio_decoder_job_->GetVolume() > 0); |
| + |
| + audible_audio_stopped_callback_.Cancel(); |
| + |
| + audible_audio_stopped_callback_.Reset( |
| + base::Bind(&MediaSourcePlayer::SetAudible, weak_this_, false)); |
| + |
| + DCHECK(audible_state_idle_period_ > base::TimeDelta()); |
| + base::MessageLoop::current()->PostDelayedTask( |
| + FROM_HERE, audible_audio_stopped_callback_.callback(), |
| + audible_state_idle_period_); |
| +} |
| + |
| void MediaSourcePlayer::DecodeMoreVideo() { |
| DVLOG(1) << __FUNCTION__; |
| DCHECK(!video_decoder_job_->is_decoding()); |