Bug 1096089: Part3. Add trimming support from beginning of source buffer. r=cajbir
authorJean-Yves Avenard <jyavenard@mozilla.com>
Tue, 24 Feb 2015 16:38:42 +1100
changeset 230427 5a745cf431cba4de373f8d7ac0f28b0a6255d2d8
parent 230426 8cd5efa83e440a6dc7b60f3846c7f9cb652e2590
child 230428 931e6cba2ac527f5b4d52307798e48c68c4d76fc
push id28324
push usercbook@mozilla.com
push dateTue, 24 Feb 2015 11:56:37 +0000
treeherdermozilla-central@007c562fab9e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscajbir
bugs1096089
milestone39.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 1096089: Part3. Add trimming support from beginning of source buffer. r=cajbir
dom/media/mediasource/TrackBuffer.cpp
--- a/dom/media/mediasource/TrackBuffer.cpp
+++ b/dom/media/mediasource/TrackBuffer.cpp
@@ -981,41 +981,62 @@ TrackBuffer::RangeRemoval(int64_t aStart
   nsRefPtr<dom::TimeRanges> buffered = new dom::TimeRanges();
   int64_t bufferedEnd = Buffered(buffered) * USECS_PER_S;
   int64_t bufferedStart = buffered->GetStartTime() * USECS_PER_S;
 
   if (bufferedStart < 0 || aStart > bufferedEnd || aEnd < bufferedStart) {
     // Nothing to remove.
     return false;
   }
-  if (aEnd < bufferedEnd) {
-    // TODO. We only handle trimming.
+
+  if (aStart > bufferedStart && aEnd < bufferedEnd) {
+    // TODO. We only handle trimming and removal from the start.
     NS_WARNING("RangeRemoval unsupported arguments. "
-               "Can only handle trimming");
+               "Can only handle trimming (trim left or trim right");
     return false;
   }
 
   nsTArray<SourceBufferDecoder*> decoders;
   decoders.AppendElements(mInitializedDecoders);
 
-  // Only trimming existing buffers.
-  for (size_t i = 0; i < decoders.Length(); ++i) {
-    decoders[i]->Trim(aStart);
-    if (aStart <= buffered->GetStartTime()) {
-      // We've completely emptied it, can clear the data.
-      int64_t size = decoders[i]->GetResource()->GetSize();
-      decoders[i]->GetResource()->EvictData(size, size);
-      if (decoders[i] == mCurrentDecoder ||
-          mParentDecoder->IsActiveReader(decoders[i]->GetReader())) {
-        continue;
+  if (aStart <= bufferedStart && aEnd < bufferedEnd) {
+    // Evict data from beginning.
+    for (size_t i = 0; i < decoders.Length(); ++i) {
+      nsRefPtr<dom::TimeRanges> buffered = new dom::TimeRanges();
+      decoders[i]->GetBuffered(buffered);
+      if (buffered->GetEndTime() < aEnd) {
+        // Can be fully removed.
+        MSE_DEBUG("remove all bufferedEnd=%f time=%f, size=%lld",
+                  buffered->GetEndTime(), time,
+                  decoders[i]->GetResource()->GetSize());
+        decoders[i]->GetResource()->EvictAll();
+      } else {
+        int64_t offset = decoders[i]->ConvertToByteOffset(aEnd);
+        MSE_DEBUG("removing some bufferedEnd=%f offset=%lld size=%lld",
+                  buffered->GetEndTime(), offset,
+                  decoders[i]->GetResource()->GetSize());
+        if (offset > 0) {
+          decoders[i]->GetResource()->EvictData(offset, offset);
+        }
       }
-      MSE_DEBUG("remove empty decoders=%d", i);
-      RemoveDecoder(decoders[i]);
+    }
+  } else {
+    // Only trimming existing buffers.
+    for (size_t i = 0; i < decoders.Length(); ++i) {
+      if (aStart <= buffered->GetStartTime()) {
+        // It will be entirely emptied, can clear all data.
+        decoders[i]->GetResource()->EvictAll();
+      } else {
+        decoders[i]->Trim(aStart);
+      }
     }
   }
+
+  RemoveEmptyDecoders(decoders);
+
   return true;
 }
 
 void
 TrackBuffer::AdjustDecodersTimestampOffset(int32_t aOffset)
 {
   ReentrantMonitorAutoEnter mon(mParentDecoder->GetReentrantMonitor());
   for (uint32_t i = 0; i < mDecoders.Length(); i++) {