Bug 1423241 - Remove DOMMediaStream::OwnedStreamListener. r=padenot
authorAndreas Pehrson <apehrson@mozilla.com>
Fri, 23 Nov 2018 15:02:16 +0000
changeset 507056 2b4b43f378d82d544f009ad64ecaa0d37e1303a8
parent 507055 76c2bf0ca8a6d6c4b21cdb71b7bf5919838b2799
child 507057 ed7c9d7a635de4c0c14c76745a8998986af3d234
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [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 DOMMediaStream::OwnedStreamListener. r=padenot Differential Revision: https://phabricator.services.mozilla.com/D12276
dom/media/DOMMediaStream.cpp
dom/media/DOMMediaStream.h
--- a/dom/media/DOMMediaStream.cpp
+++ b/dom/media/DOMMediaStream.cpp
@@ -100,76 +100,16 @@ already_AddRefed<Pledge<bool>> DOMMediaS
   return rejected.forget();
 }
 
 NS_IMPL_CYCLE_COLLECTION(DOMMediaStream::TrackPort, mTrack)
 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(DOMMediaStream::TrackPort, AddRef)
 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(DOMMediaStream::TrackPort, Release)
 
 /**
- * Listener registered on the Owned stream to detect added and ended owned
- * tracks for keeping the list of MediaStreamTracks in sync with the tracks
- * added and ended directly at the source.
- */
-class DOMMediaStream::OwnedStreamListener : public MediaStreamListener {
- public:
-  explicit OwnedStreamListener(DOMMediaStream* aStream) : mStream(aStream) {}
-
-  void Forget() { mStream = nullptr; }
-
-  void DoNotifyTrackCreated(MediaStreamGraph* aGraph, TrackID aTrackID,
-                            MediaSegment::Type aType, MediaStream* aInputStream,
-                            TrackID aInputTrackID) {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    if (!mStream) {
-      return;
-    }
-
-    MediaStreamTrack* track =
-        mStream->FindOwnedDOMTrack(aInputStream, aInputTrackID, aTrackID);
-
-    if (track) {
-      LOG(LogLevel::Debug, ("DOMMediaStream %p Track %d from owned stream %p "
-                            "bound to MediaStreamTrack %p.",
-                            mStream, aTrackID, aInputStream, track));
-      return;
-    }
-
-    // Track must exist on main thread before it's added to the graph.
-    MOZ_RELEASE_ASSERT(
-        false,
-        "A new track was detected on the input stream; creating a "
-        "corresponding "
-        "MediaStreamTrack. Initial tracks should be added manually to "
-        "immediately and synchronously be available to JS.");
-  }
-
-  void NotifyQueuedTrackChanges(MediaStreamGraph* aGraph, TrackID aID,
-                                StreamTime aTrackOffset,
-                                TrackEventCommand aTrackEvents,
-                                const MediaSegment& aQueuedMedia,
-                                MediaStream* aInputStream,
-                                TrackID aInputTrackID) override {
-    if (aTrackEvents & TrackEventCommand::TRACK_EVENT_CREATED) {
-      aGraph->DispatchToMainThreadAfterStreamStateUpdate(
-          NewRunnableMethod<MediaStreamGraph*, TrackID, MediaSegment::Type,
-                            RefPtr<MediaStream>, TrackID>(
-              "DOMMediaStream::OwnedStreamListener::DoNotifyTrackCreated", this,
-              &OwnedStreamListener::DoNotifyTrackCreated, aGraph, aID,
-              aQueuedMedia.GetType(), aInputStream, aInputTrackID));
-    }
-  }
-
- private:
-  // These fields may only be accessed on the main thread
-  DOMMediaStream* mStream;
-};
-
-/**
  * Listener registered on the Playback stream to detect when tracks end and when
  * all new tracks this iteration have been created - for when several tracks are
  * queued by the source and committed all at once.
  */
 class DOMMediaStream::PlaybackStreamListener : public MediaStreamListener {
  public:
   explicit PlaybackStreamListener(DOMMediaStream* aStream) : mStream(aStream) {}
 
@@ -309,23 +249,16 @@ DOMMediaStream::DOMMediaStream(nsPIDOMWi
     }
   }
 }
 
 DOMMediaStream::~DOMMediaStream() { Destroy(); }
 
 void DOMMediaStream::Destroy() {
   LOG(LogLevel::Debug, ("DOMMediaStream %p Being destroyed.", this));
-  if (mOwnedListener) {
-    if (mOwnedStream) {
-      mOwnedStream->RemoveListener(mOwnedListener);
-    }
-    mOwnedListener->Forget();
-    mOwnedListener = nullptr;
-  }
   if (mPlaybackListener) {
     if (mPlaybackStream) {
       mPlaybackStream->RemoveListener(mPlaybackListener);
     }
     mPlaybackListener->Forget();
     mPlaybackListener = nullptr;
   }
   for (const RefPtr<TrackPort>& info : mTracks) {
@@ -738,20 +671,16 @@ void DOMMediaStream::InitOwnedStreamComm
              "Owned stream must be initialized before playback stream");
 
   mOwnedStream = aGraph->CreateTrackUnionStream();
   mOwnedStream->QueueSetAutofinish(true);
   mOwnedStream->RegisterUser();
   if (mInputStream) {
     mOwnedPort = mOwnedStream->AllocateInputPort(mInputStream);
   }
-
-  // Setup track listeners
-  mOwnedListener = new OwnedStreamListener(this);
-  mOwnedStream->AddListener(mOwnedListener);
 }
 
 void DOMMediaStream::InitPlaybackStreamCommon(MediaStreamGraph* aGraph) {
   mPlaybackStream = aGraph->CreateTrackUnionStream();
   mPlaybackStream->QueueSetAutofinish(true);
   mPlaybackStream->RegisterUser();
   if (mOwnedStream) {
     mPlaybackPort = mPlaybackStream->AllocateInputPort(mOwnedStream);
--- a/dom/media/DOMMediaStream.h
+++ b/dom/media/DOMMediaStream.h
@@ -567,19 +567,16 @@ class DOMMediaStream
 
   // Dispatches NotifyTrackRemoved() to all registered track listeners.
   void NotifyTrackRemoved(const RefPtr<MediaStreamTrack>& aTrack);
 
   // Dispatches "addtrack" or "removetrack".
   nsresult DispatchTrackEvent(const nsAString& aName,
                               const RefPtr<MediaStreamTrack>& aTrack);
 
-  class OwnedStreamListener;
-  friend class OwnedStreamListener;
-
   class PlaybackStreamListener;
   friend class PlaybackStreamListener;
 
   class PlaybackTrackListener;
   friend class PlaybackTrackListener;
 
   /**
    * Block a track in our playback stream. Calls NotifyPlaybackTrackBlocked()
@@ -630,20 +627,16 @@ class DOMMediaStream
 
   // MediaStreamTracks corresponding to tracks in our mPlaybackStream.
   AutoTArray<RefPtr<TrackPort>, 2> mTracks;
 
   // Number of MediaStreamTracks that have been removed on main thread but are
   // waiting to be removed on MediaStreamGraph thread.
   size_t mTracksPendingRemoval;
 
-  // Listener tracking changes to mOwnedStream. We use this to notify the
-  // MediaStreamTracks we own about state changes.
-  RefPtr<OwnedStreamListener> mOwnedListener;
-
   // Listener tracking changes to mPlaybackStream. This drives state changes
   // in this DOMMediaStream and notifications to mTrackListeners.
   RefPtr<PlaybackStreamListener> mPlaybackListener;
 
   // Listener tracking when live MediaStreamTracks in mTracks end.
   RefPtr<PlaybackTrackListener> mPlaybackTrackListener;
 
   nsTArray<nsAutoPtr<OnTracksAvailableCallback>> mRunOnTracksAvailable;