Bug 1134064 - Part 5: Evict from TrackBuffer's current decoder. r=cajbir, a=lsblakk
authorJean-Yves Avenard <jyavenard@mozilla.com>
Tue, 24 Feb 2015 16:38:41 +1100
changeset 250102 d461222b1a07
parent 250101 c92f6beaa505
child 250103 4c92b1dcb67f
push id4502
push userryanvm@gmail.com
push date2015-02-27 21:16 +0000
treeherdermozilla-beta@9fb3cc1f7ff6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscajbir, lsblakk
bugs1134064
milestone37.0
Bug 1134064 - Part 5: Evict from TrackBuffer's current decoder. r=cajbir, a=lsblakk Also evicts all data from inactive decoders once there's nothing left to play in them.
dom/media/mediasource/TrackBuffer.cpp
--- a/dom/media/mediasource/TrackBuffer.cpp
+++ b/dom/media/mediasource/TrackBuffer.cpp
@@ -318,38 +318,52 @@ TrackBuffer::EvictData(double aPlaybackT
   decoders.AppendElements(mInitializedDecoders);
 
   // First try to evict data before the current play position, starting
   // with the oldest decoder.
   for (uint32_t i = 0; i < decoders.Length() && toEvict > 0; ++i) {
     nsRefPtr<dom::TimeRanges> buffered = new dom::TimeRanges();
     decoders[i]->GetBuffered(buffered);
 
-    MSE_DEBUG("decoder=%u/%u threshold=%u toEvict=%lld",
+    MSE_DEBUG("Step1. decoder=%u/%u threshold=%u toEvict=%lld",
               i, decoders.Length(), aThreshold, toEvict);
 
     // To ensure we don't evict data past the current playback position
     // we apply a threshold of a few seconds back and evict data up to
     // that point.
     if (aPlaybackTime > MSE_EVICT_THRESHOLD_TIME) {
       double time = aPlaybackTime - MSE_EVICT_THRESHOLD_TIME;
-      int64_t playbackOffset = decoders[i]->ConvertToByteOffset(time);
-      MSE_DEBUG("evicting some bufferedEnd=%f"
-                "aPlaybackTime=%f time=%f, playbackOffset=%lld size=%lld",
-                buffered->GetEndTime(), aPlaybackTime, time,
-                playbackOffset, decoders[i]->GetResource()->GetSize());
-      if (playbackOffset > 0) {
-        toEvict -= decoders[i]->GetResource()->EvictData(playbackOffset,
-                                                         playbackOffset);
+      bool isActive = decoders[i] == mCurrentDecoder ||
+        mParentDecoder->IsActiveReader(decoders[i]->GetReader());
+      if (!isActive && buffered->GetEndTime() < time) {
+        // The entire decoder is contained before our current playback time.
+        // It can be fully evicted.
+        MSE_DEBUG("evicting all bufferedEnd=%f "
+                  "aPlaybackTime=%f time=%f, size=%lld",
+                  buffered->GetEndTime(), aPlaybackTime, time,
+                  decoders[i]->GetResource()->GetSize());
+        toEvict -= decoders[i]->GetResource()->EvictAll();
+      } else {
+        int64_t playbackOffset = decoders[i]->ConvertToByteOffset(time);
+        MSE_DEBUG("evicting some bufferedEnd=%f "
+                  "aPlaybackTime=%f time=%f, playbackOffset=%lld size=%lld",
+                  buffered->GetEndTime(), aPlaybackTime, time,
+                  playbackOffset, decoders[i]->GetResource()->GetSize());
+        if (playbackOffset > 0) {
+          toEvict -= decoders[i]->GetResource()->EvictData(playbackOffset,
+                                                           playbackOffset);
+        }
       }
     }
   }
 
   // Evict all data from decoders we've likely already read from.
   for (uint32_t i = 0; i < decoders.Length() && toEvict > 0; ++i) {
+    MSE_DEBUG("Step2. decoder=%u/%u threshold=%u toEvict=%lld",
+              i, decoders.Length(), aThreshold, toEvict);
     if (mParentDecoder->IsActiveReader(decoders[i]->GetReader())) {
       break;
     }
     if (decoders[i] == mCurrentDecoder) {
       continue;
     }
     nsRefPtr<dom::TimeRanges> buffered = new dom::TimeRanges();
     decoders[i]->GetBuffered(buffered);
@@ -388,16 +402,18 @@ TrackBuffer::EvictData(double aPlaybackT
                                     EOS_FUZZ_US,
                                     mInitializedDecoders);
   }
 
   // Sort decoders by their start times.
   decoders.Sort(DecoderSorter());
 
   for (int32_t i = int32_t(decoders.Length()) - 1; i >= 0 && toEvict > 0; --i) {
+    MSE_DEBUG("Step3. decoder=%u/%u threshold=%u toEvict=%lld",
+              i, decoders.Length(), aThreshold, toEvict);
     if (decoders[i] == playingDecoder || decoders[i] == nextPlayingDecoder ||
         decoders[i] == mCurrentDecoder) {
       continue;
     }
     nsRefPtr<dom::TimeRanges> buffered = new dom::TimeRanges();
     decoders[i]->GetBuffered(buffered);
 
     MSE_DEBUG("evicting all "
@@ -465,16 +481,19 @@ TrackBuffer::GetSize()
 bool
 TrackBuffer::HasOnlyIncompleteMedia()
 {
   if (!mCurrentDecoder) {
     return false;
   }
   nsRefPtr<dom::TimeRanges> buffered = new dom::TimeRanges();
   mCurrentDecoder->GetBuffered(buffered);
+  MSE_DEBUG("mCurrentDecoder.size=%lld, start=%f end=%f",
+            mCurrentDecoder->GetResource()->GetSize(),
+            buffered->GetStartTime(), buffered->GetEndTime());
   return mCurrentDecoder->GetResource()->GetSize() && !buffered->Length();
 }
 
 void
 TrackBuffer::EvictBefore(double aTime)
 {
   MOZ_ASSERT(NS_IsMainThread());
   ReentrantMonitorAutoEnter mon(mParentDecoder->GetReentrantMonitor());