diff --git a/dom/media/mediasource/TrackBuffersManager.cpp b/dom/media/mediasource/TrackBuffersManager.cpp index 63c955be21fe..63608f755304 100644 --- a/dom/media/mediasource/TrackBuffersManager.cpp +++ b/dom/media/mediasource/TrackBuffersManager.cpp @@ -103,7 +103,7 @@ TrackBuffersManager::TrackBuffersManager(MediaSourceDecoder* aParentDecoder, 100 * 1024 * 1024)) , mAudioEvictionThreshold(Preferences::GetUint("media.mediasource.eviction_threshold.audio", 30 * 1024 * 1024)) - , mEvictionOccurred(false) + , mEvictionState(EvictionState::NO_EVICTION_NEEDED) , mMonitor("TrackBuffersManager") { MOZ_ASSERT(NS_IsMainThread(), "Must be instanciated on the main thread"); @@ -278,19 +278,23 @@ TrackBuffersManager::EvictData(const TimeUnit& aPlaybackTime, int64_t aSize) GetSize() / 1024, EvictionThreshold() / 1024, toEvict / 1024); if (toEvict <= 0) { + mEvictionState = EvictionState::NO_EVICTION_NEEDED; return EvictDataResult::NO_DATA_EVICTED; } if (toEvict <= 512*1024) { // Don't bother evicting less than 512KB. + mEvictionState = EvictionState::NO_EVICTION_NEEDED; return EvictDataResult::CANT_EVICT; } - if (mBufferFull && mEvictionOccurred) { + if (mBufferFull && mEvictionState == EvictionState::EVICTION_COMPLETED) { return EvictDataResult::BUFFER_FULL; } MSE_DEBUG("Reaching our size limit, schedule eviction of %lld bytes", toEvict); + mEvictionState = EvictionState::EVICTION_NEEDED; + QueueTask(new EvictDataTask(aPlaybackTime, toEvict)); return EvictDataResult::NO_DATA_EVICTED; @@ -411,6 +415,8 @@ TrackBuffersManager::DoEvictData(const TimeUnit& aPlaybackTime, { MOZ_ASSERT(OnTaskQueue()); + mEvictionState = EvictionState::EVICTION_COMPLETED; + // Video is what takes the most space, only evict there if we have video. const auto& track = HasVideo() ? mVideoTracks : mAudioTracks; const auto& buffer = track.mBuffers.LastElement(); @@ -563,7 +569,6 @@ TrackBuffersManager::CodedFrameRemoval(TimeInterval aInterval) if (mBufferFull && mSizeSourceBuffer < EvictionThreshold()) { mBufferFull = false; } - mEvictionOccurred = true; return dataRemoved; } @@ -1269,7 +1274,6 @@ TrackBuffersManager::CompleteCodedFrameProcessing() // 4. If this SourceBuffer is full and cannot accept more media data, then set the buffer full flag to true. if (mSizeSourceBuffer >= EvictionThreshold()) { mBufferFull = true; - mEvictionOccurred = false; } // 5. If the input buffer does not contain a complete media segment, then jump to the need more data step below. diff --git a/dom/media/mediasource/TrackBuffersManager.h b/dom/media/mediasource/TrackBuffersManager.h index 9f0f086e8eb2..ffea285a6289 100644 --- a/dom/media/mediasource/TrackBuffersManager.h +++ b/dom/media/mediasource/TrackBuffersManager.h @@ -435,7 +435,13 @@ private: Atomic mSizeSourceBuffer; const int64_t mVideoEvictionThreshold; const int64_t mAudioEvictionThreshold; - Atomic mEvictionOccurred; + enum class EvictionState + { + NO_EVICTION_NEEDED, + EVICTION_NEEDED, + EVICTION_COMPLETED, + }; + Atomic mEvictionState; // Monitor to protect following objects accessed across multipple threads. mutable Monitor mMonitor;