Bug 1361336 - part5: Register the AudioStream into AudioNotificationReceiver when it's created; r=cpearce draft
authorChun-Min Chang <chun.m.chang@gmail.com>
Wed, 26 Jul 2017 14:50:48 +0800
changeset 616564 fbe3ef1d2c254e3f5a87e1ea723e70f997b2c2e1
parent 616563 6b1fb33d3de1ab89c67a982f8cdde6f66ab63c33
child 616565 92051dd72a179713e9cc348ec1b5364e079ec643
push id70720
push userbmo:cchang@mozilla.com
push dateThu, 27 Jul 2017 05:33:55 +0000
reviewerscpearce
bugs1361336
milestone56.0a1
Bug 1361336 - part5: Register the AudioStream into AudioNotificationReceiver when it's created; r=cpearce
dom/media/AudioStream.cpp
--- a/dom/media/AudioStream.cpp
+++ b/dom/media/AudioStream.cpp
@@ -14,16 +14,19 @@
 #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
@@ -115,29 +118,39 @@ AudioStream::AudioStream(DataSource& aSo
   : mMonitor("AudioStream")
   , mChannels(0)
   , mOutChannels(0)
   , mTimeStretcher(nullptr)
   , mDumpFile(nullptr)
   , mState(INITIALIZED)
   , mDataSource(aSource)
 {
+#if defined(XP_WIN)
+  if (XRE_IsContentProcess()) {
+    audio::AudioNotificationReceiver::Register(this);
+  }
+#endif
 }
 
 AudioStream::~AudioStream()
 {
   LOG("deleted, state %d", mState);
   MOZ_ASSERT(mState == SHUTDOWN && !mCubebStream,
              "Should've called Shutdown() before deleting an AudioStream");
   if (mDumpFile) {
     fclose(mDumpFile);
   }
   if (mTimeStretcher) {
     soundtouch::destroySoundTouchObj(mTimeStretcher);
   }
+#if defined(XP_WIN)
+  if (XRE_IsContentProcess()) {
+    audio::AudioNotificationReceiver::Unregister(this);
+  }
+#endif
 }
 
 size_t
 AudioStream::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
 {
   size_t amount = aMallocSizeOf(this);
 
   // Possibly add in the future: