Bug 1464922 - Remove HTMLMediaElement::mAttemptPlayUponLoadedMetadata. r=bryce
authorChris Pearce <cpearce@mozilla.com>
Tue, 29 May 2018 08:09:26 +1200
changeset 478220 aa7ca0083dccff7fc457a1abe8bda6683427e541
parent 478219 818e455e568bc05aab4640bf1a82d65406234099
child 478221 4db37ec137d618415270ccd59f5d950e42f9deb9
push id1757
push userffxbld-merge
push dateFri, 24 Aug 2018 17:02:43 +0000
treeherdermozilla-release@736023aebdb1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbryce
bugs1464922
milestone62.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 1464922 - Remove HTMLMediaElement::mAttemptPlayUponLoadedMetadata. r=bryce We don't need to track this state anymore, as we don't need to delay calling MediaDecoder::Play() or delay firing the "playing" event anymore. MozReview-Commit-ID: E3B9l6ep7FP
dom/html/HTMLMediaElement.cpp
dom/html/HTMLMediaElement.h
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -1807,17 +1807,16 @@ HTMLMediaElement::AbortExistingLoads()
   mHaveQueuedSelectResource = false;
   mSuspendedForPreloadNone = false;
   mDownloadSuspendedByCache = false;
   mMediaInfo = MediaInfo();
   mIsEncrypted = false;
   mPendingEncryptedInitData.Reset();
   mWaitingForKey = NOT_WAITING_FOR_KEY;
   mSourcePointer = nullptr;
-  mAttemptPlayUponLoadedMetadata = false;
 
   mTags = nullptr;
 
   if (mNetworkState != NETWORK_EMPTY) {
     NS_ASSERTION(!mDecoder && !mSrcStream,
                  "How did someone setup a new stream/decoder already?");
     // ChangeNetworkState() will call UpdateAudioChannelPlayingState()
     // indirectly which depends on mPaused. So we need to update mPaused first.
@@ -4093,27 +4092,18 @@ HTMLMediaElement::PlayInternal(ErrorResu
 
   // Even if we just did Load() or ResumeLoad(), we could already have a decoder
   // here if we managed to clone an existing decoder.
   if (mDecoder) {
     if (mDecoder->IsEnded()) {
       SetCurrentTime(0);
     }
     if (!mPausedForInactiveDocumentOrChannel) {
-      if (mReadyState < HAVE_METADATA) {
-        // We don't know whether the autoplay policy will allow us to play yet,
-        // as we don't yet know whether the media has audio tracks. So delay
-        // starting playback until we've loaded metadata.
-        mAttemptPlayUponLoadedMetadata = true;
-      } else {
-        mDecoder->Play();
-      }
-    }
-  } else if (mReadyState < HAVE_METADATA) {
-    mAttemptPlayUponLoadedMetadata = true;
+      mDecoder->Play();
+    }
   }
 
   if (mCurrentPlayRangeStart == -1.0) {
     mCurrentPlayRangeStart = CurrentTime();
   }
 
   const bool oldPaused = mPaused;
   mPaused = false;
@@ -4164,18 +4154,17 @@ HTMLMediaElement::PlayInternal(ErrorResu
         DispatchAsyncEvent(NS_LITERAL_STRING("waiting"));
         break;
       case HAVE_FUTURE_DATA:
       case HAVE_ENOUGH_DATA:
         FireTimeUpdate(false);
         NotifyAboutPlaying();
         break;
     }
-  } else if (mReadyState >= HAVE_FUTURE_DATA &&
-             !mAttemptPlayUponLoadedMetadata) {
+  } else if (mReadyState >= HAVE_FUTURE_DATA) {
     // 7. Otherwise, if the media element's readyState attribute has the value
     //    HAVE_FUTURE_DATA or HAVE_ENOUGH_DATA, take pending play promises and
     //    queue a task to resolve pending play promises with the result.
     AsyncResolvePendingPlayPromises();
   }
 
   // 8. Set the media element's autoplaying flag to false. (Already done.)
 
