Bug 1456259 - Correct AnalyserNode construction issues. r?padenot draft
authorAlex Chronopoulos <achronop@gmail.com>
Thu, 26 Apr 2018 16:32:52 +0200
changeset 788478 7613314910b46e79b1cad41bfcb41244fe258de8
parent 785144 3cc613bf13443acc2fea4804872fb3ca56757181
child 788479 fb98d0c688981d9fd6e5f107a1f78326e02e3da1
push id107995
push userachronop@gmail.com
push dateThu, 26 Apr 2018 15:16:55 +0000
reviewerspadenot
bugs1456259
milestone61.0a1
Bug 1456259 - Correct AnalyserNode construction issues. r?padenot MozReview-Commit-ID: 2gMZAMonS2F
dom/media/webaudio/AnalyserNode.cpp
dom/media/webaudio/AnalyserNode.h
dom/webidl/AnalyserNode.webidl
--- a/dom/media/webaudio/AnalyserNode.cpp
+++ b/dom/media/webaudio/AnalyserNode.cpp
@@ -115,22 +115,19 @@ AnalyserNode::Create(AudioContext& aAudi
     return nullptr;
   }
 
   analyserNode->SetFftSize(aOptions.mFftSize, aRv);
   if (NS_WARN_IF(aRv.Failed())) {
     return nullptr;
   }
 
-  analyserNode->SetMinDecibels(aOptions.mMinDecibels, aRv);
-  if (NS_WARN_IF(aRv.Failed())) {
-    return nullptr;
-  }
-
-  analyserNode->SetMaxDecibels(aOptions.mMaxDecibels, aRv);
+  analyserNode->SetMinAndMaxDecibels(aOptions.mMinDecibels,
+                                     aOptions.mMaxDecibels,
+                                     aRv);
   if (NS_WARN_IF(aRv.Failed())) {
     return nullptr;
   }
 
   analyserNode->SetSmoothingTimeConstant(aOptions.mSmoothingTimeConstant, aRv);
   if (NS_WARN_IF(aRv.Failed())) {
     return nullptr;
   }
@@ -215,16 +212,27 @@ AnalyserNode::SetMaxDecibels(double aVal
   if (aValue <= mMinDecibels) {
     aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
     return;
   }
   mMaxDecibels = aValue;
 }
 
 void
+AnalyserNode::SetMinAndMaxDecibels(double aMinValue, double aMaxValue, ErrorResult& aRv)
+{
+  if (aMinValue >= aMaxValue) {
+    aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
+    return;
+  }
+  mMinDecibels = aMinValue;
+  mMaxDecibels = aMaxValue;
+}
+
+void
 AnalyserNode::SetSmoothingTimeConstant(double aValue, ErrorResult& aRv)
 {
   if (aValue < 0 || aValue > 1) {
     aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
     return;
   }
   mSmoothingTimeConstant = aValue;
 }
--- a/dom/media/webaudio/AnalyserNode.h
+++ b/dom/media/webaudio/AnalyserNode.h
@@ -67,16 +67,18 @@ public:
   virtual const char* NodeType() const override
   {
     return "AnalyserNode";
   }
 
   virtual size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const override;
   virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override;
 
+  void SetMinAndMaxDecibels(double aMinValue, double aMaxValue, ErrorResult& aRv);
+
 private:
   ~AnalyserNode() = default;
 
   friend class AnalyserNodeEngine;
   void AppendChunk(const AudioChunk& aChunk);
   bool AllocateBuffer();
   bool FFTAnalysis();
   void ApplyBlackmanWindow(float* aBuffer, uint32_t aSize);
--- a/dom/webidl/AnalyserNode.webidl
+++ b/dom/webidl/AnalyserNode.webidl
@@ -7,19 +7,19 @@
  * https://webaudio.github.io/web-audio-api/
  *
  * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
  * liability, trademark and document use rules apply.
  */
 
 dictionary AnalyserOptions : AudioNodeOptions {
              unsigned long fftSize = 2048;
-             float         maxDecibels = -30;
-             float         minDecibels = -100;
-             float         smoothingTimeConstant = 0.8;
+             double        maxDecibels = -30;
+             double        minDecibels = -100;
+             double        smoothingTimeConstant = 0.8;
 };
 
 [Pref="dom.webaudio.enabled",
  Constructor(BaseAudioContext context, optional AnalyserOptions options)]
 interface AnalyserNode : AudioNode {
 
     // Real-time frequency-domain data
     void getFloatFrequencyData(Float32Array array);