Bug 1250934: Modify MediaEngine shutdown to allow neutering the AudioDataListener r=padenot

MozReview-Commit-ID: 7LeFAbaTHMY
This commit is contained in:
Randell Jesup 2016-03-08 12:11:09 -05:00
parent 9cec436b3e
commit 8851505a96
2 changed files with 40 additions and 7 deletions

View File

@ -345,8 +345,9 @@ protected:
virtual ~WebRTCAudioDataListener() {}
public:
explicit WebRTCAudioDataListener(MediaEngineAudioSource* aAudioSource) :
mAudioSource(aAudioSource)
explicit WebRTCAudioDataListener(MediaEngineAudioSource* aAudioSource)
: mMutex("WebRTCAudioDataListener")
, mAudioSource(aAudioSource)
{}
// AudioDataListenerInterface methods
@ -354,16 +355,29 @@ public:
AudioDataValue* aBuffer, size_t aFrames,
TrackRate aRate, uint32_t aChannels) override
{
mAudioSource->NotifyOutputData(aGraph, aBuffer, aFrames, aRate, aChannels);
MutexAutoLock lock(mMutex);
if (mAudioSource) {
mAudioSource->NotifyOutputData(aGraph, aBuffer, aFrames, aRate, aChannels);
}
}
virtual void NotifyInputData(MediaStreamGraph* aGraph,
const AudioDataValue* aBuffer, size_t aFrames,
TrackRate aRate, uint32_t aChannels) override
{
mAudioSource->NotifyInputData(aGraph, aBuffer, aFrames, aRate, aChannels);
MutexAutoLock lock(mMutex);
if (mAudioSource) {
mAudioSource->NotifyInputData(aGraph, aBuffer, aFrames, aRate, aChannels);
}
}
void Shutdown()
{
MutexAutoLock lock(mMutex);
mAudioSource = nullptr;
}
private:
Mutex mMutex;
RefPtr<MediaEngineAudioSource> mAudioSource;
};
@ -459,7 +473,9 @@ public:
NS_DECL_THREADSAFE_ISUPPORTS
protected:
~MediaEngineWebRTCMicrophoneSource() { Shutdown(); }
~MediaEngineWebRTCMicrophoneSource() {
Shutdown();
}
private:
void Init();
@ -473,7 +489,9 @@ private:
ScopedCustomReleasePtr<webrtc::VoENetwork> mVoENetwork;
ScopedCustomReleasePtr<webrtc::VoEAudioProcessing> mVoEProcessing;
// accessed from the GraphDriver thread except for deletion
nsAutoPtr<AudioPacketizer<AudioDataValue, int16_t>> mPacketizer;
ScopedCustomReleasePtr<webrtc::VoEExternalMedia> mVoERenderListener;
// mMonitor protects mSources[] access/changes, and transitions of mState
// from kStarted to kStopped (which are combined with EndTrack()).

View File

@ -357,6 +357,9 @@ MediaEngineWebRTCMicrophoneSource::Start(SourceMediaStream *aStream,
aStream->RegisterForAudioMixing();
LOG(("Start audio for stream %p", aStream));
if (!mListener) {
mListener = new mozilla::WebRTCAudioDataListener(this);
}
if (mState == kStarted) {
MOZ_ASSERT(aID == mTrackID);
// Make sure we're associated with this stream
@ -418,6 +421,11 @@ MediaEngineWebRTCMicrophoneSource::Stop(SourceMediaStream *aSource, TrackID aID)
mState = kStopped;
}
if (mListener) {
// breaks a cycle, since the WebRTCAudioDataListener has a RefPtr to us
mListener->Shutdown();
mListener = nullptr;
}
mAudioInput->StopRecording(aSource);
@ -451,7 +459,8 @@ MediaEngineWebRTCMicrophoneSource::NotifyOutputData(MediaStreamGraph* aGraph,
{
}
// Called back on GraphDriver thread
// Called back on GraphDriver thread!
// Note this can be called back after ::Shutdown()
void
MediaEngineWebRTCMicrophoneSource::NotifyInputData(MediaStreamGraph* aGraph,
const AudioDataValue* aBuffer,
@ -553,6 +562,13 @@ MediaEngineWebRTCMicrophoneSource::Init()
void
MediaEngineWebRTCMicrophoneSource::Shutdown()
{
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 (!mInitDone) {
// duplicate these here in case we failed during Init()
if (mChannel != -1 && mVoENetwork) {
@ -600,7 +616,6 @@ MediaEngineWebRTCMicrophoneSource::Shutdown()
mVoEBase = nullptr;
mAudioInput = nullptr;
mListener = nullptr; // breaks a cycle, since the WebRTCAudioDataListener has a RefPtr to us
mState = kReleased;
mInitDone = false;