Bug 1187817. Part 1 - Move Set{Volume,PlaybackRate,PreservesPitch} to the audio thread. r=kinetik.
☠☠ backed out by 42521959e9b9 ☠ ☠
authorJW Wang <jwwang@mozilla.com>
Tue, 28 Jul 2015 20:21:26 +0800
changeset 286591 264dad192c22bad82d56abbd50f20ff5055e7064
parent 286590 0afe24f16cf44ed53ee5aac3fa1de1982f8aa746
child 286592 cf38bd59eb44ac9e78ac96c78b51a3b604f96e1a
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();