Pass down ChannelInfo to create_node

This commit is contained in:
Manish Goregaokar 2018-09-11 17:07:10 +05:30
parent 9779ce3b88
commit 9254606b01
8 changed files with 74 additions and 61 deletions

View file

@ -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,
}
}
}