Bug 1361336 - Part 1: A new API for AudioStream that it can reset stream to the default device. r=kinetik, a=lizzard
authorChun-Min Chang <chun.m.chang@gmail.com>
Wed, 12 Jul 2017 14:51:07 +0800
changeset 424028 4defb75014dfe3f8d77301ea89a7b43897696ca2
parent 424027 1b63df5a180b5c564efda052d9a19dc150131fc7
child 424029 7ffa5f4b3dde34ffb59a9e9b25072414f6202ced
push id1517
push userjlorenzo@mozilla.com
push dateThu, 14 Sep 2017 16:50:54 +0000
treeherdermozilla-release@3b41fd564418 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskinetik, lizzard
bugs1361336
milestone56.0
Bug 1361336 - Part 1: A new API for AudioStream that it can reset stream to the default device. r=kinetik, a=lizzard 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();