Bug 1435673 - Clean up WebRTCAudioDataListener in Deallocate(). r?padenot
MozReview-Commit-ID: LKRbMHFXtSq
--- a/dom/media/webrtc/MediaEngineWebRTCAudio.cpp
+++ b/dom/media/webrtc/MediaEngineWebRTCAudio.cpp
@@ -612,16 +612,21 @@ MediaEngineWebRTCMicrophoneSource::Deall
if (mAllocations.IsEmpty()) {
// If empty, no callbacks to deliver data should be occuring
MOZ_ASSERT(mState != kReleased, "Source not allocated");
MOZ_ASSERT(mState != kStarted, "Source not stopped");
MOZ_ASSERT(sChannelsOpen > 0);
--sChannelsOpen;
MutexAutoLock lock(mMutex);
+ if (mListener) {
+ // breaks a cycle, since the WebRTCAudioDataListener has a RefPtr to us
+ mListener->Shutdown();
+ mListener = nullptr;
+ }
mState = kReleased;
LOG(("Audio device %d deallocated", mCapIndex));
} else {
LOG(("Audio device %d deallocated but still in use", mCapIndex));
}
return NS_OK;
}
@@ -743,22 +748,16 @@ MediaEngineWebRTCMicrophoneSource::Stop(
// Another track is keeping us from stopping
return NS_OK;
}
MOZ_ASSERT(mState == kStarted, "Should be started when stopping");
mState = kStopped;
}
- if (mListener) {
- // breaks a cycle, since the WebRTCAudioDataListener has a RefPtr to us
- mListener->Shutdown();
- mListener = nullptr;
- }
-
return NS_OK;
}
void
MediaEngineWebRTCMicrophoneSource::Pull(const RefPtr<const AllocationHandle>& aHandle,
const RefPtr<SourceMediaStream>& aStream,
TrackID aTrackID,
StreamTime aDesiredTime,
@@ -1132,23 +1131,16 @@ MediaEngineWebRTCMicrophoneSource::Devic
ResetProcessingIfNeeded(noise_suppression);
}
void
MediaEngineWebRTCMicrophoneSource::Shutdown()
{
AssertIsOnOwningThread();
- if (mListener) {
- // breaks a cycle, since the WebRTCAudioDataListener has a RefPtr to us
- mListener->Shutdown();
- // Don't release the webrtc.org pointers yet until the Listener is (async) shutdown
- mListener = nullptr;
- }
-
if (mState == kStarted) {
for (const Allocation& allocation : mAllocations) {
if (allocation.mEnabled) {
Stop(allocation.mHandle);
}
}
MOZ_ASSERT(mState == kStopped);
}