diff --git a/dom/media/mediasource/SourceBuffer.cpp b/dom/media/mediasource/SourceBuffer.cpp index 771435c34b27..b5a27af04c30 100644 --- a/dom/media/mediasource/SourceBuffer.cpp +++ b/dom/media/mediasource/SourceBuffer.cpp @@ -192,6 +192,10 @@ SourceBuffer::Abort(ErrorResult& aRv) aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); return; } + if (mPendingRemoval.Exists()) { + aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); + return; + } AbortBufferAppend(); ResetParserState(); mCurrentAttributes.SetAppendWindowStart(0); @@ -248,11 +252,15 @@ SourceBuffer::RangeRemoval(double aStart, double aEnd) StartUpdating(); RefPtr self = this; - mTrackBuffersManager->RangeRemoval(TimeUnit::FromSeconds(aStart), - TimeUnit::FromSeconds(aEnd)) - ->Then(AbstractThread::MainThread(), __func__, - [self] (bool) { self->StopUpdating(); }, - []() { MOZ_ASSERT(false); }); + mPendingRemoval.Begin( + mTrackBuffersManager->RangeRemoval(TimeUnit::FromSeconds(aStart), + TimeUnit::FromSeconds(aEnd)) + ->Then(AbstractThread::MainThread(), __func__, + [self] (bool) { + self->mPendingRemoval.Complete(); + self->StopUpdating(); + }, + []() { MOZ_ASSERT(false); })); } void diff --git a/dom/media/mediasource/SourceBuffer.h b/dom/media/mediasource/SourceBuffer.h index 429998776e93..1e0bb0773d63 100644 --- a/dom/media/mediasource/SourceBuffer.h +++ b/dom/media/mediasource/SourceBuffer.h @@ -174,6 +174,7 @@ private: mozilla::Atomic mActive; MozPromiseRequestHolder mPendingAppend; + MozPromiseRequestHolder mPendingRemoval; const nsCString mType; RefPtr mBuffered;