Bug 1172394 - Forward direct listeners to all inputs over a ForwardedInputTrack's lifetime. r=padenot
authorAndreas Pehrson <apehrson@mozilla.com>
Thu, 14 Nov 2019 14:56:00 +0000
changeset 501962 2516219862e8105ea4a782aaf4b55abfed95ca43
parent 501961 ae3cd36f38f669205933cb5c54e3e9a1b4144d99
child 501963 a26e7fcb649ad67e85424c4db3bde8d91f807713
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs1172394
milestone72.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 1172394 - Forward direct listeners to all inputs over a ForwardedInputTrack's lifetime. r=padenot This was not needed when inputs to a ForwardedInputTrack could not come and go, but they can now. This keeps direct listeners for a ForwardedInputTrack around until it ends, as that's the terminal state where we know we can no longer process another input. Depends on D52049 Differential Revision: https://phabricator.services.mozilla.com/D53015
dom/media/ForwardedInputTrack.cpp
--- a/dom/media/ForwardedInputTrack.cpp
+++ b/dom/media/ForwardedInputTrack.cpp
@@ -55,21 +55,16 @@ void ForwardedInputTrack::AddInput(Media
   SetInput(aPort);
   ProcessedMediaTrack::AddInput(aPort);
 }
 
 void ForwardedInputTrack::RemoveInput(MediaInputPort* aPort) {
   TRACK_LOG(LogLevel::Debug,
             ("ForwardedInputTrack %p removing input %p", this, aPort));
   MOZ_ASSERT(aPort == mInputPort);
-  nsTArray<RefPtr<DirectMediaTrackListener>> listeners(mOwnedDirectListeners);
-  for (const auto& listener : listeners) {
-    // Remove listeners while the entry still exists.
-    RemoveDirectListenerImpl(listener);
-  }
   mInputPort = nullptr;
   ProcessedMediaTrack::RemoveInput(aPort);
 }
 
 void ForwardedInputTrack::SetInput(MediaInputPort* aPort) {
   MOZ_ASSERT(aPort);
   MOZ_ASSERT(aPort->GetSource());
   MOZ_ASSERT(aPort->GetSource()->GetData());
@@ -158,16 +153,20 @@ void ForwardedInputTrack::ProcessInput(G
     AudioSegment audio;
     ProcessInputImpl(source, &audio, aFrom, aTo, aFlags);
   } else if (mType == MediaSegment::VIDEO) {
     VideoSegment video;
     ProcessInputImpl(source, &video, aFrom, aTo, aFlags);
   } else {
     MOZ_CRASH("Unknown segment type");
   }
+
+  if (mEnded) {
+    RemoveAllDirectListenersImpl();
+  }
 }
 
 void ForwardedInputTrack::SetEnabledImpl(DisabledTrackMode aMode) {
   bool enabled = aMode == DisabledTrackMode::ENABLED;
   TRACK_LOG(LogLevel::Info, ("ForwardedInputTrack %p was explicitly %s", this,
                              enabled ? "enabled" : "disabled"));
   for (DirectMediaTrackListener* listener : mOwnedDirectListeners) {
     DisabledTrackMode oldMode = mDisabledMode;