Bug 865244 - Implement AudioContext.destination.maxChannelCount. r=ehsan
authorPaul Adenot <paul@paul.cx>
Mon, 10 Jun 2013 19:32:28 +0200
changeset 146031 f223d663d69136a1d710bbad5f6e1ced285b4189
parent 146030 116e84abedcab28ebb66e5cecd9ddb54df3a2d92
child 146032 3443f1733c2219ef40d6e0f78652a61f15b7c860
push id2697
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 18:49:53 +0000
treeherdermozilla-beta@dfec938c7b63 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs865244
milestone24.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 865244 - Implement AudioContext.destination.maxChannelCount. r=ehsan
content/media/webaudio/AudioContext.cpp
content/media/webaudio/AudioContext.h
content/media/webaudio/AudioDestinationNode.cpp
content/media/webaudio/AudioDestinationNode.h
content/media/webaudio/AudioNode.h
dom/webidl/AudioDestinationNode.webidl
--- a/content/media/webaudio/AudioContext.cpp
+++ b/content/media/webaudio/AudioContext.cpp
@@ -45,16 +45,17 @@ AudioContext::AudioContext(nsPIDOMWindow
                            bool aIsOffline,
                            uint32_t aNumberOfChannels,
                            uint32_t aLength,
                            float aSampleRate)
   : mSampleRate(aIsOffline ? aSampleRate : IdealAudioRate())
   , mDestination(new AudioDestinationNode(this, aIsOffline,
                                           aNumberOfChannels,
                                           aLength, aSampleRate))
+  , mNumberOfChannels(aNumberOfChannels)
   , mIsOffline(aIsOffline)
 {
   // Actually play audio
   mDestination->Stream()->AddAudioOutput(&gWebAudioOutputKey);
   nsDOMEventTargetHelper::BindToOwner(aWindow);
   SetIsDOMBinding();
 
   mPannerNodes.Init();
@@ -392,16 +393,22 @@ FindConnectedSourcesOn(nsPtrHashKey<Pann
 }
 
 void
 AudioContext::UpdatePannerSource()
 {
   mPannerNodes.EnumerateEntries(FindConnectedSourcesOn, nullptr);
 }
 
+uint32_t
+AudioContext::MaxChannelCount() const
+{
+  return mIsOffline ? mNumberOfChannels : AudioStream::MaxNumberOfChannels();
+}
+
 MediaStreamGraph*
 AudioContext::Graph() const
 {
   return Destination()->Stream()->Graph();
 }
 
 MediaStream*
 AudioContext::DestinationStream() const
--- a/content/media/webaudio/AudioContext.h
+++ b/content/media/webaudio/AudioContext.h
@@ -195,16 +195,18 @@ public:
 
   MediaStreamGraph* Graph() const;
   MediaStream* DestinationStream() const;
   void UnregisterAudioBufferSourceNode(AudioBufferSourceNode* aNode);
   void UnregisterPannerNode(PannerNode* aNode);
   void UnregisterScriptProcessorNode(ScriptProcessorNode* aNode);
   void UpdatePannerSource();
 
+  uint32_t MaxChannelCount() const;
+
   JSContext* GetJSContext() const;
 
 private:
   void RemoveFromDecodeQueue(WebAudioDecodeJob* aDecodeJob);
 
   friend struct ::mozilla::WebAudioDecodeJob;
 
 private:
@@ -218,16 +220,18 @@ private:
   // Two hashsets containing all the PannerNodes and AudioBufferSourceNodes,
   // to compute the doppler shift, and also to stop AudioBufferSourceNodes.
   // These are all weak pointers.
   nsTHashtable<nsPtrHashKey<PannerNode> > mPannerNodes;
   nsTHashtable<nsPtrHashKey<AudioBufferSourceNode> > mAudioBufferSourceNodes;
   // Hashset containing all ScriptProcessorNodes in order to stop them.
   // These are all weak pointers.
   nsTHashtable<nsPtrHashKey<ScriptProcessorNode> > mScriptProcessorNodes;
+  // Number of channels passed in the OfflineAudioContext ctor.
+  uint32_t mNumberOfChannels;
   bool mIsOffline;
 };
 
 }
 }
 
 #endif
 
--- a/content/media/webaudio/AudioDestinationNode.cpp
+++ b/content/media/webaudio/AudioDestinationNode.cpp
@@ -196,16 +196,33 @@ AudioDestinationNode::AudioDestinationNo
                             MediaStreamGraph::GetInstance();
   AudioNodeEngine* engine = aIsOffline ?
                             new OfflineDestinationNodeEngine(this, aNumberOfChannels,
                                                              aLength, aSampleRate) :
                             new AudioNodeEngine(this);
   mStream = graph->CreateAudioNodeStream(engine, MediaStreamGraph::EXTERNAL_STREAM);
 }
 
+uint32_t
+AudioDestinationNode::MaxChannelCount() const
+{
+  return Context()->MaxChannelCount();
+}
+
+void
+AudioDestinationNode::SetChannelCount(uint32_t aChannelCount, ErrorResult& aRv)
+{
+  if (aChannelCount > MaxChannelCount()) {
+    aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
+    return;
+  }
+
+  AudioNode::SetChannelCount(aChannelCount, aRv);
+}
+
 void
 AudioDestinationNode::DestroyGraph()
 {
   MOZ_ASSERT(Context() && Context()->IsOffline(),
              "Should only be called on a valid OfflineAudioContext");
   MediaStreamGraph::DestroyNonRealtimeInstance(mStream->Graph());
 }
 
--- a/content/media/webaudio/AudioDestinationNode.h
+++ b/content/media/webaudio/AudioDestinationNode.h
@@ -30,16 +30,20 @@ public:
   virtual JSObject* WrapObject(JSContext* aCx,
                                JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 
   virtual uint16_t NumberOfOutputs() const MOZ_FINAL MOZ_OVERRIDE
   {
     return 0;
   }
 
+  uint32_t MaxChannelCount() const;
+  virtual void SetChannelCount(uint32_t aChannelCount,
+                               ErrorResult& aRv) MOZ_OVERRIDE;
+
   void StartRendering();
 
   void DestroyGraph();
 
 private:
   uint32_t mFramesToProduce;
 };
 
--- a/content/media/webaudio/AudioNode.h
+++ b/content/media/webaudio/AudioNode.h
@@ -155,17 +155,17 @@ public:
 
   // The following two virtual methods must be implemented by each node type
   // to provide their number of input and output ports. These numbers are
   // constant for the lifetime of the node. Both default to 1.
   virtual uint16_t NumberOfInputs() const { return 1; }
   virtual uint16_t NumberOfOutputs() const { return 1; }
 
   uint32_t ChannelCount() const { return mChannelCount; }
-  void SetChannelCount(uint32_t aChannelCount, ErrorResult& aRv)
+  virtual void SetChannelCount(uint32_t aChannelCount, ErrorResult& aRv)
   {
     if (aChannelCount == 0 ||
         aChannelCount > WebAudioUtils::MaxChannelCount) {
       aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
       return;
     }
     mChannelCount = aChannelCount;
     SendChannelMixingParametersToStream();
--- a/dom/webidl/AudioDestinationNode.webidl
+++ b/dom/webidl/AudioDestinationNode.webidl
@@ -8,13 +8,12 @@
  *
  * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
  * liability, trademark and document use rules apply.
  */
 
 [PrefControlled]
 interface AudioDestinationNode : AudioNode {
 
-    //readonly attribute unsigned long maxNumberOfChannels;
-    //attribute unsigned long numberOfChannels;
+    readonly attribute unsigned long maxChannelCount;
 
 };