diff options
Diffstat (limited to 'dom/media/mediasource/SourceBuffer.cpp')
-rw-r--r-- | dom/media/mediasource/SourceBuffer.cpp | 74 |
1 files changed, 18 insertions, 56 deletions
diff --git a/dom/media/mediasource/SourceBuffer.cpp b/dom/media/mediasource/SourceBuffer.cpp index 30b98c0b4..5c063db03 100644 --- a/dom/media/mediasource/SourceBuffer.cpp +++ b/dom/media/mediasource/SourceBuffer.cpp @@ -43,27 +43,6 @@ namespace mozilla { namespace dom { -class BufferAppendRunnable : public nsRunnable { -public: - BufferAppendRunnable(SourceBuffer* aSourceBuffer, - uint32_t aUpdateID) - : mSourceBuffer(aSourceBuffer) - , mUpdateID(aUpdateID) - { - } - - NS_IMETHOD Run() override final { - - mSourceBuffer->BufferAppend(mUpdateID); - - return NS_OK; - } - -private: - nsRefPtr<SourceBuffer> mSourceBuffer; - uint32_t mUpdateID; -}; - void SourceBuffer::SetMode(SourceBufferAppendMode aMode, ErrorResult& aRv) { @@ -219,10 +198,13 @@ void SourceBuffer::AbortBufferAppend() { if (mUpdating) { - mPendingAppend.DisconnectIfExists(); - // TODO: Abort stream append loop algorithms. - // cancel any pending buffer append. - mContentManager->AbortAppendData(); + if (mPendingAppend.Exists()) { + mPendingAppend.Disconnect(); + mContentManager->AbortAppendData(); + // Some data may have been added by the Segment Parser Loop. + // Check if we need to update the duration. + CheckEndTime(); + } AbortUpdating(); } } @@ -303,7 +285,6 @@ SourceBuffer::SourceBuffer(MediaSource* aMediaSource, const nsACString& aType) , mMediaSource(aMediaSource) , mUpdating(false) , mActive(false) - , mUpdateID(0) , mReportedOffset(0) , mType(aType) { @@ -380,7 +361,6 @@ SourceBuffer::StartUpdating() MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(!mUpdating); mUpdating = true; - mUpdateID++; QueueAsyncSimpleEvent("updatestart"); } @@ -389,12 +369,8 @@ SourceBuffer::StopUpdating() { MOZ_ASSERT(NS_IsMainThread()); if (!mUpdating) { - // The buffer append algorithm has been interrupted by abort(). - // - // If the sequence appendBuffer(), abort(), appendBuffer() occurs before - // the first StopUpdating() runnable runs, then a second StopUpdating() - // runnable will be scheduled, but still only one (the first) will queue - // events. + // The buffer append or range removal algorithm has been interrupted by + // abort(). return; } mUpdating = false; @@ -406,7 +382,6 @@ void SourceBuffer::AbortUpdating() { MOZ_ASSERT(NS_IsMainThread()); - MOZ_ASSERT(mUpdating); mUpdating = false; QueueAsyncSimpleEvent("abort"); QueueAsyncSimpleEvent("updateend"); @@ -440,23 +415,14 @@ SourceBuffer::AppendData(const uint8_t* aData, uint32_t aLength, ErrorResult& aR MOZ_ASSERT(mIsUsingFormatReader || mAttributes->GetAppendMode() == SourceBufferAppendMode::Segments, "We don't handle timestampOffset for sequence mode yet"); - nsRefPtr<nsIRunnable> task = new BufferAppendRunnable(this, mUpdateID); - NS_DispatchToMainThread(task); + + BufferAppend(); } void -SourceBuffer::BufferAppend(uint32_t aUpdateID) -{ - if (!mUpdating || aUpdateID != mUpdateID) { - // The buffer append algorithm has been interrupted by abort(). - // - // If the sequence appendBuffer(), abort(), appendBuffer() occurs before - // the first StopUpdating() runnable runs, then a second StopUpdating() - // runnable will be scheduled, but still only one (the first) will queue - // events. - return; - } - +SourceBuffer::BufferAppend() +{ + MOZ_ASSERT(mUpdating); MOZ_ASSERT(mMediaSource); MOZ_ASSERT(!mPendingAppend.Exists()); @@ -469,11 +435,8 @@ SourceBuffer::BufferAppend(uint32_t aUpdateID) void SourceBuffer::AppendDataCompletedWithSuccess(bool aHasActiveTracks) { + MOZ_ASSERT(mUpdating); mPendingAppend.Complete(); - if (!mUpdating) { - // The buffer append algorithm has been interrupted by abort(). - return; - } if (aHasActiveTracks) { if (!mActive) { @@ -502,7 +465,9 @@ SourceBuffer::AppendDataCompletedWithSuccess(bool aHasActiveTracks) void SourceBuffer::AppendDataErrored(nsresult aError) { + MOZ_ASSERT(mUpdating); mPendingAppend.Complete(); + switch (aError) { case NS_ERROR_ABORT: // Nothing further to do as the trackbuffer has been shutdown. @@ -518,10 +483,7 @@ void SourceBuffer::AppendError(bool aDecoderError) { MOZ_ASSERT(NS_IsMainThread()); - if (!mUpdating) { - // The buffer append algorithm has been interrupted by abort(). - return; - } + mContentManager->ResetParserState(); mUpdating = false; |