Handle channel count constraints in panner constructor

This commit is contained in:
Manish Goregaokar 2018-08-24 12:42:50 -07:00
parent 58176c4148
commit 5dd830344b
3 changed files with 19 additions and 11 deletions

View file

@ -331,7 +331,7 @@ impl BaseAudioContextMethods for BaseAudioContext {
} }
/// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createpanner /// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createpanner
fn CreatePanner(&self) -> DomRoot<PannerNode> { fn CreatePanner(&self) -> Fallible<DomRoot<PannerNode>> {
PannerNode::new(&self.global().as_window(), &self, &PannerOptions::empty()) PannerNode::new(&self.global().as_window(), &self, &PannerOptions::empty())
} }

View file

@ -51,10 +51,18 @@ impl PannerNode {
window: &Window, window: &Window,
context: &BaseAudioContext, context: &BaseAudioContext,
options: &PannerOptions, options: &PannerOptions,
) -> PannerNode { ) -> Fallible<PannerNode> {
let count = options.parent.channelCount.unwrap_or(2);
let mode = options.parent.channelCountMode.unwrap_or(ChannelCountMode::Clamped_max);
if mode == ChannelCountMode::Max {
return Err(Error::NotSupported)
}
if count > 2 {
return Err(Error::NotSupported)
}
let mut node_options = AudioNodeOptions::empty(); let mut node_options = AudioNodeOptions::empty();
node_options.channelCount = Some(2); node_options.channelCount = Some(count);
node_options.channelCountMode = Some(ChannelCountMode::Clamped_max); node_options.channelCountMode = Some(mode);
node_options.channelInterpretation = Some(ChannelInterpretation::Speakers); node_options.channelInterpretation = Some(ChannelInterpretation::Speakers);
let options = options.into(); let options = options.into();
let node = AudioNode::new_inherited( let node = AudioNode::new_inherited(
@ -125,7 +133,7 @@ impl PannerNode {
f32::MIN, // min value f32::MIN, // min value
f32::MAX, // max value f32::MAX, // max value
); );
PannerNode { Ok(PannerNode {
node, node,
position_x: Dom::from_ref(&position_x), position_x: Dom::from_ref(&position_x),
position_y: Dom::from_ref(&position_y), position_y: Dom::from_ref(&position_y),
@ -141,7 +149,7 @@ impl PannerNode {
cone_inner_angle: Cell::new(options.cone_inner_angle), cone_inner_angle: Cell::new(options.cone_inner_angle),
cone_outer_angle: Cell::new(options.cone_outer_angle), cone_outer_angle: Cell::new(options.cone_outer_angle),
cone_outer_gain: Cell::new(options.cone_outer_gain), cone_outer_gain: Cell::new(options.cone_outer_gain),
} })
} }
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
@ -149,9 +157,9 @@ impl PannerNode {
window: &Window, window: &Window,
context: &BaseAudioContext, context: &BaseAudioContext,
options: &PannerOptions, options: &PannerOptions,
) -> DomRoot<PannerNode> { ) -> Fallible<DomRoot<PannerNode>> {
let node = PannerNode::new_inherited(window, context, options); let node = PannerNode::new_inherited(window, context, options)?;
reflect_dom_object(Box::new(node), window, PannerNodeBinding::Wrap) Ok(reflect_dom_object(Box::new(node), window, PannerNodeBinding::Wrap))
} }
pub fn Constructor( pub fn Constructor(
@ -159,7 +167,7 @@ impl PannerNode {
context: &BaseAudioContext, context: &BaseAudioContext,
options: &PannerOptions, options: &PannerOptions,
) -> Fallible<DomRoot<PannerNode>> { ) -> Fallible<DomRoot<PannerNode>> {
Ok(PannerNode::new(window, context, options)) PannerNode::new(window, context, options)
} }
} }

View file

@ -42,7 +42,7 @@ interface BaseAudioContext : EventTarget {
// IIRFilterNode createIIRFilter(sequence<double> feedforward, // IIRFilterNode createIIRFilter(sequence<double> feedforward,
// sequence<double> feedback); // sequence<double> feedback);
// WaveShaperNode createWaveShaper(); // WaveShaperNode createWaveShaper();
PannerNode createPanner(); [Throws] PannerNode createPanner();
// StereoPannerNode createStereoPanner(); // StereoPannerNode createStereoPanner();
// ConvolverNode createConvolver(); // ConvolverNode createConvolver();
// ChannelSplitterNode createChannelSplitter(optional unsigned long numberOfOutputs = 6); // ChannelSplitterNode createChannelSplitter(optional unsigned long numberOfOutputs = 6);