Bug 1187817. Part 3 - move SetPlaying to the audio thread. r=kinetik.
☠☠ backed out by 42521959e9b9 ☠ ☠
authorJW Wang <jwwang@mozilla.com>
Tue, 28 Jul 2015 20:21:26 +0800
changeset 286593 d31a0c93969f3190cd8a148d13588335ddee82de
parent 286592 cf38bd59eb44ac9e78ac96c78b51a3b604f96e1a
child 286594 74386997e5fb675f2710fbb9e3188e9254027c9e
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 3 - move SetPlaying to the audio thread. r=kinetik.
dom/media/AudioSink.cpp
--- a/dom/media/AudioSink.cpp
+++ b/dom/media/AudioSink.cpp
@@ -188,19 +188,36 @@ AudioSink::SetPreservesPitch(bool aPrese
     }
   });
   DispatchTask(r.forget());
 }
 
 void
 AudioSink::SetPlaying(bool aPlaying)
 {
-  ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
-  mPlaying = aPlaying;
-  ScheduleNextLoopCrossThread();
+  AssertNotOnAudioThread();
+  nsRefPtr<AudioSink> self = this;
+  nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction([=] () {
+    if (self->mState != AUDIOSINK_STATE_PLAYING ||
+        self->mPlaying == aPlaying) {
+      return;
+    }
+    self->mPlaying = aPlaying;
+    // pause/resume AudioStream as necessary.
+    if (!aPlaying && !self->mAudioStream->IsPaused()) {
+      self->mAudioStream->Pause();
+    } else if (aPlaying && self->mAudioStream->IsPaused()) {
+      self->mAudioStream->Resume();
+    }
+    // Wake up the audio loop to play next sample.
+    if (aPlaying && !self->mAudioLoopScheduled) {
+      self->AudioLoop();
+    }
+  });
+  DispatchTask(r.forget());
 }
 
 void
 AudioSink::NotifyData()
 {
   ScheduleNextLoopCrossThread();
 }
 
@@ -256,32 +273,25 @@ AudioSink::ExpectMoreAudioData()
 
 bool
 AudioSink::WaitingForAudioToPlay()
 {
   // Return true if we're not playing, and we're not shutting down, or we're
   // playing and we've got no audio to play.
   AssertCurrentThreadInMonitor();
   if (!mStopAudioThread && (!mPlaying || ExpectMoreAudioData())) {
-    if (!mPlaying && !mAudioStream->IsPaused()) {
-      mAudioStream->Pause();
-    }
     return true;
   }
   return false;
 }
 
 bool
 AudioSink::IsPlaybackContinuing()
 {
   AssertCurrentThreadInMonitor();
-  if (mPlaying && mAudioStream->IsPaused()) {
-    mAudioStream->Resume();
-  }
-
   // If we're shutting down, captured, or at EOS, break out and exit the audio
   // thread.
   if (mStopAudioThread || AudioQueue().AtEndOfStream()) {
     return false;
   }
 
   return true;
 }