Bug 1173016 - Properly refcount the inner PeriodicWave object. r=karlt
authorPaul Adenot <paul@paul.cx>
Mon, 06 Jul 2015 13:58:33 +0200
changeset 275866 911c598a9ef2c82458c67fc43da0512ce9064114
parent 275865 146b55675c93adf46164f124b2fb8012ab44e2a1
child 275867 01d7e27c58332ab8fd7768921034bd895c761daf
push id3246
push usergijskruitbosch@gmail.com
push dateTue, 07 Jul 2015 09:06:38 +0000
reviewerskarlt
bugs1173016
milestone42.0a1
Bug 1173016 - Properly refcount the inner PeriodicWave object. r=karlt
dom/media/webaudio/blink/PeriodicWave.cpp
dom/media/webaudio/blink/PeriodicWave.h
--- a/dom/media/webaudio/blink/PeriodicWave.cpp
+++ b/dom/media/webaudio/blink/PeriodicWave.cpp
@@ -35,58 +35,68 @@ const unsigned PeriodicWaveSize = 4096; 
 const unsigned NumberOfRanges = 36; // There should be 3 * log2(PeriodicWaveSize) 1/3 octave ranges.
 const float CentsPerRange = 1200 / 3; // 1/3 Octave.
 
 using namespace mozilla;
 using mozilla::dom::OscillatorType;
 
 namespace WebCore {
 
-PeriodicWave* PeriodicWave::create(float sampleRate,
-                                   const float* real,
-                                   const float* imag,
-                                   size_t numberOfComponents)
+already_AddRefed<PeriodicWave>
+PeriodicWave::create(float sampleRate,
+                     const float* real,
+                     const float* imag,
+                     size_t numberOfComponents)
 {
     bool isGood = real && imag && numberOfComponents > 0 &&
          numberOfComponents <= PeriodicWaveSize;
     MOZ_ASSERT(isGood);
     if (isGood) {
-        PeriodicWave* periodicWave = new PeriodicWave(sampleRate);
+        nsRefPtr<PeriodicWave> periodicWave =
+            new PeriodicWave(sampleRate);
         periodicWave->createBandLimitedTables(real, imag, numberOfComponents);
-        return periodicWave;
+        return periodicWave.forget();
     }
-    return 0;
+    return nullptr;
 }
 
-PeriodicWave* PeriodicWave::createSine(float sampleRate)
+already_AddRefed<PeriodicWave>
+PeriodicWave::createSine(float sampleRate)
 {
-      PeriodicWave* periodicWave = new PeriodicWave(sampleRate);
-          periodicWave->generateBasicWaveform(OscillatorType::Sine);
-              return periodicWave;
+    nsRefPtr<PeriodicWave> periodicWave =
+        new PeriodicWave(sampleRate);
+    periodicWave->generateBasicWaveform(OscillatorType::Sine);
+    return periodicWave.forget();
 }
 
-PeriodicWave* PeriodicWave::createSquare(float sampleRate)
+already_AddRefed<PeriodicWave>
+PeriodicWave::createSquare(float sampleRate)
 {
-      PeriodicWave* periodicWave = new PeriodicWave(sampleRate);
-          periodicWave->generateBasicWaveform(OscillatorType::Square);
-              return periodicWave;
+    nsRefPtr<PeriodicWave> periodicWave =
+        new PeriodicWave(sampleRate);
+    periodicWave->generateBasicWaveform(OscillatorType::Square);
+    return periodicWave.forget();
 }
 
-PeriodicWave* PeriodicWave::createSawtooth(float sampleRate)
+already_AddRefed<PeriodicWave>
+PeriodicWave::createSawtooth(float sampleRate)
 {
-      PeriodicWave* periodicWave = new PeriodicWave(sampleRate);
-          periodicWave->generateBasicWaveform(OscillatorType::Sawtooth);
-              return periodicWave;
+    nsRefPtr<PeriodicWave> periodicWave =
+        new PeriodicWave(sampleRate);
+    periodicWave->generateBasicWaveform(OscillatorType::Sawtooth);
+    return periodicWave.forget();
 }
 
-PeriodicWave* PeriodicWave::createTriangle(float sampleRate)
+already_AddRefed<PeriodicWave>
+PeriodicWave::createTriangle(float sampleRate)
 {
-      PeriodicWave* periodicWave = new PeriodicWave(sampleRate);
-          periodicWave->generateBasicWaveform(OscillatorType::Triangle);
-              return periodicWave;
+    nsRefPtr<PeriodicWave> periodicWave =
+        new PeriodicWave(sampleRate);
+    periodicWave->generateBasicWaveform(OscillatorType::Triangle);
+    return periodicWave.forget();
 }
 
 PeriodicWave::PeriodicWave(float sampleRate)
     : m_sampleRate(sampleRate)
     , m_periodicWaveSize(PeriodicWaveSize)
     , m_numberOfRanges(NumberOfRanges)
     , m_centsPerRange(CentsPerRange)
 {
--- a/dom/media/webaudio/blink/PeriodicWave.h
+++ b/dom/media/webaudio/blink/PeriodicWave.h
@@ -37,30 +37,29 @@
 
 namespace WebCore {
 
 typedef AlignedTArray<float> AlignedAudioFloatArray;
 typedef nsTArray<float> AudioFloatArray;
 
 class PeriodicWave {
 public:
-
-    NS_INLINE_DECL_THREADSAFE_REFCOUNTING(PeriodicWave);
+    NS_INLINE_DECL_THREADSAFE_REFCOUNTING(WebCore::PeriodicWave);
 
-    static PeriodicWave* createSine(float sampleRate);
-    static PeriodicWave* createSquare(float sampleRate);
-    static PeriodicWave* createSawtooth(float sampleRate);
-    static PeriodicWave* createTriangle(float sampleRate);
+    static already_AddRefed<PeriodicWave> createSine(float sampleRate);
+    static already_AddRefed<PeriodicWave> createSquare(float sampleRate);
+    static already_AddRefed<PeriodicWave> createSawtooth(float sampleRate);
+    static already_AddRefed<PeriodicWave> createTriangle(float sampleRate);
 
     // Creates an arbitrary periodic wave given the frequency components
     // (Fourier coefficients).
-    static PeriodicWave* create(float sampleRate,
-                                const float* real,
-                                const float* imag,
-                                size_t numberOfComponents);
+    static already_AddRefed<PeriodicWave> create(float sampleRate,
+                                                 const float* real,
+                                                 const float* imag,
+                                                 size_t numberOfComponents);
 
     // Returns pointers to the lower and higher wave data for the pitch range
     // containing the given fundamental frequency. These two tables are in
     // adjacent "pitch" ranges where the higher table will have the maximum
     // number of partials which won't alias when played back at this
     // fundamental frequency. The lower wave is the next range containing fewer
     // partials than the higher wave. Interpolation between these two tables
     // can be made according to tableInterpolationFactor. Where values