aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2018-09-12 19:11:03 -0400
committerGitHub <noreply@github.com>2018-09-12 19:11:03 -0400
commitcd02ca6c191f61865eafb4c62af532b19db53030 (patch)
treeb4098ec83b2da1682393edcda295348c9e14ff54 /components/script
parent26745b27419f687dec1e23434a5be827d4342768 (diff)
parent831201cc1b1665d082d931ac77a5aec13cd333a6 (diff)
downloadservo-cd02ca6c191f61865eafb4c62af532b19db53030.tar.gz
servo-cd02ca6c191f61865eafb4c62af532b19db53030.zip
Auto merge of #21674 - Manishearth:channel-count, r=ferjm
Pass through channel settings in AudioNode constructor Most audionodes let you pass in channel count/etc settings in their constructors, and have different defaults. Using the `create_node` argument added in https://github.com/servo/media/pull/124 , this passes that information through. r? @ferjm. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/21674) <!-- Reviewable:end -->
Diffstat (limited to 'components/script')
-rw-r--r--components/script/dom/audiobuffersourcenode.rs9
-rw-r--r--components/script/dom/audiodestinationnode.rs5
-rw-r--r--components/script/dom/audionode.rs55
-rw-r--r--components/script/dom/audioscheduledsourcenode.rs5
-rw-r--r--components/script/dom/channelmergernode.rs15
-rw-r--r--components/script/dom/gainnode.rs13
-rw-r--r--components/script/dom/oscillatornode.rs16
-rw-r--r--components/script/dom/pannernode.rs17
8 files changed, 74 insertions, 61 deletions
diff --git a/components/script/dom/audiobuffersourcenode.rs b/components/script/dom/audiobuffersourcenode.rs
index a3ddf4121a9..3e7948fdb3e 100644
--- a/components/script/dom/audiobuffersourcenode.rs
+++ b/components/script/dom/audiobuffersourcenode.rs
@@ -9,8 +9,6 @@ use dom::baseaudiocontext::BaseAudioContext;
use dom::bindings::codegen::Bindings::AudioBufferSourceNodeBinding;
use dom::bindings::codegen::Bindings::AudioBufferSourceNodeBinding::AudioBufferSourceNodeMethods;
use dom::bindings::codegen::Bindings::AudioBufferSourceNodeBinding::AudioBufferSourceOptions;
-use dom::bindings::codegen::Bindings::AudioNodeBinding::{ChannelCountMode, ChannelInterpretation};
-use dom::bindings::codegen::Bindings::AudioNodeBinding::AudioNodeOptions;
use dom::bindings::codegen::Bindings::AudioParamBinding::AutomationRate;
use dom::bindings::codegen::Bindings::AudioScheduledSourceNodeBinding::AudioScheduledSourceNodeMethods;
use dom::bindings::error::{Error, Fallible};
@@ -45,14 +43,11 @@ impl AudioBufferSourceNode {
context: &BaseAudioContext,
options: &AudioBufferSourceOptions,
) -> Fallible<AudioBufferSourceNode> {
- let mut node_options = AudioNodeOptions::empty();
- node_options.channelCount = Some(2);
- node_options.channelCountMode = Some(ChannelCountMode::Max);
- node_options.channelInterpretation = Some(ChannelInterpretation::Speakers);
+ let node_options = Default::default();
let source_node = AudioScheduledSourceNode::new_inherited(
AudioNodeInit::AudioBufferSourceNode(options.into()),
context,
- &node_options,
+ node_options,
0, /* inputs */
1, /* outputs */
)?;
diff --git a/components/script/dom/audiodestinationnode.rs b/components/script/dom/audiodestinationnode.rs
index f3c0190e193..eb3f0873156 100644
--- a/components/script/dom/audiodestinationnode.rs
+++ b/components/script/dom/audiodestinationnode.rs
@@ -5,6 +5,7 @@
use dom::audionode::{AudioNode, MAX_CHANNEL_COUNT};
use dom::baseaudiocontext::BaseAudioContext;
use dom::bindings::codegen::Bindings::AudioDestinationNodeBinding::{self, AudioDestinationNodeMethods};
+use dom::bindings::codegen::Bindings::AudioNodeBinding::{ChannelCountMode, ChannelInterpretation};
use dom::bindings::codegen::Bindings::AudioNodeBinding::AudioNodeOptions;
use dom::bindings::reflector::reflect_dom_object;
use dom::bindings::root::DomRoot;
@@ -21,11 +22,13 @@ impl AudioDestinationNode {
context: &BaseAudioContext,
options: &AudioNodeOptions,
) -> AudioDestinationNode {
+ let node_options = options.unwrap_or(2, ChannelCountMode::Max,
+ ChannelInterpretation::Speakers);
AudioDestinationNode {
node: AudioNode::new_inherited_for_id(
context.destination_node(),
context,
- options,
+ node_options,
1,
1,
),
diff --git a/components/script/dom/audionode.rs b/components/script/dom/audionode.rs
index 5a149dd814f..db0d5668b17 100644
--- a/components/script/dom/audionode.rs
+++ b/components/script/dom/audionode.rs
@@ -13,7 +13,7 @@ use dom::bindings::root::{Dom, DomRoot};
use dom::eventtarget::EventTarget;
use dom_struct::dom_struct;
use servo_media::audio::graph::NodeId;
-use servo_media::audio::node::{AudioNodeMessage, AudioNodeInit};
+use servo_media::audio::node::{AudioNodeMessage, AudioNodeInit, ChannelInfo};
use servo_media::audio::node::ChannelCountMode as ServoMediaChannelCountMode;
use servo_media::audio::node::ChannelInterpretation as ServoMediaChannelInterpretation;
use std::cell::Cell;
@@ -41,23 +41,26 @@ impl AudioNode {
pub fn new_inherited(
node_type: AudioNodeInit,
context: &BaseAudioContext,
- options: &AudioNodeOptions,
+ options: UnwrappedAudioNodeOptions,
number_of_inputs: u32,
number_of_outputs: u32,
) -> Fallible<AudioNode> {
- if let Some(c) = options.channelCount {
- if c == 0 || c > MAX_CHANNEL_COUNT {
- return Err(Error::NotSupported);
- }
+ if options.count == 0 || options.count > MAX_CHANNEL_COUNT {
+ return Err(Error::NotSupported);
}
- let node_id = context.audio_context_impl().create_node(node_type);
+ let ch = ChannelInfo {
+ count: options.count as u8,
+ mode: options.mode.into(),
+ interpretation: options.interpretation.into(),
+ };
+ let node_id = context.audio_context_impl().create_node(node_type, ch);
Ok(AudioNode::new_inherited_for_id(node_id, context, options, number_of_inputs, number_of_outputs))
}
pub fn new_inherited_for_id(
node_id: NodeId,
context: &BaseAudioContext,
- options: &AudioNodeOptions,
+ options: UnwrappedAudioNodeOptions,
number_of_inputs: u32,
number_of_outputs: u32,
) -> AudioNode {
@@ -67,9 +70,9 @@ impl AudioNode {
context: Dom::from_ref(context),
number_of_inputs,
number_of_outputs,
- channel_count: Cell::new(options.channelCount.unwrap_or(2)),
- channel_count_mode: Cell::new(options.channelCountMode.unwrap_or_default()),
- channel_interpretation: Cell::new(options.channelInterpretation.unwrap_or_default()),
+ channel_count: Cell::new(options.count),
+ channel_count_mode: Cell::new(options.mode),
+ channel_interpretation: Cell::new(options.interpretation),
}
}
@@ -317,3 +320,33 @@ impl From<ChannelInterpretation> for ServoMediaChannelInterpretation {
}
}
}
+
+
+impl AudioNodeOptions {
+ pub fn unwrap_or(&self, count: u32, mode: ChannelCountMode,
+ interpretation: ChannelInterpretation) -> UnwrappedAudioNodeOptions {
+ UnwrappedAudioNodeOptions {
+ count: self.channelCount.unwrap_or(count),
+ mode: self.channelCountMode.unwrap_or(mode),
+ interpretation: self.channelInterpretation.unwrap_or(interpretation)
+ }
+ }
+}
+
+/// Each node has a set of defaults, so this lets us work with them
+/// easily without having to deal with the Options
+pub struct UnwrappedAudioNodeOptions {
+ pub count: u32,
+ pub mode: ChannelCountMode,
+ pub interpretation: ChannelInterpretation,
+}
+
+impl Default for UnwrappedAudioNodeOptions {
+ fn default() -> Self {
+ UnwrappedAudioNodeOptions {
+ count: 2,
+ mode: ChannelCountMode::Max,
+ interpretation: ChannelInterpretation::Speakers,
+ }
+ }
+}
diff --git a/components/script/dom/audioscheduledsourcenode.rs b/components/script/dom/audioscheduledsourcenode.rs
index 871a793f6ec..972d709ba69 100644
--- a/components/script/dom/audioscheduledsourcenode.rs
+++ b/components/script/dom/audioscheduledsourcenode.rs
@@ -1,9 +1,8 @@
/* 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/. */
-use dom::audionode::AudioNode;
+use dom::audionode::{AudioNode, UnwrappedAudioNodeOptions};
use dom::baseaudiocontext::BaseAudioContext;
-use dom::bindings::codegen::Bindings::AudioNodeBinding::AudioNodeOptions;
use dom::bindings::codegen::Bindings::AudioScheduledSourceNodeBinding::AudioScheduledSourceNodeMethods;
use dom::bindings::error::{Error, Fallible};
use dom::bindings::inheritance::Castable;
@@ -28,7 +27,7 @@ impl AudioScheduledSourceNode {
pub fn new_inherited(
node_type: AudioNodeInit,
context: &BaseAudioContext,
- options: &AudioNodeOptions,
+ options: UnwrappedAudioNodeOptions,
number_of_inputs: u32,
number_of_outputs: u32,
) -> Fallible<AudioScheduledSourceNode> {
diff --git a/components/script/dom/channelmergernode.rs b/components/script/dom/channelmergernode.rs
index d36c481a158..4140f21b9b4 100644
--- a/components/script/dom/channelmergernode.rs
+++ b/components/script/dom/channelmergernode.rs
@@ -5,7 +5,6 @@
use dom::audionode::{AudioNode, MAX_CHANNEL_COUNT};
use dom::baseaudiocontext::BaseAudioContext;
use dom::bindings::codegen::Bindings::AudioNodeBinding::{ChannelCountMode, ChannelInterpretation};
-use dom::bindings::codegen::Bindings::AudioNodeBinding::AudioNodeOptions;
use dom::bindings::codegen::Bindings::ChannelMergerNodeBinding::{self, ChannelMergerOptions};
use dom::bindings::error::{Error, Fallible};
use dom::bindings::reflector::reflect_dom_object;
@@ -27,12 +26,11 @@ impl ChannelMergerNode {
context: &BaseAudioContext,
options: &ChannelMergerOptions,
) -> Fallible<ChannelMergerNode> {
- let mut node_options = AudioNodeOptions::empty();
- let count = options.parent.channelCount.unwrap_or(1);
- let mode = options.parent.channelCountMode.unwrap_or(ChannelCountMode::Explicit);
- let interpretation = options.parent.channelInterpretation.unwrap_or(ChannelInterpretation::Speakers);
+ let node_options = options.parent
+ .unwrap_or(1, ChannelCountMode::Explicit,
+ ChannelInterpretation::Speakers);
- if count != 1 || mode != ChannelCountMode::Explicit {
+ if node_options.count != 1 || node_options.mode != ChannelCountMode::Explicit {
return Err(Error::InvalidState)
}
@@ -40,13 +38,10 @@ impl ChannelMergerNode {
return Err(Error::IndexSize)
}
- node_options.channelCount = Some(count);
- node_options.channelCountMode = Some(mode);
- node_options.channelInterpretation = Some(interpretation);
let node = AudioNode::new_inherited(
AudioNodeInit::ChannelMergerNode(options.into()),
context,
- &node_options,
+ node_options,
options.numberOfInputs, // inputs
1, // outputs
)?;
diff --git a/components/script/dom/gainnode.rs b/components/script/dom/gainnode.rs
index a48cdc7c86b..1b4859e28e5 100644
--- a/components/script/dom/gainnode.rs
+++ b/components/script/dom/gainnode.rs
@@ -6,7 +6,6 @@ use dom::audionode::AudioNode;
use dom::audioparam::AudioParam;
use dom::baseaudiocontext::BaseAudioContext;
use dom::bindings::codegen::Bindings::AudioNodeBinding::{ChannelCountMode, ChannelInterpretation};
-use dom::bindings::codegen::Bindings::AudioNodeBinding::AudioNodeOptions;
use dom::bindings::codegen::Bindings::AudioParamBinding::AutomationRate;
use dom::bindings::codegen::Bindings::GainNodeBinding::{self, GainNodeMethods, GainOptions};
use dom::bindings::error::Fallible;
@@ -32,17 +31,13 @@ impl GainNode {
context: &BaseAudioContext,
options: &GainOptions,
) -> Fallible<GainNode> {
- let mut node_options = AudioNodeOptions::empty();
- let count = options.parent.channelCount.unwrap_or(2);
- let mode = options.parent.channelCountMode.unwrap_or(ChannelCountMode::Max);
- let interpretation = options.parent.channelInterpretation.unwrap_or(ChannelInterpretation::Speakers);
- node_options.channelCount = Some(count);
- node_options.channelCountMode = Some(mode);
- node_options.channelInterpretation = Some(interpretation);
+ let node_options = options.parent
+ .unwrap_or(2, ChannelCountMode::Max,
+ ChannelInterpretation::Speakers);
let node = AudioNode::new_inherited(
AudioNodeInit::GainNode(options.into()),
context,
- &node_options,
+ node_options,
1, // inputs
1, // outputs
)?;
diff --git a/components/script/dom/oscillatornode.rs b/components/script/dom/oscillatornode.rs
index 662724c4438..6f6ce8b9f72 100644
--- a/components/script/dom/oscillatornode.rs
+++ b/components/script/dom/oscillatornode.rs
@@ -6,7 +6,6 @@ use dom::audioparam::AudioParam;
use dom::audioscheduledsourcenode::AudioScheduledSourceNode;
use dom::baseaudiocontext::BaseAudioContext;
use dom::bindings::codegen::Bindings::AudioNodeBinding::{ChannelCountMode, ChannelInterpretation};
-use dom::bindings::codegen::Bindings::AudioNodeBinding::AudioNodeOptions;
use dom::bindings::codegen::Bindings::AudioParamBinding::AutomationRate;
use dom::bindings::codegen::Bindings::OscillatorNodeBinding::{self, OscillatorOptions, OscillatorType};
use dom::bindings::codegen::Bindings::OscillatorNodeBinding::OscillatorNodeMethods;
@@ -34,16 +33,15 @@ impl OscillatorNode {
pub fn new_inherited(
window: &Window,
context: &BaseAudioContext,
- oscillator_options: &OscillatorOptions,
+ options: &OscillatorOptions,
) -> Fallible<OscillatorNode> {
- let mut node_options = AudioNodeOptions::empty();
- node_options.channelCount = Some(2);
- node_options.channelCountMode = Some(ChannelCountMode::Max);
- node_options.channelInterpretation = Some(ChannelInterpretation::Speakers);
+ let node_options = options.parent
+ .unwrap_or(2, ChannelCountMode::Max,
+ ChannelInterpretation::Speakers);
let source_node = AudioScheduledSourceNode::new_inherited(
- AudioNodeInit::OscillatorNode(oscillator_options.into()),
+ AudioNodeInit::OscillatorNode(options.into()),
context,
- &node_options,
+ node_options,
0, /* inputs */
1, /* outputs */
)?;
@@ -71,7 +69,7 @@ impl OscillatorNode {
Ok(OscillatorNode {
source_node,
- oscillator_type: oscillator_options.type_,
+ oscillator_type: options.type_,
frequency: Dom::from_ref(&frequency),
detune: Dom::from_ref(&detune),
})
diff --git a/components/script/dom/pannernode.rs b/components/script/dom/pannernode.rs
index a27388f2cab..5f6124826f4 100644
--- a/components/script/dom/pannernode.rs
+++ b/components/script/dom/pannernode.rs
@@ -6,7 +6,6 @@ use dom::audionode::AudioNode;
use dom::audioparam::AudioParam;
use dom::baseaudiocontext::BaseAudioContext;
use dom::bindings::codegen::Bindings::AudioNodeBinding::{ChannelCountMode, ChannelInterpretation};
-use dom::bindings::codegen::Bindings::AudioNodeBinding::AudioNodeOptions;
use dom::bindings::codegen::Bindings::AudioParamBinding::{AudioParamMethods, AutomationRate};
use dom::bindings::codegen::Bindings::PannerNodeBinding::{self, PannerNodeMethods, PannerOptions};
use dom::bindings::codegen::Bindings::PannerNodeBinding::{DistanceModelType, PanningModelType};
@@ -52,13 +51,13 @@ impl PannerNode {
context: &BaseAudioContext,
options: &PannerOptions,
) -> Fallible<PannerNode> {
- let count = options.parent.channelCount.unwrap_or(2);
- let mode = options.parent.channelCountMode.unwrap_or(ChannelCountMode::Clamped_max);
- let interpretation = options.parent.channelInterpretation.unwrap_or(ChannelInterpretation::Speakers);
- if mode == ChannelCountMode::Max {
+ let node_options = options.parent
+ .unwrap_or(2, ChannelCountMode::Clamped_max,
+ ChannelInterpretation::Speakers);
+ if node_options.mode == ChannelCountMode::Max {
return Err(Error::NotSupported)
}
- if count > 2 || count == 0 {
+ if node_options.count > 2 || node_options.count == 0 {
return Err(Error::NotSupported)
}
if *options.maxDistance <= 0. {
@@ -73,15 +72,11 @@ impl PannerNode {
if *options.coneOuterGain < 0. || *options.coneOuterGain > 1. {
return Err(Error::InvalidState)
}
- let mut node_options = AudioNodeOptions::empty();
- node_options.channelCount = Some(count);
- node_options.channelCountMode = Some(mode);
- node_options.channelInterpretation = Some(interpretation);
let options = options.into();
let node = AudioNode::new_inherited(
AudioNodeInit::PannerNode(options),
context,
- &node_options,
+ node_options,
1, // inputs
1, // outputs
)?;