OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_codec_player.h" | 5 #include "media/base/android/media_codec_player.h" |
6 | 6 |
7 #include "base/barrier_closure.h" | 7 #include "base/barrier_closure.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 | 425 |
426 // Restrict the current time to be equal to seek_time | 426 // Restrict the current time to be equal to seek_time |
427 // for the next StartPlaybackDecoders() call. | 427 // for the next StartPlaybackDecoders() call. |
428 | 428 |
429 base::TimeDelta seek_time = seek_info_->is_browser_seek | 429 base::TimeDelta seek_time = seek_info_->is_browser_seek |
430 ? actual_browser_seek_time | 430 ? actual_browser_seek_time |
431 : seek_info_->seek_time; | 431 : seek_info_->seek_time; |
432 | 432 |
433 interpolator_.SetBounds(seek_time, seek_time); | 433 interpolator_.SetBounds(seek_time, seek_time); |
434 audio_decoder_->SetBaseTimestamp(seek_time); | 434 audio_decoder_->SetBaseTimestamp(seek_time); |
| 435 audio_decoder_->SetNeedsPreroll(true); |
| 436 video_decoder_->SetNeedsPreroll(true); |
435 | 437 |
436 // The Flush() might set the state to kStateError. | 438 // The Flush() might set the state to kStateError. |
437 if (state_ == kStateError) { | 439 if (state_ == kStateError) { |
438 // Notify the Renderer. | 440 // Notify the Renderer. |
439 if (!seek_info_->is_browser_seek) | 441 if (!seek_info_->is_browser_seek) |
440 ui_task_runner_->PostTask(FROM_HERE, | 442 ui_task_runner_->PostTask(FROM_HERE, |
441 base::Bind(seek_done_cb_, seek_time)); | 443 base::Bind(seek_done_cb_, seek_time)); |
442 | 444 |
443 seek_info_.reset(); | 445 seek_info_.reset(); |
444 return; | 446 return; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 | 550 |
549 if (HasVideo() && !video_decoder_->HasVideoSurface()) { | 551 if (HasVideo() && !video_decoder_->HasVideoSurface()) { |
550 SetState(kStateWaitingForSurface); | 552 SetState(kStateWaitingForSurface); |
551 return; | 553 return; |
552 } | 554 } |
553 | 555 |
554 SetState(kStatePlaying); | 556 SetState(kStatePlaying); |
555 StartPlaybackOrBrowserSeek(); | 557 StartPlaybackOrBrowserSeek(); |
556 } | 558 } |
557 | 559 |
| 560 void MediaCodecPlayer::OnPrerollDone() { |
| 561 DCHECK(GetMediaTaskRunner()->BelongsToCurrentThread()); |
| 562 DVLOG(1) << __FUNCTION__; |
| 563 |
| 564 if (!(audio_decoder_->IsPrerollDone() && video_decoder_->IsPrerollDone())) { |
| 565 DVLOG(1) << __FUNCTION__ << " both audio and video needs to be done" |
| 566 << " prerolling, ignoring"; |
| 567 return; // Wait until both streams are done prerolling. |
| 568 } |
| 569 |
| 570 if (!AudioFinished()) |
| 571 audio_decoder_->ResumeAfterPreroll(); |
| 572 if (!VideoFinished()) |
| 573 video_decoder_->ResumeAfterPreroll(); |
| 574 } |
| 575 |
558 void MediaCodecPlayer::OnStopDone() { | 576 void MediaCodecPlayer::OnStopDone() { |
559 DCHECK(GetMediaTaskRunner()->BelongsToCurrentThread()); | 577 DCHECK(GetMediaTaskRunner()->BelongsToCurrentThread()); |
560 DVLOG(1) << __FUNCTION__; | 578 DVLOG(1) << __FUNCTION__; |
561 | 579 |
562 if (!(audio_decoder_->IsStopped() && video_decoder_->IsStopped())) | 580 if (!(audio_decoder_->IsStopped() && video_decoder_->IsStopped())) { |
| 581 DVLOG(1) << __FUNCTION__ << " both audio and video has to be stopped" |
| 582 << ", ignoring"; |
563 return; // Wait until other stream is stopped | 583 return; // Wait until other stream is stopped |
| 584 } |
564 | 585 |
565 // At this point decoder threads should not be running | 586 // At this point decoder threads should not be running |
566 if (interpolator_.interpolating()) | 587 if (interpolator_.interpolating()) |
567 interpolator_.StopInterpolating(); | 588 interpolator_.StopInterpolating(); |
568 | 589 |
569 base::TimeDelta seek_time; | 590 base::TimeDelta seek_time; |
570 switch (state_) { | 591 switch (state_) { |
571 case kStateStopping: { | 592 case kStateStopping: { |
572 base::TimeDelta seek_time = GetPendingSeek(); | 593 base::TimeDelta seek_time = GetPendingSeek(); |
573 if (seek_time != kNoTimestamp()) { | 594 if (seek_time != kNoTimestamp()) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 | 656 |
636 DVLOG(2) << __FUNCTION__ << ": stream type:" << type << " [" << now_playing | 657 DVLOG(2) << __FUNCTION__ << ": stream type:" << type << " [" << now_playing |
637 << "," << last_buffered << "]"; | 658 << "," << last_buffered << "]"; |
638 | 659 |
639 // I assume that audio stream cannot be added after we get configs by | 660 // I assume that audio stream cannot be added after we get configs by |
640 // OnDemuxerConfigsAvailable(), but that audio can finish early. | 661 // OnDemuxerConfigsAvailable(), but that audio can finish early. |
641 | 662 |
642 if (type == DemuxerStream::VIDEO) { | 663 if (type == DemuxerStream::VIDEO) { |
643 // Ignore video PTS if there is audio stream or if it's behind current | 664 // Ignore video PTS if there is audio stream or if it's behind current |
644 // time as set by audio stream. | 665 // time as set by audio stream. |
645 if (!AudioFinished() || now_playing < interpolator_.GetInterpolatedTime()) | 666 if (!AudioFinished() || |
| 667 (HasAudio() && now_playing < interpolator_.GetInterpolatedTime())) |
646 return; | 668 return; |
647 } | 669 } |
648 | 670 |
649 interpolator_.SetBounds(now_playing, last_buffered); | 671 interpolator_.SetBounds(now_playing, last_buffered); |
650 | 672 |
651 // Post to UI thread | 673 // Post to UI thread |
652 ui_task_runner_->PostTask(FROM_HERE, | 674 ui_task_runner_->PostTask(FROM_HERE, |
653 base::Bind(time_update_cb_, GetInterpolatedTime(), | 675 base::Bind(time_update_cb_, GetInterpolatedTime(), |
654 base::TimeTicks::Now())); | 676 base::TimeTicks::Now())); |
655 } | 677 } |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
915 DCHECK(GetMediaTaskRunner()->BelongsToCurrentThread()); | 937 DCHECK(GetMediaTaskRunner()->BelongsToCurrentThread()); |
916 DVLOG(1) << __FUNCTION__; | 938 DVLOG(1) << __FUNCTION__; |
917 | 939 |
918 internal_error_cb_ = base::Bind(&MediaCodecPlayer::OnError, media_weak_this_); | 940 internal_error_cb_ = base::Bind(&MediaCodecPlayer::OnError, media_weak_this_); |
919 | 941 |
920 audio_decoder_.reset(new MediaCodecAudioDecoder( | 942 audio_decoder_.reset(new MediaCodecAudioDecoder( |
921 GetMediaTaskRunner(), base::Bind(&MediaCodecPlayer::RequestDemuxerData, | 943 GetMediaTaskRunner(), base::Bind(&MediaCodecPlayer::RequestDemuxerData, |
922 media_weak_this_, DemuxerStream::AUDIO), | 944 media_weak_this_, DemuxerStream::AUDIO), |
923 base::Bind(&MediaCodecPlayer::OnStarvation, media_weak_this_, | 945 base::Bind(&MediaCodecPlayer::OnStarvation, media_weak_this_, |
924 DemuxerStream::AUDIO), | 946 DemuxerStream::AUDIO), |
| 947 base::Bind(&MediaCodecPlayer::OnPrerollDone, media_weak_this_), |
925 base::Bind(&MediaCodecPlayer::OnStopDone, media_weak_this_), | 948 base::Bind(&MediaCodecPlayer::OnStopDone, media_weak_this_), |
926 internal_error_cb_, | 949 internal_error_cb_, |
927 base::Bind(&MediaCodecPlayer::OnTimeIntervalUpdate, media_weak_this_, | 950 base::Bind(&MediaCodecPlayer::OnTimeIntervalUpdate, media_weak_this_, |
928 DemuxerStream::AUDIO))); | 951 DemuxerStream::AUDIO))); |
929 | 952 |
930 video_decoder_.reset(new MediaCodecVideoDecoder( | 953 video_decoder_.reset(new MediaCodecVideoDecoder( |
931 GetMediaTaskRunner(), base::Bind(&MediaCodecPlayer::RequestDemuxerData, | 954 GetMediaTaskRunner(), base::Bind(&MediaCodecPlayer::RequestDemuxerData, |
932 media_weak_this_, DemuxerStream::VIDEO), | 955 media_weak_this_, DemuxerStream::VIDEO), |
933 base::Bind(&MediaCodecPlayer::OnStarvation, media_weak_this_, | 956 base::Bind(&MediaCodecPlayer::OnStarvation, media_weak_this_, |
934 DemuxerStream::VIDEO), | 957 DemuxerStream::VIDEO), |
| 958 base::Bind(&MediaCodecPlayer::OnPrerollDone, media_weak_this_), |
935 base::Bind(&MediaCodecPlayer::OnStopDone, media_weak_this_), | 959 base::Bind(&MediaCodecPlayer::OnStopDone, media_weak_this_), |
936 internal_error_cb_, | 960 internal_error_cb_, |
937 base::Bind(&MediaCodecPlayer::OnTimeIntervalUpdate, media_weak_this_, | 961 base::Bind(&MediaCodecPlayer::OnTimeIntervalUpdate, media_weak_this_, |
938 DemuxerStream::VIDEO), | 962 DemuxerStream::VIDEO), |
939 base::Bind(&MediaCodecPlayer::OnVideoResolutionChanged, media_weak_this_), | 963 base::Bind(&MediaCodecPlayer::OnVideoResolutionChanged, media_weak_this_), |
940 base::Bind(&MediaCodecPlayer::OnVideoCodecCreated, media_weak_this_))); | 964 base::Bind(&MediaCodecPlayer::OnVideoCodecCreated, media_weak_this_))); |
941 } | 965 } |
942 | 966 |
943 bool MediaCodecPlayer::AudioFinished() const { | 967 bool MediaCodecPlayer::AudioFinished() const { |
944 return audio_decoder_->IsCompleted() || !audio_decoder_->HasStream(); | 968 return audio_decoder_->IsCompleted() || !audio_decoder_->HasStream(); |
(...skipping 25 matching lines...) Expand all Loading... |
970 RETURN_STRING(kStateWaitingForSurface); | 994 RETURN_STRING(kStateWaitingForSurface); |
971 RETURN_STRING(kStateWaitingForSeek); | 995 RETURN_STRING(kStateWaitingForSeek); |
972 RETURN_STRING(kStateError); | 996 RETURN_STRING(kStateError); |
973 } | 997 } |
974 return nullptr; // crash early | 998 return nullptr; // crash early |
975 } | 999 } |
976 | 1000 |
977 #undef RETURN_STRING | 1001 #undef RETURN_STRING |
978 | 1002 |
979 } // namespace media | 1003 } // namespace media |
OLD | NEW |