Bug 1361336 - part1: A new API for AudioStream that it can reset stream to the default device; r=kinetik draft
authorChun-Min Chang <chun.m.chang@gmail.com>
Wed, 12 Jul 2017 14:51:07 +0800
changeset 616560 dbf4d05814be4eeb7d916efc5221851f5f300433
parent 616205 f1693d664f8e8ee4c79801630c181c28095cad56
child 616561 eda9093d407bc82530775f85acd5ec35213ab786
push id70720
push userbmo:cchang@mozilla.com
push dateThu, 27 Jul 2017 05:33:55 +0000
reviewerskinetik
bugs1361336
milestone56.0a1
Bug 1361336 - part1: A new API for AudioStream that it can reset stream to the default device; r=kinetik MozReview-Commit-ID: ErUYXK9fUvE
dom/media/AudioStream.cpp
dom/media/AudioStream.h
--- a/dom/media/AudioStream.cpp
+++ b/dom/media/AudioStream.cpp
@@ -469,16 +469,26 @@ AudioStream::Shutdown()
     // Must not try to shut down cubeb from within the lock!  wasapi may still
     // call our callback after Pause()/stop()!?! Bug 996162
     mCubebStream.reset();
   }
 
   mState = SHUTDOWN;
 }
 
+void
+AudioStream::ResetDefaultDevice()
+{
+  MonitorAutoLock mon(mMonitor);
+  auto r = InvokeCubeb(cubeb_stream_reset_default_device);
+  if (!(r == CUBEB_OK || r == CUBEB_ERROR_NOT_SUPPORTED)) {
+    mState = ERRORED;
+  }
+}
+
 int64_t
 AudioStream::GetPosition()
 {
   MonitorAutoLock mon(mMonitor);
   int64_t frames = GetPositionInFramesUnlocked();
   return frames >= 0 ? mAudioClock.GetPosition(frames) : -1;
 }
 
--- a/dom/media/AudioStream.h
+++ b/dom/media/AudioStream.h
@@ -207,16 +207,19 @@ public:
   void Start();
 
   // Pause audio playback.
   void Pause();
 
   // Resume audio playback.
   void Resume();
 
+  // Reset stream to default device.
+  void ResetDefaultDevice();
+
   // Return the position in microseconds of the audio frame being played by
   // the audio hardware, compensated for playback rate change. Thread-safe.
   int64_t GetPosition();
 
   // Return the position, measured in audio frames played since the stream
   // was opened, of the audio hardware.  Thread-safe.
   int64_t GetPositionInFrames();