Bug 1049318 - Make SourceBuffer eviction less aggressive. r=cajbir
authorMatthew Gregan <kinetik@flim.org>
Mon, 11 Aug 2014 14:05:09 +1200
changeset 198818 a3ce4466a3daa2d76cd218bdc2831b994c1fa35a
parent 198817 ad31e026b098da534ce0dc48a5218c959153609f
child 198819 1588a78a2feb61322a212cf55658ec6a4f3a6a7d
push id47494
push usermgregan@mozilla.com
push dateMon, 11 Aug 2014 02:06:55 +0000
treeherdermozilla-inbound@c9c9e94945fe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscajbir
bugs1049318
milestone34.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 1049318 - Make SourceBuffer eviction less aggressive. r=cajbir
content/media/mediasource/SourceBuffer.cpp
--- a/content/media/mediasource/SourceBuffer.cpp
+++ b/content/media/mediasource/SourceBuffer.cpp
@@ -457,17 +457,19 @@ SourceBuffer::AppendData(const uint8_t* 
                               mDecoder->GetResource()->GetLength());
   mDecoder->GetResource()->AppendData(aData, aLength);
 
   // Eviction uses a byte threshold. If the buffer is greater than the
   // number of bytes then data is evicted. The time range for this
   // eviction is reported back to the media source. It will then
   // evict data before that range across all SourceBuffers it knows
   // about.
-  const int evict_threshold = 1000000;
+  // TODO: Make the eviction threshold smaller for audio-only streams.
+  // TODO: Drive evictions off memory pressure notifications.
+  const uint32_t evict_threshold = 75 * (1 << 20);
   bool evicted = mDecoder->GetResource()->EvictData(evict_threshold);
   if (evicted) {
     double start = 0.0;
     double end = 0.0;
     GetBufferedStartEndTime(&start, &end);
 
     MSE_DEBUG("SourceBuffer(%p)::AppendBuffer Evict; current start=%f end=%f",
               this, start, end);
@@ -502,22 +504,27 @@ SourceBuffer::GetBufferedStartEndTime(do
 void
 SourceBuffer::Evict(double aStart, double aEnd)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MSE_DEBUG("SourceBuffer(%p)::Evict(aStart=%f, aEnd=%f)", this, aStart, aEnd);
   if (!mDecoder) {
     return;
   }
-  // Need to map time to byte offset then evict
-  int64_t end = mDecoder->ConvertToByteOffset(aEnd);
-  if (end > 0) {
-    mDecoder->GetResource()->EvictBefore(end);
+  double currentTime = mMediaSource->GetDecoder()->GetCurrentTime();
+  double evictTime = aEnd;
+  const double safety_threshold = 5;
+  if (currentTime + safety_threshold >= evictTime) {
+    evictTime -= safety_threshold;
   }
-  MSE_DEBUG("SourceBuffer(%p)::Evict offset=%lld", this, end);
+  int64_t endOffset = mDecoder->ConvertToByteOffset(evictTime);
+  if (endOffset > 0) {
+    mDecoder->GetResource()->EvictBefore(endOffset);
+  }
+  MSE_DEBUG("SourceBuffer(%p)::Evict offset=%lld", this, endOffset);
 }
 
 bool
 SourceBuffer::ContainsTime(double aTime)
 {
   MOZ_ASSERT(NS_IsMainThread());
   ErrorResult dummy;
   nsRefPtr<TimeRanges> ranges = GetBuffered(dummy);