Bug 1641161 remove some graph-thread LIFECYCLE_RUNNING conditions r=padenot
authorKarl Tomlinson <karlt+@karlt.net>
Wed, 27 May 2020 08:41:12 +0000
changeset 532352 806573d7d69a90ea111a3b235f5fa1f45bd70b4f
parent 532351 7bae1eadb123675a0b56815f8fe20002fc8f39cb
child 532353 1823eb201ef68f7f4ba6f250c6449de53230f3f5
push id37454
push userccoroiu@mozilla.com
push dateWed, 27 May 2020 16:14:31 +0000
treeherdermozilla-central@a1dd9afbfdf5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs1641161
milestone78.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 1641161 remove some graph-thread LIFECYCLE_RUNNING conditions r=padenot On the graph thread, mLifecycleState is known to be LIFECYCLE_RUNNING. OpenAudioInputImpl(), CloseAudioInputImpl(), AddAudioOutputImpl() are called only from ControlMessage::Run(), not RunDuringShutdown(). These conditions were first added in https://hg.mozilla.org/mozilla-central/rev/dcd375e2750d425af210fee36962219a97a334fd#l3.12 but I don't know why. Differential Revision: https://phabricator.services.mozilla.com/D76802
dom/media/MediaTrackGraph.cpp
--- a/dom/media/MediaTrackGraph.cpp
+++ b/dom/media/MediaTrackGraph.cpp
@@ -293,36 +293,30 @@ void MediaTrackGraphImpl::UpdateTrackOrd
   uint32_t graphOutputChannelCount = AudioOutputChannelCount();
 
   // Note that this looks for any audio tracks, input or output, and switches
   // to a SystemClockDriver if there are none.  However, if another is already
   // pending, let that switch happen.
 
   if (!audioTrackPresent && mRealtime &&
       CurrentDriver()->AsAudioCallbackDriver()) {
-    MonitorAutoLock mon(mMonitor);
     if (CurrentDriver()->AsAudioCallbackDriver()->IsStarted() && !Switching()) {
-      if (LifecycleStateRef() == LIFECYCLE_RUNNING) {
-        SwitchAtNextIteration(
-            new SystemClockDriver(this, CurrentDriver(), mSampleRate));
-      }
+      SwitchAtNextIteration(
+          new SystemClockDriver(this, CurrentDriver(), mSampleRate));
     }
   }
 
   if (audioTrackPresent && mRealtime &&
       !CurrentDriver()->AsAudioCallbackDriver() && !Switching() &&
       graphOutputChannelCount > 0) {
-    MonitorAutoLock mon(mMonitor);
-    if (LifecycleStateRef() == LIFECYCLE_RUNNING) {
-      AudioCallbackDriver* driver = new AudioCallbackDriver(
-          this, CurrentDriver(), mSampleRate, graphOutputChannelCount,
-          AudioInputChannelCount(), mOutputDeviceID, mInputDeviceID,
-          AudioInputDevicePreference());
-      SwitchAtNextIteration(driver);
-    }
+    AudioCallbackDriver* driver = new AudioCallbackDriver(
+        this, CurrentDriver(), mSampleRate, graphOutputChannelCount,
+        AudioInputChannelCount(), mOutputDeviceID, mInputDeviceID,
+        AudioInputDevicePreference());
+    SwitchAtNextIteration(driver);
   }
 
   // Check if this graph should switch to a different number of output channels.
   // Generally, a driver switch is explicitly made by an event (e.g., setting
   // the AudioDestinationNode channelCount), but if an HTMLMediaElement is
   // directly playing back via another HTMLMediaElement, the number of channels
   // of the media determines how many channels to output, and it can change
   // dynamically.
