Bug 1108917 - Part 2: Allow eviction of entire decoders that are ahead of the current play position. r=ajones
☠☠ backed out by b2f813477747 ☠ ☠
authorMatt Woodrow <mwoodrow@mozilla.com>
Thu, 11 Dec 2014 10:50:41 +1300
changeset 245027 e278ad9face80b30191e821cc4c80cce3d88f0d8
parent 245026 5c24dfe0cf87e7f70f65aa26bd9e199ce46f4fe6
child 245028 0b71e08f9d349250f0e6371e69c4dcc22d96cfa6
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersajones
bugs1108917
milestone37.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 1108917 - Part 2: Allow eviction of entire decoders that are ahead of the current play position. r=ajones
dom/media/mediasource/TrackBuffer.cpp
--- a/dom/media/mediasource/TrackBuffer.cpp
+++ b/dom/media/mediasource/TrackBuffer.cpp
@@ -239,32 +239,55 @@ TrackBuffer::EvictData(uint32_t aThresho
     totalSize += mDecoders[i]->GetResource()->GetSize();
   }
 
   int64_t toEvict = totalSize - aThreshold;
   if (toEvict <= 0) {
     return false;
   }
 
+  // Get a list of initialized decoders, sorted by their start times.
   nsTArray<SourceBufferDecoder*> decoders;
   decoders.AppendElements(mInitializedDecoders);
   decoders.Sort(DecoderSorter());
 
-  for (uint32_t i = 0; i < decoders.Length(); ++i) {
+  // First try to evict data before the current play position, starting
+  // with the earliest time.
+  uint32_t i = 0;
+  for (; i < decoders.Length(); ++i) {
     MSE_DEBUG("TrackBuffer(%p)::EvictData decoder=%u threshold=%u toEvict=%lld",
               this, i, aThreshold, toEvict);
     toEvict -= decoders[i]->GetResource()->EvictData(toEvict);
     if (!decoders[i]->GetResource()->GetSize() &&
         decoders[i] != mCurrentDecoder) {
       RemoveDecoder(decoders[i]);
     }
     if (toEvict <= 0 || decoders[i] == mCurrentDecoder) {
       break;
     }
   }
+
+  // If we still need to evict more, then try to evict entire decoders,
+  // starting from the end.
+  if (toEvict > 0) {
+    uint32_t end = i;
+    MOZ_ASSERT(decoders[end] == mCurrentDecoder);
+
+    for (i = decoders.Length() - 1; i > end; --i) {
+      MSE_DEBUG("TrackBuffer(%p)::EvictData removing entire decoder=%u from end toEvict=%lld",
+                this, i, toEvict);
+      // TODO: We could implement forward-eviction within a decoder and
+      // be able to evict within the current decoder.
+      toEvict -= decoders[i]->GetResource()->GetSize();
+      RemoveDecoder(decoders[i]);
+      if (toEvict <= 0) {
+        break;
+      }
+    }
+  }
   return toEvict < (totalSize - aThreshold);
 }
 
 void
 TrackBuffer::EvictBefore(double aTime)
 {
   MOZ_ASSERT(NS_IsMainThread());
   ReentrantMonitorAutoEnter mon(mParentDecoder->GetReentrantMonitor());