Bug 1189506. Factor out code from OneIteration into helper methods. r=karlt
authorRobert O'Callahan <robert@ocallahan.org>
Sat, 05 Sep 2015 00:26:48 +1200
changeset 295510 71ba3cb1406e9a63d4d7d09acc7420ccd5d37ab8
parent 295509 a2fa219fe521588f888559c92aa4b80fa0a2b4d1
child 295511 f38cc960f179b0e5907b0ad947f42410484905fd
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt
bugs1189506
milestone43.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 1189506. Factor out code from OneIteration into helper methods. r=karlt
dom/media/MediaStreamGraph.cpp
dom/media/MediaStreamGraphImpl.h
--- a/dom/media/MediaStreamGraph.cpp
+++ b/dom/media/MediaStreamGraph.cpp
@@ -1199,71 +1199,76 @@ MediaStreamGraphImpl::Process(GraphTime 
     }
   }
 
   if (!allBlockedForever) {
     EnsureNextIteration();
   }
 }
 
+void
+MediaStreamGraphImpl::MaybeProduceMemoryReport()
+{
+  MonitorAutoLock lock(mMemoryReportMonitor);
+  if (mNeedsMemoryReport) {
+    mNeedsMemoryReport = false;
+
+    for (MediaStream* s : AllStreams()) {
+      AudioNodeStream* stream = s->AsAudioNodeStream();
+      if (stream) {
+        AudioNodeSizes usage;
+        stream->SizeOfAudioNodesIncludingThis(MallocSizeOf, usage);
+        mAudioStreamSizes.AppendElement(usage);
+      }
+    }
+
+    lock.Notify();
+  }
+}
+
+bool
+MediaStreamGraphImpl::UpdateMainThreadState()
+{
+  MonitorAutoLock lock(mMonitor);
+  bool finalUpdate = mForceShutDown ||
+    (mProcessedTime >= mEndTime && AllFinishedStreamsNotified()) ||
+    (IsEmpty() && mBackMessageQueue.IsEmpty());
+  PrepareUpdatesToMainThreadState(finalUpdate);
+  if (finalUpdate) {
+    // Enter shutdown mode. The stable-state handler will detect this
+    // and complete shutdown. Destroy any streams immediately.
+    STREAM_LOG(LogLevel::Debug, ("MediaStreamGraph %p waiting for main thread cleanup", this));
+    // We'll shut down this graph object if it does not get restarted.
+    mLifecycleState = LIFECYCLE_WAITING_FOR_MAIN_THREAD_CLEANUP;
+    // No need to Destroy streams here. The main-thread owner of each
+    // stream is responsible for calling Destroy on them.
+    return false;
+  }
+
+  CurrentDriver()->WaitForNextIteration();
+
+  SwapMessageQueues();
+  return true;
+}
+
 bool
 MediaStreamGraphImpl::OneIteration(GraphTime aStateEnd)
 {
-  {
-    MonitorAutoLock lock(mMemoryReportMonitor);
-    if (mNeedsMemoryReport) {
-      mNeedsMemoryReport = false;
-
-      for (MediaStream* s : AllStreams()) {
-        AudioNodeStream* stream = s->AsAudioNodeStream();
-        if (stream) {
-          AudioNodeSizes usage;
-          stream->SizeOfAudioNodesIncludingThis(MallocSizeOf, usage);
-          mAudioStreamSizes.AppendElement(usage);
-        }
-      }
-
-      lock.Notify();
-    }
-  }
+  MaybeProduceMemoryReport();
 
   GraphTime stateFrom = mStateComputedTime;
   GraphTime stateEnd = std::min(aStateEnd, mEndTime);
   UpdateGraph(stateEnd);
 
   Process(stateFrom, stateEnd);
   mProcessedTime = stateEnd;
 
   UpdateCurrentTimeForStreams(stateFrom, stateEnd);
 
-  // Send updates to the main thread and wait for the next control loop
-  // iteration.
-  {
-    MonitorAutoLock lock(mMonitor);
-    bool finalUpdate = mForceShutDown ||
-      (stateEnd >= mEndTime && AllFinishedStreamsNotified()) ||
-      (IsEmpty() && mBackMessageQueue.IsEmpty());
-    PrepareUpdatesToMainThreadState(finalUpdate);
-    if (finalUpdate) {
-      // Enter shutdown mode. The stable-state handler will detect this
-      // and complete shutdown. Destroy any streams immediately.
-      STREAM_LOG(LogLevel::Debug, ("MediaStreamGraph %p waiting for main thread cleanup", this));
-      // We'll shut down this graph object if it does not get restarted.
-      mLifecycleState = LIFECYCLE_WAITING_FOR_MAIN_THREAD_CLEANUP;
-      // No need to Destroy streams here. The main-thread owner of each
-      // stream is responsible for calling Destroy on them.
-      return false;
-    }
-
-    CurrentDriver()->WaitForNextIteration();
-
-    SwapMessageQueues();
-  }
-
-  return true;
+  return UpdateMainThreadState();
 }
 
 void
 MediaStreamGraphImpl::ApplyStreamUpdate(StreamUpdate* aUpdate)
 {
   mMonitor.AssertCurrentThreadOwns();
 
   MediaStream* stream = aUpdate->mStream;
--- a/dom/media/MediaStreamGraphImpl.h
+++ b/dom/media/MediaStreamGraphImpl.h
@@ -162,22 +162,27 @@ public:
       if (!(mDetectedNotRunning &&
             mLifecycleState > LIFECYCLE_RUNNING &&
             NS_IsMainThread())) {
         mMonitor.AssertCurrentThreadOwns();
       }
     }
 #endif
   }
-  /*
-   * This does the actual iteration: Message processing, MediaStream ordering,
-   * blocking computation and processing.
+
+  void MaybeProduceMemoryReport();
+
+  /**
+   * Returns true if this MediaStreamGraph should keep running
    */
-  void DoIteration();
+  bool UpdateMainThreadState();
 
+  /**
+   * Returns true if this MediaStreamGraph should keep running
+   */
   bool OneIteration(GraphTime aStateEnd);
 
   bool Running() const
   {
     mMonitor.AssertCurrentThreadOwns();
     return mLifecycleState == LIFECYCLE_RUNNING;
   }