diff options
Diffstat (limited to 'components/script/dom/audionode.rs')
-rw-r--r-- | components/script/dom/audionode.rs | 55 |
1 files changed, 44 insertions, 11 deletions
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, + } + } +} |