Bug 1187817. Part 1 - Move Set{Volume,PlaybackRate,PreservesPitch} to the audio thread. r=kinetik.
authorJW Wang <jwwang@mozilla.com>
Fri, 31 Jul 2015 13:26:06 +0800
changeset 287250 ecf03b35eac02455ad1b8080f78400e5040329df
parent 287249 692828b8e47a601b4c8dc83ff26409d6f5b1ec54
child 287251 f8721ef7b2b272369fde58ab1edfa4dc4d04c46a
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskinetik
bugs1187817
milestone42.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 1187817. Part 1 - Move Set{Volume,PlaybackRate,PreservesPitch} to the audio thread. r=kinetik.
dom/media/AudioSink.cpp
--- a/dom/media/AudioSink.cpp
+++ b/dom/media/AudioSink.cpp
@@ -154,36 +154,51 @@ AudioSink::Shutdown()
              mState == AUDIOSINK_STATE_ERROR);
   // Should have no pending state change.
   MOZ_ASSERT(mPendingState.isNothing());
 }
 
 void
 AudioSink::SetVolume(double aVolume)
 {
-  ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
-  mVolume = aVolume;
-  mSetVolume = true;
+  AssertNotOnAudioThread();
+  nsRefPtr<AudioSink> self = this;
+  nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction([=] () {
+    if (self->mState == AUDIOSINK_STATE_PLAYING) {
+      self->mAudioStream->SetVolume(aVolume);
+    }
+  });
+  DispatchTask(r.forget());
 }
 
 void
 AudioSink::SetPlaybackRate(double aPlaybackRate)
 {
-  ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
-  NS_ASSERTION(mPlaybackRate != 0, "Don't set the playbackRate to 0 on AudioStream");
-  mPlaybackRate = aPlaybackRate;
-  mSetPlaybackRate = true;
+  AssertNotOnAudioThread();
+  MOZ_ASSERT(aPlaybackRate != 0, "Don't set the playbackRate to 0 on AudioStream");
+  nsRefPtr<AudioSink> self = this;
+  nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction([=] () {
+    if (self->mState == AUDIOSINK_STATE_PLAYING) {
+      self->mAudioStream->SetPlaybackRate(aPlaybackRate);
+    }
+  });
+  DispatchTask(r.forget());
 }
 
 void
 AudioSink::SetPreservesPitch(bool aPreservesPitch)
 {
-  ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
-  mPreservesPitch = aPreservesPitch;
-  mSetPreservesPitch = true;
+  AssertNotOnAudioThread();
+  nsRefPtr<AudioSink> self = this;
+  nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction([=] () {
+    if (self->mState == AUDIOSINK_STATE_PLAYING) {
+      self->mAudioStream->SetPreservesPitch(aPreservesPitch);
+    }
+  });
+  DispatchTask(r.forget());
 }
 
 void
 AudioSink::SetPlaying(bool aPlaying)
 {
   ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
   mPlaying = aPlaying;
   ScheduleNextLoopCrossThread();