Bug 882543 - Use a linked list for ordering stream instead of an array. r=ehsan

This commit is contained in:
Paul Adenot 2013-07-19 16:40:58 +02:00
parent f6754911f0
commit e9213cc266
3 changed files with 16 additions and 11 deletions

View File

@ -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<MediaStream*>* aStack,
MediaStreamGraphImpl::UpdateStreamOrderForStream(mozilla::LinkedList<MediaStream>* aStack,
already_AddRefed<MediaStream> aStream)
{
nsRefPtr<MediaStream> 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<MediaStream*>* aStack,
UpdateStreamOrderForStream(aStack, s.forget());
}
}
aStack->RemoveElementAt(aStack->Length() - 1);
aStack->popLast();
stream->mIsOnOrderingStack = false;
}
@ -514,7 +515,7 @@ MediaStreamGraphImpl::UpdateStreamOrder()
}
}
nsAutoTArray<MediaStream*,10> stack;
mozilla::LinkedList<MediaStream> stack;
for (uint32_t i = 0; i < mOldStreams.Length(); ++i) {
nsRefPtr<MediaStream>& s = mOldStreams[i];
if (!s->mAudioOutputs.IsEmpty() || !s->mVideoOutputs.IsEmpty()) {

View File

@ -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<MediaStream> {
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaStream)

View File

@ -15,6 +15,9 @@
namespace mozilla {
template <typename T>
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<MediaStream*>* aStack,
void UpdateStreamOrderForStream(mozilla::LinkedList<MediaStream>* aStack,
already_AddRefed<MediaStream> aStream);
/**
* Mark aStream and all its inputs (recursively) as consumed.