Bug 1392930 - part 2: Make AudioStream inherit from DeviceChangeListener; r=jwwang
authorChun-Min Chang <chun.m.chang@gmail.com>
Tue, 29 Aug 2017 18:08:46 +0800
changeset 377803 02bf9496d1c8543c6f32539bf8562babb78127af
parent 377802 674670bfea13fa67b2cadee2ab66561801c0dcdf
child 377804 89d020630629fac5b4c2ae6f0a1107ae2405e7f2
push id94338
push userkwierso@gmail.com
push dateThu, 31 Aug 2017 02:58:58 +0000
treeherdermozilla-inbound@9ca18987dabb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwwang
bugs1392930
milestone57.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 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();