Bug 1404997 - P22. Make mConduit release on main thread consistent. r?pehrsons draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Mon, 11 Dec 2017 00:32:00 +0100
changeset 712542 4587bcde88c0d089c9168ccabc9e0e8c89ed704d
parent 712541 6f436d98eae9e7eba1aaf77d1a3ee25b8d576f0e
child 712543 80976e983656e79ca823206824e7cd27433791f9
push id93357
push userbmo:jyavenard@mozilla.com
push dateSun, 17 Dec 2017 09:29:04 +0000
reviewerspehrsons
bugs1404997
milestone59.0a1
Bug 1404997 - P22. Make mConduit release on main thread consistent. r?pehrsons There's no need for a custom class to perform this task. MozReview-Commit-ID: JxpDQVM97fl
media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
media/webrtc/signaling/src/mediapipeline/MediaPipeline.h
--- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
+++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
@@ -627,19 +627,18 @@ MediaPipeline::MediaPipeline(const std::
   } else {
     mConduit->SetTransmitterTransport(mTransport);
   }
 }
 
 MediaPipeline::~MediaPipeline()
 {
   CSFLogInfo(LOGTAG, "Destroying MediaPipeline: %s", mDescription.c_str());
-  // MediaSessionConduit insists that it be released on main.
-  RUN_ON_THREAD(
-    mMainThread, WrapRelease(mConduit.forget()), NS_DISPATCH_NORMAL);
+  NS_ReleaseOnMainThreadSystemGroup("MediaPipeline::mConduit",
+                                    mConduit.forget());
 }
 
 void
 MediaPipeline::Shutdown_m()
 {
   CSFLogInfo(LOGTAG, "%s in %s", mDescription.c_str(), __FUNCTION__);
 
   Stop();
@@ -1330,27 +1329,18 @@ public:
     , mActive(false)
     , mEnabled(false)
     , mDirectConnect(false)
   {
   }
 
   ~PipelineListener()
   {
-    if (!NS_IsMainThread()) {
-      // release conduit on mainthread.  Must use forget()!
-      nsresult rv =
-        NS_DispatchToMainThread(new ConduitDeleteEvent(mConduit.forget()));
-      MOZ_ASSERT(!NS_FAILED(rv), "Could not dispatch conduit shutdown to main");
-      if (NS_FAILED(rv)) {
-        MOZ_CRASH();
-      }
-    } else {
-      mConduit = nullptr;
-    }
+    NS_ReleaseOnMainThreadSystemGroup("MediaPipeline::mConduit",
+                                      mConduit.forget());
     if (mConverter) {
       mConverter->Shutdown();
     }
   }
 
   // Dispatches setting the internal TrackID to TRACK_INVALID to the media
   // graph thread to keep it in sync with other MediaStreamGraph operations
   // like RemoveListener() and AddListener(). The TrackID will be updated on
@@ -2213,24 +2203,18 @@ public:
       return SourceMediaStream::NotifyPullPromise::CreateAndResolve(true,
                                                                     __func__);
     });
   }
 
 private:
   ~PipelineListener()
   {
-    if (!NS_IsMainThread()) {
-      // release conduit on mainthread.  Must use forget()!
-      nsresult rv =
-        NS_DispatchToMainThread(new ConduitDeleteEvent(mConduit.forget()));
-      MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
-    } else {
-      mConduit = nullptr;
-    }
+    NS_ReleaseOnMainThreadSystemGroup("MediaPipeline::mConduit",
+                                      mConduit.forget());
   }
 
   void NotifyPullImpl(StreamTime aDesiredTime)
   {
     uint32_t samplesPer10ms = mRate / 100;
     // Determine how many frames we need.
     // As we get frames from conduit_ at the same rate as the graph's rate,
     // the number of frames needed straightfully determined.
--- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.h
+++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.h
@@ -309,32 +309,16 @@ private:
   // Gets the current time as a DOMHighResTimeStamp
   static DOMHighResTimeStamp GetNow();
 
   bool IsRtp(const unsigned char* aData, size_t aLen) const;
   // Must be called on the STS thread.  Must be called after DetachMedia().
   void DetachTransport_s();
 };
 
-class ConduitDeleteEvent : public Runnable
-{
-public:
-  explicit ConduitDeleteEvent(already_AddRefed<MediaSessionConduit> aConduit)
-    : Runnable("ConduitDeleteEvent")
-    , mConduit(aConduit)
-  {
-  }
-
-  /* we exist solely to proxy release of the conduit */
-  NS_IMETHOD Run() override { return NS_OK; }
-
-private:
-  const RefPtr<MediaSessionConduit> mConduit;
-};
-
 // A specialization of pipeline for reading from an input device
 // and transmitting to the network.
 class MediaPipelineTransmit : public MediaPipeline
 {
 public:
   // Set aRtcpTransport to nullptr to use rtcp-mux
   MediaPipelineTransmit(const std::string& aPc,
                         nsCOMPtr<nsIEventTarget> aMainThread,