Bug 1573102 - Remove MediaStreamGraphImpl strong-refs from MediaEngineWebRTCAudio. r=karlt
authorAndreas Pehrson <apehrson@mozilla.com>
Thu, 29 Aug 2019 13:33:08 +0000
changeset 554432 08faaf9d4ef714eea2daea43c137cd02609830e5
parent 554431 c9807cc4506756639c2d48803fa5fc302871bab6
child 554433 fcc8383a1c4f04e0309463c778d6aeaa9aa7acdf
push id2165
push userffxbld-merge
push dateMon, 14 Oct 2019 16:30:58 +0000
treeherdermozilla-release@0eae18af659f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt
bugs1573102
milestone70.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 1573102 - Remove MediaStreamGraphImpl strong-refs from MediaEngineWebRTCAudio. r=karlt Differential Revision: https://phabricator.services.mozilla.com/D43668
dom/media/webrtc/MediaEngineWebRTCAudio.cpp
--- a/dom/media/webrtc/MediaEngineWebRTCAudio.cpp
+++ b/dom/media/webrtc/MediaEngineWebRTCAudio.cpp
@@ -167,20 +167,18 @@ nsresult MediaEngineWebRTCMicrophoneSour
 }
 
 void MediaEngineWebRTCMicrophoneSource::UpdateAECSettings(
     bool aEnable, bool aUseAecMobile,
     EchoCancellation::SuppressionLevel aLevel) {
   AssertIsOnOwningThread();
 
   RefPtr<MediaEngineWebRTCMicrophoneSource> that = this;
-  RefPtr<MediaStreamGraphImpl> gripGraph = mStream->GraphImpl();
   NS_DispatchToMainThread(NS_NewRunnableFunction(
-      __func__,
-      [that, graph = std::move(gripGraph), aEnable, aUseAecMobile, aLevel] {
+      __func__, [that, stream = mStream, aEnable, aUseAecMobile, aLevel] {
         class Message : public ControlMessage {
          public:
           Message(AudioInputProcessing* aInputProcessing, bool aEnable,
                   bool aUseAecMobile, EchoCancellation::SuppressionLevel aLevel)
               : ControlMessage(nullptr),
                 mInputProcessing(aInputProcessing),
                 mEnable(aEnable),
                 mUseAecMobile(aUseAecMobile),
@@ -192,31 +190,32 @@ void MediaEngineWebRTCMicrophoneSource::
 
          protected:
           RefPtr<AudioInputProcessing> mInputProcessing;
           bool mEnable;
           bool mUseAecMobile;
           EchoCancellation::SuppressionLevel mLevel;
         };
 
-        if (graph) {
-          graph->AppendMessage(MakeUnique<Message>(
-              that->mInputProcessing, aEnable, aUseAecMobile, aLevel));
+        if (stream->IsDestroyed()) {
+          return;
         }
+
+        stream->GraphImpl()->AppendMessage(MakeUnique<Message>(
+            that->mInputProcessing, aEnable, aUseAecMobile, aLevel));
       }));
 }
 
 void MediaEngineWebRTCMicrophoneSource::UpdateAGCSettings(
     bool aEnable, GainControl::Mode aMode) {
   AssertIsOnOwningThread();
 
   RefPtr<MediaEngineWebRTCMicrophoneSource> that = this;
-  RefPtr<MediaStreamGraphImpl> gripGraph = mStream->GraphImpl();
   NS_DispatchToMainThread(NS_NewRunnableFunction(
-      __func__, [that, graph = std::move(gripGraph), aEnable, aMode] {
+      __func__, [that, stream = mStream, aEnable, aMode] {
         class Message : public ControlMessage {
          public:
           Message(AudioInputProcessing* aInputProcessing, bool aEnable,
                   GainControl::Mode aMode)
               : ControlMessage(nullptr),
                 mInputProcessing(aInputProcessing),
                 mEnable(aEnable),
                 mMode(aMode) {}
@@ -226,31 +225,32 @@ void MediaEngineWebRTCMicrophoneSource::
           }
 
          protected:
           RefPtr<AudioInputProcessing> mInputProcessing;
           bool mEnable;
           GainControl::Mode mMode;
         };
 
-        if (graph) {
-          graph->AppendMessage(
-              MakeUnique<Message>(that->mInputProcessing, aEnable, aMode));
+        if (stream->IsDestroyed()) {
+          return;
         }
+
+        stream->GraphImpl()->AppendMessage(
+            MakeUnique<Message>(that->mInputProcessing, aEnable, aMode));
       }));
 }
 
 void MediaEngineWebRTCMicrophoneSource::UpdateNSSettings(
     bool aEnable, webrtc::NoiseSuppression::Level aLevel) {
   AssertIsOnOwningThread();
 
   RefPtr<MediaEngineWebRTCMicrophoneSource> that = this;
-  RefPtr<MediaStreamGraphImpl> gripGraph = mStream->GraphImpl();
   NS_DispatchToMainThread(NS_NewRunnableFunction(
-      __func__, [that, graph = std::move(gripGraph), aEnable, aLevel] {
+      __func__, [that, stream = mStream, aEnable, aLevel] {
         class Message : public ControlMessage {
          public:
           Message(AudioInputProcessing* aInputProcessing, bool aEnable,
                   webrtc::NoiseSuppression::Level aLevel)
               : ControlMessage(nullptr),
                 mInputProcessing(aInputProcessing),
                 mEnable(aEnable),
                 mLevel(aLevel) {}
@@ -260,32 +260,32 @@ void MediaEngineWebRTCMicrophoneSource::
           }
 
          protected:
           RefPtr<AudioInputProcessing> mInputProcessing;
           bool mEnable;
           webrtc::NoiseSuppression::Level mLevel;
         };
 
-        if (graph) {
-          graph->AppendMessage(
-              MakeUnique<Message>(that->mInputProcessing, aEnable, aLevel));
+        if (stream->IsDestroyed()) {
+          return;
         }
+
+        stream->GraphImpl()->AppendMessage(
+            MakeUnique<Message>(that->mInputProcessing, aEnable, aLevel));
       }));
 }
 
 void MediaEngineWebRTCMicrophoneSource::UpdateAPMExtraOptions(
     bool aExtendedFilter, bool aDelayAgnostic) {
   AssertIsOnOwningThread();
 
   RefPtr<MediaEngineWebRTCMicrophoneSource> that = this;
-  RefPtr<MediaStreamGraphImpl> gripGraph = mStream->GraphImpl();
   NS_DispatchToMainThread(NS_NewRunnableFunction(
-      __func__,
-      [that, graph = std::move(gripGraph), aExtendedFilter, aDelayAgnostic] {
+      __func__, [that, stream = mStream, aExtendedFilter, aDelayAgnostic] {
         class Message : public ControlMessage {
          public:
           Message(AudioInputProcessing* aInputProcessing, bool aExtendedFilter,
                   bool aDelayAgnostic)
               : ControlMessage(nullptr),
                 mInputProcessing(aInputProcessing),
                 mExtendedFilter(aExtendedFilter),
                 mDelayAgnostic(aDelayAgnostic) {}
@@ -296,20 +296,22 @@ void MediaEngineWebRTCMicrophoneSource::
           }
 
          protected:
           RefPtr<AudioInputProcessing> mInputProcessing;
           bool mExtendedFilter;
           bool mDelayAgnostic;
         };
 
-        if (graph) {
-          graph->AppendMessage(MakeUnique<Message>(
-              that->mInputProcessing, aExtendedFilter, aDelayAgnostic));
+        if (stream->IsDestroyed()) {
+          return;
         }
+
+        stream->GraphImpl()->AppendMessage(MakeUnique<Message>(
+            that->mInputProcessing, aExtendedFilter, aDelayAgnostic));
       }));
 }
 
 void MediaEngineWebRTCMicrophoneSource::ApplySettings(
     const MediaEnginePrefs& aPrefs) {
   AssertIsOnOwningThread();
 
   MOZ_ASSERT(
@@ -325,19 +327,18 @@ void MediaEngineWebRTCMicrophoneSource::
     UpdateAECSettings(
         aPrefs.mAecOn, aPrefs.mUseAecMobile,
         static_cast<webrtc::EchoCancellation::SuppressionLevel>(aPrefs.mAec));
 
     UpdateAPMExtraOptions(mExtendedFilter, mDelayAgnostic);
   }
 
   RefPtr<MediaEngineWebRTCMicrophoneSource> that = this;
-  RefPtr<MediaStreamGraphImpl> graphImpl = mStream->GraphImpl();
   NS_DispatchToMainThread(NS_NewRunnableFunction(
-      __func__, [that, graph = std::move(graphImpl), prefs = aPrefs] {
+      __func__, [that, stream = mStream, prefs = aPrefs] {
         that->mSettings->mEchoCancellation.Value() = prefs.mAecOn;
         that->mSettings->mAutoGainControl.Value() = prefs.mAgcOn;
         that->mSettings->mNoiseSuppression.Value() = prefs.mNoiseOn;
         that->mSettings->mChannelCount.Value() = prefs.mChannels;
 
         class Message : public ControlMessage {
          public:
           Message(AudioInputProcessing* aInputProcessing, bool aPassThrough,
@@ -355,20 +356,22 @@ void MediaEngineWebRTCMicrophoneSource::
 
          protected:
           RefPtr<AudioInputProcessing> mInputProcessing;
           bool mPassThrough;
           uint32_t mRequestedInputChannelCount;
         };
 
         bool passThrough = !(prefs.mAecOn || prefs.mAgcOn || prefs.mNoiseOn);
-        if (graph) {
-          graph->AppendMessage(MakeUnique<Message>(
-              that->mInputProcessing, passThrough, prefs.mChannels));
+        if (stream->IsDestroyed()) {
+          return;
         }
+
+        stream->GraphImpl()->AppendMessage(MakeUnique<Message>(
+            that->mInputProcessing, passThrough, prefs.mChannels));
       }));
 }
 
 nsresult MediaEngineWebRTCMicrophoneSource::Allocate(
     const dom::MediaTrackConstraints& aConstraints,
     const MediaEnginePrefs& aPrefs, const ipc::PrincipalInfo& aPrincipalInfo,
     const char** aOutBadConstraint) {
   AssertIsOnOwningThread();
@@ -417,28 +420,26 @@ nsresult MediaEngineWebRTCMicrophoneSour
     }
 
    protected:
     RefPtr<AudioInputProcessing> mInputProcessing;
     TrackID mTrackID;
   };
 
   if (mStream && IsTrackIDExplicit(mTrackID)) {
-    RefPtr<MediaStream> sourceStream = mStream;
     RefPtr<AudioInputProcessing> inputProcessing = mInputProcessing;
     NS_DispatchToMainThread(NS_NewRunnableFunction(
-        __func__, [stream = std::move(sourceStream),
-                   audioInputProcessing = std::move(inputProcessing),
-                   trackID = mTrackID] {
+        __func__,
+        [stream = mStream, audioInputProcessing = std::move(inputProcessing),
+         trackID = mTrackID] {
           if (stream->IsDestroyed()) {
             // This stream has already been destroyed on main thread by its
             // DOMMediaStream. No cleanup left to do.
             return;
           }
-          MOZ_ASSERT(stream->GraphImpl());
           stream->GraphImpl()->AppendMessage(MakeUnique<EndTrackMessage>(
               stream, audioInputProcessing, trackID));
         }));
   }
 
   MOZ_ASSERT(mTrackID != TRACK_NONE, "Only deallocate once");
 
   // Reset all state. This is not strictly necessary, this instance will get