Bug 1062661 - Part 1: Fix ResourceQueue::Evict so that it tries to remove enough data to get us under the threshold. r=kinetik
authorMatt Woodrow <mwoodrow@mozilla.com>
Tue, 04 Nov 2014 11:16:31 +1300
changeset 214299 974bf86f7002
parent 214298 5b4199d058a1
child 214300 bb67cbef0a07
push id27777
push usercbook@mozilla.com
push dateThu, 06 Nov 2014 12:50:56 +0000
treeherdermozilla-central@0c66a9fd9085 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskinetik
bugs1062661
milestone36.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1062661 - Part 1: Fix ResourceQueue::Evict so that it tries to remove enough data to get us under the threshold. r=kinetik
dom/media/mediasource/ResourceQueue.h
--- a/dom/media/mediasource/ResourceQueue.h
+++ b/dom/media/mediasource/ResourceQueue.h
@@ -97,30 +97,32 @@ public:
     }
   }
 
   void AppendItem(const uint8_t* aData, uint32_t aLength) {
     mLogicalLength += aLength;
     Push(new ResourceItem(aData, aLength));
   }
 
-  // Evict data in queue if the total queue size is greater than
-  // aThreshold past the offset. Returns amount evicted.
-  uint32_t Evict(uint64_t aOffset, uint32_t aThreshold) {
+  // Tries to evict at least aSizeToEvict from the queue up until
+  // aOffset. Returns amount evicted.
+  uint32_t Evict(uint64_t aOffset, uint32_t aSizeToEvict) {
     uint32_t evicted = 0;
-    while (GetLength() - mOffset > aThreshold) {
-      ResourceItem* item = ResourceAt(0);
+    while (ResourceItem* item = ResourceAt(0)) {
       if (item->mData.Length() + mOffset > aOffset) {
         break;
       }
       mOffset += item->mData.Length();
       evicted += item->mData.Length();
       SBR_DEBUGV("ResourceQueue(%p)::Evict(%llu, %u) removed chunk length=%u",
-                 this, aOffset, aThreshold, item->mData.Length());
+                 this, aOffset, aSizeToEvict, item->mData.Length());
       delete PopFront();
+      if (aSizeToEvict && evicted >= aSizeToEvict) {
+        break;
+      }
     }
     return evicted;
   }
 
   size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const {
     // Calculate the size of the internal deque.
     size_t size = nsDeque::SizeOfExcludingThis(aMallocSizeOf);