mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Auto merge of #22648 - collares:ChannelSplitterNode, r=Manishearth
Implement DOM APIs for ChannelSplitterNode <!-- Please describe your changes on the following line: --> Based on #21591. Fixes #21558. I tried to update the expected results for WPT using "./mach update-wpt"; let me know if I got something wrong. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix the second half of #21558 <!-- Either: --> - [x] There are web-platform-tests tests for these changes - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- 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/22648) <!-- Reviewable:end -->
This commit is contained in:
commit
c7cd1b83a1
16 changed files with 188 additions and 139 deletions
|
@ -237,9 +237,10 @@ impl AudioNodeMethods for AudioNode {
|
|||
}
|
||||
},
|
||||
EventTargetTypeId::AudioNode(AudioNodeTypeId::ChannelMergerNode) => {
|
||||
if value != 1 {
|
||||
return Err(Error::InvalidState);
|
||||
}
|
||||
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
|
||||
|
@ -280,9 +281,10 @@ impl AudioNodeMethods for AudioNode {
|
|||
}
|
||||
},
|
||||
EventTargetTypeId::AudioNode(AudioNodeTypeId::ChannelMergerNode) => {
|
||||
if value != ChannelCountMode::Explicit {
|
||||
return Err(Error::InvalidState);
|
||||
}
|
||||
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
|
||||
|
@ -301,14 +303,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(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
80
components/script/dom/channelsplitternode.rs
Normal file
80
components/script/dom/channelsplitternode.rs
Normal file
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -57,5 +57,6 @@ interface AudioNode : EventTarget {
|
|||
attribute unsigned long channelCount;
|
||||
[SetterThrows]
|
||||
attribute ChannelCountMode channelCountMode;
|
||||
[SetterThrows]
|
||||
attribute ChannelInterpretation channelInterpretation;
|
||||
};
|
||||
|
|
|
@ -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();
|
||||
|
|
16
components/script/dom/webidls/ChannelSplitterNode.webidl
Normal file
16
components/script/dom/webidls/ChannelSplitterNode.webidl
Normal file
|
@ -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 {
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue