Bug 1261900: [MSE] P4. Only evict no longer used data from resource. r=gerald draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Fri, 22 Apr 2016 16:33:56 +1000
changeset 356314 de1d346e443bdcc06eb77a99a685ba5da80bdd7e
parent 356313 e2bcc90143d2ea92947b6fbfbe3d1a2648b05871
child 356315 512d0eab59ce958561b3252e5b2f8385c25af334
push id16492
push userbmo:jyavenard@mozilla.com
push dateTue, 26 Apr 2016 06:48:07 +0000
reviewersgerald
bugs1261900
milestone49.0a1
Bug 1261900: [MSE] P4. Only evict no longer used data from resource. r=gerald MozReview-Commit-ID: 9ueagW9ufky
dom/media/mediasource/TrackBuffersManager.cpp
--- a/dom/media/mediasource/TrackBuffersManager.cpp
+++ b/dom/media/mediasource/TrackBuffersManager.cpp
@@ -1326,19 +1326,31 @@ TrackBuffersManager::CompleteCodedFrameP
     return;
   }
 
   mLastParsedEndTime = Some(std::max(mAudioTracks.mLastParsedEndTime,
                                      mVideoTracks.mLastParsedEndTime));
 
   // 6. Remove the media segment bytes from the beginning of the input buffer.
   // Clear our demuxer from any already processed data.
-  // As we have handled a complete media segment, it is safe to evict all data
-  // from the resource.
-  mCurrentInputBuffer->EvictAll();
+  int64_t safeToEvict = std::min(
+    HasVideo()
+      ? mVideoTracks.mDemuxer->GetEvictionOffset(mVideoTracks.mLastParsedEndTime)
+      : INT64_MAX,
+    HasAudio()
+      ? mAudioTracks.mDemuxer->GetEvictionOffset(mAudioTracks.mLastParsedEndTime)
+      : INT64_MAX);
+  ErrorResult rv;
+  mCurrentInputBuffer->EvictBefore(safeToEvict, rv);
+  if (rv.Failed()) {
+    rv.SuppressException();
+    RejectProcessing(NS_ERROR_OUT_OF_MEMORY, __func__);
+    return;
+  }
+
   mInputDemuxer->NotifyDataRemoved();
   RecreateParser(true);
 
   // 7. Set append state to WAITING_FOR_SEGMENT.
   SetAppendState(AppendState::WAITING_FOR_SEGMENT);
 
   // 8. Jump to the loop top step above.
   ResolveProcessing(false, __func__);