diff --git a/content/media/MediaStreamGraph.cpp b/content/media/MediaStreamGraph.cpp index 994c245e35b..d323f5758cb 100644 --- a/content/media/MediaStreamGraph.cpp +++ b/content/media/MediaStreamGraph.cpp @@ -4,6 +4,7 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "MediaStreamGraphImpl.h" +#include "mozilla/LinkedList.h" #include "AudioSegment.h" #include "VideoSegment.h" @@ -465,22 +466,22 @@ MediaStreamGraphImpl::MarkConsumed(MediaStream* aStream) } void -MediaStreamGraphImpl::UpdateStreamOrderForStream(nsTArray* aStack, +MediaStreamGraphImpl::UpdateStreamOrderForStream(mozilla::LinkedList* aStack, already_AddRefed aStream) { nsRefPtr stream = aStream; NS_ASSERTION(!stream->mHasBeenOrdered, "stream should not have already been ordered"); if (stream->mIsOnOrderingStack) { - for (int32_t i = aStack->Length() - 1; ; --i) { - aStack->ElementAt(i)->AsProcessedStream()->mInCycle = true; - if (aStack->ElementAt(i) == stream) - break; - } + MediaStream* iter = aStack->getLast(); + do { + iter->AsProcessedStream()->mInCycle = true; + iter = iter->getPrevious(); + } while (iter != stream); return; } ProcessedMediaStream* ps = stream->AsProcessedStream(); if (ps) { - aStack->AppendElement(stream); + aStack->insertBack(stream); stream->mIsOnOrderingStack = true; for (uint32_t i = 0; i < ps->mInputs.Length(); ++i) { MediaStream* source = ps->mInputs[i]->mSource; @@ -489,7 +490,7 @@ MediaStreamGraphImpl::UpdateStreamOrderForStream(nsTArray* aStack, UpdateStreamOrderForStream(aStack, s.forget()); } } - aStack->RemoveElementAt(aStack->Length() - 1); + aStack->popLast(); stream->mIsOnOrderingStack = false; } @@ -514,7 +515,7 @@ MediaStreamGraphImpl::UpdateStreamOrder() } } - nsAutoTArray stack; + mozilla::LinkedList stack; for (uint32_t i = 0; i < mOldStreams.Length(); ++i) { nsRefPtr& s = mOldStreams[i]; if (!s->mAudioOutputs.IsEmpty() || !s->mVideoOutputs.IsEmpty()) { diff --git a/content/media/MediaStreamGraph.h b/content/media/MediaStreamGraph.h index 9cf5df5459b..2465e673780 100644 --- a/content/media/MediaStreamGraph.h +++ b/content/media/MediaStreamGraph.h @@ -7,6 +7,7 @@ #define MOZILLA_MEDIASTREAMGRAPH_H_ #include "mozilla/Mutex.h" +#include "mozilla/LinkedList.h" #include "AudioStream.h" #include "nsTArray.h" #include "nsIRunnable.h" @@ -257,7 +258,7 @@ struct AudioChunk; * for those objects in arbitrary order and the MediaStreamGraph has to be able * to handle this. */ -class MediaStream { +class MediaStream : public mozilla::LinkedListElement { public: NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaStream) diff --git a/content/media/MediaStreamGraphImpl.h b/content/media/MediaStreamGraphImpl.h index dcc9ba719aa..695fb5f1239 100644 --- a/content/media/MediaStreamGraphImpl.h +++ b/content/media/MediaStreamGraphImpl.h @@ -15,6 +15,9 @@ namespace mozilla { +template +class LinkedList; + #ifdef PR_LOGGING extern PRLogModuleInfo* gMediaStreamGraphLog; #define LOG(type, msg) PR_LOG(gMediaStreamGraphLog, type, msg) @@ -221,7 +224,7 @@ public: * If aStream hasn't already been ordered, push it onto aStack and order * its children. */ - void UpdateStreamOrderForStream(nsTArray* aStack, + void UpdateStreamOrderForStream(mozilla::LinkedList* aStack, already_AddRefed aStream); /** * Mark aStream and all its inputs (recursively) as consumed.