diff --git a/dom/media/DecodedStream.cpp b/dom/media/DecodedStream.cpp index 0430c23c6054..dcc950228f72 100644 --- a/dom/media/DecodedStream.cpp +++ b/dom/media/DecodedStream.cpp @@ -628,13 +628,18 @@ DecodedStream::SendData(double aVolume, bool aIsSameOrigin) return finished; } -CheckedInt64 +int64_t DecodedStream::AudioEndTime() const { ReentrantMonitorAutoEnter mon(GetReentrantMonitor()); - MOZ_ASSERT(mStartTime.isSome(), "Must be called after StartPlayback()"); - return mStartTime.ref() + - FramesToUsecs(mData->mAudioFramesWritten, mInfo.mAudio.mRate); + if (mStartTime.isSome() && mInfo.HasAudio()) { + CheckedInt64 t = mStartTime.ref() + + FramesToUsecs(mData->mAudioFramesWritten, mInfo.mAudio.mRate); + if (t.isValid()) { + return t.value(); + } + } + return -1; } int64_t diff --git a/dom/media/DecodedStream.h b/dom/media/DecodedStream.h index edba87cebc37..8b25b95c9f7d 100644 --- a/dom/media/DecodedStream.h +++ b/dom/media/DecodedStream.h @@ -111,7 +111,7 @@ public: void Connect(ProcessedMediaStream* aStream, bool aFinishWhenEnded); void Remove(MediaStream* aStream); void SetPlaying(bool aPlaying); - CheckedInt64 AudioEndTime() const; + int64_t AudioEndTime() const; int64_t GetPosition() const; bool IsFinished() const; diff --git a/dom/media/MediaDecoderStateMachine.cpp b/dom/media/MediaDecoderStateMachine.cpp index d4f2fc432e11..b66849879b22 100644 --- a/dom/media/MediaDecoderStateMachine.cpp +++ b/dom/media/MediaDecoderStateMachine.cpp @@ -372,13 +372,6 @@ void MediaDecoderStateMachine::SendStreamData() bool finished = mDecodedStream->SendData(mVolume, mDecoder->IsSameOriginMedia()); - if (mInfo.HasAudio()) { - CheckedInt64 playedUsecs = mDecodedStream->AudioEndTime(); - if (playedUsecs.isValid()) { - OnAudioEndTimeUpdate(playedUsecs.value()); - } - } - const auto clockTime = GetClock(); while (true) { const AudioData* a = AudioQueue().PeekFront(); @@ -3080,11 +3073,14 @@ MediaDecoderStateMachine::AudioEndTime() const AssertCurrentThreadInMonitor(); if (mAudioSink) { return mAudioSink->GetEndTime(); + } else if (mAudioCaptured) { + return mDecodedStream->AudioEndTime(); } // Don't call this after mAudioSink becomes null since we can't distinguish - // "before StartAudioThread" and "after StopAudioThread". - MOZ_ASSERT(mAudioCaptured || !mAudioCompleted); - return mAudioEndTime; + // "before StartAudioThread" and "after StopAudioThread" where mAudioSink + // is null in both cases. + MOZ_ASSERT(!mAudioCompleted); + return -1; } void MediaDecoderStateMachine::OnAudioEndTimeUpdate(int64_t aAudioEndTime)