Bug 1458446 - Add AudioWorkletNode interface definitions. r=baku,karlt
authorArnaud Bienner <arnaud.bienner@gmail.com>
Fri, 01 Jun 2018 19:10:02 +0200
changeset 480067 af8ef80f3326ee96a7a33f55a07ea2914756a92f
parent 480064 7f7a190b3d0de55a0e231d9a32b82e2ce0643697
child 480068 a32be868e151ab9f1cf945976316f730292a8b09
push id1757
push userffxbld-merge
push dateFri, 24 Aug 2018 17:02:43 +0000
treeherdermozilla-release@736023aebdb1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku, karlt
bugs1458446
milestone62.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 1458446 - Add AudioWorkletNode interface definitions. r=baku,karlt 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
@@ -380,16 +380,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
@@ -803,16 +803,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")