bug 1391482 keep custom oscillator data buffer on graph thread only long enough to initialize the PeriodicWave r?padenot
MozReview-Commit-ID: 6gdBZDruCc6
--- a/dom/media/webaudio/OscillatorNode.cpp
+++ b/dom/media/webaudio/OscillatorNode.cpp
@@ -102,17 +102,16 @@ public:
switch (aIndex) {
case TYPE:
// Set the new type.
mType = static_cast<OscillatorType>(aParam);
if (mType == OscillatorType::Sine) {
// Forget any previous custom data.
mCustomLength = 0;
mCustomDisableNormalization = false;
- mCustom = nullptr;
mPeriodicWave = nullptr;
mRecomputeParameters = true;
}
switch (mType) {
case OscillatorType::Sine:
mPhase = 0.0;
break;
case OscillatorType::Square:
@@ -139,22 +138,22 @@ public:
NS_ERROR("Bad OscillatorNodeEngine Int32Parameter.");
}
// End index switch.
}
void SetBuffer(already_AddRefed<ThreadSharedFloatArrayBufferList> aBuffer) override
{
MOZ_ASSERT(mCustomLength, "Custom buffer sent before length");
- mCustom = aBuffer;
- MOZ_ASSERT(mCustom->GetChannels() == 2,
+ RefPtr<ThreadSharedFloatArrayBufferList> custom = aBuffer;
+ MOZ_ASSERT(custom->GetChannels() == 2,
"PeriodicWave should have sent two channels");
mPeriodicWave = WebCore::PeriodicWave::create(mSource->SampleRate(),
- mCustom->GetData(0),
- mCustom->GetData(1),
+ custom->GetData(0),
+ custom->GetData(1),
mCustomLength,
mCustomDisableNormalization);
}
void IncrementPhase()
{
const float twoPiFloat = float(2 * M_PI);
mPhase += mPhaseIncrement;
@@ -368,20 +367,16 @@ public:
size_t amount = AudioNodeEngine::SizeOfExcludingThis(aMallocSizeOf);
// Not owned:
// - mSource
// - mDestination
// - mFrequency (internal ref owned by node)
// - mDetune (internal ref owned by node)
- if (mCustom) {
- amount += mCustom->SizeOfIncludingThis(aMallocSizeOf);
- }
-
if (mPeriodicWave) {
amount += mPeriodicWave->sizeOfIncludingThis(aMallocSizeOf);
}
return amount;
}
size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override
@@ -396,17 +391,16 @@ public:
StreamTime mStop;
AudioParamTimeline mFrequency;
AudioParamTimeline mDetune;
OscillatorType mType;
float mPhase;
float mFinalFrequency;
float mPhaseIncrement;
bool mRecomputeParameters;
- RefPtr<ThreadSharedFloatArrayBufferList> mCustom;
RefPtr<BasicWaveFormCache> mBasicWaveFormCache;
uint32_t mCustomLength;
bool mCustomDisableNormalization;
RefPtr<WebCore::PeriodicWave> mPeriodicWave;
};
OscillatorNode::OscillatorNode(AudioContext* aContext)
: AudioScheduledSourceNode(aContext,