Bug 1122358: Implement partial reset parser. r=cajbir a=lmandel
authorJean-Yves Avenard <jyavenard@mozilla.com>
Wed, 04 Feb 2015 20:20:16 +1100
changeset 249840 378dac73d66dd37fc4bb794800ffff7ba46549f0
parent 249839 cb47d8fa838fcfb834d2a74278895b535975213c
child 249841 bfb746be073770753b82b4a741377ceb1a18b248
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscajbir, lmandel
bugs1122358
milestone37.0a2
Bug 1122358: Implement partial reset parser. r=cajbir a=lmandel Only handles resetting parser and incomplete init segments at this stage.
dom/media/mediasource/SourceBuffer.cpp
dom/media/mediasource/TrackBuffer.cpp
dom/media/mediasource/TrackBuffer.h
--- a/dom/media/mediasource/SourceBuffer.cpp
+++ b/dom/media/mediasource/SourceBuffer.cpp
@@ -222,17 +222,19 @@ SourceBuffer::Abort(ErrorResult& aRv)
   MSE_DEBUG("SourceBuffer(%p)::Abort() Discarding decoder", this);
   mTrackBuffer->DiscardDecoder();
 }
 
 void
 SourceBuffer::Abort()
 {
   if (mUpdating) {
-    // TODO: Abort segment parser loop, buffer append, and stream append loop algorithms.
+    // abort any pending buffer append.
+    mTrackBuffer->Abort();
+    // TODO: Abort segment parser loop, and stream append loop algorithms.
     AbortUpdating();
   }
 }
 
 void
 SourceBuffer::Remove(double aStart, double aEnd, ErrorResult& aRv)
 {
   MOZ_ASSERT(NS_IsMainThread());
@@ -469,17 +471,25 @@ SourceBuffer::AppendDataCompletedWithSuc
   }
 
   StopUpdating();
 }
 
 void
 SourceBuffer::AppendDataErrored(nsresult aError)
 {
-  AppendError(true);
+  switch (aError) {
+    case NS_ERROR_ABORT:
+      // Nothing further to do as the handling of the events is being done
+      // by Abort().
+      break;
+    default:
+      AppendError(true);
+      break;
+  }
 }
 
 void
 SourceBuffer::AppendError(bool aDecoderError)
 {
   MOZ_ASSERT(NS_IsMainThread());
   if (!mUpdating) {
     // The buffer append algorithm has been interrupted by abort().
--- a/dom/media/mediasource/TrackBuffer.cpp
+++ b/dom/media/mediasource/TrackBuffer.cpp
@@ -730,17 +730,30 @@ TrackBuffer::ResetDecode()
   for (uint32_t i = 0; i < mDecoders.Length(); ++i) {
     mDecoders[i]->GetReader()->ResetDecode();
   }
 }
 
 void
 TrackBuffer::ResetParserState()
 {
-  // TODO
+  MOZ_ASSERT(NS_IsMainThread());
+
+  if (mParser->HasInitData() && !mParser->HasCompleteInitData()) {
+    // We have an incomplete init segment pending. reset current parser and
+    // discard the current decoder.
+    mParser = ContainerParser::CreateForMIMEType(mType);
+    DiscardDecoder();
+  }
+}
+
+void
+TrackBuffer::Abort()
+{
+  mInitializationPromise.RejectIfExists(NS_ERROR_ABORT, __func__);
 }
 
 const nsTArray<nsRefPtr<SourceBufferDecoder>>&
 TrackBuffer::Decoders()
 {
   // XXX assert OnDecodeThread
   return mInitializedDecoders;
 }
--- a/dom/media/mediasource/TrackBuffer.h
+++ b/dom/media/mediasource/TrackBuffer.h
@@ -98,16 +98,19 @@ public:
 
   // Runs MSE range removal algorithm.
   // http://w3c.github.io/media-source/#sourcebuffer-coded-frame-removal
   // Implementation is only partial, we can only trim a buffer.
   // Returns true if data was evicted.
   // Times are in microseconds.
   bool RangeRemoval(int64_t aStart, int64_t aEnd);
 
+  // Abort any pending appendBuffer by rejecting any pending promises.
+  void Abort();
+
 #ifdef MOZ_EME
   nsresult SetCDMProxy(CDMProxy* aProxy);
 #endif
 
 #if defined(DEBUG)
   void Dump(const char* aPath);
 #endif