mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Pass down ChannelInfo to create_node
This commit is contained in:
parent
9779ce3b88
commit
9254606b01
8 changed files with 74 additions and 61 deletions
|
@ -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 */
|
||||
)?;
|
||||
|
|
|
@ -6,6 +6,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::AudioNodeOptions;
|
||||
use dom::bindings::codegen::Bindings::AudioNodeBinding::{ChannelCountMode, ChannelInterpretation};
|
||||
use dom::bindings::reflector::reflect_dom_object;
|
||||
use dom::bindings::root::DomRoot;
|
||||
use dom::globalscope::GlobalScope;
|
||||
|
@ -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,
|
||||
),
|
||||
|
|
|
@ -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 {
|
||||
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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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> {
|
||||
|
|
|
@ -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
|
||||
)?;
|
||||
|
|
|
@ -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
|
||||
)?;
|
||||
|
|
|
@ -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),
|
||||
})
|
||||
|
|
|
@ -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
|
||||
)?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue