Bug 1208371 - Don't dispatch conduit destruction to main thread when not needed. r?bwc draft
authorAndreas Pehrson <pehrsons@gmail.com>
Tue, 05 Jan 2016 10:16:32 +0800
changeset 342164 517b9deed7065d9318278799c1135b4a3dc1eff8
parent 342163 f338639b37cf3371012436f1f9ad163b37719f36
child 342165 9a334eadae40baa2d5f69ba4b60f455500c7d380
push id13352
push userpehrsons@gmail.com
push dateFri, 18 Mar 2016 13:49:47 +0000
reviewersbwc
bugs1208371
milestone47.0a1
Bug 1208371 - Don't dispatch conduit destruction to main thread when not needed. r?bwc In case MediaPipeline gets destructed on main thread we cannot dispatch to main thread. In this case, destroy the conduits directly. The easiest way to test this that I have found is to shut Firefox down in the middle of a PeerConnection mochitest, when the PeerConnection is still active. MozReview-Commit-ID: 3gLhtIKTkx1
media/webrtc/signaling/src/mediapipeline/MediaPipeline.h
--- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.h
+++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.h
@@ -446,16 +446,23 @@ public:
 #if !defined(MOZILLA_EXTERNAL_LINKAGE)
         , last_img_(-1)
 #endif // MOZILLA_INTERNAL_API
     {
     }
 
     ~PipelineListener()
     {
+      if (NS_IsMainThread()) {
+        // This would happen if the cycle collector is destructing us, in which
+        // case it'd be too late to dispatch something to main thread anyway.
+        conduit_ = nullptr;
+        return;
+      }
+
       // release conduit on mainthread.  Must use forget()!
       nsresult rv = NS_DispatchToMainThread(new
         ConduitDeleteEvent(conduit_.forget()));
       MOZ_ASSERT(!NS_FAILED(rv),"Could not dispatch conduit shutdown to main");
       if (NS_FAILED(rv)) {
         MOZ_CRASH();
       }
     }
@@ -608,16 +615,23 @@ class MediaPipelineReceiveAudio : public
   class PipelineListener : public GenericReceiveListener {
    public:
     PipelineListener(SourceMediaStream * source, TrackID track_id,
                      const RefPtr<MediaSessionConduit>& conduit,
                      bool queue_track);
 
     ~PipelineListener()
     {
+      if (NS_IsMainThread()) {
+        // This would happen if the cycle collector is destructing us, in which
+        // case it'd be too late to dispatch something to main thread anyway.
+        conduit_ = nullptr;
+        return;
+      }
+
       // release conduit on mainthread.  Must use forget()!
       nsresult rv = NS_DispatchToMainThread(new
         ConduitDeleteEvent(conduit_.forget()));
       MOZ_ASSERT(!NS_FAILED(rv),"Could not dispatch conduit shutdown to main");
       if (NS_FAILED(rv)) {
         MOZ_CRASH();
       }
     }