Bug 1361336 - Part 5: Register the AudioStream into AudioNotificationReceiver when it's created. r=cpearce, a=lizzard
authorChun-Min Chang <chun.m.chang@gmail.com>
Wed, 26 Jul 2017 14:50:48 +0800
changeset 421658 18e55ae0fc5348e7ae7967fa46c547fdf6e032a2
parent 421657 2194d0f757a9db0b1189940cdebde4177e12c35b
child 421659 a4605a256ecda20c88baf1499ab0fc6a3d32fdff
push id7736
push userryanvm@gmail.com
push dateMon, 11 Sep 2017 15:47:51 +0000
treeherdermozilla-beta@94cf7f1ee06b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce, lizzard
bugs1361336
milestone56.0
Bug 1361336 - Part 5: Register the AudioStream into AudioNotificationReceiver when it's created. r=cpearce, a=lizzard
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: