From b3e7a4b2a3230df5f00bc051216da509b28fc21a Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Sat, 6 Jun 2015 15:00:36 -0700 Subject: [PATCH] Bug 1163223 - Use AwaitStartTime to invoke MediaDecoderReader::SetStartTime. r=jww --- dom/media/MediaDecoderReader.cpp | 1 + dom/media/MediaDecoderReader.h | 8 +++++++- dom/media/MediaDecoderStateMachine.cpp | 13 +++++++++---- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/dom/media/MediaDecoderReader.cpp b/dom/media/MediaDecoderReader.cpp index 533237eafb6d..44e30512509a 100644 --- a/dom/media/MediaDecoderReader.cpp +++ b/dom/media/MediaDecoderReader.cpp @@ -148,6 +148,7 @@ void MediaDecoderReader::SetStartTime(int64_t aStartTime) { mDecoder->GetReentrantMonitor().AssertCurrentThreadIn(); + MOZ_ASSERT(mStartTime == -1); mStartTime = aStartTime; } diff --git a/dom/media/MediaDecoderReader.h b/dom/media/MediaDecoderReader.h index 185bdae7cded..8513ed6d4788 100644 --- a/dom/media/MediaDecoderReader.h +++ b/dom/media/MediaDecoderReader.h @@ -328,7 +328,13 @@ protected: // The start time of the media, in microseconds. This is the presentation // time of the first frame decoded from the media. This is initialized to -1, // and then set to a value >= by MediaDecoderStateMachine::SetStartTime(), - // after which point it never changes. + // after which point it never changes (though SetStartTime may be called + // multiple times with the same value). + // + // This is an ugly breach of abstractions - it's currently necessary for the + // readers to return the correct value of GetBuffered. We should refactor + // things such that all GetBuffered calls go through the MDSM, which would + // offset the range accordingly. int64_t mStartTime; // This is a quick-and-dirty way for DecodeAudioData implementations to diff --git a/dom/media/MediaDecoderStateMachine.cpp b/dom/media/MediaDecoderStateMachine.cpp index 0a12972b28b9..f2b51fccde78 100644 --- a/dom/media/MediaDecoderStateMachine.cpp +++ b/dom/media/MediaDecoderStateMachine.cpp @@ -2177,6 +2177,15 @@ MediaDecoderStateMachine::OnMetadataRead(MetadataHolder* aMetadata) if (!mStartTimeRendezvous) { mStartTimeRendezvous = new StartTimeRendezvous(TaskQueue(), HasAudio(), HasVideo(), mReader->ForceZeroStartTime() || IsRealTime()); + + mStartTimeRendezvous->AwaitStartTime()->Then(TaskQueue(), __func__, + [self] () -> void { + NS_ENSURE_TRUE_VOID(!self->IsShutdown()); + ReentrantMonitorAutoEnter mon(self->mDecoder->GetReentrantMonitor()); + self->mReader->SetStartTime(self->StartTime()); + }, + [] () -> void { NS_WARNING("Setting start time on reader failed"); } + ); } if (mInfo.mMetadataDuration.isSome()) { @@ -3176,10 +3185,6 @@ void MediaDecoderStateMachine::SetStartTime(int64_t aStartTimeUsecs) } } - // Pass along this immutable value to the reader so that it can make - // calculations independently of the state machine. - mReader->SetStartTime(mStartTime); - // Set the audio start time to be start of media. If this lies before the // first actual audio frame we have, we'll inject silence during playback // to ensure the audio starts at the correct time.