Bug 882543 - Retain storage for media streams accross iterations instead of reallocating. r=jlebar,roc

This commit is contained in:
Paul Adenot 2013-07-19 16:40:56 +02:00
parent a4793c674a
commit 77d11314c9
3 changed files with 25 additions and 6 deletions

View File

@ -489,10 +489,10 @@ MediaStreamGraphImpl::UpdateStreamOrderForStream(nsTArray<MediaStream*>* aStack,
void
MediaStreamGraphImpl::UpdateStreamOrder()
{
nsTArray<nsRefPtr<MediaStream> > oldStreams;
oldStreams.SwapElements(mStreams);
for (uint32_t i = 0; i < oldStreams.Length(); ++i) {
MediaStream* stream = oldStreams[i];
mOldStreams.SwapElements(mStreams);
mStreams.ClearAndRetainStorage();
for (uint32_t i = 0; i < mOldStreams.Length(); ++i) {
MediaStream* stream = mOldStreams[i];
stream->mHasBeenOrdered = false;
stream->mIsConsumed = false;
stream->mIsOnOrderingStack = false;
@ -504,8 +504,8 @@ MediaStreamGraphImpl::UpdateStreamOrder()
}
nsAutoTArray<MediaStream*,10> stack;
for (uint32_t i = 0; i < oldStreams.Length(); ++i) {
nsRefPtr<MediaStream>& s = oldStreams[i];
for (uint32_t i = 0; i < mOldStreams.Length(); ++i) {
nsRefPtr<MediaStream>& s = mOldStreams[i];
if (!s->mAudioOutputs.IsEmpty() || !s->mVideoOutputs.IsEmpty()) {
MarkConsumed(s);
}

View File

@ -370,6 +370,11 @@ public:
// is not running and this state can be used from the main thread.
nsTArray<nsRefPtr<MediaStream> > mStreams;
/**
* mOldStreams is used as temporary storage for streams when computing the
* order in which we compute them.
*/
nsTArray<nsRefPtr<MediaStream> > mOldStreams;
/**
* The current graph time for the current iteration of the RunThread control
* loop.

View File

@ -1042,6 +1042,20 @@ 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.