Bug 1130826: Run range removal algorithm when setting mediasource duration. r=cajbir
authorJean-Yves Avenard <jyavenard@mozilla.com>
Thu, 12 Feb 2015 18:52:12 +1100
changeset 228814 5adf82c926e36c66dee8a89b34f62724c7063741
parent 228813 dccaeb191e5f9979a4cb74fa24cd100782930131
child 228815 8df52c8e52e3856bc75f013d0f6f45d3824b926d
push id28271
push usercbook@mozilla.com
push dateThu, 12 Feb 2015 14:33:39 +0000
treeherdermozilla-central@81f979b17fbd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscajbir
bugs1130826
milestone38.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 1130826: Run range removal algorithm when setting mediasource duration. r=cajbir
dom/media/mediasource/SourceBuffer.cpp
dom/media/mediasource/SourceBuffer.h
--- a/dom/media/mediasource/SourceBuffer.cpp
+++ b/dom/media/mediasource/SourceBuffer.cpp
@@ -67,26 +67,31 @@ private:
   nsRefPtr<LargeDataBuffer> mData;
   double mTimestampOffset;
   uint32_t mUpdateID;
 };
 
 class RangeRemovalRunnable : public nsRunnable {
 public:
   RangeRemovalRunnable(SourceBuffer* aSourceBuffer,
-                     double aStart,
-                     double aEnd)
+                       double aStart,
+                       double aEnd)
   : mSourceBuffer(aSourceBuffer)
   , mStart(aStart)
   , mEnd(aEnd)
   { }
 
   NS_IMETHOD Run() MOZ_OVERRIDE MOZ_FINAL {
 
+    if (!mSourceBuffer->mUpdating) {
+      // abort was called in between.
+      return NS_OK;
+    }
     mSourceBuffer->DoRangeRemoval(mStart, mEnd);
+    mSourceBuffer->StopUpdating();
 
     return NS_OK;
   }
 
 private:
   nsRefPtr<SourceBuffer> mSourceBuffer;
   double mStart;
   double mEnd;
@@ -255,44 +260,41 @@ SourceBuffer::Remove(double aStart, doub
   }
   if (mUpdating) {
     aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
     return;
   }
   if (mMediaSource->ReadyState() == MediaSourceReadyState::Ended) {
     mMediaSource->SetReadyState(MediaSourceReadyState::Open);
   }
-  RangeRemoval(aStart, aEnd);
+
+  StartUpdating();
+  nsRefPtr<nsIRunnable> task = new RangeRemovalRunnable(this, aStart, aEnd);
+  NS_DispatchToMainThread(task);
 }
 
 void
 SourceBuffer::RangeRemoval(double aStart, double aEnd)
 {
   StartUpdating();
-
-  nsRefPtr<nsIRunnable> task = new RangeRemovalRunnable(this, aStart, aEnd);
+  DoRangeRemoval(aStart, aEnd);
+  nsRefPtr<nsIRunnable> task =
+    NS_NewRunnableMethod(this, &SourceBuffer::StopUpdating);
   NS_DispatchToMainThread(task);
 }
 
 void
 SourceBuffer::DoRangeRemoval(double aStart, double aEnd)
 {
-  MSE_DEBUG("SourceBuffer(%p)::DoRangeRemoval (updating:%d)",
-            this, mUpdating);
-  if (!mUpdating) {
-    // abort was called in between.
-    return;
-  }
+  MSE_DEBUG("SourceBuffer(%p)::DoRangeRemoval", this);
   if (mTrackBuffer && !IsInfinite(aStart)) {
     int64_t start = aStart * USECS_PER_S;
     int64_t end = IsInfinite(aEnd) ? INT64_MAX : (int64_t)(aEnd * USECS_PER_S);
     mTrackBuffer->RangeRemoval(start, end);
   }
-
-  StopUpdating();
 }
 
 void
 SourceBuffer::Detach()
 {
   MOZ_ASSERT(NS_IsMainThread());
   MSE_DEBUG("SourceBuffer(%p)::Detach", this);
   AbortBufferAppend();
--- a/dom/media/mediasource/SourceBuffer.h
+++ b/dom/media/mediasource/SourceBuffer.h
@@ -108,29 +108,30 @@ public:
 
   // Evict data in the source buffer in the given time range.
   void Evict(double aStart, double aEnd);
 
   double GetBufferedStart();
   double GetBufferedEnd();
 
   // Runs the range removal algorithm as defined by the MSE spec.
-  // RangeRemoval will queue a call to DoRangeRemoval.
   void RangeRemoval(double aStart, double aEnd);
+  // Actually remove data between aStart and aEnd
   void DoRangeRemoval(double aStart, double aEnd);
 
 #if defined(DEBUG)
   void Dump(const char* aPath);
 #endif
 
 private:
   ~SourceBuffer();
 
   friend class AsyncEventRunner<SourceBuffer>;
   friend class AppendDataRunnable;
+  friend class RangeRemovalRunnable;
   void DispatchSimpleEvent(const char* aName);
   void QueueAsyncSimpleEvent(const char* aName);
 
   // Update mUpdating and fire the appropriate events.
   void StartUpdating();
   void StopUpdating();
   void AbortUpdating();