diff --git a/content/media/MediaStreamGraph.cpp b/content/media/MediaStreamGraph.cpp index d323f5758cb..369d423cf19 100644 --- a/content/media/MediaStreamGraph.cpp +++ b/content/media/MediaStreamGraph.cpp @@ -4,7 +4,6 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "MediaStreamGraphImpl.h" -#include "mozilla/LinkedList.h" #include "AudioSegment.h" #include "VideoSegment.h" @@ -24,7 +23,6 @@ #include "AudioNodeStream.h" #include #include "DOMMediaStream.h" -#include "GeckoProfiler.h" using namespace mozilla::layers; using namespace mozilla::dom; @@ -315,30 +313,20 @@ MediaStreamGraphImpl::GetAudioPosition(MediaStream* aStream) void MediaStreamGraphImpl::UpdateCurrentTime() { - GraphTime prevCurrentTime, nextCurrentTime; - if (mRealtime) { - TimeStamp now = TimeStamp::Now(); - prevCurrentTime = mCurrentTime; - nextCurrentTime = - SecondsToMediaTime((now - mCurrentTimeStamp).ToSeconds()) + mCurrentTime; - - mCurrentTimeStamp = now; - LOG(PR_LOG_DEBUG+1, ("Updating current time to %f (real %f, mStateComputedTime %f)", - MediaTimeToSeconds(nextCurrentTime), - (now - mInitialTimeStamp).ToSeconds(), - MediaTimeToSeconds(mStateComputedTime))); - } else { - prevCurrentTime = mCurrentTime; - nextCurrentTime = mCurrentTime + MEDIA_GRAPH_TARGET_PERIOD_MS; - LOG(PR_LOG_DEBUG+1, ("Updating offline current time to %f (mStateComputedTime %f)", - MediaTimeToSeconds(nextCurrentTime), - MediaTimeToSeconds(mStateComputedTime))); - } - + GraphTime prevCurrentTime = mCurrentTime; + TimeStamp now = TimeStamp::Now(); + GraphTime nextCurrentTime = + SecondsToMediaTime((now - mCurrentTimeStamp).ToSeconds()) + mCurrentTime; if (mStateComputedTime < nextCurrentTime) { LOG(PR_LOG_WARNING, ("Media graph global underrun detected")); nextCurrentTime = mStateComputedTime; } + mCurrentTimeStamp = now; + + LOG(PR_LOG_DEBUG+1, ("Updating current time to %f (real %f, mStateComputedTime %f)", + MediaTimeToSeconds(nextCurrentTime), + (now - mInitialTimeStamp).ToSeconds(), + MediaTimeToSeconds(mStateComputedTime))); if (prevCurrentTime >= nextCurrentTime) { NS_ASSERTION(prevCurrentTime == nextCurrentTime, "Time can't go backwards!"); @@ -466,22 +454,22 @@ MediaStreamGraphImpl::MarkConsumed(MediaStream* aStream) } void -MediaStreamGraphImpl::UpdateStreamOrderForStream(mozilla::LinkedList* aStack, +MediaStreamGraphImpl::UpdateStreamOrderForStream(nsTArray* aStack, already_AddRefed aStream) { nsRefPtr stream = aStream; NS_ASSERTION(!stream->mHasBeenOrdered, "stream should not have already been ordered"); if (stream->mIsOnOrderingStack) { - MediaStream* iter = aStack->getLast(); - do { - iter->AsProcessedStream()->mInCycle = true; - iter = iter->getPrevious(); - } while (iter != stream); + for (int32_t i = aStack->Length() - 1; ; --i) { + aStack->ElementAt(i)->AsProcessedStream()->mInCycle = true; + if (aStack->ElementAt(i) == stream) + break; + } return; } ProcessedMediaStream* ps = stream->AsProcessedStream(); if (ps) { - aStack->insertBack(stream); + aStack->AppendElement(stream); stream->mIsOnOrderingStack = true; for (uint32_t i = 0; i < ps->mInputs.Length(); ++i) { MediaStream* source = ps->mInputs[i]->mSource; @@ -490,7 +478,7 @@ MediaStreamGraphImpl::UpdateStreamOrderForStream(mozilla::LinkedListpopLast(); + aStack->RemoveElementAt(aStack->Length() - 1); stream->mIsOnOrderingStack = false; } @@ -501,10 +489,10 @@ MediaStreamGraphImpl::UpdateStreamOrderForStream(mozilla::LinkedList > oldStreams; + oldStreams.SwapElements(mStreams); + for (uint32_t i = 0; i < oldStreams.Length(); ++i) { + MediaStream* stream = oldStreams[i]; stream->mHasBeenOrdered = false; stream->mIsConsumed = false; stream->mIsOnOrderingStack = false; @@ -515,9 +503,9 @@ MediaStreamGraphImpl::UpdateStreamOrder() } } - mozilla::LinkedList stack; - for (uint32_t i = 0; i < mOldStreams.Length(); ++i) { - nsRefPtr& s = mOldStreams[i]; + nsAutoTArray stack; + for (uint32_t i = 0; i < oldStreams.Length(); ++i) { + nsRefPtr& s = oldStreams[i]; if (!s->mAudioOutputs.IsEmpty() || !s->mVideoOutputs.IsEmpty()) { MarkConsumed(s); } @@ -900,47 +888,28 @@ MediaStreamGraphImpl::PlayVideo(MediaStream* aStream) } } -bool -MediaStreamGraphImpl::ShouldUpdateMainThread() -{ - if (mRealtime) { - return true; - } - - TimeStamp now = TimeStamp::Now(); - if ((now - mLastMainThreadUpdate).ToMilliseconds() > MEDIA_GRAPH_TARGET_PERIOD_MS) { - mLastMainThreadUpdate = now; - return true; - } - return false; -} - void MediaStreamGraphImpl::PrepareUpdatesToMainThreadState(bool aFinalUpdate) { mMonitor.AssertCurrentThreadOwns(); - // We don't want to update the main thread about timing update when we are not - // running in realtime. - if (ShouldUpdateMainThread()) { - mStreamUpdates.SetCapacity(mStreamUpdates.Length() + mStreams.Length()); - for (uint32_t i = 0; i < mStreams.Length(); ++i) { - MediaStream* stream = mStreams[i]; - if (!stream->MainThreadNeedsUpdates()) { - continue; - } - StreamUpdate* update = mStreamUpdates.AppendElement(); - update->mGraphUpdateIndex = stream->mGraphUpdateIndices.GetAt(mCurrentTime); - update->mStream = stream; - update->mNextMainThreadCurrentTime = - GraphTimeToStreamTime(stream, mCurrentTime); - update->mNextMainThreadFinished = - stream->mFinished && - StreamTimeToGraphTime(stream, stream->GetBufferEnd()) <= mCurrentTime; - } - if (!mPendingUpdateRunnables.IsEmpty()) { - mUpdateRunnables.MoveElementsFrom(mPendingUpdateRunnables); + mStreamUpdates.SetCapacity(mStreamUpdates.Length() + mStreams.Length()); + for (uint32_t i = 0; i < mStreams.Length(); ++i) { + MediaStream* stream = mStreams[i]; + if (!stream->MainThreadNeedsUpdates()) { + continue; } + StreamUpdate* update = mStreamUpdates.AppendElement(); + update->mGraphUpdateIndex = stream->mGraphUpdateIndices.GetAt(mCurrentTime); + update->mStream = stream; + update->mNextMainThreadCurrentTime = + GraphTimeToStreamTime(stream, mCurrentTime); + update->mNextMainThreadFinished = + stream->mFinished && + StreamTimeToGraphTime(stream, stream->GetBufferEnd()) <= mCurrentTime; + } + if (!mPendingUpdateRunnables.IsEmpty()) { + mUpdateRunnables.MoveElementsFrom(mPendingUpdateRunnables); } // Don't send the message to the main thread if it's not going to have @@ -1203,7 +1172,6 @@ MediaStreamGraphImpl::RunThread() if (!mRealtime) { mNonRealtimeIsRunning = false; } - profiler_unregister_thread(); } void @@ -1249,23 +1217,6 @@ MediaStreamGraphImpl::ForceShutDown() namespace { -class MediaStreamGraphInitThreadRunnable : public nsRunnable { -public: - explicit MediaStreamGraphInitThreadRunnable(MediaStreamGraphImpl* aGraph) - : mGraph(aGraph) - { - } - NS_IMETHOD Run() - { - char aLocal; - profiler_register_thread("MediaStreamGraph", &aLocal); - mGraph->RunThread(); - return NS_OK; - } -private: - MediaStreamGraphImpl* mGraph; -}; - class MediaStreamGraphThreadRunnable : public nsRunnable { public: explicit MediaStreamGraphThreadRunnable(MediaStreamGraphImpl* aGraph) @@ -1405,7 +1356,7 @@ MediaStreamGraphImpl::RunInStableState() // Start the thread now. We couldn't start it earlier because // the graph might exit immediately on finding it has no streams. The // first message for a new graph must create a stream. - nsCOMPtr event = new MediaStreamGraphInitThreadRunnable(this); + nsCOMPtr event = new MediaStreamGraphThreadRunnable(this); NS_NewNamedThread("MediaStreamGrph", getter_AddRefs(mThread), event); } @@ -2217,7 +2168,7 @@ MediaStreamGraphImpl::MediaStreamGraphImpl(bool aRealtime) } #endif - mCurrentTimeStamp = mInitialTimeStamp = mLastMainThreadUpdate = TimeStamp::Now(); + mCurrentTimeStamp = mInitialTimeStamp = TimeStamp::Now(); } NS_IMPL_ISUPPORTS1(MediaStreamGraphShutdownObserver, nsIObserver) diff --git a/content/media/MediaStreamGraph.h b/content/media/MediaStreamGraph.h index 2465e673780..9cf5df5459b 100644 --- a/content/media/MediaStreamGraph.h +++ b/content/media/MediaStreamGraph.h @@ -7,7 +7,6 @@ #define MOZILLA_MEDIASTREAMGRAPH_H_ #include "mozilla/Mutex.h" -#include "mozilla/LinkedList.h" #include "AudioStream.h" #include "nsTArray.h" #include "nsIRunnable.h" @@ -258,7 +257,7 @@ struct AudioChunk; * for those objects in arbitrary order and the MediaStreamGraph has to be able * to handle this. */ -class MediaStream : public mozilla::LinkedListElement { +class MediaStream { public: NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaStream) diff --git a/content/media/MediaStreamGraphImpl.h b/content/media/MediaStreamGraphImpl.h index 695fb5f1239..628c1f5525a 100644 --- a/content/media/MediaStreamGraphImpl.h +++ b/content/media/MediaStreamGraphImpl.h @@ -15,9 +15,6 @@ namespace mozilla { -template -class LinkedList; - #ifdef PR_LOGGING extern PRLogModuleInfo* gMediaStreamGraphLog; #define LOG(type, msg) PR_LOG(gMediaStreamGraphLog, type, msg) @@ -193,12 +190,6 @@ public: * mMonitor must be held. */ void PrepareUpdatesToMainThreadState(bool aFinalUpdate); - /** - * If we are rendering in non-realtime mode, we don't want to send messages to - * the main thread at each iteration for performance reasons. We instead - * notify the main thread at the same rate - */ - bool ShouldUpdateMainThread(); // The following methods are the various stages of RunThread processing. /** * Compute a new current time for the graph and advance all on-graph-thread @@ -224,7 +215,7 @@ public: * If aStream hasn't already been ordered, push it onto aStack and order * its children. */ - void UpdateStreamOrderForStream(mozilla::LinkedList* aStack, + void UpdateStreamOrderForStream(nsTArray* aStack, already_AddRefed aStream); /** * Mark aStream and all its inputs (recursively) as consumed. @@ -379,11 +370,6 @@ public: // is not running and this state can be used from the main thread. nsTArray > mStreams; - /** - * mOldStreams is used as temporary storage for streams when computing the - * order in which we compute them. - */ - nsTArray > mOldStreams; /** * The current graph time for the current iteration of the RunThread control * loop. @@ -403,10 +389,6 @@ public: * The real timestamp of the latest run of UpdateCurrentTime. */ TimeStamp mCurrentTimeStamp; - /** - * Date of the last time we updated the main thread with the graph state. - */ - TimeStamp mLastMainThreadUpdate; /** * Which update batch we are currently processing. */ diff --git a/xpcom/glue/nsTArray.h b/xpcom/glue/nsTArray.h index 3a386477005..06a6ae64f3a 100644 --- a/xpcom/glue/nsTArray.h +++ b/xpcom/glue/nsTArray.h @@ -1042,20 +1042,6 @@ public: // // Mutation methods // - // This method call the destructor on each element of the array, empties it, - // but does not shrink the array's capacity. - // - // Make sure to call Compact() if needed to avoid keeping a huge array - // around. - void ClearAndRetainStorage() { - if (base_type::mHdr == EmptyHdr()) { - return; - } - - DestructRange(0, Length()); - base_type::mHdr->mLength = 0; - } - // This method replaces a range of elements in this array. // @param start The starting index of the elements to replace.