Bug 1250934: Don't reopen input AudioCallbackDrivers on a second use r?padenot draft
authorRandell Jesup <rjesup@jesup.org>
Fri, 26 Feb 2016 00:36:25 -0500
changeset 334843 185aeccd9fc2388d58f8bb2ac9d6f388687c7360
parent 334842 ce159423bcfee9cba4db0b813adbe66e6a9e1ba2
child 334844 7f57879d32dfb1feca0ac4437cadfef4d6afd222
push id11645
push userrjesup@wgate.com
push dateFri, 26 Feb 2016 05:38:04 +0000
reviewerspadenot
bugs1250934
milestone47.0a1
Bug 1250934: Don't reopen input AudioCallbackDrivers on a second use r?padenot MozReview-Commit-ID: A8Xibvg484X
dom/media/MediaStreamGraph.cpp
--- a/dom/media/MediaStreamGraph.cpp
+++ b/dom/media/MediaStreamGraph.cpp
@@ -975,29 +975,35 @@ MediaStreamGraphImpl::OpenAudioInputImpl
   // XXX Since we can't rely on IDs staying valid (ugh), use the listener as
   // a stand-in for the ID.  Fix as part of support for multiple-captures
   // (Bug 1238038)
   uint32_t count = 0;
   mInputDeviceUsers.Get(aListener, &count); // ok if this fails
   count++;
   mInputDeviceUsers.Put(aListener, count); // creates a new entry in the hash if needed
 
-  // aID is a cubeb_devid, and we assume that opaque ptr is valid until
-  // we close cubeb.
-  mInputDeviceID = aID;
   if (count == 1) { // first open for this listener
+    // aID is a cubeb_devid, and we assume that opaque ptr is valid until
+    // we close cubeb.
+    mInputDeviceID = aID;
     mAudioInputs.AppendElement(aListener); // always monitor speaker data
-  }
-
-  // Switch Drivers since we're adding input (to input-only or full-duplex)
-  MonitorAutoLock mon(mMonitor);
-  if (mLifecycleState == LIFECYCLE_RUNNING) {
-    AudioCallbackDriver* driver = new AudioCallbackDriver(this);
-    driver->SetInputListener(aListener);
-    CurrentDriver()->SwitchAtNextIteration(driver);
+
+    // Switch Drivers since we're adding input (to input-only or full-duplex)
+    MonitorAutoLock mon(mMonitor);
+    if (mLifecycleState == LIFECYCLE_RUNNING) {
+      AudioCallbackDriver* driver = new AudioCallbackDriver(this);
+      STREAM_LOG(LogLevel::Debug, ("OpenAudioInput: starting new AudioCallbackDriver(input) %p", driver));
+      LIFECYCLE_LOG("OpenAudioInput: starting new AudioCallbackDriver(input) %p", driver);
+      driver->SetInputListener(aListener);
+      CurrentDriver()->SwitchAtNextIteration(driver);
+   } else {
+      STREAM_LOG(LogLevel::Error, ("OpenAudioInput in shutdown!"));
+      LIFECYCLE_LOG("OpenAudioInput in shutdown!");
+      NS_ASSERTION(false, "Can't open cubeb inputs in shutdown");
+    }
   }
 }
 
 nsresult
 MediaStreamGraphImpl::OpenAudioInput(CubebUtils::AudioDeviceID aID,
                                      AudioDataListener *aListener)
 {
   // So, so, so annoying.  Can't AppendMessage except on Mainthread