Chromium Code Reviews| 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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 void MediaSourcePlayer::Release() { | 187 void MediaSourcePlayer::Release() { |
| 188 DVLOG(1) << __FUNCTION__; | 188 DVLOG(1) << __FUNCTION__; |
| 189 | 189 |
| 190 audio_decoder_job_->ReleaseDecoderResources(); | 190 audio_decoder_job_->ReleaseDecoderResources(); |
| 191 video_decoder_job_->ReleaseDecoderResources(); | 191 video_decoder_job_->ReleaseDecoderResources(); |
| 192 | 192 |
| 193 // Prevent player restart, including job re-creation attempts. | 193 // Prevent player restart, including job re-creation attempts. |
| 194 playing_ = false; | 194 playing_ = false; |
| 195 | 195 |
| 196 decoder_starvation_callback_.Cancel(); | 196 decoder_starvation_callback_.Cancel(); |
| 197 | |
| 198 SetAudible(false); | |
| 197 DetachListener(); | 199 DetachListener(); |
| 198 } | 200 } |
| 199 | 201 |
| 200 void MediaSourcePlayer::SetVolume(double volume) { | 202 void MediaSourcePlayer::SetVolume(double volume) { |
| 201 audio_decoder_job_->SetVolume(volume); | 203 audio_decoder_job_->SetVolume(volume); |
| 202 } | 204 } |
| 203 | 205 |
| 204 bool MediaSourcePlayer::CanPause() { | 206 bool MediaSourcePlayer::CanPause() { |
| 205 return Seekable(); | 207 return Seekable(); |
| 206 } | 208 } |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 231 AttachListener(NULL); | 233 AttachListener(NULL); |
| 232 | 234 |
| 233 SetPendingEvent(PREFETCH_REQUEST_EVENT_PENDING); | 235 SetPendingEvent(PREFETCH_REQUEST_EVENT_PENDING); |
| 234 ProcessPendingEvents(); | 236 ProcessPendingEvents(); |
| 235 } | 237 } |
| 236 | 238 |
| 237 void MediaSourcePlayer::OnDemuxerConfigsAvailable( | 239 void MediaSourcePlayer::OnDemuxerConfigsAvailable( |
| 238 const DemuxerConfigs& configs) { | 240 const DemuxerConfigs& configs) { |
| 239 DVLOG(1) << __FUNCTION__; | 241 DVLOG(1) << __FUNCTION__; |
| 240 DCHECK(!HasAudio() && !HasVideo()); | 242 DCHECK(!HasAudio() && !HasVideo()); |
| 243 | |
| 241 duration_ = configs.duration; | 244 duration_ = configs.duration; |
| 242 | 245 |
| 243 audio_decoder_job_->SetDemuxerConfigs(configs); | 246 audio_decoder_job_->SetDemuxerConfigs(configs); |
| 244 video_decoder_job_->SetDemuxerConfigs(configs); | 247 video_decoder_job_->SetDemuxerConfigs(configs); |
| 245 OnDemuxerConfigsChanged(); | 248 OnDemuxerConfigsChanged(); |
| 246 } | 249 } |
| 247 | 250 |
| 248 void MediaSourcePlayer::OnDemuxerDataAvailable(const DemuxerData& data) { | 251 void MediaSourcePlayer::OnDemuxerDataAvailable(const DemuxerData& data) { |
| 249 DVLOG(1) << __FUNCTION__ << "(" << data.type << ")"; | 252 DVLOG(1) << __FUNCTION__ << "(" << data.type << ")"; |
| 250 DCHECK_LT(0u, data.access_units.size()); | 253 DCHECK_LT(0u, data.access_units.size()); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 392 | 395 |
| 393 if (IsEventPending(DECODER_CREATION_EVENT_PENDING)) { | 396 if (IsEventPending(DECODER_CREATION_EVENT_PENDING)) { |
| 394 // Don't continue if one of the decoder is not created. | 397 // Don't continue if one of the decoder is not created. |
| 395 if (is_waiting_for_audio_decoder_ || is_waiting_for_video_decoder_) | 398 if (is_waiting_for_audio_decoder_ || is_waiting_for_video_decoder_) |
| 396 return; | 399 return; |
| 397 ClearPendingEvent(DECODER_CREATION_EVENT_PENDING); | 400 ClearPendingEvent(DECODER_CREATION_EVENT_PENDING); |
| 398 } | 401 } |
| 399 | 402 |
| 400 if (IsEventPending(PREFETCH_REQUEST_EVENT_PENDING)) { | 403 if (IsEventPending(PREFETCH_REQUEST_EVENT_PENDING)) { |
| 401 DVLOG(1) << __FUNCTION__ << " : Handling PREFETCH_REQUEST_EVENT."; | 404 DVLOG(1) << __FUNCTION__ << " : Handling PREFETCH_REQUEST_EVENT."; |
| 405 | |
| 402 int count = (AudioFinished() ? 0 : 1) + (VideoFinished() ? 0 : 1); | 406 int count = (AudioFinished() ? 0 : 1) + (VideoFinished() ? 0 : 1); |
| 403 | 407 |
| 404 // It is possible that all streams have finished decode, yet starvation | 408 // 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 | 409 // occurred during the last stream's EOS decode. In this case, prefetch is a |
| 406 // no-op. | 410 // no-op. |
| 407 ClearPendingEvent(PREFETCH_REQUEST_EVENT_PENDING); | 411 ClearPendingEvent(PREFETCH_REQUEST_EVENT_PENDING); |
| 408 if (count == 0) | 412 if (count == 0) |
| 409 return; | 413 return; |
| 410 | 414 |
| 411 SetPendingEvent(PREFETCH_DONE_EVENT_PENDING); | 415 SetPendingEvent(PREFETCH_DONE_EVENT_PENDING); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 486 PlaybackCompleted(is_audio); | 490 PlaybackCompleted(is_audio); |
| 487 if (is_clock_manager) | 491 if (is_clock_manager) |
| 488 interpolator_.StopInterpolating(); | 492 interpolator_.StopInterpolating(); |
| 489 } | 493 } |
| 490 | 494 |
| 491 if (pending_event_ != NO_EVENT_PENDING) { | 495 if (pending_event_ != NO_EVENT_PENDING) { |
| 492 ProcessPendingEvents(); | 496 ProcessPendingEvents(); |
| 493 return; | 497 return; |
| 494 } | 498 } |
| 495 | 499 |
| 496 if (status == MEDIA_CODEC_OUTPUT_END_OF_STREAM) | 500 if (status == MEDIA_CODEC_OUTPUT_END_OF_STREAM) { |
| 501 if (is_audio) | |
| 502 SetAudible(false); | |
| 497 return; | 503 return; |
| 504 } | |
| 498 | 505 |
| 499 if (!playing_) { | 506 if (!playing_) { |
| 500 if (is_clock_manager) | 507 if (is_clock_manager) |
| 501 interpolator_.StopInterpolating(); | 508 interpolator_.StopInterpolating(); |
| 509 | |
| 510 if (is_audio) | |
| 511 SetAudible(false); | |
| 502 return; | 512 return; |
| 503 } | 513 } |
| 504 | 514 |
| 505 if (status == MEDIA_CODEC_NO_KEY) { | 515 if (status == MEDIA_CODEC_NO_KEY) { |
| 506 if (key_added_while_decode_pending_) { | 516 if (key_added_while_decode_pending_) { |
| 507 DVLOG(2) << __FUNCTION__ << ": Key was added during decoding."; | 517 DVLOG(2) << __FUNCTION__ << ": Key was added during decoding."; |
| 508 ResumePlaybackAfterKeyAdded(); | 518 ResumePlaybackAfterKeyAdded(); |
| 509 } else { | 519 } else { |
|
qinmin
2015/03/24 21:38:37
we need setAudible(false) here too
Tima Vaisburd
2015/03/24 22:24:50
Done.
| |
| 510 is_waiting_for_key_ = true; | 520 is_waiting_for_key_ = true; |
| 511 manager()->OnWaitingForDecryptionKey(player_id()); | 521 manager()->OnWaitingForDecryptionKey(player_id()); |
| 512 } | 522 } |
| 513 return; | 523 return; |
| 514 } | 524 } |
| 515 | 525 |
| 516 // If |key_added_while_decode_pending_| is true and both audio and video | 526 // If |key_added_while_decode_pending_| is true and both audio and video |
| 517 // decoding succeeded, we should clear |key_added_while_decode_pending_| here. | 527 // decoding succeeded, we should clear |key_added_while_decode_pending_| here. |
| 518 // But that would add more complexity into this function. If we don't clear it | 528 // But that would add more complexity into this function. If we don't clear it |
| 519 // here, the worst case would be we call ResumePlaybackAfterKeyAdded() when | 529 // here, the worst case would be we call ResumePlaybackAfterKeyAdded() when |
| 520 // we don't really have a new key. This should rarely happen and the | 530 // we don't really have a new key. This should rarely happen and the |
| 521 // performance impact should be pretty small. | 531 // performance impact should be pretty small. |
| 522 // TODO(qinmin/xhwang): This class is complicated because we handle both audio | 532 // TODO(qinmin/xhwang): This class is complicated because we handle both audio |
| 523 // and video in one file. If we separate them, we should be able to remove a | 533 // and video in one file. If we separate them, we should be able to remove a |
| 524 // lot of duplication. | 534 // lot of duplication. |
| 525 | 535 |
| 526 // If the status is MEDIA_CODEC_ABORT, stop decoding new data. The player is | 536 // If the status is MEDIA_CODEC_ABORT, stop decoding new data. The player is |
| 527 // in the middle of a seek or stop event and needs to wait for the IPCs to | 537 // in the middle of a seek or stop event and needs to wait for the IPCs to |
| 528 // come. | 538 // come. |
| 529 if (status == MEDIA_CODEC_ABORT) | 539 if (status == MEDIA_CODEC_ABORT) { |
| 540 if (is_audio) | |
| 541 SetAudible(false); | |
| 530 return; | 542 return; |
| 543 } | |
| 531 | 544 |
| 532 if (prerolling_ && IsPrerollFinished(is_audio)) { | 545 if (prerolling_ && IsPrerollFinished(is_audio)) { |
| 533 if (IsPrerollFinished(!is_audio)) { | 546 if (IsPrerollFinished(!is_audio)) { |
| 534 prerolling_ = false; | 547 prerolling_ = false; |
| 535 StartInternal(); | 548 StartInternal(); |
| 536 } | 549 } |
| 537 return; | 550 return; |
| 538 } | 551 } |
| 539 | 552 |
| 553 // We successfully decoded a frame and going to the next one. | |
| 554 // Set the audible state. | |
| 555 if (is_audio) { | |
| 556 bool is_audible = !prerolling_ && audio_decoder_job_->GetVolume() > 0; | |
| 557 SetAudible(is_audible); | |
| 558 } | |
| 559 | |
| 540 if (is_clock_manager) { | 560 if (is_clock_manager) { |
| 541 // If we have a valid timestamp, start the starvation callback. Otherwise, | 561 // If we have a valid timestamp, start the starvation callback. Otherwise, |
| 542 // reset the |start_time_ticks_| so that the next frame will not suffer | 562 // reset the |start_time_ticks_| so that the next frame will not suffer |
| 543 // from the decoding delay caused by the current frame. | 563 // from the decoding delay caused by the current frame. |
| 544 if (current_presentation_timestamp != kNoTimestamp()) | 564 if (current_presentation_timestamp != kNoTimestamp()) |
| 545 StartStarvationCallback(current_presentation_timestamp, | 565 StartStarvationCallback(current_presentation_timestamp, |
| 546 max_presentation_timestamp); | 566 max_presentation_timestamp); |
| 547 else | 567 else |
| 548 start_time_ticks_ = base::TimeTicks::Now(); | 568 start_time_ticks_ = base::TimeTicks::Now(); |
| 549 } | 569 } |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 641 bool MediaSourcePlayer::AudioFinished() { | 661 bool MediaSourcePlayer::AudioFinished() { |
| 642 return audio_decoder_job_->OutputEOSReached() || !HasAudio(); | 662 return audio_decoder_job_->OutputEOSReached() || !HasAudio(); |
| 643 } | 663 } |
| 644 | 664 |
| 645 bool MediaSourcePlayer::VideoFinished() { | 665 bool MediaSourcePlayer::VideoFinished() { |
| 646 return video_decoder_job_->OutputEOSReached() || !HasVideo(); | 666 return video_decoder_job_->OutputEOSReached() || !HasVideo(); |
| 647 } | 667 } |
| 648 | 668 |
| 649 void MediaSourcePlayer::OnDecoderStarved() { | 669 void MediaSourcePlayer::OnDecoderStarved() { |
| 650 DVLOG(1) << __FUNCTION__; | 670 DVLOG(1) << __FUNCTION__; |
| 671 | |
| 672 if (HasAudio()) { | |
| 673 // If the starvation timer fired but there are no encoded frames | |
| 674 // in the queue we believe the demuxer (i.e. renderer process) froze. | |
| 675 if (!audio_decoder_job_->HasData()) { | |
|
qinmin
2015/03/24 21:38:37
no {} needed
Tima Vaisburd
2015/03/24 22:24:50
Done.
| |
| 676 SetAudible(false); | |
| 677 } | |
| 678 } | |
| 679 | |
| 651 SetPendingEvent(PREFETCH_REQUEST_EVENT_PENDING); | 680 SetPendingEvent(PREFETCH_REQUEST_EVENT_PENDING); |
| 652 ProcessPendingEvents(); | 681 ProcessPendingEvents(); |
| 653 } | 682 } |
| 654 | 683 |
| 655 void MediaSourcePlayer::StartStarvationCallback( | 684 void MediaSourcePlayer::StartStarvationCallback( |
| 656 base::TimeDelta current_presentation_timestamp, | 685 base::TimeDelta current_presentation_timestamp, |
| 657 base::TimeDelta max_presentation_timestamp) { | 686 base::TimeDelta max_presentation_timestamp) { |
| 658 // 20ms was chosen because it is the typical size of a compressed audio frame. | 687 // 20ms was chosen because it is the typical size of a compressed audio frame. |
| 659 // Anything smaller than this would likely cause unnecessary cycling in and | 688 // Anything smaller than this would likely cause unnecessary cycling in and |
| 660 // out of the prefetch state. | 689 // out of the prefetch state. |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 816 // support setMediaKeys(0) (see http://crbug.com/330324), or when we release | 845 // 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 | 846 // MediaDrm when the video is paused, or when the device goes to sleep (see |
| 818 // http://crbug.com/272421). | 847 // http://crbug.com/272421). |
| 819 audio_decoder_job_->SetDrmBridge(NULL); | 848 audio_decoder_job_->SetDrmBridge(NULL); |
| 820 video_decoder_job_->SetDrmBridge(NULL); | 849 video_decoder_job_->SetDrmBridge(NULL); |
| 821 cdm_registration_id_ = 0; | 850 cdm_registration_id_ = 0; |
| 822 drm_bridge_ = NULL; | 851 drm_bridge_ = NULL; |
| 823 } | 852 } |
| 824 | 853 |
| 825 } // namespace media | 854 } // namespace media |
| OLD | NEW |