From 29636604453544deb2ffa8ca26e603c48cc9d10c Mon Sep 17 00:00:00 2001 From: Sebastian Hengst Date: Tue, 17 May 2016 09:50:29 +0200 Subject: [PATCH] Backed out changeset 14b8c2f4764f (bug 1264694) --- dom/media/mediasource/TrackBuffersManager.cpp | 38 +++++++++++++++++++ dom/media/mediasource/TrackBuffersManager.h | 5 +-- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/dom/media/mediasource/TrackBuffersManager.cpp b/dom/media/mediasource/TrackBuffersManager.cpp index a0b251e04291..8353d6af8a0c 100644 --- a/dom/media/mediasource/TrackBuffersManager.cpp +++ b/dom/media/mediasource/TrackBuffersManager.cpp @@ -111,6 +111,7 @@ TrackBuffersManager::TrackBuffersManager(MediaSourceDecoder* aParentDecoder, TrackBuffersManager::~TrackBuffersManager() { + CancelAllTasks(); ShutdownDemuxers(); } @@ -203,6 +204,43 @@ TrackBuffersManager::ProcessTasks() GetTaskQueue()->Dispatch(NewRunnableMethod(this, &TrackBuffersManager::ProcessTasks)); } +// A PromiseHolder will assert upon destruction if it has a pending promise +// that hasn't been completed. It is possible that a task didn't get processed +// due to the owning SourceBuffer having shutdown. +// We resolve/reject all pending promises and remove all pending tasks from the +// queue. +void +TrackBuffersManager::CancelAllTasks() +{ + typedef SourceBufferTask::Type Type; + + if (mCurrentTask) { + mQueue.Push(mCurrentTask); + mCurrentTask = nullptr; + } + + RefPtr task; + while ((task = mQueue.Pop())) { + switch (task->GetType()) { + case Type::AppendBuffer: + task->As()->mPromise.RejectIfExists(NS_ERROR_ABORT, __func__); + break; + case Type::RangeRemoval: + task->As()->mPromise.ResolveIfExists(false, __func__); + break; + case Type::EvictData: + break; + case Type::Abort: + // not handled yet, and probably never. + break; + case Type::Reset: + break; + default: + NS_WARNING("Invalid Task"); + } + } +} + // The MSE spec requires that we abort the current SegmentParserLoop // which is then followed by a call to ResetParserState. // However due to our asynchronous design this causes inherent difficulties. diff --git a/dom/media/mediasource/TrackBuffersManager.h b/dom/media/mediasource/TrackBuffersManager.h index 3ab7f3c459ca..fa5194f9fc60 100644 --- a/dom/media/mediasource/TrackBuffersManager.h +++ b/dom/media/mediasource/TrackBuffersManager.h @@ -35,10 +35,6 @@ public: SourceBufferTaskQueue() : mMonitor("SourceBufferTaskQueue") {} - ~SourceBufferTaskQueue() - { - MOZ_ASSERT(mQueue.IsEmpty(), "All tasks must have been processed"); - } void Push(SourceBufferTask* aTask) { @@ -383,6 +379,7 @@ private: // SourceBuffer Queues and running context. SourceBufferTaskQueue mQueue; void ProcessTasks(); + void CancelAllTasks(); // Set if the TrackBuffersManager is currently processing a task. // At this stage, this task is always a AppendBufferTask. RefPtr mCurrentTask;