Bug 1392930 - part 2: Make AudioStream inherit from DeviceChangeListener; r=jwwang draft
authorChun-Min Chang <chun.m.chang@gmail.com>
Tue, 29 Aug 2017 18:08:46 +0800
changeset 654858 7bc746f4ec3b374d6598280e223649b070d93eeb
parent 654857 e0c1a56ff5318ef8e581576bc80443001828569b
child 654859 5f39e51ac663454a4c48ad8c7342dcb5c6aff81d
push id76710
push userbmo:cchang@mozilla.com
push dateTue, 29 Aug 2017 10:34:23 +0000
reviewersjwwang
bugs1392930
milestone57.0a1
Bug 1392930 - part 2: Make AudioStream inherit from DeviceChangeListener; r=jwwang
dom/media/AudioStream.cpp
dom/media/AudioStream.h
--- a/dom/media/AudioStream.cpp
+++ b/dom/media/AudioStream.cpp
@@ -14,19 +14,16 @@
 #include "mozilla/Mutex.h"
 #include "mozilla/Sprintf.h"
 #include <algorithm>
 #include "mozilla/Telemetry.h"
 #include "CubebUtils.h"
 #include "nsPrintfCString.h"
 #include "gfxPrefs.h"
 #include "AudioConverter.h"
-#if defined(XP_WIN)
-#include "mozilla/audio/AudioNotificationReceiver.h"
-#endif
 
 namespace mozilla {
 
 #undef LOG
 #undef LOGW
 
 LazyLogModule gAudioStreamLog("AudioStream");
 // For simple logs
@@ -470,30 +467,32 @@ 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;
 }
 
+#if defined(XP_WIN)
 void
 AudioStream::ResetDefaultDevice()
 {
   MonitorAutoLock mon(mMonitor);
   if (mState != STARTED && mState != STOPPED) {
     return;
   }
 
   MOZ_ASSERT(mCubebStream);
   auto r = InvokeCubeb(cubeb_stream_reset_default_device);
   if (!(r == CUBEB_OK || r == CUBEB_ERROR_NOT_SUPPORTED)) {
     mState = ERRORED;
   }
 }
+#endif
 
 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
@@ -12,16 +12,20 @@
 #include "nsThreadUtils.h"
 #include "mozilla/Monitor.h"
 #include "mozilla/RefPtr.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/UniquePtr.h"
 #include "CubebUtils.h"
 #include "soundtouch/SoundTouchFactory.h"
 
+#if defined(XP_WIN)
+#include "mozilla/audio/AudioNotificationReceiver.h"
+#endif
+
 namespace mozilla {
 
 struct CubebDestroyPolicy
 {
   void operator()(cubeb_stream* aStream) const {
     cubeb_stream_destroy(aStream);
   }
 };
@@ -145,16 +149,19 @@ public:
   using AudioBufferCursor::Available;
 };
 
 // Access to a single instance of this class must be synchronized by
 // callers, or made from a single thread.  One exception is that access to
 // GetPosition, GetPositionInFrames, SetVolume, and Get{Rate,Channels},
 // SetMicrophoneActive is thread-safe without external synchronization.
 class AudioStream final
+#if defined(XP_WIN)
+  : public audio::DeviceChangeListener
+#endif
 {
   virtual ~AudioStream();
 
 public:
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(AudioStream)
 
   class Chunk {
   public:
@@ -205,18 +212,20 @@ public:
   void Start();
 
   // Pause audio playback.
   void Pause();
 
   // Resume audio playback.
   void Resume();
 
-  // Reset stream to default device.
-  void ResetDefaultDevice();
+#if defined(XP_WIN)
+  // Reset stream to the default device.
+  void ResetDefaultDevice() override;
+#endif
 
   // 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();