From cdf4e9937861975147cbc8dfe627909808bad068 Mon Sep 17 00:00:00 2001 From: Jean-Yves Avenard Date: Thu, 14 Jul 2016 21:37:04 +1000 Subject: [PATCH] Bug 1286810: [MSE] P1. Error on abort() during Range Removals. r=gerald As per https://github.com/w3c/media-source/issues/26 MozReview-Commit-ID: 1rNKVTBDjFY --- dom/media/mediasource/SourceBuffer.cpp | 18 +++++++++++++----- dom/media/mediasource/SourceBuffer.h | 1 + 2 files changed, 14 insertions(+), 5 deletions(-) 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;