aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
authorMauricio Collares <mauricio@collares.org>2019-01-07 17:46:38 -0500
committerMauricio Collares <mauricio@collares.org>2019-01-10 11:58:10 -0500
commitff0cf9e93a2cd80a255f79337cc92920e0bb71ab (patch)
tree531383762fe525cdf25761f5f9970ad8498b85aa /components/script
parent4ac5b8a3aea5df3bf374dcfdb22c34f5ff0bafe8 (diff)
downloadservo-ff0cf9e93a2cd80a255f79337cc92920e0bb71ab.tar.gz
servo-ff0cf9e93a2cd80a255f79337cc92920e0bb71ab.zip
Implement DOM APIs for ChannelSplitterNode
Diffstat (limited to 'components/script')
-rw-r--r--components/script/dom/audionode.rs18
-rw-r--r--components/script/dom/baseaudiocontext.rs9
-rw-r--r--components/script/dom/channelsplitternode.rs80
-rw-r--r--components/script/dom/mod.rs1
-rw-r--r--components/script/dom/webidls/AudioNode.webidl1
-rw-r--r--components/script/dom/webidls/BaseAudioContext.webidl2
-rw-r--r--components/script/dom/webidls/ChannelSplitterNode.webidl16
7 files changed, 124 insertions, 3 deletions
diff --git a/components/script/dom/audionode.rs b/components/script/dom/audionode.rs
index 204f38e2e5d..6e0dedd8025 100644
--- a/components/script/dom/audionode.rs
+++ b/components/script/dom/audionode.rs
@@ -241,6 +241,9 @@ impl AudioNodeMethods for AudioNode {
return Err(Error::InvalidState);
}
},
+ EventTargetTypeId::AudioNode(AudioNodeTypeId::ChannelSplitterNode) => {
+ return Err(Error::InvalidState);
+ },
// XXX We do not support any of the other AudioNodes with
// constraints yet. Add more cases here as we add support
// for new AudioNodes.
@@ -284,6 +287,9 @@ impl AudioNodeMethods for AudioNode {
return Err(Error::InvalidState);
}
},
+ EventTargetTypeId::AudioNode(AudioNodeTypeId::ChannelSplitterNode) => {
+ return Err(Error::InvalidState);
+ },
// XXX We do not support any of the other AudioNodes with
// constraints yet. Add more cases here as we add support
// for new AudioNodes.
@@ -301,14 +307,22 @@ impl AudioNodeMethods for AudioNode {
}
// https://webaudio.github.io/web-audio-api/#dom-audionode-channelinterpretation
- fn SetChannelInterpretation(&self, value: ChannelInterpretation) {
+ fn SetChannelInterpretation(&self, value: ChannelInterpretation) -> ErrorResult {
// Channel interpretation mode has no effect for nodes with no inputs.
if self.number_of_inputs == 0 {
- return;
+ return Ok(());
}
+ match self.upcast::<EventTarget>().type_id() {
+ EventTargetTypeId::AudioNode(AudioNodeTypeId::ChannelSplitterNode) => {
+ return Err(Error::InvalidState);
+ },
+ _ => (),
+ };
+
self.channel_interpretation.set(value);
self.message(AudioNodeMessage::SetChannelInterpretation(value.into()));
+ Ok(())
}
}
diff --git a/components/script/dom/baseaudiocontext.rs b/components/script/dom/baseaudiocontext.rs
index 697b152ee69..9429a03c1aa 100644
--- a/components/script/dom/baseaudiocontext.rs
+++ b/components/script/dom/baseaudiocontext.rs
@@ -22,6 +22,7 @@ use crate::dom::bindings::codegen::Bindings::BaseAudioContextBinding::DecodeErro
use crate::dom::bindings::codegen::Bindings::BaseAudioContextBinding::DecodeSuccessCallback;
use crate::dom::bindings::codegen::Bindings::BiquadFilterNodeBinding::BiquadFilterOptions;
use crate::dom::bindings::codegen::Bindings::ChannelMergerNodeBinding::ChannelMergerOptions;
+use crate::dom::bindings::codegen::Bindings::ChannelSplitterNodeBinding::ChannelSplitterOptions;
use crate::dom::bindings::codegen::Bindings::GainNodeBinding::GainOptions;
use crate::dom::bindings::codegen::Bindings::OscillatorNodeBinding::OscillatorOptions;
use crate::dom::bindings::codegen::Bindings::PannerNodeBinding::PannerOptions;
@@ -33,6 +34,7 @@ use crate::dom::bindings::reflector::DomObject;
use crate::dom::bindings::root::{DomRoot, MutNullableDom};
use crate::dom::biquadfilternode::BiquadFilterNode;
use crate::dom::channelmergernode::ChannelMergerNode;
+use crate::dom::channelsplitternode::ChannelSplitterNode;
use crate::dom::domexception::{DOMErrorName, DOMException};
use crate::dom::eventtarget::EventTarget;
use crate::dom::gainnode::GainNode;
@@ -360,6 +362,13 @@ impl BaseAudioContextMethods for BaseAudioContext {
ChannelMergerNode::new(&self.global().as_window(), &self, &opts)
}
+ /// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createchannelsplitter
+ fn CreateChannelSplitter(&self, count: u32) -> Fallible<DomRoot<ChannelSplitterNode>> {
+ let mut opts = ChannelSplitterOptions::empty();
+ opts.numberOfOutputs = count;
+ ChannelSplitterNode::new(&self.global().as_window(), &self, &opts)
+ }
+
/// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createbuffer
fn CreateBuffer(
&self,
diff --git a/components/script/dom/channelsplitternode.rs b/components/script/dom/channelsplitternode.rs
new file mode 100644
index 00000000000..6803e3e5a67
--- /dev/null
+++ b/components/script/dom/channelsplitternode.rs
@@ -0,0 +1,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/. */
+
+use crate::dom::audionode::{AudioNode, MAX_CHANNEL_COUNT};
+use crate::dom::baseaudiocontext::BaseAudioContext;
+use crate::dom::bindings::codegen::Bindings::AudioNodeBinding::{
+ ChannelCountMode, ChannelInterpretation,
+};
+use crate::dom::bindings::codegen::Bindings::ChannelSplitterNodeBinding::{
+ self, ChannelSplitterOptions,
+};
+use crate::dom::bindings::error::{Error, Fallible};
+use crate::dom::bindings::reflector::reflect_dom_object;
+use crate::dom::bindings::root::DomRoot;
+use crate::dom::window::Window;
+use dom_struct::dom_struct;
+use servo_media::audio::node::AudioNodeInit;
+
+#[dom_struct]
+pub struct ChannelSplitterNode {
+ node: AudioNode,
+}
+
+impl ChannelSplitterNode {
+ #[allow(unrooted_must_root)]
+ pub fn new_inherited(
+ _: &Window,
+ context: &BaseAudioContext,
+ options: &ChannelSplitterOptions,
+ ) -> Fallible<ChannelSplitterNode> {
+ if options.numberOfOutputs < 1 || options.numberOfOutputs > MAX_CHANNEL_COUNT {
+ return Err(Error::IndexSize);
+ }
+
+ let node_options = options.parent.unwrap_or(
+ options.numberOfOutputs,
+ ChannelCountMode::Explicit,
+ ChannelInterpretation::Discrete,
+ );
+
+ if node_options.count != options.numberOfOutputs ||
+ node_options.mode != ChannelCountMode::Explicit ||
+ node_options.interpretation != ChannelInterpretation::Discrete
+ {
+ return Err(Error::InvalidState);
+ }
+
+ let node = AudioNode::new_inherited(
+ AudioNodeInit::ChannelSplitterNode,
+ context,
+ node_options,
+ 1, // inputs
+ options.numberOfOutputs, // outputs
+ )?;
+ Ok(ChannelSplitterNode { node })
+ }
+
+ #[allow(unrooted_must_root)]
+ pub fn new(
+ window: &Window,
+ context: &BaseAudioContext,
+ options: &ChannelSplitterOptions,
+ ) -> Fallible<DomRoot<ChannelSplitterNode>> {
+ let node = ChannelSplitterNode::new_inherited(window, context, options)?;
+ Ok(reflect_dom_object(
+ Box::new(node),
+ window,
+ ChannelSplitterNodeBinding::Wrap,
+ ))
+ }
+
+ pub fn Constructor(
+ window: &Window,
+ context: &BaseAudioContext,
+ options: &ChannelSplitterOptions,
+ ) -> Fallible<DomRoot<ChannelSplitterNode>> {
+ ChannelSplitterNode::new(window, context, options)
+ }
+}
diff --git a/components/script/dom/mod.rs b/components/script/dom/mod.rs
index 253dc2b54bb..675b9dcd403 100644
--- a/components/script/dom/mod.rs
+++ b/components/script/dom/mod.rs
@@ -244,6 +244,7 @@ pub mod canvasgradient;
pub mod canvaspattern;
pub mod canvasrenderingcontext2d;
pub mod channelmergernode;
+pub mod channelsplitternode;
pub mod characterdata;
pub mod client;
pub mod closeevent;
diff --git a/components/script/dom/webidls/AudioNode.webidl b/components/script/dom/webidls/AudioNode.webidl
index f5e51689cf2..bf4f88e02b6 100644
--- a/components/script/dom/webidls/AudioNode.webidl
+++ b/components/script/dom/webidls/AudioNode.webidl
@@ -57,5 +57,6 @@ interface AudioNode : EventTarget {
attribute unsigned long channelCount;
[SetterThrows]
attribute ChannelCountMode channelCountMode;
+ [SetterThrows]
attribute ChannelInterpretation channelInterpretation;
};
diff --git a/components/script/dom/webidls/BaseAudioContext.webidl b/components/script/dom/webidls/BaseAudioContext.webidl
index 5c475d5233a..0f645177d31 100644
--- a/components/script/dom/webidls/BaseAudioContext.webidl
+++ b/components/script/dom/webidls/BaseAudioContext.webidl
@@ -45,7 +45,7 @@ interface BaseAudioContext : EventTarget {
[Throws] PannerNode createPanner();
// StereoPannerNode createStereoPanner();
// ConvolverNode createConvolver();
- // ChannelSplitterNode createChannelSplitter(optional unsigned long numberOfOutputs = 6);
+ [Throws] ChannelSplitterNode createChannelSplitter(optional unsigned long numberOfOutputs = 6);
[Throws] ChannelMergerNode createChannelMerger(optional unsigned long numberOfInputs = 6);
// DynamicsCompressorNode createDynamicsCompressor();
[Throws] OscillatorNode createOscillator();
diff --git a/components/script/dom/webidls/ChannelSplitterNode.webidl b/components/script/dom/webidls/ChannelSplitterNode.webidl
new file mode 100644
index 00000000000..1056fce61bf
--- /dev/null
+++ b/components/script/dom/webidls/ChannelSplitterNode.webidl
@@ -0,0 +1,16 @@
+/* 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/. */
+/*
+ * The origin of this IDL file is
+ * https://webaudio.github.io/web-audio-api/#channelsplitternode
+ */
+
+dictionary ChannelSplitterOptions : AudioNodeOptions {
+ unsigned long numberOfOutputs = 6;
+};
+
+[Exposed=Window,
+ Constructor (BaseAudioContext context, optional ChannelSplitterOptions options)]
+interface ChannelSplitterNode : AudioNode {
+};