Bug 1404997 - P22. Make mConduit release on main thread consistent. r=pehrsons
authorJean-Yves Avenard <jyavenard@mozilla.com>
Mon, 11 Dec 2017 00:32:00 +0100
changeset 448423 09a1076a2a9fa173923d293b6496ca812e49d142
parent 448422 4b0c8c6ed4ccd0ae02d4540b5727428f4ebbe07c
child 448424 a695b9c49eda544cef788728505b4a0e985d1fce
push id8527
push userCallek@gmail.com
push dateThu, 11 Jan 2018 21:05:50 +0000
treeherdermozilla-beta@95342d212a7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspehrsons
bugs1404997
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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,