OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/base/android/media_source_player.h" | 5 #include "media/base/android/media_source_player.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
54 weak_factory_.GetWeakPtr()))); | 54 weak_factory_.GetWeakPtr()))); |
55 video_decoder_job_.reset(new VideoDecoderJob( | 55 video_decoder_job_.reset(new VideoDecoderJob( |
56 base::Bind(&DemuxerAndroid::RequestDemuxerData, | 56 base::Bind(&DemuxerAndroid::RequestDemuxerData, |
57 base::Unretained(demuxer_.get()), | 57 base::Unretained(demuxer_.get()), |
58 DemuxerStream::VIDEO), | 58 DemuxerStream::VIDEO), |
59 base::Bind(request_media_resources_cb_, player_id), | 59 base::Bind(request_media_resources_cb_, player_id), |
60 base::Bind(&MediaSourcePlayer::OnDemuxerConfigsChanged, | 60 base::Bind(&MediaSourcePlayer::OnDemuxerConfigsChanged, |
61 weak_factory_.GetWeakPtr()))); | 61 weak_factory_.GetWeakPtr()))); |
62 demuxer_->Initialize(this); | 62 demuxer_->Initialize(this); |
63 interpolator_.SetUpperBound(base::TimeDelta()); | 63 interpolator_.SetUpperBound(base::TimeDelta()); |
64 audible_state_idle_period_ = base::TimeDelta::FromMilliseconds(1000); | |
64 weak_this_ = weak_factory_.GetWeakPtr(); | 65 weak_this_ = weak_factory_.GetWeakPtr(); |
65 } | 66 } |
66 | 67 |
67 MediaSourcePlayer::~MediaSourcePlayer() { | 68 MediaSourcePlayer::~MediaSourcePlayer() { |
68 Release(); | 69 Release(); |
69 DCHECK_EQ(!drm_bridge_, !cdm_registration_id_); | 70 DCHECK_EQ(!drm_bridge_, !cdm_registration_id_); |
70 if (drm_bridge_) { | 71 if (drm_bridge_) { |
71 drm_bridge_->UnregisterPlayer(cdm_registration_id_); | 72 drm_bridge_->UnregisterPlayer(cdm_registration_id_); |
72 cdm_registration_id_ = 0; | 73 cdm_registration_id_ = 0; |
73 } | 74 } |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 void MediaSourcePlayer::Release() { | 188 void MediaSourcePlayer::Release() { |
188 DVLOG(1) << __FUNCTION__; | 189 DVLOG(1) << __FUNCTION__; |
189 | 190 |
190 audio_decoder_job_->ReleaseDecoderResources(); | 191 audio_decoder_job_->ReleaseDecoderResources(); |
191 video_decoder_job_->ReleaseDecoderResources(); | 192 video_decoder_job_->ReleaseDecoderResources(); |
192 | 193 |
193 // Prevent player restart, including job re-creation attempts. | 194 // Prevent player restart, including job re-creation attempts. |
194 playing_ = false; | 195 playing_ = false; |
195 | 196 |
196 decoder_starvation_callback_.Cancel(); | 197 decoder_starvation_callback_.Cancel(); |
198 audible_audio_stopped_callback_.Cancel(); | |
199 | |
200 SetAudible(false); | |
197 DetachListener(); | 201 DetachListener(); |
198 } | 202 } |
199 | 203 |
200 void MediaSourcePlayer::SetVolume(double volume) { | 204 void MediaSourcePlayer::SetVolume(double volume) { |
201 audio_decoder_job_->SetVolume(volume); | 205 audio_decoder_job_->SetVolume(volume); |
202 } | 206 } |
203 | 207 |
204 bool MediaSourcePlayer::CanPause() { | 208 bool MediaSourcePlayer::CanPause() { |
205 return Seekable(); | 209 return Seekable(); |
206 } | 210 } |
(...skipping 24 matching lines...) Expand all Loading... | |
231 AttachListener(NULL); | 235 AttachListener(NULL); |
232 | 236 |
233 SetPendingEvent(PREFETCH_REQUEST_EVENT_PENDING); | 237 SetPendingEvent(PREFETCH_REQUEST_EVENT_PENDING); |
234 ProcessPendingEvents(); | 238 ProcessPendingEvents(); |
235 } | 239 } |
236 | 240 |
237 void MediaSourcePlayer::OnDemuxerConfigsAvailable( | 241 void MediaSourcePlayer::OnDemuxerConfigsAvailable( |
238 const DemuxerConfigs& configs) { | 242 const DemuxerConfigs& configs) { |
239 DVLOG(1) << __FUNCTION__; | 243 DVLOG(1) << __FUNCTION__; |
240 DCHECK(!HasAudio() && !HasVideo()); | 244 DCHECK(!HasAudio() && !HasVideo()); |
245 | |
241 duration_ = configs.duration; | 246 duration_ = configs.duration; |
242 | 247 |
243 audio_decoder_job_->SetDemuxerConfigs(configs); | 248 audio_decoder_job_->SetDemuxerConfigs(configs); |
244 video_decoder_job_->SetDemuxerConfigs(configs); | 249 video_decoder_job_->SetDemuxerConfigs(configs); |
245 OnDemuxerConfigsChanged(); | 250 OnDemuxerConfigsChanged(); |
246 } | 251 } |
247 | 252 |
248 void MediaSourcePlayer::OnDemuxerDataAvailable(const DemuxerData& data) { | 253 void MediaSourcePlayer::OnDemuxerDataAvailable(const DemuxerData& data) { |
249 DVLOG(1) << __FUNCTION__ << "(" << data.type << ")"; | 254 DVLOG(1) << __FUNCTION__ << "(" << data.type << ")"; |
250 DCHECK_LT(0u, data.access_units.size()); | 255 DCHECK_LT(0u, data.access_units.size()); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
392 | 397 |
393 if (IsEventPending(DECODER_CREATION_EVENT_PENDING)) { | 398 if (IsEventPending(DECODER_CREATION_EVENT_PENDING)) { |
394 // Don't continue if one of the decoder is not created. | 399 // Don't continue if one of the decoder is not created. |
395 if (is_waiting_for_audio_decoder_ || is_waiting_for_video_decoder_) | 400 if (is_waiting_for_audio_decoder_ || is_waiting_for_video_decoder_) |
396 return; | 401 return; |
397 ClearPendingEvent(DECODER_CREATION_EVENT_PENDING); | 402 ClearPendingEvent(DECODER_CREATION_EVENT_PENDING); |
398 } | 403 } |
399 | 404 |
400 if (IsEventPending(PREFETCH_REQUEST_EVENT_PENDING)) { | 405 if (IsEventPending(PREFETCH_REQUEST_EVENT_PENDING)) { |
401 DVLOG(1) << __FUNCTION__ << " : Handling PREFETCH_REQUEST_EVENT."; | 406 DVLOG(1) << __FUNCTION__ << " : Handling PREFETCH_REQUEST_EVENT."; |
407 | |
402 int count = (AudioFinished() ? 0 : 1) + (VideoFinished() ? 0 : 1); | 408 int count = (AudioFinished() ? 0 : 1) + (VideoFinished() ? 0 : 1); |
403 | 409 |
404 // It is possible that all streams have finished decode, yet starvation | 410 // It is possible that all streams have finished decode, yet starvation |
405 // occurred during the last stream's EOS decode. In this case, prefetch is a | 411 // occurred during the last stream's EOS decode. In this case, prefetch is a |
406 // no-op. | 412 // no-op. |
407 ClearPendingEvent(PREFETCH_REQUEST_EVENT_PENDING); | 413 ClearPendingEvent(PREFETCH_REQUEST_EVENT_PENDING); |
408 if (count == 0) | 414 if (count == 0) |
409 return; | 415 return; |
410 | 416 |
411 SetPendingEvent(PREFETCH_DONE_EVENT_PENDING); | 417 SetPendingEvent(PREFETCH_DONE_EVENT_PENDING); |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
567 | 573 |
568 MediaDecoderJob::MediaDecoderJobStatus status = audio_decoder_job_->Decode( | 574 MediaDecoderJob::MediaDecoderJobStatus status = audio_decoder_job_->Decode( |
569 start_time_ticks_, | 575 start_time_ticks_, |
570 start_presentation_timestamp_, | 576 start_presentation_timestamp_, |
571 base::Bind(&MediaSourcePlayer::MediaDecoderCallback, weak_this_, true)); | 577 base::Bind(&MediaSourcePlayer::MediaDecoderCallback, weak_this_, true)); |
572 | 578 |
573 switch (status) { | 579 switch (status) { |
574 case MediaDecoderJob::STATUS_SUCCESS: | 580 case MediaDecoderJob::STATUS_SUCCESS: |
575 TRACE_EVENT_ASYNC_BEGIN0("media", "MediaSourcePlayer::DecodeMoreAudio", | 581 TRACE_EVENT_ASYNC_BEGIN0("media", "MediaSourcePlayer::DecodeMoreAudio", |
576 audio_decoder_job_.get()); | 582 audio_decoder_job_.get()); |
583 UpdateAudibleStatus(); | |
577 break; | 584 break; |
578 case MediaDecoderJob::STATUS_KEY_FRAME_REQUIRED: | 585 case MediaDecoderJob::STATUS_KEY_FRAME_REQUIRED: |
579 NOTREACHED(); | 586 NOTREACHED(); |
580 break; | 587 break; |
581 case MediaDecoderJob::STATUS_FAILURE: | 588 case MediaDecoderJob::STATUS_FAILURE: |
582 is_waiting_for_audio_decoder_ = true; | 589 is_waiting_for_audio_decoder_ = true; |
583 if (!IsEventPending(DECODER_CREATION_EVENT_PENDING)) | 590 if (!IsEventPending(DECODER_CREATION_EVENT_PENDING)) |
584 SetPendingEvent(DECODER_CREATION_EVENT_PENDING); | 591 SetPendingEvent(DECODER_CREATION_EVENT_PENDING); |
585 break; | 592 break; |
586 } | 593 } |
587 } | 594 } |
588 | 595 |
596 void MediaSourcePlayer::SetAudibleStateIdlePeriod(base::TimeDelta duration) { | |
597 audible_state_idle_period_ = duration; | |
598 } | |
599 | |
600 void MediaSourcePlayer::UpdateAudibleStatus() { | |
qinmin
2015/03/19 23:34:23
I don't think we really need a timer for this. We
| |
601 SetAudible(audio_decoder_job_->GetVolume() > 0); | |
602 | |
603 audible_audio_stopped_callback_.Cancel(); | |
604 | |
605 audible_audio_stopped_callback_.Reset( | |
606 base::Bind(&MediaSourcePlayer::SetAudible, weak_this_, false)); | |
607 | |
608 DCHECK(audible_state_idle_period_ > base::TimeDelta()); | |
609 base::MessageLoop::current()->PostDelayedTask( | |
610 FROM_HERE, audible_audio_stopped_callback_.callback(), | |
611 audible_state_idle_period_); | |
612 } | |
613 | |
589 void MediaSourcePlayer::DecodeMoreVideo() { | 614 void MediaSourcePlayer::DecodeMoreVideo() { |
590 DVLOG(1) << __FUNCTION__; | 615 DVLOG(1) << __FUNCTION__; |
591 DCHECK(!video_decoder_job_->is_decoding()); | 616 DCHECK(!video_decoder_job_->is_decoding()); |
592 DCHECK(!VideoFinished()); | 617 DCHECK(!VideoFinished()); |
593 | 618 |
594 MediaDecoderJob::MediaDecoderJobStatus status = video_decoder_job_->Decode( | 619 MediaDecoderJob::MediaDecoderJobStatus status = video_decoder_job_->Decode( |
595 start_time_ticks_, | 620 start_time_ticks_, |
596 start_presentation_timestamp_, | 621 start_presentation_timestamp_, |
597 base::Bind(&MediaSourcePlayer::MediaDecoderCallback, weak_this_, | 622 base::Bind(&MediaSourcePlayer::MediaDecoderCallback, weak_this_, |
598 false)); | 623 false)); |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
816 // support setMediaKeys(0) (see http://crbug.com/330324), or when we release | 841 // support setMediaKeys(0) (see http://crbug.com/330324), or when we release |
817 // MediaDrm when the video is paused, or when the device goes to sleep (see | 842 // MediaDrm when the video is paused, or when the device goes to sleep (see |
818 // http://crbug.com/272421). | 843 // http://crbug.com/272421). |
819 audio_decoder_job_->SetDrmBridge(NULL); | 844 audio_decoder_job_->SetDrmBridge(NULL); |
820 video_decoder_job_->SetDrmBridge(NULL); | 845 video_decoder_job_->SetDrmBridge(NULL); |
821 cdm_registration_id_ = 0; | 846 cdm_registration_id_ = 0; |
822 drm_bridge_ = NULL; | 847 drm_bridge_ = NULL; |
823 } | 848 } |
824 | 849 |
825 } // namespace media | 850 } // namespace media |
OLD | NEW |