Bug 1258567 - per comment 3, ensure volume is only applied once to the AudioSegment. r=kinetik.
MozReview-Commit-ID: Bks59JySrep
--- 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) {