From 4ca24c269d72bfc93890d75ec931173fe61d7dd3 Mon Sep 17 00:00:00 2001 From: Andreas Pehrson Date: Thu, 29 Aug 2019 13:33:08 +0000 Subject: [PATCH] Bug 1573102 - Remove MediaStreamGraphImpl strong-refs from MediaEngineWebRTCAudio. r=karlt Differential Revision: https://phabricator.services.mozilla.com/D43668 --HG-- extra : moz-landing-system : lando --- dom/media/webrtc/MediaEngineWebRTCAudio.cpp | 65 +++++++++++---------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/dom/media/webrtc/MediaEngineWebRTCAudio.cpp b/dom/media/webrtc/MediaEngineWebRTCAudio.cpp index 1d04ab1b6b47..98a7732baa18 100644 --- a/dom/media/webrtc/MediaEngineWebRTCAudio.cpp +++ b/dom/media/webrtc/MediaEngineWebRTCAudio.cpp @@ -172,10 +172,8 @@ void MediaEngineWebRTCMicrophoneSource::UpdateAECSettings( AssertIsOnOwningThread(); RefPtr that = this; - RefPtr 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, @@ -197,10 +195,12 @@ void MediaEngineWebRTCMicrophoneSource::UpdateAECSettings( EchoCancellation::SuppressionLevel mLevel; }; - if (graph) { - graph->AppendMessage(MakeUnique( - that->mInputProcessing, aEnable, aUseAecMobile, aLevel)); + if (stream->IsDestroyed()) { + return; } + + stream->GraphImpl()->AppendMessage(MakeUnique( + that->mInputProcessing, aEnable, aUseAecMobile, aLevel)); })); } @@ -209,9 +209,8 @@ void MediaEngineWebRTCMicrophoneSource::UpdateAGCSettings( AssertIsOnOwningThread(); RefPtr that = this; - RefPtr 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, @@ -231,10 +230,12 @@ void MediaEngineWebRTCMicrophoneSource::UpdateAGCSettings( GainControl::Mode mMode; }; - if (graph) { - graph->AppendMessage( - MakeUnique(that->mInputProcessing, aEnable, aMode)); + if (stream->IsDestroyed()) { + return; } + + stream->GraphImpl()->AppendMessage( + MakeUnique(that->mInputProcessing, aEnable, aMode)); })); } @@ -243,9 +244,8 @@ void MediaEngineWebRTCMicrophoneSource::UpdateNSSettings( AssertIsOnOwningThread(); RefPtr that = this; - RefPtr 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, @@ -265,10 +265,12 @@ void MediaEngineWebRTCMicrophoneSource::UpdateNSSettings( webrtc::NoiseSuppression::Level mLevel; }; - if (graph) { - graph->AppendMessage( - MakeUnique(that->mInputProcessing, aEnable, aLevel)); + if (stream->IsDestroyed()) { + return; } + + stream->GraphImpl()->AppendMessage( + MakeUnique(that->mInputProcessing, aEnable, aLevel)); })); } @@ -277,10 +279,8 @@ void MediaEngineWebRTCMicrophoneSource::UpdateAPMExtraOptions( AssertIsOnOwningThread(); RefPtr that = this; - RefPtr 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, @@ -301,10 +301,12 @@ void MediaEngineWebRTCMicrophoneSource::UpdateAPMExtraOptions( bool mDelayAgnostic; }; - if (graph) { - graph->AppendMessage(MakeUnique( - that->mInputProcessing, aExtendedFilter, aDelayAgnostic)); + if (stream->IsDestroyed()) { + return; } + + stream->GraphImpl()->AppendMessage(MakeUnique( + that->mInputProcessing, aExtendedFilter, aDelayAgnostic)); })); } @@ -330,9 +332,8 @@ void MediaEngineWebRTCMicrophoneSource::ApplySettings( } RefPtr that = this; - RefPtr 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; @@ -360,10 +361,12 @@ void MediaEngineWebRTCMicrophoneSource::ApplySettings( }; bool passThrough = !(prefs.mAecOn || prefs.mAgcOn || prefs.mNoiseOn); - if (graph) { - graph->AppendMessage(MakeUnique( - that->mInputProcessing, passThrough, prefs.mChannels)); + if (stream->IsDestroyed()) { + return; } + + stream->GraphImpl()->AppendMessage(MakeUnique( + that->mInputProcessing, passThrough, prefs.mChannels)); })); } @@ -422,18 +425,16 @@ nsresult MediaEngineWebRTCMicrophoneSource::Deallocate() { }; if (mStream && IsTrackIDExplicit(mTrackID)) { - RefPtr sourceStream = mStream; RefPtr 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( stream, audioInputProcessing, trackID)); }));