aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--components/script/dom/audiodestinationnode.rs6
-rw-r--r--components/script/dom/audionode.rs27
-rw-r--r--components/script/dom/audioscheduledsourcenode.rs19
-rw-r--r--components/script/dom/baseaudiocontext.rs10
-rw-r--r--components/script/dom/bindings/trace.rs2
-rw-r--r--components/script/dom/oscillatornode.rs84
6 files changed, 83 insertions, 65 deletions
diff --git a/components/script/dom/audiodestinationnode.rs b/components/script/dom/audiodestinationnode.rs
index a9e63cb2bb9..0d3b5798c87 100644
--- a/components/script/dom/audiodestinationnode.rs
+++ b/components/script/dom/audiodestinationnode.rs
@@ -4,13 +4,13 @@
use dom::audionode::{AudioNode, MAX_CHANNEL_COUNT};
use dom::baseaudiocontext::BaseAudioContext;
-use dom::bindings::codegen::Bindings::AudioDestinationNodeBinding;
-use dom::bindings::codegen::Bindings::AudioDestinationNodeBinding::AudioDestinationNodeMethods;
+use dom::bindings::codegen::Bindings::AudioDestinationNodeBinding::{self, AudioDestinationNodeMethods};
use dom::bindings::codegen::Bindings::AudioNodeBinding::AudioNodeOptions;
use dom::bindings::reflector::reflect_dom_object;
use dom::bindings::root::DomRoot;
use dom::globalscope::GlobalScope;
use dom_struct::dom_struct;
+use servo_media::audio::node::AudioNodeType;
#[dom_struct]
pub struct AudioDestinationNode {
@@ -21,7 +21,7 @@ impl AudioDestinationNode {
fn new_inherited(context: &BaseAudioContext,
options: &AudioNodeOptions) -> AudioDestinationNode {
AudioDestinationNode {
- node: AudioNode::new_inherited(context, options, 1, 1),
+ node: AudioNode::new_inherited(AudioNodeType::DestinationNode, context, options, 1, 1),
}
}
diff --git a/components/script/dom/audionode.rs b/components/script/dom/audionode.rs
index 3fc64147fcd..56e3bdd25ba 100644
--- a/components/script/dom/audionode.rs
+++ b/components/script/dom/audionode.rs
@@ -3,15 +3,14 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::baseaudiocontext::BaseAudioContext;
-use dom::bindings::codegen::Bindings::AudioNodeBinding;
use dom::bindings::codegen::Bindings::AudioNodeBinding::{AudioNodeMethods, AudioNodeOptions};
use dom::bindings::codegen::Bindings::AudioNodeBinding::{ChannelCountMode, ChannelInterpretation};
use dom::bindings::error::{Error, ErrorResult, Fallible};
-use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
+use dom::bindings::reflector::Reflector;
use dom::bindings::root::DomRoot;
use dom::audioparam::AudioParam;
-use dom::globalscope::GlobalScope;
use dom_struct::dom_struct;
+use servo_media::audio::node::AudioNodeType;
use std::cell::Cell;
// 32 is the minimum required by the spec for createBuffer() and
@@ -22,6 +21,7 @@ pub static MAX_CHANNEL_COUNT: u32 = 32;
#[dom_struct]
pub struct AudioNode {
reflector_: Reflector,
+ engine_id: usize,
context: DomRoot<BaseAudioContext>,
number_of_inputs: u32,
number_of_outputs: u32,
@@ -31,12 +31,14 @@ pub struct AudioNode {
}
impl AudioNode {
- pub fn new_inherited(context: &BaseAudioContext,
+ pub fn new_inherited(node_type: AudioNodeType,
+ context: &BaseAudioContext,
options: &AudioNodeOptions,
number_of_inputs: u32,
number_of_outputs: u32) -> AudioNode {
AudioNode {
reflector_: Reflector::new(),
+ engine_id: context.create_node_engine(node_type),
context: DomRoot::from_ref(context),
number_of_inputs,
number_of_outputs,
@@ -45,29 +47,16 @@ impl AudioNode {
channel_interpretation: Cell::new(options.channelInterpretation.unwrap_or_default()),
}
}
-
- #[allow(unrooted_must_root)]
- pub fn new(global: &GlobalScope,
- context: &BaseAudioContext,
- options: &AudioNodeOptions) -> DomRoot<AudioNode> {
- let audio_node = AudioNode::new_inherited(context, options, 1, 1);
- reflect_dom_object(Box::new(audio_node), global, AudioNodeBinding::Wrap)
- }
}
impl AudioNodeMethods for AudioNode {
// https://webaudio.github.io/web-audio-api/#dom-audionode-connect
fn Connect(&self,
- _destinationNode: &AudioNode,
+ destination: &AudioNode,
_output: u32,
_input: u32) -> Fallible<DomRoot<AudioNode>> {
// TODO
- let options = AudioNodeOptions {
- channelCount: Some(self.channel_count.get()),
- channelCountMode: Some(self.channel_count_mode.get()),
- channelInterpretation: Some(self.channel_interpretation.get()),
- };
- Ok(AudioNode::new(&self.global(), &self.context, &options))
+ Ok(DomRoot::from_ref(destination))
}
fn Connect_(&self,
diff --git a/components/script/dom/audioscheduledsourcenode.rs b/components/script/dom/audioscheduledsourcenode.rs
index ca506374964..523ac633fb1 100644
--- a/components/script/dom/audioscheduledsourcenode.rs
+++ b/components/script/dom/audioscheduledsourcenode.rs
@@ -7,7 +7,7 @@ use dom::bindings::codegen::Bindings::AudioScheduledSourceNodeBinding::AudioSche
use dom::bindings::codegen::Bindings::AudioNodeBinding::AudioNodeOptions;
use dom::bindings::num::Finite;
use dom_struct::dom_struct;
-use servo_media::ServoMedia;
+use servo_media::audio::node::AudioNodeType;
#[dom_struct]
pub struct AudioScheduledSourceNode {
@@ -15,12 +15,13 @@ pub struct AudioScheduledSourceNode {
}
impl AudioScheduledSourceNode {
- pub fn new_inherited(context: &BaseAudioContext,
+ pub fn new_inherited(node_type: AudioNodeType,
+ context: &BaseAudioContext,
options: &AudioNodeOptions,
number_of_inputs: u32,
number_of_outputs: u32) -> AudioScheduledSourceNode {
AudioScheduledSourceNode {
- node: AudioNode::new_inherited(context, options, number_of_inputs, number_of_outputs),
+ node: AudioNode::new_inherited(node_type, context, options, number_of_inputs, number_of_outputs),
}
}
}
@@ -31,18 +32,6 @@ impl AudioScheduledSourceNodeMethods for AudioScheduledSourceNode {
// https://webaudio.github.io/web-audio-api/#dom-audioscheduledsourcenode-start
fn Start(&self, _when: Finite<f64>) {
- // XXX This is just here to test servo_media from servo.
- // ServoMedia needs to expose a way to feed the audio stream and
- // we need to implement all the AudioContext logic to connect
- // AudioNodes.
- match ServoMedia::get().get_audio_stream() {
- Ok(stream) => {
- stream.play();
- },
- Err(_) => {
- println!("OH NOES");
- }
- };
}
// https://webaudio.github.io/web-audio-api/#dom-audioscheduledsourcenode-stop
diff --git a/components/script/dom/baseaudiocontext.rs b/components/script/dom/baseaudiocontext.rs
index 2bc1cb5343c..8fc25940d7f 100644
--- a/components/script/dom/baseaudiocontext.rs
+++ b/components/script/dom/baseaudiocontext.rs
@@ -15,11 +15,16 @@ use dom::globalscope::GlobalScope;
use dom::promise::Promise;
use dom::oscillatornode::OscillatorNode;
use dom_struct::dom_struct;
+use servo_media::ServoMedia;
+use servo_media::audio::graph::AudioGraph;
+use servo_media::audio::node::AudioNodeType;
use std::rc::Rc;
#[dom_struct]
pub struct BaseAudioContext {
reflector_: Reflector,
+ #[ignore_malloc_size_of = "XXX"]
+ audio_graph: AudioGraph,
destination: Option<DomRoot<AudioDestinationNode>>,
sample_rate: f32,
current_time: f64,
@@ -36,6 +41,7 @@ impl BaseAudioContext {
) -> BaseAudioContext {
let mut context = BaseAudioContext {
reflector_: Reflector::new(),
+ audio_graph: ServoMedia::get().unwrap().create_audio_graph().unwrap(),
destination: None,
current_time: 0.,
sample_rate,
@@ -51,6 +57,10 @@ impl BaseAudioContext {
context
}
+
+ pub fn create_node_engine(&self, node_type: AudioNodeType) -> usize {
+ self.audio_graph.create_node(node_type)
+ }
}
impl BaseAudioContextMethods for BaseAudioContext {
diff --git a/components/script/dom/bindings/trace.rs b/components/script/dom/bindings/trace.rs
index cbce5f53f17..c8f26a8ba5a 100644
--- a/components/script/dom/bindings/trace.rs
+++ b/components/script/dom/bindings/trace.rs
@@ -80,6 +80,7 @@ use offscreen_gl_context::GLLimits;
use parking_lot::RwLock;
use profile_traits::mem::ProfilerChan as MemProfilerChan;
use profile_traits::time::ProfilerChan as TimeProfilerChan;
+use servo_media::AudioGraph;
use script_layout_interface::OpaqueStyleAndLayoutData;
use script_layout_interface::reporter::CSSErrorReporter;
use script_layout_interface::rpc::LayoutRPC;
@@ -429,6 +430,7 @@ unsafe_no_jsmanaged_fields!(InteractiveMetrics);
unsafe_no_jsmanaged_fields!(InteractiveWindow);
unsafe_no_jsmanaged_fields!(CanvasId);
unsafe_no_jsmanaged_fields!(SourceSet);
+unsafe_no_jsmanaged_fields!(AudioGraph);
unsafe impl<'a> JSTraceable for &'a str {
#[inline]
diff --git a/components/script/dom/oscillatornode.rs b/components/script/dom/oscillatornode.rs
index 558e44357a7..a6e65260ce1 100644
--- a/components/script/dom/oscillatornode.rs
+++ b/components/script/dom/oscillatornode.rs
@@ -6,18 +6,20 @@ use dom::audioscheduledsourcenode::AudioScheduledSourceNode;
use dom::baseaudiocontext::BaseAudioContext;
use dom::bindings::codegen::Bindings::AudioNodeBinding::AudioNodeOptions;
use dom::bindings::codegen::Bindings::AudioNodeBinding::{ChannelCountMode, ChannelInterpretation};
-use dom::bindings::codegen::Bindings::OscillatorNodeBinding;
-use dom::bindings::codegen::Bindings::OscillatorNodeBinding::OscillatorOptions;
+use dom::bindings::codegen::Bindings::OscillatorNodeBinding::{self, OscillatorOptions, OscillatorType};
use dom::bindings::error::Fallible;
use dom::bindings::reflector::reflect_dom_object;
use dom::bindings::root::DomRoot;
use dom::window::Window;
use dom_struct::dom_struct;
+use servo_media::audio::node::AudioNodeType;
+use servo_media::audio::oscillator_node::OscillatorNodeOptions as ServoMediaOscillatorOptions;
+use servo_media::audio::oscillator_node::OscillatorType as ServoMediaOscillatorType;
#[dom_struct]
pub struct OscillatorNode {
node: AudioScheduledSourceNode,
- // oscillator_type: OscillatorType,
+ oscillator_type: OscillatorType,
// frequency: AudioParam,
// detune: AudioParam,
}
@@ -28,18 +30,21 @@ impl OscillatorNode {
pub fn new_inherited(
window: &Window,
context: &BaseAudioContext,
- ) -> OscillatorNode {
- let mut options = unsafe { AudioNodeOptions::empty(window.get_cx()) };
- options.channelCount = Some(2);
- options.channelCountMode = Some(ChannelCountMode::Max);
- options.channelInterpretation = Some(ChannelInterpretation::Speakers);
+ oscillator_options: &OscillatorOptions,
+ ) -> OscillatorNode {
+ let mut node_options = unsafe { AudioNodeOptions::empty(window.get_cx()) };
+ node_options.channelCount = Some(2);
+ node_options.channelCountMode = Some(ChannelCountMode::Max);
+ node_options.channelInterpretation = Some(ChannelInterpretation::Speakers);
OscillatorNode {
node: AudioScheduledSourceNode::new_inherited(
- context,
- &options,
- 0, /* inputs */
- 1, /* outputs */
- ),
+ AudioNodeType::OscillatorNode(oscillator_options.into()),
+ context,
+ &node_options,
+ 0, /* inputs */
+ 1, /* outputs */
+ ),
+ oscillator_type: oscillator_options.type_,
}
}
@@ -47,9 +52,9 @@ impl OscillatorNode {
pub fn new(
window: &Window,
context: &BaseAudioContext,
- _options: &OscillatorOptions,
- ) -> DomRoot<OscillatorNode> {
- let node = OscillatorNode::new_inherited(window, context);
+ options: &OscillatorOptions,
+ ) -> DomRoot<OscillatorNode> {
+ let node = OscillatorNode::new_inherited(window, context, options);
reflect_dom_object(Box::new(node), window, OscillatorNodeBinding::Wrap)
}
@@ -57,25 +62,48 @@ impl OscillatorNode {
window: &Window,
context: &BaseAudioContext,
options: &OscillatorOptions,
- ) -> Fallible<DomRoot<OscillatorNode>> {
+ ) -> Fallible<DomRoot<OscillatorNode>> {
Ok(OscillatorNode::new(window, context, options))
}
}
/*impl OscillatorNodeMethods for OscillatorNode {
- fn SetPeriodicWave(&self, periodic_wave: PeriodicWave) {
- // XXX
- }
+ fn SetPeriodicWave(&self, periodic_wave: PeriodicWave) {
+// XXX
+}
- fn Type(&self) -> OscillatorType {
- self.oscillator_type
- }
+fn Type(&self) -> OscillatorType {
+self.oscillator_type
+}
+
+fn Frequency(&self) -> DomRoot<AudioParam> {
+DomRoot::from_ref(&self.frequency)
+}
- fn Frequency(&self) -> DomRoot<AudioParam> {
- DomRoot::from_ref(&self.frequency)
+fn Detune(&self) -> DomRoot<AudioParam> {
+DomRoot::from_ref(&self.detune)
+}
+}*/
+
+impl<'a> From<&'a OscillatorOptions> for ServoMediaOscillatorOptions {
+ fn from(options: &'a OscillatorOptions) -> Self {
+ Self {
+ oscillator_type: options.type_.into(),
+ freq: *options.frequency,
+ detune: *options.detune,
+ periodic_wave_options: None, // XXX
+ }
}
+}
- fn Detune(&self) -> DomRoot<AudioParam> {
- DomRoot::from_ref(&self.detune)
+impl From<OscillatorType> for ServoMediaOscillatorType {
+ fn from(oscillator_type: OscillatorType) -> Self {
+ match oscillator_type {
+ OscillatorType::Sine => ServoMediaOscillatorType::Sine,
+ OscillatorType::Square => ServoMediaOscillatorType::Square,
+ OscillatorType::Sawtooth => ServoMediaOscillatorType::Sawtooth,
+ OscillatorType::Triangle => ServoMediaOscillatorType::Triangle,
+ OscillatorType::Custom => ServoMediaOscillatorType::Custom,
+ }
}
-}*/
+}