Bug 1187817. Part 5 - assert some code in the audio thread and don't enter the monitor. r=kinetik.
authorJW Wang <jwwang@mozilla.com>
Fri, 31 Jul 2015 13:26:06 +0800
changeset 287254 b0c6d424125aa2d1c319f2a325bad22689c8f09e
parent 287253 9e795629afc2f36cf78d50dd7b63861847c2110b
child 287255 5eaae3107f44f19c58c206473d3f59236c6ee016
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 5 - assert some code in the audio thread and don't enter the monitor. r=kinetik.
dom/media/AudioSink.cpp
media/libcubeb/src/cubeb_opensl.c
--- a/dom/media/AudioSink.cpp
+++ b/dom/media/AudioSink.cpp
@@ -245,59 +245,56 @@ AudioSink::InitializeAudioStream()
   mAudioStream = audioStream;
 
   return NS_OK;
 }
 
 void
 AudioSink::Drain()
 {
+  AssertOnAudioThread();
   MOZ_ASSERT(mPlaying && !mAudioStream->IsPaused());
-  AssertCurrentThreadInMonitor();
   // If the media was too short to trigger the start of the audio stream,
   // start it now.
   mAudioStream->Start();
-  {
-    ReentrantMonitorAutoExit exit(GetReentrantMonitor());
-    mAudioStream->Drain();
-  }
+  mAudioStream->Drain();
 }
 
 void
 AudioSink::Cleanup()
 {
-  AssertCurrentThreadInMonitor();
+  AssertOnAudioThread();
   mEndPromise.Resolve(true, __func__);
   // Since the promise if resolved asynchronously, we don't shutdown
   // AudioStream here so MDSM::ResyncAudioClock can get the correct
   // audio position.
 }
 
 bool
 AudioSink::ExpectMoreAudioData()
 {
   return AudioQueue().GetSize() == 0 && !AudioQueue().IsFinished();
 }
 
 bool
 AudioSink::WaitingForAudioToPlay()
 {
+  AssertOnAudioThread();
   // 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())) {
     return true;
   }
   return false;
 }
 
 bool
 AudioSink::IsPlaybackContinuing()
 {
-  AssertCurrentThreadInMonitor();
+  AssertOnAudioThread();
   // If we're shutting down, captured, or at EOS, break out and exit the audio
   // thread.
   if (mStopAudioThread || AudioQueue().AtEndOfStream()) {
     return false;
   }
 
   return true;
 }
@@ -318,26 +315,23 @@ AudioSink::AudioLoop()
         SetState(AUDIOSINK_STATE_ERROR);
         break;
       }
       SetState(AUDIOSINK_STATE_PLAYING);
       break;
     }
 
     case AUDIOSINK_STATE_PLAYING: {
-      {
-        ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
-        if (WaitingForAudioToPlay()) {
-          // NotifyData() will schedule next loop.
-          break;
-        }
-        if (!IsPlaybackContinuing()) {
-          SetState(AUDIOSINK_STATE_COMPLETE);
-          break;
-        }
+      if (WaitingForAudioToPlay()) {
+        // NotifyData() will schedule next loop.
+        break;
+      }
+      if (!IsPlaybackContinuing()) {
+        SetState(AUDIOSINK_STATE_COMPLETE);
+        break;
       }
       if (!PlayAudio()) {
         SetState(AUDIOSINK_STATE_COMPLETE);
         break;
       }
       // Schedule next loop to play next sample.
       ScheduleNextLoop();
       break;
@@ -400,17 +394,17 @@ AudioSink::PlayAudio()
   }
 
   return true;
 }
 
 void
 AudioSink::FinishAudioLoop()
 {
-  ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
+  AssertOnAudioThread();
   MOZ_ASSERT(mStopAudioThread || AudioQueue().AtEndOfStream());
   if (!mStopAudioThread && mPlaying) {
     Drain();
   }
   SINK_LOG("AudioLoop complete");
   Cleanup();
   SINK_LOG("AudioLoop exit");
 }
--- a/media/libcubeb/src/cubeb_opensl.c
+++ b/media/libcubeb/src/cubeb_opensl.c
@@ -666,18 +666,20 @@ opensl_stream_init(cubeb * ctx, cubeb_st
 
   *stream = stm;
   return CUBEB_OK;
 }
 
 static void
 opensl_stream_destroy(cubeb_stream * stm)
 {
-  if (stm->playerObj)
+  if (stm->playerObj) {
+    (*stm->bufq)->Clear(stm->bufq);
     (*stm->playerObj)->Destroy(stm->playerObj);
+  }
   int i;
   for (i = 0; i < NBUFS; i++) {
     free(stm->queuebuf[i]);
   }
   pthread_mutex_destroy(&stm->mutex);
 
   cubeb_resampler_destroy(stm->resampler);