Bug 1308432 - Add webidl for ConstantSourceNode; r?smaug draft
authorDan Minor <dminor@mozilla.com>
Thu, 13 Oct 2016 10:40:29 -0400
changeset 427080 643d4b0dfe1d3e391c46d622496acab34e39d2f6
parent 427079 2c3f1e5a382a3317d8d842428593700530e65dbb
child 427081 f343b92c59c783b5808b2b39baa50ebe4c1619a6
push id32907
push userdminor@mozilla.com
push dateWed, 19 Oct 2016 17:06:37 +0000
reviewerssmaug
bugs1308432
milestone52.0a1
Bug 1308432 - Add webidl for ConstantSourceNode; r?smaug MozReview-Commit-ID: 1VtsBk7icrW
dom/media/webaudio/AudioContext.cpp
dom/media/webaudio/AudioContext.h
dom/media/webaudio/ConstantSourceNode.cpp
dom/media/webaudio/ConstantSourceNode.h
dom/media/webaudio/moz.build
dom/tests/mochitest/general/test_interfaces.html
dom/webidl/AudioContext.webidl
dom/webidl/ConstantSourceNode.webidl
dom/webidl/moz.build
--- a/dom/media/webaudio/AudioContext.cpp
+++ b/dom/media/webaudio/AudioContext.cpp
@@ -21,16 +21,17 @@
 #include "AudioBufferSourceNode.h"
 #include "AudioChannelService.h"
 #include "AudioDestinationNode.h"
 #include "AudioListener.h"
 #include "AudioStream.h"
 #include "BiquadFilterNode.h"
 #include "ChannelMergerNode.h"
 #include "ChannelSplitterNode.h"
+#include "ConstantSourceNode.h"
 #include "ConvolverNode.h"
 #include "DelayNode.h"
 #include "DynamicsCompressorNode.h"
 #include "GainNode.h"
 #include "IIRFilterNode.h"
 #include "MediaElementAudioSourceNode.h"
 #include "MediaStreamAudioDestinationNode.h"
 #include "MediaStreamAudioSourceNode.h"
@@ -244,16 +245,28 @@ AudioContext::CreateBufferSource(ErrorRe
     return nullptr;
   }
 
   RefPtr<AudioBufferSourceNode> bufferNode =
     new AudioBufferSourceNode(this);
   return bufferNode.forget();
 }
 
