Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Side by Side Diff: media/base/android/media_codec_player.cc

Issue 1254293003: MediaCodecPlayer implementation (stage 4 - preroll) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mtplayer-browserseek
Patch Set: Removed unused var, fixed unit test compilation Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 414
415 // Restrict the current time to be equal to seek_time 415 // Restrict the current time to be equal to seek_time
416 // for the next StartPlaybackDecoders() call. 416 // for the next StartPlaybackDecoders() call.
417 417
418 base::TimeDelta seek_time = seek_info_->is_browser_seek 418 base::TimeDelta seek_time = seek_info_->is_browser_seek
419 ? actual_browser_seek_time 419 ? actual_browser_seek_time
420 : seek_info_->seek_time; 420 : seek_info_->seek_time;
421 421
422 interpolator_.SetBounds(seek_time, seek_time); 422 interpolator_.SetBounds(seek_time, seek_time);
423 audio_decoder_->SetBaseTimestamp(seek_time); 423 audio_decoder_->SetBaseTimestamp(seek_time);
424 audio_decoder_->SetPrerollTimestamp(seek_time);
425 video_decoder_->SetPrerollTimestamp(seek_time);
424 426
425 base::TimeDelta pending_seek_time = GetPendingSeek(); 427 base::TimeDelta pending_seek_time = GetPendingSeek();
426 if (pending_seek_time != kNoTimestamp()) { 428 if (pending_seek_time != kNoTimestamp()) {
427 // Keep STATE_WAITING_FOR_SEEK 429 // Keep STATE_WAITING_FOR_SEEK
428 SetPendingSeek(kNoTimestamp()); 430 SetPendingSeek(kNoTimestamp());
429 RequestDemuxerSeek(pending_seek_time); 431 RequestDemuxerSeek(pending_seek_time);
430 return; 432 return;
431 } 433 }
432 434
433 if (HasPendingStart()) { 435 if (HasPendingStart()) {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 525
524 if (HasVideo() && !video_decoder_->HasVideoSurface()) { 526 if (HasVideo() && !video_decoder_->HasVideoSurface()) {
525 SetState(STATE_WAITING_FOR_SURFACE); 527 SetState(STATE_WAITING_FOR_SURFACE);
526 return; 528 return;
527 } 529 }
528 530
529 SetState(STATE_PLAYING); 531 SetState(STATE_PLAYING);
530 StartPlaybackOrBrowserSeek(); 532 StartPlaybackOrBrowserSeek();
531 } 533 }
532 534
535 void MediaCodecPlayer::OnPrerollDone() {
536 DCHECK(GetMediaTaskRunner()->BelongsToCurrentThread());
537 DVLOG(1) << __FUNCTION__;
538
539 if (!(audio_decoder_->IsPrerollDone() && video_decoder_->IsPrerollDone())) {
540 DVLOG(1) << __FUNCTION__ << " both audio and video needs to be done"
541 << " prerolling, ignoring";
542 return; // Wait until both streams are done prerolling.
543 }
544
545 if (!AudioFinished())
546 audio_decoder_->ResumeAfterPreroll();
547 if (!VideoFinished())
548 video_decoder_->ResumeAfterPreroll();
549 }
550
533 void MediaCodecPlayer::OnStopDone() { 551 void MediaCodecPlayer::OnStopDone() {
534 DCHECK(GetMediaTaskRunner()->BelongsToCurrentThread()); 552 DCHECK(GetMediaTaskRunner()->BelongsToCurrentThread());
535 DVLOG(1) << __FUNCTION__; 553 DVLOG(1) << __FUNCTION__;
536 554
537 if (!(audio_decoder_->IsStopped() && video_decoder_->IsStopped())) 555 if (!(audio_decoder_->IsStopped() && video_decoder_->IsStopped())) {
556 DVLOG(1) << __FUNCTION__ << " both audio and video has to be stopped"
557 << ", ignoring";
538 return; // Wait until other stream is stopped 558 return; // Wait until other stream is stopped
559 }
539 560
540 // At this point decoder threads should not be running 561 // At this point decoder threads should not be running
541 if (interpolator_.interpolating()) 562 if (interpolator_.interpolating())
542 interpolator_.StopInterpolating(); 563 interpolator_.StopInterpolating();
543 564
544 base::TimeDelta seek_time; 565 base::TimeDelta seek_time;
545 switch (state_) { 566 switch (state_) {
546 case STATE_STOPPING: { 567 case STATE_STOPPING: {
547 base::TimeDelta seek_time = GetPendingSeek(); 568 base::TimeDelta seek_time = GetPendingSeek();
548 if (seek_time != kNoTimestamp()) { 569 if (seek_time != kNoTimestamp()) {
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 DCHECK(GetMediaTaskRunner()->BelongsToCurrentThread()); 911 DCHECK(GetMediaTaskRunner()->BelongsToCurrentThread());
891 DVLOG(1) << __FUNCTION__; 912 DVLOG(1) << __FUNCTION__;
892 913
893 internal_error_cb_ = base::Bind(&MediaCodecPlayer::OnError, media_weak_this_); 914 internal_error_cb_ = base::Bind(&MediaCodecPlayer::OnError, media_weak_this_);
894 915
895 audio_decoder_.reset(new MediaCodecAudioDecoder( 916 audio_decoder_.reset(new MediaCodecAudioDecoder(
896 GetMediaTaskRunner(), base::Bind(&MediaCodecPlayer::RequestDemuxerData, 917 GetMediaTaskRunner(), base::Bind(&MediaCodecPlayer::RequestDemuxerData,
897 media_weak_this_, DemuxerStream::AUDIO), 918 media_weak_this_, DemuxerStream::AUDIO),
898 base::Bind(&MediaCodecPlayer::OnStarvation, media_weak_this_, 919 base::Bind(&MediaCodecPlayer::OnStarvation, media_weak_this_,
899 DemuxerStream::AUDIO), 920 DemuxerStream::AUDIO),
921 base::Bind(&MediaCodecPlayer::OnPrerollDone, media_weak_this_),
900 base::Bind(&MediaCodecPlayer::OnStopDone, media_weak_this_), 922 base::Bind(&MediaCodecPlayer::OnStopDone, media_weak_this_),
901 internal_error_cb_, 923 internal_error_cb_,
902 base::Bind(&MediaCodecPlayer::OnTimeIntervalUpdate, media_weak_this_, 924 base::Bind(&MediaCodecPlayer::OnTimeIntervalUpdate, media_weak_this_,
903 DemuxerStream::AUDIO))); 925 DemuxerStream::AUDIO)));
904 926
905 video_decoder_.reset(new MediaCodecVideoDecoder( 927 video_decoder_.reset(new MediaCodecVideoDecoder(
906 GetMediaTaskRunner(), base::Bind(&MediaCodecPlayer::RequestDemuxerData, 928 GetMediaTaskRunner(), base::Bind(&MediaCodecPlayer::RequestDemuxerData,
907 media_weak_this_, DemuxerStream::VIDEO), 929 media_weak_this_, DemuxerStream::VIDEO),
908 base::Bind(&MediaCodecPlayer::OnStarvation, media_weak_this_, 930 base::Bind(&MediaCodecPlayer::OnStarvation, media_weak_this_,
909 DemuxerStream::VIDEO), 931 DemuxerStream::VIDEO),
932 base::Bind(&MediaCodecPlayer::OnPrerollDone, media_weak_this_),
910 base::Bind(&MediaCodecPlayer::OnStopDone, media_weak_this_), 933 base::Bind(&MediaCodecPlayer::OnStopDone, media_weak_this_),
911 internal_error_cb_, 934 internal_error_cb_,
912 base::Bind(&MediaCodecPlayer::OnTimeIntervalUpdate, media_weak_this_, 935 base::Bind(&MediaCodecPlayer::OnTimeIntervalUpdate, media_weak_this_,
913 DemuxerStream::VIDEO), 936 DemuxerStream::VIDEO),
914 base::Bind(&MediaCodecPlayer::OnVideoResolutionChanged, media_weak_this_), 937 base::Bind(&MediaCodecPlayer::OnVideoResolutionChanged, media_weak_this_),
915 base::Bind(&MediaCodecPlayer::OnVideoCodecCreated, media_weak_this_))); 938 base::Bind(&MediaCodecPlayer::OnVideoCodecCreated, media_weak_this_)));
916 } 939 }
917 940
918 bool MediaCodecPlayer::AudioFinished() const { 941 bool MediaCodecPlayer::AudioFinished() const {
919 return audio_decoder_->IsCompleted() || !audio_decoder_->HasStream(); 942 return audio_decoder_->IsCompleted() || !audio_decoder_->HasStream();
(...skipping 25 matching lines...) Expand all
945 RETURN_STRING(STATE_WAITING_FOR_SURFACE); 968 RETURN_STRING(STATE_WAITING_FOR_SURFACE);
946 RETURN_STRING(STATE_WAITING_FOR_SEEK); 969 RETURN_STRING(STATE_WAITING_FOR_SEEK);
947 RETURN_STRING(STATE_ERROR); 970 RETURN_STRING(STATE_ERROR);
948 } 971 }
949 return nullptr; // crash early 972 return nullptr; // crash early
950 } 973 }
951 974
952 #undef RETURN_STRING 975 #undef RETURN_STRING
953 976
954 } // namespace media 977 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698