Bug 1289016 - [1.2] Don't initialize suspended decoders and fix removing readers from the queue.
authorEugen Sawin <esawin@mozilla.com>
Tue, 26 Jul 2016 17:38:42 +0200
changeset 333587 02f8c8bd057d7ccc5096c880ec3458174008426c
parent 333586 8248ff77be0fa18183018e081ad62c9fb050b6d6
child 333588 8921d7e9425799fb294023f5863913f4a0b5db47
push id10033
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:50:26 +0000
treeherdermozilla-aurora@5dddbefdf759 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1289016
milestone51.0a1
Bug 1289016 - [1.2] Don't initialize suspended decoders and fix removing readers from the queue.
dom/media/MediaDecoderReader.cpp
dom/media/MediaFormatReader.cpp
--- a/dom/media/MediaDecoderReader.cpp
+++ b/dom/media/MediaDecoderReader.cpp
@@ -117,27 +117,26 @@ public:
       DispatchSuspendResume(suspendReader, aReader);
     }
   }
 
   void Remove(MediaDecoderReader* aReader)
   {
     MutexAutoLock lock(mMutex);
 
-    if (aReader->IsSuspended()) {
-      // Removing suspended readers has no immediate side-effects.
-      DebugOnly<bool> result = mSuspended.RemoveElement(aReader);
-      MOZ_ASSERT(result, "Suspended reader must be in mSuspended");
-    } else {
+    // Remove the reader from the queue. Note that the reader's IsSuspended
+    // state is updated on the task queue, so we cannot depend on it here to
+    // determine the factual suspension state.
+    DebugOnly<bool> suspended = mSuspended.RemoveElement(aReader);
+    bool active = mActive.RemoveElement(aReader);
+
+    MOZ_ASSERT(suspended || active, "Reader must be in the queue");
+
+    if (active && !mSuspended.IsEmpty()) {
       // For each removed active reader, we resume a suspended one.
-      DebugOnly<bool> result = mActive.RemoveElement(aReader);
-      MOZ_ASSERT(result, "Non-suspended reader must be in mActive");
-      if (mSuspended.IsEmpty()) {
-        return;
-      }
       MediaDecoderReader* resumeReader = mSuspended.LastElement();
       mActive.AppendElement(resumeReader);
       mSuspended.RemoveElementAt(mSuspended.Length() - 1);
       DispatchResume(resumeReader);
     }
   }
 
 private:
--- a/dom/media/MediaFormatReader.cpp
+++ b/dom/media/MediaFormatReader.cpp
@@ -457,16 +457,20 @@ MediaFormatReader::EnsureDecoderInitiali
 
   if (!decoder.mDecoder || decoder.mInitPromise.Exists()) {
     MOZ_ASSERT(decoder.mDecoder);
     return false;
   }
   if (decoder.mDecoderInitialized) {
     return true;
   }
+  if (IsSuspended()) {
+    return false;
+  }
+
   RefPtr<MediaFormatReader> self = this;
   decoder.mInitPromise.Begin(decoder.mDecoder->Init()
        ->Then(OwnerThread(), __func__,
               [self] (TrackType aTrack) {
                 auto& decoder = self->GetDecoderData(aTrack);
                 decoder.mInitPromise.Complete();
 
                 if (self->IsSuspended()) {