Bug 1258567 - per comment 3, ensure volume is only applied once to the AudioSegment. r=kinetik. draft
authorJW Wang <jwwang@mozilla.com>
Tue, 22 Mar 2016 14:11:03 +0800
changeset 343288 81e945091f15b3aff8478b2b6cbafd9f67e1d833
parent 343287 eb121348fa2d68422743d8d6b218b8c2f74c7a19
child 343319 9331589a7b17d1e2d0078faa5b922db7e1c5343e
push id13576
push userjwwang@mozilla.com
push dateTue, 22 Mar 2016 06:12:26 +0000
reviewerskinetik
bugs1258567
milestone48.0a1
Bug 1258567 - per comment 3, ensure volume is only applied once to the AudioSegment. r=kinetik. MozReview-Commit-ID: Bks59JySrep
dom/media/mediasink/DecodedStream.cpp
--- a/dom/media/mediasink/DecodedStream.cpp
+++ b/dom/media/mediasink/DecodedStream.cpp
@@ -447,18 +447,17 @@ void
 DecodedStream::SetPreservesPitch(bool aPreservesPitch)
 {
   AssertOwnerThread();
   mParams.mPreservesPitch = aPreservesPitch;
 }
 
 static void
 SendStreamAudio(DecodedStreamData* aStream, int64_t aStartTime,
-                MediaData* aData, AudioSegment* aOutput,
-                uint32_t aRate, double aVolume)
+                MediaData* aData, AudioSegment* aOutput, uint32_t aRate)
 {
   // The amount of audio frames that is used to fuzz rounding errors.
   static const int64_t AUDIO_FUZZ_FRAMES = 1;
 
   MOZ_ASSERT(aData);
   AudioData* audio = aData->As<AudioData>();
   // This logic has to mimic AudioSink closely to make sure we write
   // the exact same silences
@@ -489,17 +488,16 @@ SendStreamAudio(DecodedStreamData* aStre
   RefPtr<SharedBuffer> buffer = audio->mAudioBuffer;
   AudioDataValue* bufferData = static_cast<AudioDataValue*>(buffer->Data());
   AutoTArray<const AudioDataValue*, 2> channels;
   for (uint32_t i = 0; i < audio->mChannels; ++i) {
     channels.AppendElement(bufferData + i * audio->mFrames);
   }
   aOutput->AppendFrames(buffer.forget(), channels, audio->mFrames);
   aStream->mAudioFramesWritten += audio->mFrames;
-  aOutput->ApplyVolume(aVolume);
 
   aStream->mNextAudioTime = audio->GetEndTime();
 }
 
 void
 DecodedStream::SendAudio(double aVolume, bool aIsSameOrigin)
 {
   AssertOwnerThread();
@@ -513,19 +511,21 @@ DecodedStream::SendAudio(double aVolume,
   AutoTArray<RefPtr<MediaData>,10> audio;
   TrackID audioTrackId = mInfo.mAudio.mTrackId;
   SourceMediaStream* sourceStream = mData->mStream;
 
   // It's OK to hold references to the AudioData because AudioData
   // is ref-counted.
   mAudioQueue.GetElementsAfter(mData->mNextAudioTime, &audio);
   for (uint32_t i = 0; i < audio.Length(); ++i) {
-    SendStreamAudio(mData.get(), mStartTime.ref(), audio[i], &output, rate, aVolume);
+    SendStreamAudio(mData.get(), mStartTime.ref(), audio[i], &output, rate);
   }
 
+  output.ApplyVolume(aVolume);
+
   if (!aIsSameOrigin) {
     output.ReplaceWithDisabled();
   }
 
   // |mNextAudioTime| is updated as we process each audio sample in
   // SendStreamAudio(). This is consistent with how |mNextVideoTime|
   // is updated for video samples.
   if (output.GetDuration() > 0) {