Bug 1423241 - Remove HTMLMediaElement::StreamListener::NotifyHasCurrentData. r=jya
authorAndreas Pehrson <apehrson@mozilla.com>
Fri, 23 Nov 2018 15:00:49 +0000
changeset 504262 7db08b6156f234337e4a87b3f67aec6e8771bf56
parent 504261 d53898abd647120cf424d5c5c75e3aa63f8bbe45
child 504263 69551bbbf203a1fe303ba319639094695f887467
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1423241
milestone65.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 1423241 - Remove HTMLMediaElement::StreamListener::NotifyHasCurrentData. r=jya Differential Revision: https://phabricator.services.mozilla.com/D9098
dom/html/HTMLMediaElement.cpp
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -2601,16 +2601,17 @@ HTMLMediaElement::NotifyMediaStreamTrack
   bool videoHasChanged = IsVideo() && HasVideo() != !VideoTracks()->IsEmpty();
 
   if (videoHasChanged) {
     // We are a video element and HasVideo() changed so update the screen
     // wakelock
     NotifyOwnerDocumentActivityChanged();
   }
 
+  FirstFrameLoaded();
   UpdateReadyStateInternal();
 }
 
 void
 HTMLMediaElement::DealWithFailedElement(nsIContent* aSourceElement)
 {
   if (mShuttingDown) {
     return;
@@ -5183,91 +5184,59 @@ HTMLMediaElement::FinishDecoderSetup(Med
   return NS_OK;
 }
 
 class HTMLMediaElement::StreamListener : public MediaStreamListener
 {
 public:
   StreamListener(HTMLMediaElement* aElement, const char* aName)
     : mElement(aElement)
-    , mHaveCurrentData(false)
-    , mFinished(false)
     , mMutex(aName)
     , mPendingNotifyOutput(false)
   {
   }
+
   void Forget()
   {
-    if (mElement) {
-      HTMLMediaElement* element = mElement;
-      mElement = nullptr;
-      element->UpdateReadyStateInternal();
-    }
+    mElement = nullptr;
   }
 
   // Main thread
 
-  MediaDecoderOwner::NextFrameStatus NextFrameStatus()
-  {
-    if (!mElement || !mHaveCurrentData || mFinished) {
-      return MediaDecoderOwner::NEXT_FRAME_UNAVAILABLE;
-    }
-    return MediaDecoderOwner::NEXT_FRAME_AVAILABLE;
-  }
-
   void DoNotifyOutput()
   {
+    MOZ_ASSERT(NS_IsMainThread());
     {
       MutexAutoLock lock(mMutex);
       mPendingNotifyOutput = false;
     }
-    if (mElement && mHaveCurrentData) {
-      RefPtr<HTMLMediaElement> kungFuDeathGrip = mElement;
-      kungFuDeathGrip->FireTimeUpdate(true);
-    }
-  }
-  void DoNotifyHaveCurrentData()
-  {
-    mHaveCurrentData = true;
-    if (mElement) {
-      RefPtr<HTMLMediaElement> kungFuDeathGrip = mElement;
-      kungFuDeathGrip->FirstFrameLoaded();
-      kungFuDeathGrip->UpdateReadyStateInternal();
-    }
-    DoNotifyOutput();
-  }
-
-  // These notifications run on the media graph thread so we need to
+    if (mElement && mElement->ReadyState() >= HAVE_CURRENT_DATA) {
+      mElement->FireTimeUpdate(true);
+    }
+  }
+
+  // This notification runs on the media graph thread so we need to
   // dispatch events to the main thread.
-  virtual void NotifyHasCurrentData(MediaStreamGraph* aGraph) override
-  {
-    MutexAutoLock lock(mMutex);
-    aGraph->DispatchToMainThreadAfterStreamStateUpdate(NewRunnableMethod(
-      "dom::HTMLMediaElement::StreamListener::DoNotifyHaveCurrentData",
-      this,
-      &StreamListener::DoNotifyHaveCurrentData));
-  }
   virtual void NotifyOutput(MediaStreamGraph* aGraph,
                             GraphTime aCurrentTime) override
   {
     MutexAutoLock lock(mMutex);
-    if (mPendingNotifyOutput)
+    if (mPendingNotifyOutput) {
       return;
+    }
     mPendingNotifyOutput = true;
     aGraph->DispatchToMainThreadAfterStreamStateUpdate(
       NewRunnableMethod("dom::HTMLMediaElement::StreamListener::DoNotifyOutput",
                         this,
                         &StreamListener::DoNotifyOutput));
   }
 
 private:
   // These fields may only be accessed on the main thread
   HTMLMediaElement* mElement;
-  bool mHaveCurrentData;
-  bool mFinished;
 
   // mMutex protects the fields below; they can be accessed on any thread
   Mutex mMutex;
   bool mPendingNotifyOutput;
 };
 
 class HTMLMediaElement::MediaStreamTracksAvailableCallback
   : public OnTracksAvailableCallback
@@ -5329,16 +5298,17 @@ public:
         ("%p, mSrcStream %p became inactive",
          mElement,
          mElement->mSrcStream.get()));
     MOZ_ASSERT(!mElement->mSrcStream->Active());
     if (mElement->mMediaStreamListener) {
       mElement->mMediaStreamListener->Forget();
     }
     mElement->PlaybackEnded();
+    mElement->UpdateReadyStateInternal();
   }
 
 protected:
   HTMLMediaElement* const mElement;
 };
 
 void
 HTMLMediaElement::UpdateSrcMediaStreamPlaying(uint32_t aFlags)
@@ -7644,18 +7614,22 @@ HTMLMediaElement::GetOrCreateTextTrackMa
   return mTextTrackManager;
 }
 
 MediaDecoderOwner::NextFrameStatus
 HTMLMediaElement::NextFrameStatus()
 {
   if (mDecoder) {
     return mDecoder->NextFrameStatus();
-  } else if (mMediaStreamListener) {
-    return mMediaStreamListener->NextFrameStatus();
+  }
+  if (mSrcStream) {
+    if (mSrcStreamTracksAvailable && !mSrcStreamPlaybackEnded) {
+      return NEXT_FRAME_AVAILABLE;
+    }
+    return NEXT_FRAME_UNAVAILABLE;
   }
   return NEXT_FRAME_UNINITIALIZED;
 }
 
 void
 HTMLMediaElement::SetDecoder(MediaDecoder* aDecoder)
 {
   MOZ_ASSERT(aDecoder); // Use ShutdownDecoder() to clear.