Bug 1015519 - Don't write uninitialized buffers to the AudioStream in AudioSegment::WriteTo. r=roc, a=sledru
authorPaul Adenot <paul@paul.cx>
Thu, 19 Jun 2014 13:30:27 +0200
changeset 200639 6ed66a6c932cb16c6d2bca341746e96545203907
parent 200638 80a9e64d75f5d0894358080d46f00af25ce441e8
child 200640 643d6fce5bee186ac4923d1b5479a177885c9130
push id486
push userasasaki@mozilla.com
push dateMon, 14 Jul 2014 18:39:42 +0000
treeherdermozilla-release@d33428174ff1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc, sledru
bugs1015519
milestone31.0
Bug 1015519 - Don't write uninitialized buffers to the AudioStream in AudioSegment::WriteTo. r=roc, a=sledru
content/media/AudioSegment.cpp
--- a/content/media/AudioSegment.cpp
+++ b/content/media/AudioSegment.cpp
@@ -149,26 +149,26 @@ void AudioSegment::ResampleChunks(SpeexR
 }
 
 void
 AudioSegment::WriteTo(uint64_t aID, AudioStream* aOutput, AudioMixer* aMixer)
 {
   uint32_t outputChannels = aOutput->GetChannels();
   nsAutoTArray<AudioDataValue,AUDIO_PROCESSING_FRAMES*GUESS_AUDIO_CHANNELS> buf;
   nsAutoTArray<const void*,GUESS_AUDIO_CHANNELS> channelData;
+  // Offset in the buffer that will end up sent to the AudioStream, in samples.
+  uint32_t offset = 0;
 
   if (!GetDuration()) {
     return;
   }
 
   uint32_t outBufferLength = GetDuration() * outputChannels;
   buf.SetLength(outBufferLength);
 
-  // Offset in the buffer that will end up sent to the AudioStream.
-  uint32_t offset = 0;
 
   for (ChunkIterator ci(*this); !ci.IsEnded(); ci.Next()) {
     AudioChunk& c = *ci;
     uint32_t frames = c.mDuration;
 
     // If we have written data in the past, or we have real (non-silent) data
     // to write, we can proceed. Otherwise, it means we just started the
     // AudioStream, and we don't have real data to write to it (just silence).
@@ -196,29 +196,28 @@ AudioSegment::WriteTo(uint64_t aID, Audi
                                      frames, c.mVolume,
                                      outputChannels,
                                      buf.Elements() + offset);
         }
       } else {
         // Assumes that a bit pattern of zeroes == 0.0f
         memset(buf.Elements() + offset, 0, outputChannels * frames * sizeof(AudioDataValue));
       }
+      offset += frames * outputChannels;
     }
 
-    offset += frames * outputChannels;
-
     if (!c.mTimeStamp.IsNull()) {
       TimeStamp now = TimeStamp::Now();
       // would be more efficient to c.mTimeStamp to ms on create time then pass here
       LogTime(AsyncLatencyLogger::AudioMediaStreamTrack, aID,
               (now - c.mTimeStamp).ToMilliseconds(), c.mTimeStamp);
     }
   }
 
-  aOutput->Write(buf.Elements(), GetDuration(), &(mChunks[mChunks.Length() - 1].mTimeStamp));
+  aOutput->Write(buf.Elements(), offset / outputChannels, &(mChunks[mChunks.Length() - 1].mTimeStamp));
 
   if (aMixer) {
     aMixer->Mix(buf.Elements(), outputChannels, GetDuration(), aOutput->GetRate());
   }
   aOutput->Start();
 }
 
 }