Bug 1293976: make mAudioInputs use RefPtrs r=pehrsons a=abillings
authorRandell Jesup <rjesup@jesup.org>
Wed, 17 Aug 2016 16:31:56 -0400
changeset 340367 27e2b6774c007e81482176828283c9ee1d2c2960
parent 340366 f3e74826733db6303a374c6878871a347a32120a
child 340368 8ea0c38aae0b5cdb76bc32f59938424fbde469df
push id6315
push userrjesup@wgate.com
push dateThu, 18 Aug 2016 05:19:36 +0000
treeherdermozilla-beta@8ea0c38aae0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspehrsons, abillings
bugs1293976
milestone49.0
Bug 1293976: make mAudioInputs use RefPtrs r=pehrsons a=abillings MozReview-Commit-ID: J6WZSz8xpwu
dom/media/MediaStreamGraph.cpp
dom/media/MediaStreamGraph.h
dom/media/webrtc/MediaEngineWebRTC.h
--- a/dom/media/MediaStreamGraph.cpp
+++ b/dom/media/MediaStreamGraph.cpp
@@ -1154,17 +1154,17 @@ MediaStreamGraphImpl::OpenAudioInputImpl
 nsresult
 MediaStreamGraphImpl::OpenAudioInput(int aID,
                                      AudioDataListener *aListener)
 {
   // So, so, so annoying.  Can't AppendMessage except on Mainthread
   if (!NS_IsMainThread()) {
     NS_DispatchToMainThread(WrapRunnable(this,
                                          &MediaStreamGraphImpl::OpenAudioInput,
-                                         aID, aListener));
+                                         aID, RefPtr<AudioDataListener>(aListener)));
     return NS_OK;
   }
   class Message : public ControlMessage {
   public:
     Message(MediaStreamGraphImpl *aGraph, int aID,
             AudioDataListener *aListener) :
       ControlMessage(nullptr), mGraph(aGraph), mID(aID), mListener(aListener) {}
     virtual void Run()
@@ -1223,17 +1223,17 @@ MediaStreamGraphImpl::CloseAudioInputImp
 
 void
 MediaStreamGraphImpl::CloseAudioInput(AudioDataListener *aListener)
 {
   // So, so, so annoying.  Can't AppendMessage except on Mainthread
   if (!NS_IsMainThread()) {
     NS_DispatchToMainThread(WrapRunnable(this,
                                          &MediaStreamGraphImpl::CloseAudioInput,
-                                         aListener));
+                                         RefPtr<AudioDataListener>(aListener)));
     return;
   }
   class Message : public ControlMessage {
   public:
     Message(MediaStreamGraphImpl *aGraph, AudioDataListener *aListener) :
       ControlMessage(nullptr), mGraph(aGraph), mListener(aListener) {}
     virtual void Run()
     {
--- a/dom/media/MediaStreamGraph.h
+++ b/dom/media/MediaStreamGraph.h
@@ -1598,17 +1598,16 @@ protected:
   /**
    * Sample rate at which this graph runs. For real time graphs, this is
    * the rate of the audio mixer. For offline graphs, this is the rate specified
    * at construction.
    */
   TrackRate mSampleRate;
 
   /**
-   * Lifetime is controlled by OpenAudioInput/CloseAudioInput.  Destroying the listener
-   * without removing it is an error; callers should assert on that.
+   * CloseAudioInput is async, so hold a reference here.
    */
-  nsTArray<AudioDataListener *> mAudioInputs;
+  nsTArray<RefPtr<AudioDataListener>> mAudioInputs;
 };
 
 } // namespace mozilla
 
 #endif /* MOZILLA_MEDIASTREAMGRAPH_H_ */
--- a/dom/media/webrtc/MediaEngineWebRTC.h
+++ b/dom/media/webrtc/MediaEngineWebRTC.h
@@ -390,16 +390,17 @@ public:
   {
     MutexAutoLock lock(mMutex);
     if (mAudioSource) {
       mAudioSource->NotifyInputData(aGraph, aBuffer, aFrames, aRate, aChannels);
     }
   }
   virtual void DeviceChanged() override
   {
+    MutexAutoLock lock(mMutex);
     if (mAudioSource) {
       mAudioSource->DeviceChanged();
     }
   }
 
   void Shutdown()
   {
     MutexAutoLock lock(mMutex);