Bug 1402584. P2 - reset readyState to HAVE_NOTHING before loading next source child. See comment 18 for the root cause. draft
authorJW Wang <jwwang@mozilla.com>
Sat, 07 Oct 2017 09:05:56 +0800
changeset 676289 9b63f9eaa250ebe7259cc7fab709aac00858aaf6
parent 676288 394da3f085e52296e62af852add26e72fa688a62
child 734909 75b99e4690c51ad5c0eaf4734c29c5075be8190f
push id83462
push userjwwang@mozilla.com
push dateSat, 07 Oct 2017 06:51:21 +0000
bugs1402584
milestone58.0a1
Bug 1402584. P2 - reset readyState to HAVE_NOTHING before loading next source child. See comment 18 for the root cause. Also assert readyState is HAVE_NOTHING before creating a new decoder. MozReview-Commit-ID: B0QACf96AA3
dom/html/HTMLMediaElement.cpp
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -1908,16 +1908,22 @@ void HTMLMediaElement::RunInStableState(
 }
 
 void HTMLMediaElement::QueueLoadFromSourceTask()
 {
   if (!mIsLoadingFromSourceChildren || mShuttingDown) {
     return;
   }
 
+  if (mDecoder) {
+    // Reset readyState to HAVE_NOTHING since we're gonna load a new decoder.
+    ShutdownDecoder();
+    ChangeReadyState(nsIDOMHTMLMediaElement::HAVE_NOTHING);
+  }
+
   ChangeDelayLoadStatus(true);
   ChangeNetworkState(nsIDOMHTMLMediaElement::NETWORK_LOADING);
   RefPtr<Runnable> r = NewRunnableMethod("HTMLMediaElement::LoadFromSourceChildren",
                                          this, &HTMLMediaElement::LoadFromSourceChildren);
   RunInStableState(r);
 }
 
 void HTMLMediaElement::QueueSelectResourceTask()
@@ -4851,16 +4857,17 @@ HTMLMediaElement::CanPlayType(const nsAS
   return NS_OK;
 }
 
 nsresult
 HTMLMediaElement::InitializeDecoderAsClone(ChannelMediaDecoder* aOriginal)
 {
   NS_ASSERTION(mLoadingSrc, "mLoadingSrc must already be set");
   NS_ASSERTION(mDecoder == nullptr, "Shouldn't have a decoder");
+  MOZ_DIAGNOSTIC_ASSERT(mReadyState == nsIDOMHTMLMediaElement::HAVE_NOTHING);
 
   MediaDecoderInit decoderInit(this,
                                mMuted ? 0.0 : mVolume,
                                mPreservesPitch,
                                mPlaybackRate,
                                mPreloadAction ==
                                  HTMLMediaElement::PRELOAD_METADATA,
                                mHasSuspendTaint,
@@ -4904,16 +4911,17 @@ HTMLMediaElement::SetupDecoder(DecoderTy
 
   return rv;
 }
 
 nsresult HTMLMediaElement::InitializeDecoderForChannel(nsIChannel* aChannel,
                                                        nsIStreamListener** aListener)
 {
   NS_ASSERTION(mLoadingSrc, "mLoadingSrc must already be set");
+  MOZ_DIAGNOSTIC_ASSERT(mReadyState == nsIDOMHTMLMediaElement::HAVE_NOTHING);
 
   DecoderDoctorDiagnostics diagnostics;
 
   nsAutoCString mimeType;
   aChannel->GetContentType(mimeType);
   NS_ASSERTION(!mimeType.IsEmpty(), "We should have the Content-Type.");
   NS_ConvertUTF8toUTF16 mimeUTF16(mimeType);