Bug 1187763. Part 1 - move while loop out of WaitingForAudioToPlay(). r=kinetik.
authorJW Wang <jwwang@mozilla.com>
Tue, 28 Jul 2015 11:49:42 +0800
changeset 286556 d0fe041a5500a49c6c759de9b6b62342f436a37f
parent 286555 c63a6810b2bb84ada4fe207ec58171a080c0447d
child 286557 2360777e82ad624bd749c10af0e1b80af1ea014f
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
bugs1187763
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 1187763. Part 1 - move while loop out of WaitingForAudioToPlay(). r=kinetik.
dom/media/AudioSink.cpp
dom/media/AudioSink.h
--- a/dom/media/AudioSink.cpp
+++ b/dom/media/AudioSink.cpp
@@ -162,17 +162,19 @@ AudioSink::AudioLoop()
     NS_WARNING("Initializing AudioStream failed.");
     mEndPromise.Reject(rv, __func__);
     return;
   }
 
   while (1) {
     {
       ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
-      WaitForAudioToPlay();
+      while (WaitingForAudioToPlay()) {
+        GetReentrantMonitor().Wait();
+      }
       if (!IsPlaybackContinuing()) {
         break;
       }
     }
     // See if there's a gap in the audio. If there is, push silence into the
     // audio hardware, so we can play across the gap.
     // Calculate the timestamp of the next chunk of audio in numbers of
     // samples.
@@ -256,28 +258,29 @@ AudioSink::Cleanup()
 }
 
 bool
 AudioSink::ExpectMoreAudioData()
 {
   return AudioQueue().GetSize() == 0 && !AudioQueue().IsFinished();
 }
 
-void
-AudioSink::WaitForAudioToPlay()
+bool
+AudioSink::WaitingForAudioToPlay()
 {
-  // Wait while we're not playing, and we're not shutting down, or we're
+  // 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();
-  while (!mStopAudioThread && (!mPlaying || ExpectMoreAudioData())) {
+  if (!mStopAudioThread && (!mPlaying || ExpectMoreAudioData())) {
     if (!mPlaying && !mAudioStream->IsPaused()) {
       mAudioStream->Pause();
     }
-    GetReentrantMonitor().Wait();
+    return true;
   }
+  return false;
 }
 
 bool
 AudioSink::IsPlaybackContinuing()
 {
   AssertCurrentThreadInMonitor();
   if (mPlaying && mAudioStream->IsPaused()) {
     mAudioStream->Resume();
--- a/dom/media/AudioSink.h
+++ b/dom/media/AudioSink.h
@@ -68,18 +68,18 @@ private:
   nsresult InitializeAudioStream();
 
   void Drain();
 
   void Cleanup();
 
   bool ExpectMoreAudioData();
 
-  // Wait on the decoder monitor until playback is ready or the sink is told to shut down.
-  void WaitForAudioToPlay();
+  // Return true if playback is not ready and the sink is not told to shut down.
+  bool WaitingForAudioToPlay();
 
   // Check if the sink has been told to shut down, resuming mAudioStream if
   // not.  Returns true if processing should continue, false if AudioLoop
   // should shutdown.
   bool IsPlaybackContinuing();
 
   // Write aFrames of audio frames of silence to the audio hardware. Returns
   // the number of frames actually written. The write size is capped at