diff --git a/dom/media/mediasource/TrackBuffersManager.cpp b/dom/media/mediasource/TrackBuffersManager.cpp index 3f8857199fd7..3c9c6c9cc0d2 100644 --- a/dom/media/mediasource/TrackBuffersManager.cpp +++ b/dom/media/mediasource/TrackBuffersManager.cpp @@ -104,6 +104,7 @@ TrackBuffersManager::TrackBuffersManager(dom::SourceBufferAttributes* aAttribute , mEvictionOccurred(false) , mMonitor("TrackBuffersManager") , mAppendRunning(false) + , mSegmentParserLoopRunning(false) { MOZ_ASSERT(NS_IsMainThread(), "Must be instanciated on the main thread"); } @@ -300,7 +301,7 @@ void TrackBuffersManager::CompleteResetParserState() { MOZ_ASSERT(OnTaskQueue()); - MOZ_DIAGNOSTIC_ASSERT(!mAppendRunning, "Append is running"); + MOZ_DIAGNOSTIC_ASSERT(!mSegmentParserLoopRunning); MSE_DEBUG(""); for (auto& track : GetTracksList()) { @@ -428,7 +429,6 @@ RefPtr TrackBuffersManager::CodedFrameRemovalWithPromise(TimeInterval aInterval) { MOZ_ASSERT(OnTaskQueue()); - MOZ_DIAGNOSTIC_ASSERT(!mAppendRunning, "Logic error: Append in progress"); bool rv = CodedFrameRemoval(aInterval); return RangeRemovalPromise::CreateAndResolve(rv, __func__); } @@ -437,6 +437,7 @@ bool TrackBuffersManager::CodedFrameRemoval(TimeInterval aInterval) { MOZ_ASSERT(OnTaskQueue()); + MOZ_ASSERT(!mSegmentParserLoopRunning, "Logic error: Append in progress"); MSE_DEBUG("From %.2fs to %.2f", aInterval.mStart.ToSeconds(), aInterval.mEnd.ToSeconds()); @@ -575,6 +576,8 @@ TrackBuffersManager::SegmentParserLoop() { MOZ_ASSERT(OnTaskQueue()); + mSegmentParserLoopRunning = true; + while (true) { // 1. If the input buffer is empty, then jump to the need more data step below. if (!mInputBuffer || mInputBuffer->IsEmpty()) { @@ -699,6 +702,7 @@ TrackBuffersManager::NeedMoreData() MSE_DEBUG(""); RestoreCachedVariables(); mAppendRunning = false; + mSegmentParserLoopRunning = false; { // Wake-up any pending Abort() MonitorAutoLock mon(mMonitor); @@ -712,6 +716,7 @@ TrackBuffersManager::RejectAppend(nsresult aRejectValue, const char* aName) { MSE_DEBUG("rv=%d", aRejectValue); mAppendRunning = false; + mSegmentParserLoopRunning = false; { // Wake-up any pending Abort() MonitorAutoLock mon(mMonitor); diff --git a/dom/media/mediasource/TrackBuffersManager.h b/dom/media/mediasource/TrackBuffersManager.h index 6188df4d5474..f150e0d49819 100644 --- a/dom/media/mediasource/TrackBuffersManager.h +++ b/dom/media/mediasource/TrackBuffersManager.h @@ -350,8 +350,11 @@ private: // Monitor to protect following objects accessed across multipple threads. // mMonitor is also notified if the value of mAppendRunning becomes false. mutable Monitor mMonitor; - // Set to true while a BufferAppend is running or is pending. + // Set to true while SegmentParserLoop is running. Atomic mAppendRunning; + // Set to true while SegmentParserLoop is running. + // This is for diagnostic only. Only accessed on the task queue. + bool mSegmentParserLoopRunning; // Stable audio and video track time ranges. media::TimeIntervals mVideoBufferedRanges; media::TimeIntervals mAudioBufferedRanges;