Bug 1100409 - Set AudioNodeStream::mLastChunks length only once. r=padenot, a=lsblakk
authorKarl Tomlinson <karlt+@karlt.net>
Tue, 18 Nov 2014 16:22:45 +1300
changeset 234113 d21e91a547d8b5e2254046ea25a095216af2b354
parent 234112 f6726a81435109887c163c6afa89136af3ea8fe2
child 234114 2d431a82b30da90ee2c48e74c7fc271f433e5f0d
push id1
push usersledru@mozilla.com
push dateThu, 04 Dec 2014 17:57:20 +0000
reviewerspadenot, lsblakk
bugs1100409
milestone35.0
Bug 1100409 - Set AudioNodeStream::mLastChunks length only once. r=padenot, a=lsblakk This can be done because AudioNodeEngine::mOutputCount is const.
content/media/webaudio/AudioNodeExternalInputStream.cpp
content/media/webaudio/AudioNodeStream.cpp
--- a/content/media/webaudio/AudioNodeExternalInputStream.cpp
+++ b/content/media/webaudio/AudioNodeExternalInputStream.cpp
@@ -315,17 +315,17 @@ ConvertSegmentToAudioBlock(AudioSegment*
   }
 }
 
 void
 AudioNodeExternalInputStream::ProcessInput(GraphTime aFrom, GraphTime aTo,
                                            uint32_t aFlags)
 {
   // According to spec, number of outputs is always 1.
-  mLastChunks.SetLength(1);
+  MOZ_ASSERT(mLastChunks.Length() == 1);
 
   // GC stuff can result in our input stream being destroyed before this stream.
   // Handle that.
   if (!IsEnabled() || mInputs.IsEmpty() || mPassThrough) {
     mLastChunks[0].SetNull(WEBAUDIO_BLOCK_SIZE);
     AdvanceOutputSegment();
     return;
   }
--- a/content/media/webaudio/AudioNodeStream.cpp
+++ b/content/media/webaudio/AudioNodeStream.cpp
@@ -37,16 +37,17 @@ AudioNodeStream::AudioNodeStream(AudioNo
     mAudioParamStream(false),
     mPassThrough(false)
 {
   MOZ_ASSERT(NS_IsMainThread());
   mChannelCountMode = ChannelCountMode::Max;
   mChannelInterpretation = ChannelInterpretation::Speakers;
   // AudioNodes are always producing data
   mHasCurrentData = true;
+  mLastChunks.SetLength(std::max(uint16_t(1), mEngine->OutputCount()));
   MOZ_COUNT_CTOR(AudioNodeStream);
 }
 
 AudioNodeStream::~AudioNodeStream()
 {
   MOZ_COUNT_DTOR(AudioNodeStream);
 }
 
@@ -465,18 +466,18 @@ void
 AudioNodeStream::ProcessInput(GraphTime aFrom, GraphTime aTo, uint32_t aFlags)
 {
   if (!mFinished) {
     EnsureTrack(AUDIO_TRACK, mSampleRate);
   }
   // No more tracks will be coming
   mBuffer.AdvanceKnownTracksTime(STREAM_TIME_MAX);
 
-  uint16_t outputCount = std::max(uint16_t(1), mEngine->OutputCount());
-  mLastChunks.SetLength(outputCount);
+  uint16_t outputCount = mLastChunks.Length();
+  MOZ_ASSERT(outputCount == std::max(uint16_t(1), mEngine->OutputCount()));
 
   // Consider this stream blocked if it has already finished output. Normally
   // mBlocked would reflect this, but due to rounding errors our audio track may
   // appear to extend slightly beyond aFrom, so we might not be blocked yet.
   bool blocked = mFinished || mBlocked.GetAt(aFrom);
   // If the stream has finished at this time, it will be blocked.
   if (blocked || InMutedCycle()) {
     for (uint16_t i = 0; i < outputCount; ++i) {
@@ -490,17 +491,17 @@ AudioNodeStream::ProcessInput(GraphTime 
     for (uint16_t i = 0; i < maxInputs; ++i) {
       ObtainInputBlock(inputChunks[i], i);
     }
     bool finished = false;
     if (mPassThrough) {
       MOZ_ASSERT(outputCount == 1, "For now, we only support nodes that have one output port");
       mLastChunks[0] = inputChunks[0];
     } else {
-      if (maxInputs <= 1 && mEngine->OutputCount() <= 1) {
+      if (maxInputs <= 1 && outputCount <= 1) {
         mEngine->ProcessBlock(this, inputChunks[0], &mLastChunks[0], &finished);
       } else {
         mEngine->ProcessBlocksOnPorts(this, inputChunks, mLastChunks, &finished);
       }
     }
     for (uint16_t i = 0; i < outputCount; ++i) {
       NS_ASSERTION(mLastChunks[i].GetDuration() == WEBAUDIO_BLOCK_SIZE,
                    "Invalid WebAudio chunk size");
@@ -530,17 +531,17 @@ AudioNodeStream::ProcessInput(GraphTime 
 
 void
 AudioNodeStream::ProduceOutputBeforeInput(GraphTime aFrom)
 {
   MOZ_ASSERT(mEngine->AsDelayNodeEngine());
   MOZ_ASSERT(mEngine->OutputCount() == 1,
              "DelayNodeEngine output count should be 1");
   MOZ_ASSERT(!InMutedCycle(), "DelayNodes should break cycles");
-  mLastChunks.SetLength(1);
+  MOZ_ASSERT(mLastChunks.Length() == 1);
 
   // Consider this stream blocked if it has already finished output. Normally
   // mBlocked would reflect this, but due to rounding errors our audio track may
   // appear to extend slightly beyond aFrom, so we might not be blocked yet.
   bool blocked = mFinished || mBlocked.GetAt(aFrom);
   // If the stream has finished at this time, it will be blocked.
   if (blocked) {
     mLastChunks[0].SetNull(WEBAUDIO_BLOCK_SIZE);