Bug 1391666 - Part 3: Change to HAVE_ENOUGH_DATA when possible. r=cpearce, a=lizzard
authorJean-Yves Avenard <jyavenard@mozilla.com>
Fri, 18 Aug 2017 21:00:08 +0200
changeset 423700 065ea81827aeffc6d1ea57ad7c31f5684a66bd87
parent 423699 53d7d0601775bdd794e1099ffaebe6afad3708f7
child 423701 21bc77a750df162c8336864e8fff060f1f179616
push id1517
push userjlorenzo@mozilla.com
push dateThu, 14 Sep 2017 16:50:54 +0000
treeherdermozilla-release@3b41fd564418 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce, lizzard
bugs1391666, 1312886
milestone56.0
Bug 1391666 - Part 3: Change to HAVE_ENOUGH_DATA when possible. r=cpearce, a=lizzard In bug 1312886, we made sure that readyState would never become HAVE_ENOUGH_DATA if we were waiting for a key. However, this is in effect useless as the next call to ChangeReadyState would have reset mWaitingForKey. In practice, it only meant that we delayed the change from HAVE_FUTURE_DATA to HAVE_ENOUGH_DATA until the next call to UpdateReadyState. MozReview-Commit-ID: 2wnMeN8xxCS
dom/html/HTMLMediaElement.cpp
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -5818,25 +5818,31 @@ HTMLMediaElement::UpdateReadyStateIntern
 
   if (mSrcStream) {
     LOG(LogLevel::Debug, ("MediaElement %p UpdateReadyStateInternal() "
                           "Stream HAVE_ENOUGH_DATA", this));
     ChangeReadyState(nsIDOMHTMLMediaElement::HAVE_ENOUGH_DATA);
     return;
   }
 
+  if (!mPaused || mAutoplaying) {
+    // We only want to reset mWaitingForKey if we have played all decoded data
+    // or if we haven't played anything yet.
+    mWaitingForKey = NOT_WAITING_FOR_KEY;
+  }
+
   // Now see if we should set HAVE_ENOUGH_DATA.
   // If it's something we don't know the size of, then we can't
   // make a real estimate, so we go straight to HAVE_ENOUGH_DATA once
   // we've downloaded enough data that our download rate is considered
   // reliable. We have to move to HAVE_ENOUGH_DATA at some point or
   // autoplay elements for live streams will never play. Otherwise we
   // move to HAVE_ENOUGH_DATA if we can play through the entire media
   // without stopping to buffer.
-  if (mWaitingForKey == NOT_WAITING_FOR_KEY && mDecoder->CanPlayThrough()) {
+  if (mDecoder->CanPlayThrough()) {
     LOG(LogLevel::Debug, ("MediaElement %p UpdateReadyStateInternal() "
                           "Decoder can play through", this));
     ChangeReadyState(nsIDOMHTMLMediaElement::HAVE_ENOUGH_DATA);
     return;
   }
   LOG(LogLevel::Debug, ("MediaElement %p UpdateReadyStateInternal() "
                         "Default; Decoder has future data", this));
   ChangeReadyState(nsIDOMHTMLMediaElement::HAVE_FUTURE_DATA);
@@ -5895,21 +5901,16 @@ void HTMLMediaElement::ChangeReadyState(
   if (oldState < nsIDOMHTMLMediaElement::HAVE_FUTURE_DATA &&
       mReadyState >= nsIDOMHTMLMediaElement::HAVE_FUTURE_DATA) {
     DispatchAsyncEvent(NS_LITERAL_STRING("canplay"));
     if (!mPaused) {
       NotifyAboutPlaying();
     }
   }
 
-  if (mReadyState >= nsIDOMHTMLMediaElement::HAVE_FUTURE_DATA &&
-      (!mPaused || mAutoplaying)) {
-    mWaitingForKey = NOT_WAITING_FOR_KEY;
-  }
-
   CheckAutoplayDataReady();
 
   if (oldState < nsIDOMHTMLMediaElement::HAVE_ENOUGH_DATA &&
       mReadyState >= nsIDOMHTMLMediaElement::HAVE_ENOUGH_DATA) {
     DispatchAsyncEvent(NS_LITERAL_STRING("canplaythrough"));
   }
 }