Bug 848954 - Part 27 - Only attempt to sleep if the graph is still running. r=jesup
authorPaul Adenot <paul@paul.cx>
Tue, 26 Aug 2014 17:04:36 +0200
changeset 223517 f0f902ee963628bc03658ee25785a76569a70be2
parent 223516 6e4e5d289d3a794edf71bf75c11805152c9f505d
child 223518 fdd81b782104f1bcfd8683aa511673efbeb6372e
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs848954
milestone34.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 848954 - Part 27 - Only attempt to sleep if the graph is still running. r=jesup
content/media/GraphDriver.cpp
content/media/MediaStreamGraphImpl.h
--- a/content/media/GraphDriver.cpp
+++ b/content/media/GraphDriver.cpp
@@ -129,17 +129,17 @@ public:
   {
   }
   NS_IMETHOD Run()
   {
     MOZ_ASSERT(NS_IsMainThread());
     // We can't release an audio driver on the main thread, because it can be
     // blocking.
     if (mDriver->AsAudioCallbackDriver()) {
-      printf("Releasing audio driver off main thread.\n");
+      STREAM_LOG(PR_LOG_DEBUG, ("Releasing audio driver off main thread.\n"));
       nsRefPtr<AsyncCubebTask> releaseEvent =
         new AsyncCubebTask(mDriver->AsAudioCallbackDriver(), AsyncCubebTask::SHUTDOWN);
       mDriver = nullptr;
       releaseEvent->Dispatch();
     } else {
       mDriver = nullptr;
     }
     return NS_OK;
@@ -433,22 +433,23 @@ AsyncCubebTask::Run()
     case AsyncCubebOperation::SHUTDOWN:
       mDriver->Stop();
       mDriver = nullptr;
       break;
     case AsyncCubebOperation::SLEEP: {
       {
         MonitorAutoLock mon(mDriver->mGraphImpl->GetMonitor());
         // We might just have been awoken
-        if (mDriver->mNeedAnotherIteration ||
-            mDriver->mWaitState != AudioCallbackDriver::WAITSTATE_WAITING_INDEFINITELY) {
+        if (mDriver->mNeedAnotherIteration) {
           mDriver->mPauseRequested = false;
+          mDriver->mWaitState = AudioCallbackDriver::WAITSTATE_RUNNING;
           break;
         }
         mDriver->Stop();
+        mDriver->mWaitState = AudioCallbackDriver::WAITSTATE_WAITING_INDEFINITELY;
         mDriver->mPauseRequested = false;
         mDriver->mGraphImpl->GetMonitor().Wait(PR_INTERVAL_NO_TIMEOUT);
       }
       STREAM_LOG(PR_LOG_DEBUG, ("Restarting audio stream from sleep."));
       mDriver->StartStream();
       break;
     }
     default:
@@ -629,18 +630,17 @@ AudioCallbackDriver::GetCurrentTime()
 
 void AudioCallbackDriver::WaitForNextIteration()
 {
   mGraphImpl->GetMonitor().AssertCurrentThreadOwns();
 
   // We can't block on the monitor in the audio callback, so we kick off a new
   // thread that will pause the audio stream, and restart it when unblocked.
   // We don't want to sleep when we haven't started the driver yet.
-  if (!mNeedAnotherIteration && mAudioStream) {
-    mWaitState = WAITSTATE_WAITING_INDEFINITELY;
+  if (!mNeedAnotherIteration && mAudioStream && mGraphImpl->Running()) {
     STREAM_LOG(PR_LOG_DEBUG+1, ("AudioCallbackDriver going to sleep"));
     mPauseRequested = true;
     nsRefPtr<AsyncCubebTask> sleepEvent =
       new AsyncCubebTask(this, AsyncCubebTask::SLEEP);
     sleepEvent->Dispatch();
   }
 }
 
--- a/content/media/MediaStreamGraphImpl.h
+++ b/content/media/MediaStreamGraphImpl.h
@@ -151,16 +151,21 @@ public:
    * This does the actual iteration: Message processing, MediaStream ordering,
    * blocking computation and processing.
    */
   void DoIteration();
 
   bool OneIteration(GraphTime aFrom, GraphTime aTo,
                     GraphTime aStateFrom, GraphTime aStateEnd);
 
+  bool Running() {
+    mMonitor.AssertCurrentThreadOwns();
+    return mLifecycleState == LIFECYCLE_RUNNING;
+  }
+
   // Get the message queue, from the current GraphDriver thread.
   nsTArray<MessageBlock>& MessageQueue() {
     mMonitor.AssertCurrentThreadOwns();
     return mFrontMessageQueue;
   }
 
   /* This is the end of the current iteration, that is, the current time of the
    * graph. */