Bug 1458446 - Add AudioWorkletNode interface definitions. r=karlt,baku draft
authorArnaud Bienner <arnaud.bienner@gmail.com>
Fri, 01 Jun 2018 19:10:02 +0200
changeset 809317 6de0ee76f57e7453fe53ba5bcb3fdad75fbd05b6
parent 804864 04cc917f68c5d554e5b9542cb3745c9453bba58d
push id113634
push userbmo:arnaud.bienner@gmail.com
push dateThu, 21 Jun 2018 20:16:57 +0000
reviewerskarlt, baku
bugs1458446
milestone62.0a1
Bug 1458446 - Add AudioWorkletNode interface definitions. r=karlt,baku MozReview-Commit-ID: BLumJG4BDke
dom/media/webaudio/AudioWorkletNode.cpp
dom/media/webaudio/AudioWorkletNode.h
dom/media/webaudio/moz.build
dom/tests/mochitest/general/test_interfaces.js
dom/webidl/AudioWorkletNode.webidl
dom/webidl/moz.build
xpcom/ds/nsGkAtomList.h
new file mode 100644
--- /dev/null
+++ b/dom/media/webaudio/AudioWorkletNode.cpp
@@ -0,0 +1,103 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
+
+#include "AudioWorkletNode.h"
+
+#include "AudioParamMap.h"
+#include "mozilla/dom/AudioWorkletNodeBinding.h"
+#include "mozilla/dom/MessagePort.h"
+
+namespace mozilla {
+namespace dom {
+
+NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(AudioWorkletNode, AudioNode)
+
+AudioWorkletNode::AudioWorkletNode(AudioContext* aAudioContext,
+                                   const nsAString& aName)
+  : AudioNode(aAudioContext,
+              2,
+              ChannelCountMode::Max,
+              ChannelInterpretation::Speakers)
+  , mNodeName(aName)
+{
+}
+
+/* static */ already_AddRefed<AudioWorkletNode>
+AudioWorkletNode::Constructor(const GlobalObject& aGlobal,
+                              AudioContext& aAudioContext,
+                              const nsAString& aName,
+                              const AudioWorkletNodeOptions& aOptions,
+                              ErrorResult& aRv)
+{
+  if (aAudioContext.CheckClosed(aRv)) {
+    return nullptr;
+  }
+
+  if (aOptions.mNumberOfInputs == 0 && aOptions.mNumberOfOutputs == 0) {
+    aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
+    return nullptr;
+  }
+
+  if (aOptions.mOutputChannelCount.WasPassed()) {
+    if (aOptions.mOutputChannelCount.Value().Length() !=
+        aOptions.mNumberOfOutputs) {
+      aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
+      return nullptr;
+    }
+
+    for (uint32_t channelCount : aOptions.mOutputChannelCount.Value()) {
+      if (channelCount == 0 ||
+          channelCount > WebAudioUtils::MaxChannelCount) {
+        aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
+        return nullptr;
+      }
+    }
+  }
+
+  RefPtr<AudioWorkletNode> audioWorkletNode =
+      new AudioWorkletNode(&aAudioContext, aName);
+
+  audioWorkletNode->Initialize(aOptions, aRv);
+  if (NS_WARN_IF(aRv.Failed())) {
+    return nullptr;
+  }
+
+  return audioWorkletNode.forget();
+}
+
+AudioParamMap* AudioWorkletNode::GetParameters(ErrorResult& aRv) const
+{
+  aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
+  return nullptr;
+}
+
+MessagePort* AudioWorkletNode::GetPort(ErrorResult& aRv) const
+{
+  aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
+  return nullptr;
+}
+
+JSObject*
+AudioWorkletNode::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
+{
+  return AudioWorkletNodeBinding::Wrap(aCx, this, aGivenProto);
+}
+
+size_t
+AudioWorkletNode::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
+{
+  size_t amount = AudioNode::SizeOfExcludingThis(aMallocSizeOf);
+  return amount;
+}
+
+size_t
+AudioWorkletNode::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
+{
+  return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
+}
+
+} // namespace dom
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/dom/media/webaudio/AudioWorkletNode.h
@@ -0,0 +1,58 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
+
+#ifndef AudioWorkletNode_h_
+#define AudioWorkletNode_h_
+
+#include "AudioNode.h"
+
+namespace mozilla {
+namespace dom {
+
+class AudioParamMap;
+struct AudioWorkletNodeOptions;
+class MessagePort;
+
+class AudioWorkletNode : public AudioNode
+{
+public:
+
+  NS_DECL_ISUPPORTS_INHERITED
+
+  IMPL_EVENT_HANDLER(processorerror)
+
+  static already_AddRefed<AudioWorkletNode>
+  Constructor(const GlobalObject& aGlobal,
+              AudioContext& aAudioContext,
+              const nsAString& aName,
+              const AudioWorkletNodeOptions& aOptions,
+              ErrorResult& aRv);
+
+  AudioParamMap* GetParameters(ErrorResult& aRv) const;
+
+  MessagePort* GetPort(ErrorResult& aRv) const;
+
+  JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
+
+  const char* NodeType() const override
+  {
+    return "AudioWorkletNode";
+  }
+
+  size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const override;
+  size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override;
+
+private:
+  AudioWorkletNode(AudioContext* aAudioContext, const nsAString& aName);
+  ~AudioWorkletNode() = default;
+
+  nsString mNodeName;
+};
+
+} // namespace dom
+} // namespace mozilla
+
+#endif // AudioWorkletNode_h_
\ No newline at end of file
--- a/dom/media/webaudio/moz.build
+++ b/dom/media/webaudio/moz.build
@@ -47,16 +47,17 @@ EXPORTS.mozilla.dom += [
     'AudioContext.h',
     'AudioDestinationNode.h',
     'AudioListener.h',
     'AudioNode.h',
     'AudioParam.h',
     'AudioParamMap.h',
     'AudioProcessingEvent.h',
     'AudioScheduledSourceNode.h',
+    'AudioWorkletNode.h',
     'BiquadFilterNode.h',
     'ChannelMergerNode.h',
     'ChannelSplitterNode.h',
     'ConstantSourceNode.h',
     'ConvolverNode.h',
     'DelayNode.h',
     'DynamicsCompressorNode.h',
     'GainNode.h',
@@ -84,16 +85,17 @@ UNIFIED_SOURCES += [
     'AudioNode.cpp',
     'AudioNodeEngine.cpp',
     'AudioNodeExternalInputStream.cpp',
     'AudioNodeStream.cpp',
     'AudioParam.cpp',
     'AudioParamMap.cpp',
     'AudioProcessingEvent.cpp',
     'AudioScheduledSourceNode.cpp',
+    'AudioWorkletNode.cpp',
     'BiquadFilterNode.cpp',
     'ChannelMergerNode.cpp',
     'ChannelSplitterNode.cpp',
     'ConstantSourceNode.cpp',
     'ConvolverNode.cpp',
     'DelayBuffer.cpp',
     'DelayNode.cpp',
     'DynamicsCompressorNode.cpp',
--- a/dom/tests/mochitest/general/test_interfaces.js
+++ b/dom/tests/mochitest/general/test_interfaces.js
@@ -154,16 +154,18 @@ var interfaceNamesInGlobalScope =
     {name: "AudioParamMap", insecureContext: true, disabled: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "AudioProcessingEvent", insecureContext: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "AudioScheduledSourceNode", insecureContext: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "AudioStreamTrack", insecureContext: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
+    {name: "AudioWorkletNode", insecureContext: false, disabled: true},
+// IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "AuthenticatorAssertionResponse"},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "AuthenticatorAttestationResponse"},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "AuthenticatorResponse"},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "BarProp", insecureContext: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
new file mode 100644
--- /dev/null
+++ b/dom/webidl/AudioWorkletNode.webidl
@@ -0,0 +1,29 @@
+/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * The origin of this IDL file is
+ * 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 AudioWorkletNodeOptions : AudioNodeOptions {
+             unsigned long             numberOfInputs = 1;
+             unsigned long             numberOfOutputs = 1;
+             sequence<unsigned long>   outputChannelCount;
+             record<DOMString, double> parameterData;
+             object?                   processorOptions = null;
+};
+
+[SecureContext, Pref="dom.audioworklet.enabled",
+ Constructor (BaseAudioContext context, DOMString name, optional AudioWorkletNodeOptions options)]
+interface AudioWorkletNode : AudioNode {
+    [Throws]
+    readonly        attribute AudioParamMap              parameters;
+    [Throws]
+    readonly        attribute MessagePort                port;
+                    attribute EventHandler               onprocessorerror;
+};
--- a/dom/webidl/moz.build
+++ b/dom/webidl/moz.build
@@ -381,16 +381,17 @@ WEBIDL_FILES = [
     'AudioParam.webidl',
     'AudioParamMap.webidl',
     'AudioProcessingEvent.webidl',
     'AudioScheduledSourceNode.webidl',
     'AudioStreamTrack.webidl',
     'AudioTrack.webidl',
     'AudioTrackList.webidl',
     'AudioWorkletGlobalScope.webidl',
+    'AudioWorkletNode.webidl',
     'AutocompleteInfo.webidl',
     'BarProp.webidl',
     'BaseAudioContext.webidl',
     'BaseKeyframeTypes.webidl',
     'BasicCardPayment.webidl',
     'BatteryManager.webidl',
     'BeforeUnloadEvent.webidl',
     'BiquadFilterNode.webidl',
--- a/xpcom/ds/nsGkAtomList.h
+++ b/xpcom/ds/nsGkAtomList.h
@@ -802,16 +802,17 @@ GK_ATOM(onpageshow, "onpageshow")
 GK_ATOM(onpaste, "onpaste")
 GK_ATOM(onpointerlockchange, "onpointerlockchange")
 GK_ATOM(onpointerlockerror, "onpointerlockerror")
 GK_ATOM(onpopuphidden, "onpopuphidden")
 GK_ATOM(onpopuphiding, "onpopuphiding")
 GK_ATOM(onpopuppositioned, "onpopuppositioned")
 GK_ATOM(onpopupshowing, "onpopupshowing")
 GK_ATOM(onpopupshown, "onpopupshown")
+GK_ATOM(onprocessorerror, "onprocessorerror")
 GK_ATOM(onpush, "onpush")
 GK_ATOM(onpushsubscriptionchange, "onpushsubscriptionchange")
 GK_ATOM(onRadioStateChange, "onRadioStateChange")
 GK_ATOM(onreadystatechange, "onreadystatechange")
 GK_ATOM(onrequestprogress, "onrequestprogress")
 GK_ATOM(onresourcetimingbufferfull, "onresourcetimingbufferfull")
 GK_ATOM(onresponseprogress, "onresponseprogress")
 GK_ATOM(onRequest, "onRequest")