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

Unified 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: Added unit tests that check A/V sync after preroll 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 side-by-side diff with in-line comments
Download patch
Index: media/base/android/media_codec_player.cc
diff --git a/media/base/android/media_codec_player.cc b/media/base/android/media_codec_player.cc
index e1b7562c4e2f29c940fd6cf776485a9e16426bdb..6be3db608281926df0e12fa3c320625809af4c9c 100644
--- a/media/base/android/media_codec_player.cc
+++ b/media/base/android/media_codec_player.cc
@@ -432,6 +432,8 @@ void MediaCodecPlayer::OnDemuxerSeekDone(
interpolator_.SetBounds(seek_time, seek_time);
audio_decoder_->SetBaseTimestamp(seek_time);
+ audio_decoder_->SetNeedsPreroll(true);
+ video_decoder_->SetNeedsPreroll(true);
// The Flush() might set the state to kStateError.
if (state_ == kStateError) {
@@ -482,6 +484,24 @@ void MediaCodecPlayer::OnDemuxerDurationChanged(
duration_ = duration;
}
+void MediaCodecPlayer::SetDecodersTimeCallbackForTests(
+ DecodersTimeCallback cb) {
+ DCHECK(ui_task_runner_->BelongsToCurrentThread());
+ decoders_time_cb_ = cb;
+}
+
+bool MediaCodecPlayer::IsPrerollingForTests(DemuxerStream::Type type) const {
+ DCHECK(ui_task_runner_->BelongsToCurrentThread());
+ DCHECK(audio_decoder_ && video_decoder_);
+
+ if (type == DemuxerStream::AUDIO)
+ return audio_decoder_->IsPrerollingForTests();
+ else if (type == DemuxerStream::VIDEO)
+ return video_decoder_->IsPrerollingForTests();
+ else
+ return false;
+}
+
// Events from Player, called on UI thread
void MediaCodecPlayer::OnMediaMetadataChanged(base::TimeDelta duration,
@@ -555,12 +575,31 @@ void MediaCodecPlayer::OnPrefetchDone() {
StartPlaybackOrBrowserSeek();
}
+void MediaCodecPlayer::OnPrerollDone() {
+ DCHECK(GetMediaTaskRunner()->BelongsToCurrentThread());
+ DVLOG(1) << __FUNCTION__;
+
+ if (!(audio_decoder_->IsPrerollDone() && video_decoder_->IsPrerollDone())) {
+ DVLOG(1) << __FUNCTION__ << " both audio and video needs to be done"
+ << " prerolling, ignoring";
+ return; // Wait until both streams are done prerolling.
+ }
+
+ if (!AudioFinished())
+ audio_decoder_->ResumeAfterPreroll();
+ if (!VideoFinished())
+ video_decoder_->ResumeAfterPreroll();
+}
+
void MediaCodecPlayer::OnStopDone() {
DCHECK(GetMediaTaskRunner()->BelongsToCurrentThread());
DVLOG(1) << __FUNCTION__;
- if (!(audio_decoder_->IsStopped() && video_decoder_->IsStopped()))
+ if (!(audio_decoder_->IsStopped() && video_decoder_->IsStopped())) {
+ DVLOG(1) << __FUNCTION__ << " both audio and video has to be stopped"
+ << ", ignoring";
return; // Wait until other stream is stopped
+ }
// At this point decoder threads should not be running
if (interpolator_.interpolating())
@@ -636,13 +675,22 @@ void MediaCodecPlayer::OnTimeIntervalUpdate(DemuxerStream::Type type,
DVLOG(2) << __FUNCTION__ << ": stream type:" << type << " [" << now_playing
<< "," << last_buffered << "]";
+ // For testing only: report time interval as we receive it from decoders
+ // as an indication of what is being rendered.
+ if (!decoders_time_cb_.is_null()) {
+ ui_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(decoders_time_cb_, type, now_playing, last_buffered));
+ }
+
// I assume that audio stream cannot be added after we get configs by
// OnDemuxerConfigsAvailable(), but that audio can finish early.
if (type == DemuxerStream::VIDEO) {
// Ignore video PTS if there is audio stream or if it's behind current
// time as set by audio stream.
- if (!AudioFinished() || now_playing < interpolator_.GetInterpolatedTime())
+ if (!AudioFinished() ||
+ (HasAudio() && now_playing < interpolator_.GetInterpolatedTime()))
return;
}
@@ -922,6 +970,7 @@ void MediaCodecPlayer::CreateDecoders() {
media_weak_this_, DemuxerStream::AUDIO),
base::Bind(&MediaCodecPlayer::OnStarvation, media_weak_this_,
DemuxerStream::AUDIO),
+ base::Bind(&MediaCodecPlayer::OnPrerollDone, media_weak_this_),
base::Bind(&MediaCodecPlayer::OnStopDone, media_weak_this_),
internal_error_cb_,
base::Bind(&MediaCodecPlayer::OnTimeIntervalUpdate, media_weak_this_,
@@ -932,6 +981,7 @@ void MediaCodecPlayer::CreateDecoders() {
media_weak_this_, DemuxerStream::VIDEO),
base::Bind(&MediaCodecPlayer::OnStarvation, media_weak_this_,
DemuxerStream::VIDEO),
+ base::Bind(&MediaCodecPlayer::OnPrerollDone, media_weak_this_),
base::Bind(&MediaCodecPlayer::OnStopDone, media_weak_this_),
internal_error_cb_,
base::Bind(&MediaCodecPlayer::OnTimeIntervalUpdate, media_weak_this_,

Powered by Google App Engine
This is Rietveld 408576698