@@ -635,30 +629,24 @@ void MediaTrackGraphImpl::OpenAudioInput
 
   MOZ_ASSERT(!listeners.Contains(aListener), "Don't add a listener twice.");
 
   listeners.AppendElement(aListener);
 
   if (listeners.Length() == 1) {  // first open for this device
     mInputDeviceID = aID;
     // Switch Drivers since we're adding input (to input-only or full-duplex)
-    MonitorAutoLock mon(mMonitor);
-    if (LifecycleStateRef() == LIFECYCLE_RUNNING) {
-      AudioCallbackDriver* driver = new AudioCallbackDriver(
-          this, CurrentDriver(), mSampleRate, AudioOutputChannelCount(),
-          AudioInputChannelCount(), mOutputDeviceID, mInputDeviceID,
-          AudioInputDevicePreference());
-      LOG(LogLevel::Debug,
-          ("%p OpenAudioInput: starting new AudioCallbackDriver(input) %p",
-           this, driver));
-      SwitchAtNextIteration(driver);
-    } else {
-      LOG(LogLevel::Error, ("OpenAudioInput in shutdown!"));
-      MOZ_ASSERT_UNREACHABLE("Can't open cubeb inputs in shutdown");
-    }
+    AudioCallbackDriver* driver = new AudioCallbackDriver(
+        this, CurrentDriver(), mSampleRate, AudioOutputChannelCount(),
+        AudioInputChannelCount(), mOutputDeviceID, mInputDeviceID,
+        AudioInputDevicePreference());
+    LOG(LogLevel::Debug,
+        ("%p OpenAudioInput: starting new AudioCallbackDriver(input) %p", this,
+         driver));
+    SwitchAtNextIteration(driver);
   }
 }
 
 nsresult MediaTrackGraphImpl::OpenAudioInput(CubebUtils::AudioDeviceID aID,
                                              AudioDataListener* aListener) {
   MOZ_ASSERT(NS_IsMainThread());
   class Message : public ControlMessage {
    public:
@@ -708,56 +696,50 @@ void MediaTrackGraphImpl::CloseAudioInpu
 
   mInputDeviceID = nullptr;  // reset to default
   mInputDeviceUsers.Remove(aID.value());
 
   // Switch Drivers since we're adding or removing an input (to nothing/system
   // or output only)
   bool audioTrackPresent = AudioTrackPresent();
 
-  MonitorAutoLock mon(mMonitor);
-  if (LifecycleStateRef() == LIFECYCLE_RUNNING) {
-    GraphDriver* driver;
-    if (audioTrackPresent) {
-      // We still have audio output
-      LOG(LogLevel::Debug,
-          ("%p: CloseInput: output present (AudioCallback)", this));
-
-      driver = new AudioCallbackDriver(
-          this, CurrentDriver(), mSampleRate, AudioOutputChannelCount(),
-          AudioInputChannelCount(), mOutputDeviceID, mInputDeviceID,
-          AudioInputDevicePreference());
-      SwitchAtNextIteration(driver);
-    } else if (CurrentDriver()->AsAudioCallbackDriver()) {
-      LOG(LogLevel::Debug,
-          ("%p: CloseInput: no output present (SystemClockCallback)", this));
-
-      driver = new SystemClockDriver(this, CurrentDriver(), mSampleRate);
-      SwitchAtNextIteration(driver);
-    }  // else SystemClockDriver->SystemClockDriver, no switch
-  }
+  GraphDriver* driver;
+  if (audioTrackPresent) {
+    // We still have audio output
+    LOG(LogLevel::Debug,
+        ("%p: CloseInput: output present (AudioCallback)", this));
+
+    driver = new AudioCallbackDriver(
+        this, CurrentDriver(), mSampleRate, AudioOutputChannelCount(),
+        AudioInputChannelCount(), mOutputDeviceID, mInputDeviceID,
+        AudioInputDevicePreference());
+    SwitchAtNextIteration(driver);
+  } else if (CurrentDriver()->AsAudioCallbackDriver()) {
+    LOG(LogLevel::Debug,
+        ("%p: CloseInput: no output present (SystemClockCallback)", this));
+
+    driver = new SystemClockDriver(this, CurrentDriver(), mSampleRate);
+    SwitchAtNextIteration(driver);
+  }  // else SystemClockDriver->SystemClockDriver, no switch
 }
 
 void MediaTrackGraphImpl::RegisterAudioOutput(MediaTrack* aTrack, void* aKey) {
   MOZ_ASSERT(OnGraphThread());
 
   TrackKeyAndVolume* tkv = mAudioOutputs.AppendElement();
   tkv->mTrack = aTrack;
   tkv->mKey = aKey;
   tkv->mVolume = 1.0;
 
   if (!CurrentDriver()->AsAudioCallbackDriver() && !Switching()) {
-    MonitorAutoLock mon(mMonitor);
-    if (LifecycleStateRef() == LIFECYCLE_RUNNING) {
-      AudioCallbackDriver* driver = new AudioCallbackDriver(
-          this, CurrentDriver(), mSampleRate, AudioOutputChannelCount(),
-          AudioInputChannelCount(), mOutputDeviceID, mInputDeviceID,
-          AudioInputDevicePreference());
-      SwitchAtNextIteration(driver);
-    }
+    AudioCallbackDriver* driver = new AudioCallbackDriver(
+        this, CurrentDriver(), mSampleRate, AudioOutputChannelCount(),
+        AudioInputChannelCount(), mOutputDeviceID, mInputDeviceID,
+        AudioInputDevicePreference());
+    SwitchAtNextIteration(driver);
   }
 }
 
 void MediaTrackGraphImpl::UnregisterAllAudioOutputs(MediaTrack* aTrack) {
   MOZ_ASSERT(OnGraphThreadOrNotRunning());
 
   for (int32_t i = mAudioOutputs.Length() - 1; i >= 0; i--) {
     if (mAudioOutputs[i].mTrack == aTrack) {