bug 1388656 keep response buffer on graph thread only long enough to initialize the Reverb r?padenot draft
authorKarl Tomlinson <karlt+@karlt.net>
Tue, 08 Aug 2017 16:08:21 +1200
changeset 645162 bd79599d0d103db038d2487274db47226b88067b
parent 645161 b4746306e776fab1aa3656b9b3a93b6c9fe70bab
child 645163 76bfa8df319f61851f4755bd48648476bc83803b
push id73684
push userktomlinson@mozilla.com
push dateFri, 11 Aug 2017 22:29:12 +0000
reviewerspadenot
bugs1388656
milestone57.0a1
bug 1388656 keep response buffer on graph thread only long enough to initialize the Reverb r?padenot
dom/media/webaudio/ConvolverNode.cpp
--- a/dom/media/webaudio/ConvolverNode.cpp
+++ b/dom/media/webaudio/ConvolverNode.cpp
@@ -44,17 +44,16 @@ public:
     NORMALIZE
   };
   void SetInt32Parameter(uint32_t aIndex, int32_t aParam) override
   {
     switch (aIndex) {
     case BUFFER_LENGTH:
       // BUFFER_LENGTH is the first parameter that we set when setting a new buffer,
       // so we should be careful to invalidate the rest of our state here.
-      mBuffer = nullptr;
       mSampleRate = 0.0f;
       mBufferLength = aParam;
       mLeftOverData = INT32_MIN;
       break;
     case NORMALIZE:
       mNormalize = !!aParam;
       break;
     default:
@@ -70,33 +69,33 @@ public:
       // mReverb will be set using this sample rate when the buffer is received.
       break;
     default:
       NS_ERROR("Bad ConvolverNodeEngine DoubleParameter");
     }
   }
   void SetBuffer(already_AddRefed<ThreadSharedFloatArrayBufferList> aBuffer) override
   {
-    mBuffer = aBuffer;
+    RefPtr<ThreadSharedFloatArrayBufferList> buffer = aBuffer;
 
     // Note about empirical tuning (this is copied from Blink)
     // The maximum FFT size affects reverb performance and accuracy.
     // If the reverb is single-threaded and processes entirely in the real-time audio thread,
     // it's important not to make this too high.  In this case 8192 is a good value.
     // But, the Reverb object is multi-threaded, so we want this as high as possible without losing too much accuracy.
     // Very large FFTs will have worse phase errors. Given these constraints 32768 is a good compromise.
     const size_t MaxFFTSize = 32768;
 
-    if (!mBuffer || !mBufferLength || !mSampleRate) {
+    if (!buffer || !mBufferLength || !mSampleRate) {
       mReverb = nullptr;
       mLeftOverData = INT32_MIN;
       return;
     }
 
-    mReverb = new WebCore::Reverb(mBuffer, mBufferLength,
+    mReverb = new WebCore::Reverb(buffer, mBufferLength,
                                   MaxFFTSize, mUseBackgroundThreads,
                                   mNormalize, mSampleRate);
   }
 
   void ProcessBlock(AudioNodeStream* aStream,
                     GraphTime aFrom,
                     const AudioBlock& aInput,
                     AudioBlock* aOutput,
@@ -154,34 +153,30 @@ public:
   bool IsActive() const override
   {
     return mLeftOverData != INT32_MIN;
   }
 
   size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const override
   {
     size_t amount = AudioNodeEngine::SizeOfExcludingThis(aMallocSizeOf);
-    if (mBuffer && !mBuffer->IsShared()) {
-      amount += mBuffer->SizeOfIncludingThis(aMallocSizeOf);
-    }
 
     if (mReverb) {
       amount += mReverb->sizeOfIncludingThis(aMallocSizeOf);
     }
 
     return amount;
   }
 
   size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override
   {
     return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
   }
 
 private:
-  RefPtr<ThreadSharedFloatArrayBufferList> mBuffer;
   nsAutoPtr<WebCore::Reverb> mReverb;
   int32_t mBufferLength;
   int32_t mLeftOverData;
   float mSampleRate;
   bool mUseBackgroundThreads;
   bool mNormalize;
 };