@@ -4997,17 +4986,17 @@ HTMLMediaElement::FinishDecoderSetup(Med
   // We may want to suspend the new stream now.
   // This will also do an AddRemoveSelfReference.
   NotifyOwnerDocumentActivityChanged();
 
   if (mPausedForInactiveDocumentOrChannel) {
     mDecoder->Suspend();
   }
 
-  if (!mPaused && !mAttemptPlayUponLoadedMetadata) {
+  if (!mPaused) {
     SetPlayedOrSeeked(true);
     if (!mPausedForInactiveDocumentOrChannel) {
       mDecoder->Play();
     }
   }
 
   return NS_OK;
 }
@@ -6044,26 +6033,16 @@ HTMLMediaElement::ChangeReadyState(nsMed
   DDLOG(DDLogCategory::Property, "ready_state", gReadyStateToString[aState]);
 
   if (mNetworkState == NETWORK_EMPTY) {
     return;
   }
 
   UpdateAudioChannelPlayingState();
 
-  if (oldState < HAVE_METADATA && mReadyState >= HAVE_METADATA &&
-      mAttemptPlayUponLoadedMetadata) {
-    mAttemptPlayUponLoadedMetadata = false;
-    if (!mPaused && !IsAllowedToPlay()) {
-      mPaused = true;
-      DispatchAsyncEvent(NS_LITERAL_STRING("pause"));
-      AsyncRejectPendingPlayPromises(NS_ERROR_DOM_MEDIA_NOT_ALLOWED_ERR);
-    }
-  }
-
   // Handle raising of "waiting" event during seek (see 4.8.10.9)
   // or
   // 4.8.12.7 Ready states:
   // "If the previous ready state was HAVE_FUTURE_DATA or more, and the new
   // ready state is HAVE_CURRENT_DATA or less
   // If the media element was potentially playing before its readyState
   // attribute changed to a value lower than HAVE_FUTURE_DATA, and the element
   // has not ended playback, and playback has not stopped due to errors,
@@ -6208,17 +6187,16 @@ HTMLMediaElement::CheckAutoplayDataReady
   UpdateSrcMediaStreamPlaying();
   UpdateAudioChannelPlayingState();
 
   if (mDecoder) {
     SetPlayedOrSeeked(true);
     if (mCurrentPlayRangeStart == -1.0) {
       mCurrentPlayRangeStart = CurrentTime();
     }
-    MOZ_ASSERT(!mAttemptPlayUponLoadedMetadata);
     mDecoder->Play();
   } else if (mSrcStream) {
     SetPlayedOrSeeked(true);
   }
 
   // For blocked media, the event would be pending until it is resumed.
   DispatchAsyncEvent(NS_LITERAL_STRING("play"));
 
@@ -6572,17 +6550,16 @@ HTMLMediaElement::SuspendOrResumeElement
         mDecoder->Pause();
         mDecoder->Suspend();
       }
       mEventDeliveryPaused = aSuspendEvents;
     } else {
       if (mDecoder) {
         mDecoder->Resume();
         if (!mPaused && !mDecoder->IsEnded()) {
-          MOZ_ASSERT(!mAttemptPlayUponLoadedMetadata);
           mDecoder->Play();
         }
       }
       if (mEventDeliveryPaused) {
         mEventDeliveryPaused = false;
         DispatchPendingMediaEvents();
       }
     }
--- a/dom/html/HTMLMediaElement.h
+++ b/dom/html/HTMLMediaElement.h
@@ -1821,23 +1821,16 @@ private:
   // True if media element has been marked as 'tainted' and can't
   // participate in video decoder suspending.
   bool mHasSuspendTaint = false;
 
   // True if media element has been forced into being considered 'hidden'.
   // For use by mochitests. Enabling pref "media.test.video-suspend"
   bool mForcedHidden = false;
 
-  // True if we attempted to play before the media element had loaded
-  // metadata, and we need to attempt the play once we reach loaded metadata.
-  // If autoplay is disabled, we can't decide whether to allow a play()
-  // until we've loaded metadata, as we need to know whether the resource
-  // has an audio track.
-  bool mAttemptPlayUponLoadedMetadata = false;
-
   // True if audio tracks and video tracks are constructed and added into the
   // track list, false if all tracks are removed from the track list.
   bool mMediaTracksConstructed = false;
 
   Visibility mVisibilityState = Visibility::UNTRACKED;
 
   UniquePtr<ErrorSink> mErrorSink;