Bug 1378067 - Label more runnables in dom/media (GraphDriver.cpp, CubebUtils.cpp, DOMMediaStream.cpp). r=jesup
authorPaul Adenot <paul@paul.cx>
Tue, 18 Jul 2017 11:26:58 +0200
changeset 369563 38615ea1031444020b37b34a7c759e15a2b2e6bf
parent 369562 5015dd6551326119159b1252ffb216739983c05a
child 369564 b669da0374a2d7d7d946983865c0a799362725d9
push id32199
push userryanvm@gmail.com
push dateWed, 19 Jul 2017 14:00:47 +0000
treeherdermozilla-central@c5ea72577f79 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs1378067
milestone56.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 1378067 - Label more runnables in dom/media (GraphDriver.cpp, CubebUtils.cpp, DOMMediaStream.cpp). r=jesup MozReview-Commit-ID: EQzR1AfzvzE
dom/media/CubebUtils.cpp
dom/media/DOMMediaStream.cpp
dom/media/GraphDriver.cpp
dom/media/webaudio/WebAudioUtils.cpp
--- a/dom/media/CubebUtils.cpp
+++ b/dom/media/CubebUtils.cpp
@@ -420,17 +420,17 @@ Maybe<uint32_t> GetCubebMSGLatencyInFram
 void InitLibrary()
 {
   Preferences::RegisterCallbackAndCall(PrefChanged, PREF_VOLUME_SCALE);
   Preferences::RegisterCallbackAndCall(PrefChanged, PREF_CUBEB_LATENCY_PLAYBACK);
   Preferences::RegisterCallbackAndCall(PrefChanged, PREF_CUBEB_LATENCY_MSG);
   Preferences::RegisterCallbackAndCall(PrefChanged, PREF_CUBEB_BACKEND);
   Preferences::RegisterCallbackAndCall(PrefChanged, PREF_CUBEB_LOG_LEVEL);
 #ifndef MOZ_WIDGET_ANDROID
-  NS_DispatchToMainThread(
+  AbstractThread::MainThread()->Dispatch(
     NS_NewRunnableFunction("CubebUtils::InitLibrary", &InitBrandName));
 #endif
 }
 
 void ShutdownLibrary()
 {
   Preferences::UnregisterCallback(PrefChanged, PREF_VOLUME_SCALE);
   Preferences::UnregisterCallback(PrefChanged, PREF_CUBEB_BACKEND);
--- a/dom/media/DOMMediaStream.cpp
+++ b/dom/media/DOMMediaStream.cpp
@@ -142,18 +142,19 @@ NS_IMPL_CYCLE_COLLECTION_0(MediaStreamTr
 class DOMMediaStream::OwnedStreamListener : public MediaStreamListener {
 public:
   explicit OwnedStreamListener(DOMMediaStream* aStream)
     : mStream(aStream)
   {}
 
   void Forget() { mStream = nullptr; }
 
-  void DoNotifyTrackCreated(TrackID aTrackID, MediaSegment::Type aType,
-                            MediaStream* aInputStream, TrackID aInputTrackID)
+  void DoNotifyTrackCreated(MediaStreamGraph* aGraph, TrackID aTrackID,
+                            MediaSegment::Type aType, MediaStream* aInputStream,
+                            TrackID aInputTrackID)
   {
     MOZ_ASSERT(NS_IsMainThread());
 
     if (!mStream) {
       return;
     }
 
     MediaStreamTrack* track =
@@ -181,70 +182,72 @@ public:
       nsPIDOMWindowInner* window = mStream->GetParentObject();
       nsIDocument* doc = window ? window->GetExtantDoc() : nullptr;
       nsIPrincipal* principal = doc ? doc->NodePrincipal() : nullptr;
       source = new BasicTrackSource(principal);
     }
 
     RefPtr<MediaStreamTrack> newTrack =
       mStream->CreateDOMTrack(aTrackID, aType, source);
-    NS_DispatchToMainThread(NewRunnableMethod<RefPtr<MediaStreamTrack>>(
+    aGraph->AbstractMainThread()->Dispatch(NewRunnableMethod<RefPtr<MediaStreamTrack>>(
       "DOMMediaStream::AddTrackInternal",
       mStream,
       &DOMMediaStream::AddTrackInternal,
       newTrack));
   }
 
-  void DoNotifyTrackEnded(MediaStream* aInputStream, TrackID aInputTrackID,
-                          TrackID aTrackID)
+  void DoNotifyTrackEnded(MediaStreamGraph* aGraph, MediaStream* aInputStream,
+                          TrackID aInputTrackID, TrackID aTrackID)
   {
     MOZ_ASSERT(NS_IsMainThread());
 
     if (!mStream) {
       return;
     }
 
     RefPtr<MediaStreamTrack> track =
       mStream->FindOwnedDOMTrack(aInputStream, aInputTrackID, aTrackID);
     NS_ASSERTION(track, "Owned MediaStreamTracks must be known by the DOMMediaStream");
     if (track) {
       LOG(LogLevel::Debug, ("DOMMediaStream %p MediaStreamTrack %p ended at the source. Marking it ended.",
                             mStream, track.get()));
-      NS_DispatchToMainThread(
+      aGraph->AbstractMainThread()->Dispatch(
         NewRunnableMethod("dom::MediaStreamTrack::OverrideEnded",
                           track,
                           &MediaStreamTrack::OverrideEnded));
     }
   }
 
   void NotifyQueuedTrackChanges(MediaStreamGraph* aGraph, TrackID aID,
                                 StreamTime aTrackOffset, TrackEventCommand aTrackEvents,
                                 const MediaSegment& aQueuedMedia,
                                 MediaStream* aInputStream,
                                 TrackID aInputTrackID) override
   {
     if (aTrackEvents & TrackEventCommand::TRACK_EVENT_CREATED) {
       aGraph->DispatchToMainThreadAfterStreamStateUpdate(
-        NewRunnableMethod<TrackID,
+        NewRunnableMethod<MediaStreamGraph*, TrackID,
                           MediaSegment::Type,
                           RefPtr<MediaStream>,
                           TrackID>(
           "DOMMediaStream::OwnedStreamListener::DoNotifyTrackCreated",
           this,
           &OwnedStreamListener::DoNotifyTrackCreated,
+          aGraph,
           aID,
           aQueuedMedia.GetType(),
           aInputStream,
           aInputTrackID));
     } else if (aTrackEvents & TrackEventCommand::TRACK_EVENT_ENDED) {
       aGraph->DispatchToMainThreadAfterStreamStateUpdate(
-        NewRunnableMethod<RefPtr<MediaStream>, TrackID, TrackID>(
+        NewRunnableMethod<MediaStreamGraph*, RefPtr<MediaStream>, TrackID, TrackID>(
           "DOMMediaStream::OwnedStreamListener::DoNotifyTrackEnded",
           this,
           &OwnedStreamListener::DoNotifyTrackEnded,
+          aGraph,
           aInputStream,
           aInputTrackID,
           aID));
     }
   }
 
 private:
   // These fields may only be accessed on the main thread
@@ -274,33 +277,35 @@ public:
 
     if (!mStream) {
       return;
     }
 
     // The owned stream listener adds its tracks after another main thread
     // dispatch. We have to do the same to notify of created tracks to stay
     // in sync. (Or NotifyTracksCreated is called before tracks are added).
-    NS_DispatchToMainThread(
+    MOZ_ASSERT(mStream->GetPlaybackStream());
+    mStream->GetPlaybackStream()->Graph()->AbstractMainThread()->Dispatch(
       NewRunnableMethod("DOMMediaStream::NotifyTracksCreated",
                         mStream,
                         &DOMMediaStream::NotifyTracksCreated));
   }
 
   void DoNotifyFinished()
   {
     MOZ_ASSERT(NS_IsMainThread());
 
     if (!mStream) {
       return;
     }
 
-    NS_DispatchToMainThread(NewRunnableMethod("DOMMediaStream::NotifyFinished",
-                                              mStream,
-                                              &DOMMediaStream::NotifyFinished));
+    mStream->GetPlaybackStream()->Graph()->AbstractMainThread()->Dispatch(
+        NewRunnableMethod("DOMMediaStream::NotifyFinished",
+                          mStream,
+                          &DOMMediaStream::NotifyFinished));
   }
 
   // The methods below are called on the MediaStreamGraph thread.
 
   void NotifyFinishedTrackCreation(MediaStreamGraph* aGraph) override
   {
     aGraph->DispatchToMainThreadAfterStreamStateUpdate(
       NewRunnableMethod(
--- a/dom/media/GraphDriver.cpp
+++ b/dom/media/GraphDriver.cpp
@@ -160,19 +160,20 @@ private:
   nsCOMPtr<nsIThread> mThread;
 };
 
 ThreadedDriver::~ThreadedDriver()
 {
   if (mThread) {
     nsCOMPtr<nsIRunnable> event =
       new MediaStreamGraphShutdownThreadRunnable(mThread.forget());
-    NS_DispatchToMainThread(event);
+    GraphImpl()->Dispatch(event.forget());
   }
 }
+
 class MediaStreamGraphInitThreadRunnable : public Runnable {
 public:
   explicit MediaStreamGraphInitThreadRunnable(ThreadedDriver* aDriver)
     : Runnable("MediaStreamGraphInitThreadRunnable")
     , mDriver(aDriver)
   {
   }
   NS_IMETHOD Run() override
@@ -488,20 +489,21 @@ AsyncCubebTask::EnsureThread()
   if (!sThreadPool) {
     nsCOMPtr<nsIThreadPool> threadPool =
       SharedThreadPool::Get(NS_LITERAL_CSTRING("CubebOperation"), 1);
     sThreadPool = threadPool;
     // Need to null this out before xpcom-shutdown-threads Observers run
     // since we don't know the order that the shutdown-threads observers
     // will run.  ClearOnShutdown guarantees it runs first.
     if (!NS_IsMainThread()) {
-      NS_DispatchToMainThread(
+      nsCOMPtr<nsIRunnable> runnable =
         NS_NewRunnableFunction("AsyncCubebTask::EnsureThread", []() -> void {
           ClearOnShutdown(&sThreadPool, ShutdownPhase::ShutdownThreads);
-        }));
+        });
+      AbstractThread::MainThread()->Dispatch(runnable.forget());
     } else {
       ClearOnShutdown(&sThreadPool, ShutdownPhase::ShutdownThreads);
     }
 
     const uint32_t kIdleThreadTimeoutMs = 2000;
 
     nsresult rv = sThreadPool->SetIdleThreadTimeout(PR_MillisecondsToInterval(kIdleThreadTimeoutMs));
     if (NS_WARN_IF(NS_FAILED(rv))) {
--- a/dom/media/webaudio/WebAudioUtils.cpp
+++ b/dom/media/webaudio/WebAudioUtils.cpp
@@ -98,18 +98,19 @@ WebAudioUtils::LogToDeveloperConsole(uin
 {
   // This implementation is derived from dom/media/VideoUtils.cpp, but we
   // use a windowID so that the message is delivered to the developer console.
   // It is similar to ContentUtils::ReportToConsole, but also works off main
   // thread.
   if (!NS_IsMainThread()) {
     nsCOMPtr<nsIRunnable> task = NS_NewRunnableFunction(
       "dom::WebAudioUtils::LogToDeveloperConsole",
-      [aWindowID, aKey]() { LogToDeveloperConsole(aWindowID, aKey); });
-    NS_DispatchToMainThread(task.forget(), NS_DISPATCH_NORMAL);
+      [aWindowID, aKey] { LogToDeveloperConsole(aWindowID, aKey); });
+    SystemGroup::Dispatch("dom::WebAudioUtils::LogToDeveloperConsole",
+        TaskCategory::Other, task.forget());
     return;
   }
 
   nsCOMPtr<nsIConsoleService> console(
     do_GetService("@mozilla.org/consoleservice;1"));
   if (!console) {
     NS_WARNING("Failed to log message to console.");
     return;