From d6f6b3944716aa8fc8aff69ce43e6cc960c403e3 Mon Sep 17 00:00:00 2001 From: Karl Tomlinson Date: Tue, 3 Dec 2013 12:07:17 +1300 Subject: [PATCH] b=937475 separate stream position from buffer position so that stop time can use stream position r=ehsan --HG-- extra : transplant_source : %8C%F0%05w%0A%C6%21%11%D5A4%85%FD%BC%D6%1F%9A%B8%FE%CB --- .../media/webaudio/AudioBufferSourceNode.cpp | 37 +++++++------------ 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/content/media/webaudio/AudioBufferSourceNode.cpp b/content/media/webaudio/AudioBufferSourceNode.cpp index e5f1c178638..b320e0a43d8 100644 --- a/content/media/webaudio/AudioBufferSourceNode.cpp +++ b/content/media/webaudio/AudioBufferSourceNode.cpp @@ -265,7 +265,7 @@ public: /** * Copy as many frames as possible from the source buffer to aOutput, and * advance aOffsetWithinBlock and aCurrentPosition based on how many frames - * we copy. This will never advance aOffsetWithinBlock past + * we write. This will never advance aOffsetWithinBlock past * WEBAUDIO_BLOCK_SIZE, or aCurrentPosition past mStop. It takes data from * the buffer at aBufferOffset, and never takes more data than aBufferMax. * This function knows when it needs to allocate the output buffer, and also @@ -306,20 +306,12 @@ public: CopyFromInputBufferWithResampling(aStream, aOutput, aChannels, aBufferOffset, *aOffsetWithinBlock, availableInInputBuffer, framesRead, framesWritten); *aOffsetWithinBlock += framesWritten; - *aCurrentPosition += framesRead; + *aCurrentPosition += framesWritten; mPosition += framesRead; } } } - TrackTicks GetPosition(AudioNodeStream* aStream) - { - if (aStream->GetCurrentPosition() < mStart) { - return aStream->GetCurrentPosition(); - } - return mStart + mPosition; - } - uint32_t ComputeFinalOutSampleRate(TrackRate aStreamSampleRate) { if (mPlaybackRate <= 0 || mPlaybackRate != mPlaybackRate) { @@ -386,38 +378,37 @@ public: UpdateSampleRateIfNeeded(aStream, channels); uint32_t written = 0; - TrackTicks currentPosition = GetPosition(aStream); + TrackTicks streamPosition = aStream->GetCurrentPosition(); while (written < WEBAUDIO_BLOCK_SIZE) { if (mStop != TRACK_TICKS_MAX && - currentPosition >= mStop) { - FillWithZeroes(aOutput, channels, &written, ¤tPosition, TRACK_TICKS_MAX); + streamPosition >= mStop) { + FillWithZeroes(aOutput, channels, &written, &streamPosition, TRACK_TICKS_MAX); continue; } - if (currentPosition < mStart) { - FillWithZeroes(aOutput, channels, &written, ¤tPosition, mStart); + if (streamPosition < mStart) { + FillWithZeroes(aOutput, channels, &written, &streamPosition, mStart); continue; } - TrackTicks t = currentPosition - mStart; + TrackTicks t = mPosition; if (mLoop) { if (mOffset + t < mLoopEnd) { - CopyFromBuffer(aStream, aOutput, channels, &written, ¤tPosition, mOffset + t, mLoopEnd); + CopyFromBuffer(aStream, aOutput, channels, &written, &streamPosition, mOffset + t, mLoopEnd); } else { uint32_t offsetInLoop = (mOffset + t - mLoopEnd) % (mLoopEnd - mLoopStart); - CopyFromBuffer(aStream, aOutput, channels, &written, ¤tPosition, mLoopStart + offsetInLoop, mLoopEnd); + CopyFromBuffer(aStream, aOutput, channels, &written, &streamPosition, mLoopStart + offsetInLoop, mLoopEnd); } } else { if (t < mDuration) { - CopyFromBuffer(aStream, aOutput, channels, &written, ¤tPosition, mOffset + t, mOffset + mDuration); + CopyFromBuffer(aStream, aOutput, channels, &written, &streamPosition, mOffset + t, mOffset + mDuration); } else { - FillWithZeroes(aOutput, channels, &written, ¤tPosition, TRACK_TICKS_MAX); + FillWithZeroes(aOutput, channels, &written, &streamPosition, TRACK_TICKS_MAX); } } } // We've finished if we've gone past mStop, or if we're past mDuration when // looping is disabled. - if (currentPosition >= mStop || - (!mLoop && currentPosition - mStart >= mDuration)) { + if (streamPosition >= mStop || (!mLoop && mPosition >= mDuration)) { *aFinished = true; } } @@ -431,7 +422,7 @@ public: int32_t mLoopStart; int32_t mLoopEnd; int32_t mBufferSampleRate; - uint32_t mPosition; + int32_t mPosition; uint32_t mChannels; float mPlaybackRate; float mDopplerShift;