Bug 883010 - Part 1: Optimize MediaStreamGraphImpl::UpdateStreamOrder in order to optimize away how much time we spend on it in every iteration of the MSG; r=roc
☠☠ backed out by f0db2c84b4d1 ☠ ☠
authorEhsan Akhgari <ehsan@mozilla.com>
Mon, 17 Jun 2013 11:29:47 -0400
changeset 135280 07708c9fc5efdb8d81248550e817253098327d80
parent 135279 95d757b44adc3303438587681eeefbff90cae068
child 135281 459376ae11c778af5a828ec0803907837f1900b3
push id29595
push usereakhgari@mozilla.com
push dateMon, 17 Jun 2013 15:30:31 +0000
treeherdermozilla-inbound@07708c9fc5ef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs883010
milestone24.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 883010 - Part 1: Optimize MediaStreamGraphImpl::UpdateStreamOrder in order to optimize away how much time we spend on it in every iteration of the MSG; r=roc
content/media/MediaStreamGraph.cpp
content/media/MediaStreamGraph.h
content/media/MediaStreamGraphImpl.h
--- a/content/media/MediaStreamGraph.cpp
+++ b/content/media/MediaStreamGraph.cpp
@@ -1010,17 +1010,21 @@ MediaStreamGraphImpl::RunThread()
       nsTArray<nsAutoPtr<ControlMessage> >& messages = messageQueue[i].mMessages;
 
       for (uint32_t j = 0; j < messages.Length(); ++j) {
         messages[j]->Run();
       }
     }
     messageQueue.Clear();
 
-    UpdateStreamOrder();
+    // Only update the stream order if needed, since it can be expensive.
+    if (mStreamOrderDirty) {
+      UpdateStreamOrder();
+      mStreamOrderDirty = false;
+    }
 
     // Find the sampling rate that we need to use for non-realtime graphs.
     TrackRate sampleRate = IdealAudioRate();
     if (!mRealtime) {
       for (uint32_t i = 0; i < mStreams.Length(); ++i) {
         AudioNodeStream* n = mStreams[i]->AsAudioNodeStream();
         if (n) {
           // We know that the rest of the streams will run at the same rate.
@@ -2146,16 +2150,17 @@ MediaStreamGraphImpl::MediaStreamGraphIm
   , mNeedAnotherIteration(false)
   , mForceShutDown(false)
   , mPostedRunInStableStateEvent(false)
   , mNonRealtimeIsRunning(false)
   , mDetectedNotRunning(false)
   , mPostedRunInStableState(false)
   , mRealtime(aRealtime)
   , mNonRealtimeProcessing(false)
+  , mStreamOrderDirty(false)
 {
 #ifdef PR_LOGGING
   if (!gMediaStreamGraphLog) {
     gMediaStreamGraphLog = PR_NewLogModule("MediaStreamGraph");
   }
 #endif
 
   mCurrentTimeStamp = mInitialTimeStamp = TimeStamp::Now();
@@ -2275,9 +2280,16 @@ MediaStreamGraph::StartNonRealtimeProces
 
   if (graph->mNonRealtimeProcessing)
     return;
   graph->mNonRealtimeTicksToProcess = aTicksToProcess;
   graph->mNonRealtimeProcessing = true;
   graph->EnsureRunInStableState();
 }
 
+void
+ProcessedMediaStream::AddInput(MediaInputPort* aPort)
+{
+  mInputs.AppendElement(aPort);
+  GraphImpl()->SetStreamOrderDirty();
 }
+
+}
--- a/content/media/MediaStreamGraph.h
+++ b/content/media/MediaStreamGraph.h
@@ -266,16 +266,21 @@ public:
     , mExplicitBlockerCount(0)
     , mBlocked(false)
     , mGraphUpdateIndices(0)
     , mFinished(false)
     , mNotifiedFinished(false)
     , mNotifiedBlocked(false)
     , mHasCurrentData(false)
     , mNotifiedHasCurrentData(false)
+    , mHasBeenOrdered(false)
+    , mIsOnOrderingStack(false)
+    , mIsConsumed(false)
+    , mInBlockingSet(false)
+    , mBlockInThisPhase(false)
     , mWrapper(aWrapper)
     , mMainThreadCurrentTime(0)
     , mMainThreadFinished(false)
     , mMainThreadDestroyed(false)
     , mGraph(nullptr)
   {
     MOZ_COUNT_CTOR(MediaStream);
   }
@@ -853,20 +858,17 @@ public:
    */
   void SetAutofinish(bool aAutofinish);
 
   virtual ProcessedMediaStream* AsProcessedStream() { return this; }
 
   friend class MediaStreamGraphImpl;
 
   // Do not call these from outside MediaStreamGraph.cpp!
-  virtual void AddInput(MediaInputPort* aPort)
-  {
-    mInputs.AppendElement(aPort);
-  }
+  virtual void AddInput(MediaInputPort* aPort);
   virtual void RemoveInput(MediaInputPort* aPort)
   {
     mInputs.RemoveElement(aPort);
   }
   bool HasInputPort(MediaInputPort* aPort)
   {
     return mInputs.Contains(aPort);
   }
--- a/content/media/MediaStreamGraphImpl.h
+++ b/content/media/MediaStreamGraphImpl.h
@@ -351,16 +351,23 @@ public:
    * Remove aStream from the graph. Ensures that pending messages about the
    * stream back to the main thread are flushed.
    */
   void RemoveStream(MediaStream* aStream);
   /**
    * Remove aPort from the graph and release it.
    */
   void DestroyPort(MediaInputPort* aPort);
+  /**
+   * Mark the media stream order as dirty.
+   */
+  void SetStreamOrderDirty()
+  {
+    mStreamOrderDirty = true;
+  }
 
   // Data members
 
   /**
    * Media graph thread.
    * Readonly after initialization on the main thread.
    */
   nsCOMPtr<nsIThread> mThread;
@@ -531,13 +538,18 @@ public:
    * audio.
    */
   bool mRealtime;
   /**
    * True when a non-realtime MediaStreamGraph has started to process input.  This
    * value is only accessed on the main thread.
    */
   bool mNonRealtimeProcessing;
+  /**
+   * True when a change has happened which requires us to recompute the stream
+   * blocking order.
+   */
+  bool mStreamOrderDirty;
 };
 
 }
 
 #endif /* MEDIASTREAMGRAPHIMPL_H_ */