+already_AddRefed<ConstantSourceNode>
+AudioContext::CreateConstantSource(ErrorResult& aRv)
+{
+  if (CheckClosed(aRv)) {
+    return nullptr;
+  }
+
+  RefPtr<ConstantSourceNode> constantSourceNode =
+    new ConstantSourceNode(this);
+  return constantSourceNode.forget();
+}
+
 already_AddRefed<AudioBuffer>
 AudioContext::CreateBuffer(uint32_t aNumberOfChannels, uint32_t aLength,
                            float aSampleRate,
                            ErrorResult& aRv)
 {
   if (!aNumberOfChannels) {
     aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
     return nullptr;
--- a/dom/media/webaudio/AudioContext.h
+++ b/dom/media/webaudio/AudioContext.h
@@ -47,16 +47,17 @@ class AnalyserNode;
 class AudioBuffer;
 class AudioBufferSourceNode;
 class AudioDestinationNode;
 class AudioListener;
 class AudioNode;
 class BiquadFilterNode;
 class ChannelMergerNode;
 class ChannelSplitterNode;
+class ConstantSourceNode;
 class ConvolverNode;
 class DelayNode;
 class DynamicsCompressorNode;
 class GainNode;
 class GlobalObject;
 class HTMLMediaElement;
 class IIRFilterNode;
 class MediaElementAudioSourceNode;
@@ -195,16 +196,18 @@ public:
   // thread and removing the reference we added.
   already_AddRefed<Promise> Suspend(ErrorResult& aRv);
   already_AddRefed<Promise> Resume(ErrorResult& aRv);
   already_AddRefed<Promise> Close(ErrorResult& aRv);
   IMPL_EVENT_HANDLER(statechange)
 
   already_AddRefed<AudioBufferSourceNode> CreateBufferSource(ErrorResult& aRv);
 
+  already_AddRefed<ConstantSourceNode> CreateConstantSource(ErrorResult& aRv);
+
   already_AddRefed<AudioBuffer>
   CreateBuffer(uint32_t aNumberOfChannels, uint32_t aLength, float aSampleRate,
                ErrorResult& aRv);
 
   already_AddRefed<MediaStreamAudioDestinationNode>
   CreateMediaStreamDestination(ErrorResult& aRv);
 
   already_AddRefed<ScriptProcessorNode>
new file mode 100644
--- /dev/null
+++ b/dom/media/webaudio/ConstantSourceNode.cpp
@@ -0,0 +1,86 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et cindent: */
+/* 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/. */
+
+#include "ConstantSourceNode.h"
+
+#include "AudioDestinationNode.h"
+#include "nsContentUtils.h"
+
+namespace mozilla {
+namespace dom {
+
+NS_IMPL_CYCLE_COLLECTION_INHERITED(ConstantSourceNode, AudioNode,
+                                   mOffset)
+
+NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(ConstantSourceNode)
+NS_INTERFACE_MAP_END_INHERITING(AudioNode)
+
+NS_IMPL_ADDREF_INHERITED(ConstantSourceNode, AudioNode)
+NS_IMPL_RELEASE_INHERITED(ConstantSourceNode, AudioNode)
+
+ConstantSourceNode::ConstantSourceNode(AudioContext* aContext)
+  : AudioNode(aContext,
+              1,
+              ChannelCountMode::Max,
+              ChannelInterpretation::Speakers)
+{
+}
+
+ConstantSourceNode::~ConstantSourceNode()
+{
+}
+
+size_t
+ConstantSourceNode::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
+{
+  size_t amount = AudioNode::SizeOfExcludingThis(aMallocSizeOf);
+
+  amount += mOffset->SizeOfIncludingThis(aMallocSizeOf);
+  return amount;
+}
+
+size_t
+ConstantSourceNode::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
+{
+  return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
+}
+
+JSObject*
+ConstantSourceNode::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
+{
+  return ConstantSourceNodeBinding::Wrap(aCx, this, aGivenProto);
+}
+
+already_AddRefed<ConstantSourceNode>
+ConstantSourceNode::Constructor(const GlobalObject& aGlobal,
+                                const AudioContext& aContext,
+                                const ConstantSourceOptions& aOptions,
+                                ErrorResult& aRv)
+{
+}
+
+void
+ConstantSourceNode::DestroyMediaStream()
+{
+}
+
+void
+ConstantSourceNode::Start(double aWhen, ErrorResult& rv)
+{
+}
+
+void
+ConstantSourceNode::Stop(double aWhen, ErrorResult& rv)
+{
+}
+
+void
+ConstantSourceNode::NotifyMainThreadStreamFinished()
+{
+}
+
+} // namespace dom
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/dom/media/webaudio/ConstantSourceNode.h
@@ -0,0 +1,75 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et cindent: */
+/* 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/. */
+
+#ifndef ConstantSourceNode_h_
+#define ConstantSourceNode_h_
+
+#include "AudioNode.h"
+#include "AudioParam.h"
+#include "mozilla/dom/ConstantSourceNodeBinding.h"
+
+namespace mozilla {
+namespace dom {
+
+class AudioContext;
+
+class ConstantSourceNode final : public AudioNode,
+                                 public MainThreadMediaStreamListener
+{
+public:
+  explicit ConstantSourceNode(AudioContext* aContext);
+
+  NS_DECL_ISUPPORTS_INHERITED
+  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ConstantSourceNode, AudioNode)
+
+  JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
+
+  static already_AddRefed<ConstantSourceNode>
+  Constructor(const GlobalObject& aGlobal,
+              const AudioContext& aContext,
+              const ConstantSourceOptions& aOptions,
+              ErrorResult& aRv);
+
+  void DestroyMediaStream() override;
+
+  uint16_t NumberOfInputs() const final override
+  {
+    return 0;
+  }
+
+  AudioParam* Offset() const
+  {
+    return mOffset;
+  }
+
+  void Start(double aWhen, ErrorResult& rv);
+  void Stop(double aWhen, ErrorResult& rv);
+
+  IMPL_EVENT_HANDLER(ended)
+
+  void NotifyMainThreadStreamFinished() override;
+
+  const char* NodeType() const override
+  {
+    return "ConstantSourceNode";
+  }
+
+  size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const override;
+  size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override;
+
+protected:
+  virtual ~ConstantSourceNode();
+
+private:
+  RefPtr<AudioParam> mOffset;
+
+};
+
+} // namespace dom
+} // namespace mozilla
+
+#endif
+
--- a/dom/media/webaudio/moz.build
+++ b/dom/media/webaudio/moz.build
@@ -52,16 +52,17 @@ EXPORTS.mozilla.dom += [
     'AudioDestinationNode.h',
     'AudioListener.h',
     'AudioNode.h',
     'AudioParam.h',
     'AudioProcessingEvent.h',
     'BiquadFilterNode.h',
     'ChannelMergerNode.h',
     'ChannelSplitterNode.h',
+    'ConstantSourceNode.h',
     'ConvolverNode.h',
     'DelayNode.h',
     'DynamicsCompressorNode.h',
     'GainNode.h',
     'IIRFilterNode.h',
     'MediaElementAudioSourceNode.h',
     'MediaStreamAudioDestinationNode.h',
     'MediaStreamAudioSourceNode.h',
@@ -88,16 +89,17 @@ UNIFIED_SOURCES += [
     'AudioNodeExternalInputStream.cpp',
     'AudioNodeStream.cpp',
     'AudioParam.cpp',
     'AudioProcessingEvent.cpp',
     'BiquadFilterNode.cpp',
     'BufferDecoder.cpp',
     'ChannelMergerNode.cpp',
     'ChannelSplitterNode.cpp',
+    'ConstantSourceNode.cpp',
     'ConvolverNode.cpp',
     'DelayBuffer.cpp',
     'DelayNode.cpp',
     'DynamicsCompressorNode.cpp',
     'FFTBlock.cpp',
     'GainNode.cpp',
     'IIRFilterNode.cpp',
     'MediaBufferDecoder.cpp',
--- a/dom/tests/mochitest/general/test_interfaces.html
+++ b/dom/tests/mochitest/general/test_interfaces.html
@@ -204,16 +204,18 @@ var interfaceNamesInGlobalScope =
     "CloseEvent",
 // IMPORTANT: Do not change this list without review from a DOM peer!
     "CommandEvent",
 // IMPORTANT: Do not change this list without review from a DOM peer!
     "Comment",
 // IMPORTANT: Do not change this list without review from a DOM peer!
     "CompositionEvent",
 // IMPORTANT: Do not change this list without review from a DOM peer!
+    "ConstantSourceNode",
+// IMPORTANT: Do not change this list without review from a DOM peer!
     "Controllers",
 // IMPORTANT: Do not change this list without review from a DOM peer!
     "ConvolverNode",
 // IMPORTANT: Do not change this list without review from a DOM peer!
     "Crypto",
 // IMPORTANT: Do not change this list without review from a DOM peer!
     "CryptoKey",
 // IMPORTANT: Do not change this list without review from a DOM peer!
--- a/dom/webidl/AudioContext.webidl
+++ b/dom/webidl/AudioContext.webidl
@@ -49,16 +49,19 @@ interface AudioContext : EventTarget {
                                          optional DecodeSuccessCallback successCallback,
                                          optional DecodeErrorCallback errorCallback);
 
     // AudioNode creation
     [NewObject, Throws]
     AudioBufferSourceNode createBufferSource();
 
     [NewObject, Throws]
+    ConstantSourceNode createConstantSource();
+
+    [NewObject, Throws]
     MediaStreamAudioDestinationNode createMediaStreamDestination();
 
     [NewObject, Throws]
     ScriptProcessorNode createScriptProcessor(optional unsigned long bufferSize = 0,
                                               optional unsigned long numberOfInputChannels = 2,
                                               optional unsigned long numberOfOutputChannels = 2);
 
     [NewObject, Throws]
new file mode 100644
--- /dev/null
+++ b/dom/webidl/ConstantSourceNode.webidl
@@ -0,0 +1,26 @@
+/* -*- 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 ConstantSourceOptions {
+    float offset = 1;
+};
+
+[Pref="dom.webaudio.enabled",
+ Constructor(AudioContext context, optional ConstantSourceOptions options)]
+interface ConstantSourceNode : AudioNode {
+    readonly        attribute AudioParam   offset;
+                    attribute EventHandler onended;
+    [Throws, UnsafeInPrerendering]
+    void start (optional double when = 0);
+    [Throws, UnsafeInPrerendering]
+    void stop (optional double when = 0);
+};
--- a/dom/webidl/moz.build
+++ b/dom/webidl/moz.build
@@ -78,16 +78,17 @@ WEBIDL_FILES = [
     'ChromeUtils.webidl',
     'Client.webidl',
     'Clients.webidl',
     'ClipboardEvent.webidl',
     'CommandEvent.webidl',
     'Comment.webidl',
     'CompositionEvent.webidl',
     'Console.webidl',
+    'ConstantSourceNode.webidl',
     'Contacts.webidl',
     'ContainerBoxObject.webidl',
     'ConvolverNode.webidl',
     'Coordinates.webidl',
     'CreateOfferRequest.webidl',
     'Crypto.webidl',
     'CSPDictionaries.webidl',
     'CSPReport.webidl',