Bug 1423241 - Remove OnTracksAvailableCallback from HTMLMediaElement. r=padenot
authorAndreas Pehrson <apehrson@mozilla.com>
Fri, 23 Nov 2018 15:02:23 +0000
changeset 504277 ed7c9d7a635de4c0c14c76745a8998986af3d234
parent 504276 2b4b43f378d82d544f009ad64ecaa0d37e1303a8
child 504278 7fef8af7ad930efb067a7d6b75f646f9c809b0fd
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)
reviewerspadenot
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 OnTracksAvailableCallback from HTMLMediaElement. r=padenot Differential Revision: https://phabricator.services.mozilla.com/D12277
dom/html/HTMLMediaElement.cpp
dom/html/HTMLMediaElement.h
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -2444,31 +2444,16 @@ HTMLMediaElement::NotifyMediaTrackDisabl
                  "The same MediaTrack was forwarded to the output stream more "
                  "than once. This shouldn't happen.");
     }
 #endif
   }
 }
 
 void
-HTMLMediaElement::NotifyMediaStreamTracksAvailable(DOMMediaStream* aStream)
-{
-  if (!mSrcStream || mSrcStream != aStream) {
-    return;
-  }
-
-  LOG(LogLevel::Debug, ("MediaElement %p MediaStream tracks available", this));
-
-  mSrcStreamTracksAvailable = true;
-
-  FirstFrameLoaded();
-  UpdateReadyStateInternal();
-}
-
-void
 HTMLMediaElement::DealWithFailedElement(nsIContent* aSourceElement)
 {
   if (mShuttingDown) {
     return;
   }
 
   DispatchAsyncSourceError(aSourceElement);
   mMainThreadEventTarget->Dispatch(
@@ -5009,39 +4994,16 @@ HTMLMediaElement::FinishDecoderSetup(Med
     if (!mPausedForInactiveDocumentOrChannel) {
       mDecoder->Play();
     }
   }
 
   return NS_OK;
 }
 
-class HTMLMediaElement::MediaStreamTracksAvailableCallback
-  : public OnTracksAvailableCallback
-{
-public:
-  explicit MediaStreamTracksAvailableCallback(HTMLMediaElement* aElement)
-    : OnTracksAvailableCallback()
-    , mElement(aElement)
-  {
-  }
-  virtual void NotifyTracksAvailable(DOMMediaStream* aStream) override
-  {
-    NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
-
-    if (!mElement) {
-      return;
-    }
-    mElement->NotifyMediaStreamTracksAvailable(aStream);
-  }
-
-private:
-  WeakPtr<HTMLMediaElement> mElement;
-};
-
 class HTMLMediaElement::MediaStreamTrackListener
   : public DOMMediaStream::TrackListener
 {
 public:
   explicit MediaStreamTrackListener(HTMLMediaElement* aElement)
     : mElement(aElement)
   {
   }
@@ -5198,28 +5160,27 @@ HTMLMediaElement::SetupSrcMediaStreamPla
   // will continue to fire events at this element and alter its track list.
   // That's simpler than delaying the events, but probably confusing...
   nsTArray<RefPtr<MediaStreamTrack>> tracks;
   mSrcStream->GetTracks(tracks);
   for (const RefPtr<MediaStreamTrack>& track : tracks) {
     NotifyMediaStreamTrackAdded(track);
   }
 
-  mSrcStream->OnTracksAvailable(new MediaStreamTracksAvailableCallback(this));
   mMediaStreamTrackListener = MakeUnique<MediaStreamTrackListener>(this);
   mSrcStream->RegisterTrackListener(mMediaStreamTrackListener.get());
 
   mSrcStream->AddPrincipalChangeObserver(this);
   mSrcStreamVideoPrincipal = mSrcStream->GetVideoPrincipal();
 
   ChangeNetworkState(NETWORK_IDLE);
   ChangeDelayLoadStatus(false);
   CheckAutoplayDataReady();
 
-  // FirstFrameLoaded() will be called when the stream has current data.
+  // FirstFrameLoaded() will be called when the stream has tracks.
 }
 
 void
 HTMLMediaElement::EndSrcMediaStreamPlayback()
 {
   MOZ_ASSERT(mSrcStream);
 
   UpdateSrcMediaStreamPlaying(REMOVING_SRC_STREAM);
@@ -5318,16 +5279,34 @@ HTMLMediaElement::NotifyMediaStreamTrack
     // video track when there is no selected track.
     if (VideoTracks()->SelectedIndex() == -1) {
       MOZ_ASSERT(!mSelectedVideoStreamTrack);
       videoTrack->SetEnabledInternal(true, MediaTrack::FIRE_NO_EVENTS);
     }
   }
 
   UpdateReadyStateInternal();
+
+  if (!mSrcStreamTracksAvailable) {
+    mAbstractMainThread->Dispatch(NS_NewRunnableFunction(
+      "HTMLMediaElement::NotifyMediaStreamTrackAdded->FirstFrameLoaded",
+      [this, self = RefPtr<HTMLMediaElement>(this), stream = mSrcStream]()
+      {
+        if (!mSrcStream || mSrcStream != stream) {
+          return;
+        }
+
+        LOG(LogLevel::Debug, ("MediaElement %p MediaStream tracks available", this));
+
+        mSrcStreamTracksAvailable = true;
+
+        FirstFrameLoaded();
+        UpdateReadyStateInternal();
+      }));
+  }
 }
 
 void
 HTMLMediaElement::NotifyMediaStreamTrackRemoved(
   const RefPtr<MediaStreamTrack>& aTrack)
 {
   MOZ_ASSERT(aTrack);
 
--- a/dom/html/HTMLMediaElement.h
+++ b/dom/html/HTMLMediaElement.h
@@ -338,21 +338,16 @@ public:
 
   /**
    * Called by one of our associated MediaTrackLists (audio/video) when an
    * AudioTrack is disabled or a VideoTrack is unselected.
    */
   void NotifyMediaTrackDisabled(MediaTrack* aTrack);
 
   /**
-   * Called when tracks become available to the source media stream.
-   */
-  void NotifyMediaStreamTracksAvailable(DOMMediaStream* aStream);
-
-  /**
    * Called when a captured MediaStreamTrack is stopped so we can clean up its
    * MediaInputPort.
    */
   void NotifyOutputTrackStopped(DOMMediaStream* aOwningStream,
                                 TrackID aDestinationTrackID);
 
   /**
    * Returns the current load ID. Asynchronous events store the ID that was
@@ -816,17 +811,16 @@ public:
 
 protected:
   virtual ~HTMLMediaElement();
 
   class AudioChannelAgentCallback;
   class ChannelLoader;
   class ErrorSink;
   class MediaLoadListener;
-  class MediaStreamTracksAvailableCallback;
   class MediaStreamTrackListener;
   class VideoFrameListener;
   class ShutdownObserver;
 
   MediaDecoderOwner::NextFrameStatus NextFrameStatus();
 
   void SetDecoder(MediaDecoder* aDecoder);