Bug 890072 - Part 2: Keep the ConvolverNode alive while its reverb buffers are being exhausted; r=roc

This commit is contained in:
Ehsan Akhgari 2013-07-03 20:20:57 -04:00
parent f9030f5b71
commit 97da2b6baa
2 changed files with 28 additions and 0 deletions

View File

@ -26,10 +26,12 @@ NS_IMPL_RELEASE_INHERITED(ConvolverNode, AudioNode)
class ConvolverNodeEngine : public AudioNodeEngine
{
typedef PlayingRefChanged<ConvolverNode> PlayingRefChanged;
public:
ConvolverNodeEngine(AudioNode* aNode, bool aNormalize)
: AudioNodeEngine(aNode)
, mBufferLength(0)
, mLeftOverData(INT32_MIN)
, mSampleRate(0.0f)
, mUseBackgroundThreads(!aNode->Context()->IsOffline())
, mNormalize(aNormalize)
@ -51,6 +53,7 @@ public:
mBuffer = nullptr;
mSampleRate = 0.0f;
mBufferLength = aParam;
mLeftOverData = INT32_MIN;
break;
case SAMPLE_RATE:
mSampleRate = aParam;
@ -92,6 +95,7 @@ public:
if (!mBuffer || !mBufferLength || !mSampleRate) {
mReverb = nullptr;
mSeenInput = false;
mLeftOverData = INT32_MIN;
return;
}
@ -136,12 +140,32 @@ public:
AllocateAudioBlock(numChannels, aOutput);
mReverb->process(&input, aOutput, WEBAUDIO_BLOCK_SIZE);
if (!aInput.IsNull()) {
if (mLeftOverData == INT32_MIN) {
// Start counting the left over data
mLeftOverData = mBufferLength + WEBAUDIO_BLOCK_SIZE;
MOZ_ASSERT(mLeftOverData > 0);
nsRefPtr<PlayingRefChanged> refchanged =
new PlayingRefChanged(aStream, PlayingRefChanged::ADDREF);
NS_DispatchToMainThread(refchanged);
} else {
mLeftOverData -= WEBAUDIO_BLOCK_SIZE;
}
if (mLeftOverData <= 0) {
nsRefPtr<PlayingRefChanged> refchanged =
new PlayingRefChanged(aStream, PlayingRefChanged::RELEASE);
NS_DispatchToMainThread(refchanged);
}
}
}
private:
nsRefPtr<ThreadSharedFloatArrayBufferList> mBuffer;
nsAutoPtr<WebCore::Reverb> mReverb;
int32_t mBufferLength;
int32_t mLeftOverData;
float mSampleRate;
bool mUseBackgroundThreads;
bool mNormalize;

View File

@ -9,6 +9,7 @@
#include "AudioNode.h"
#include "AudioBuffer.h"
#include "PlayingRefChanged.h"
namespace mozilla {
namespace dom {
@ -39,7 +40,10 @@ public:
void SetNormalize(bool aNormal);
private:
friend class PlayingRefChanged<ConvolverNode>;
nsRefPtr<AudioBuffer> mBuffer;
SelfReference<ConvolverNode> mPlayingRef;
bool mNormalize;
};