Bug 1122358: Implement partial reset parser. r=cajbir
authorJean-Yves Avenard <jyavenard@mozilla.com>
Wed, 04 Feb 2015 20:20:16 +1100
changeset 227440 22fb2f111021e4e04dfe91efa8c52a632c7e189a
parent 227439 455dc9d4628748f074a916f40fb824d86d8d1fe3
child 227441 d2c9755aaee2ddd816814465d8550aaaf79e76d8
push id28230
push userryanvm@gmail.com
push dateWed, 04 Feb 2015 19:42:59 +0000
treeherdermozilla-central@3cda3997f45d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscajbir
bugs1122358
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 1122358: Implement partial reset parser. r=cajbir 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
@@ -732,17 +732,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