mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Update to use latest servo-media API
This commit is contained in:
parent
d8365111c9
commit
53d4933a40
6 changed files with 84 additions and 66 deletions
|
@ -4,13 +4,13 @@
|
||||||
|
|
||||||
use dom::audionode::{AudioNode, MAX_CHANNEL_COUNT};
|
use dom::audionode::{AudioNode, MAX_CHANNEL_COUNT};
|
||||||
use dom::baseaudiocontext::BaseAudioContext;
|
use dom::baseaudiocontext::BaseAudioContext;
|
||||||
use dom::bindings::codegen::Bindings::AudioDestinationNodeBinding;
|
use dom::bindings::codegen::Bindings::AudioDestinationNodeBinding::{self, AudioDestinationNodeMethods};
|
||||||
use dom::bindings::codegen::Bindings::AudioDestinationNodeBinding::AudioDestinationNodeMethods;
|
|
||||||
use dom::bindings::codegen::Bindings::AudioNodeBinding::AudioNodeOptions;
|
use dom::bindings::codegen::Bindings::AudioNodeBinding::AudioNodeOptions;
|
||||||
use dom::bindings::reflector::reflect_dom_object;
|
use dom::bindings::reflector::reflect_dom_object;
|
||||||
use dom::bindings::root::DomRoot;
|
use dom::bindings::root::DomRoot;
|
||||||
use dom::globalscope::GlobalScope;
|
use dom::globalscope::GlobalScope;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
|
use servo_media::audio::node::AudioNodeType;
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct AudioDestinationNode {
|
pub struct AudioDestinationNode {
|
||||||
|
@ -21,7 +21,7 @@ impl AudioDestinationNode {
|
||||||
fn new_inherited(context: &BaseAudioContext,
|
fn new_inherited(context: &BaseAudioContext,
|
||||||
options: &AudioNodeOptions) -> AudioDestinationNode {
|
options: &AudioNodeOptions) -> AudioDestinationNode {
|
||||||
AudioDestinationNode {
|
AudioDestinationNode {
|
||||||
node: AudioNode::new_inherited(context, options, 1, 1),
|
node: AudioNode::new_inherited(AudioNodeType::DestinationNode, context, options, 1, 1),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,15 +3,14 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use dom::baseaudiocontext::BaseAudioContext;
|
use dom::baseaudiocontext::BaseAudioContext;
|
||||||
use dom::bindings::codegen::Bindings::AudioNodeBinding;
|
|
||||||
use dom::bindings::codegen::Bindings::AudioNodeBinding::{AudioNodeMethods, AudioNodeOptions};
|
use dom::bindings::codegen::Bindings::AudioNodeBinding::{AudioNodeMethods, AudioNodeOptions};
|
||||||
use dom::bindings::codegen::Bindings::AudioNodeBinding::{ChannelCountMode, ChannelInterpretation};
|
use dom::bindings::codegen::Bindings::AudioNodeBinding::{ChannelCountMode, ChannelInterpretation};
|
||||||
use dom::bindings::error::{Error, ErrorResult, Fallible};
|
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::bindings::root::DomRoot;
|
||||||
use dom::audioparam::AudioParam;
|
use dom::audioparam::AudioParam;
|
||||||
use dom::globalscope::GlobalScope;
|
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
|
use servo_media::audio::node::AudioNodeType;
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
|
||||||
// 32 is the minimum required by the spec for createBuffer() and
|
// 32 is the minimum required by the spec for createBuffer() and
|
||||||
|
@ -22,6 +21,7 @@ pub static MAX_CHANNEL_COUNT: u32 = 32;
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct AudioNode {
|
pub struct AudioNode {
|
||||||
reflector_: Reflector,
|
reflector_: Reflector,
|
||||||
|
engine_id: usize,
|
||||||
context: DomRoot<BaseAudioContext>,
|
context: DomRoot<BaseAudioContext>,
|
||||||
number_of_inputs: u32,
|
number_of_inputs: u32,
|
||||||
number_of_outputs: u32,
|
number_of_outputs: u32,
|
||||||
|
@ -31,12 +31,14 @@ pub struct AudioNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AudioNode {
|
impl AudioNode {
|
||||||
pub fn new_inherited(context: &BaseAudioContext,
|
pub fn new_inherited(node_type: AudioNodeType,
|
||||||
|
context: &BaseAudioContext,
|
||||||
options: &AudioNodeOptions,
|
options: &AudioNodeOptions,
|
||||||
number_of_inputs: u32,
|
number_of_inputs: u32,
|
||||||
number_of_outputs: u32) -> AudioNode {
|
number_of_outputs: u32) -> AudioNode {
|
||||||
AudioNode {
|
AudioNode {
|
||||||
reflector_: Reflector::new(),
|
reflector_: Reflector::new(),
|
||||||
|
engine_id: context.create_node_engine(node_type),
|
||||||
context: DomRoot::from_ref(context),
|
context: DomRoot::from_ref(context),
|
||||||
number_of_inputs,
|
number_of_inputs,
|
||||||
number_of_outputs,
|
number_of_outputs,
|
||||||
|
@ -45,29 +47,16 @@ impl AudioNode {
|
||||||
channel_interpretation: Cell::new(options.channelInterpretation.unwrap_or_default()),
|
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 {
|
impl AudioNodeMethods for AudioNode {
|
||||||
// https://webaudio.github.io/web-audio-api/#dom-audionode-connect
|
// https://webaudio.github.io/web-audio-api/#dom-audionode-connect
|
||||||
fn Connect(&self,
|
fn Connect(&self,
|
||||||
_destinationNode: &AudioNode,
|
destination: &AudioNode,
|
||||||
_output: u32,
|
_output: u32,
|
||||||
_input: u32) -> Fallible<DomRoot<AudioNode>> {
|
_input: u32) -> Fallible<DomRoot<AudioNode>> {
|
||||||
// TODO
|
// TODO
|
||||||
let options = AudioNodeOptions {
|
Ok(DomRoot::from_ref(destination))
|
||||||
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))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn Connect_(&self,
|
fn Connect_(&self,
|
||||||
|
|
|
@ -7,7 +7,7 @@ use dom::bindings::codegen::Bindings::AudioScheduledSourceNodeBinding::AudioSche
|
||||||
use dom::bindings::codegen::Bindings::AudioNodeBinding::AudioNodeOptions;
|
use dom::bindings::codegen::Bindings::AudioNodeBinding::AudioNodeOptions;
|
||||||
use dom::bindings::num::Finite;
|
use dom::bindings::num::Finite;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
use servo_media::ServoMedia;
|
use servo_media::audio::node::AudioNodeType;
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct AudioScheduledSourceNode {
|
pub struct AudioScheduledSourceNode {
|
||||||
|
@ -15,12 +15,13 @@ pub struct AudioScheduledSourceNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AudioScheduledSourceNode {
|
impl AudioScheduledSourceNode {
|
||||||
pub fn new_inherited(context: &BaseAudioContext,
|
pub fn new_inherited(node_type: AudioNodeType,
|
||||||
|
context: &BaseAudioContext,
|
||||||
options: &AudioNodeOptions,
|
options: &AudioNodeOptions,
|
||||||
number_of_inputs: u32,
|
number_of_inputs: u32,
|
||||||
number_of_outputs: u32) -> AudioScheduledSourceNode {
|
number_of_outputs: u32) -> AudioScheduledSourceNode {
|
||||||
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
|
// https://webaudio.github.io/web-audio-api/#dom-audioscheduledsourcenode-start
|
||||||
fn Start(&self, _when: Finite<f64>) {
|
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
|
// https://webaudio.github.io/web-audio-api/#dom-audioscheduledsourcenode-stop
|
||||||
|
|
|
@ -15,11 +15,16 @@ use dom::globalscope::GlobalScope;
|
||||||
use dom::promise::Promise;
|
use dom::promise::Promise;
|
||||||
use dom::oscillatornode::OscillatorNode;
|
use dom::oscillatornode::OscillatorNode;
|
||||||
use dom_struct::dom_struct;
|
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;
|
use std::rc::Rc;
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct BaseAudioContext {
|
pub struct BaseAudioContext {
|
||||||
reflector_: Reflector,
|
reflector_: Reflector,
|
||||||
|
#[ignore_malloc_size_of = "XXX"]
|
||||||
|
audio_graph: AudioGraph,
|
||||||
destination: Option<DomRoot<AudioDestinationNode>>,
|
destination: Option<DomRoot<AudioDestinationNode>>,
|
||||||
sample_rate: f32,
|
sample_rate: f32,
|
||||||
current_time: f64,
|
current_time: f64,
|
||||||
|
@ -36,6 +41,7 @@ impl BaseAudioContext {
|
||||||
) -> BaseAudioContext {
|
) -> BaseAudioContext {
|
||||||
let mut context = BaseAudioContext {
|
let mut context = BaseAudioContext {
|
||||||
reflector_: Reflector::new(),
|
reflector_: Reflector::new(),
|
||||||
|
audio_graph: ServoMedia::get().unwrap().create_audio_graph().unwrap(),
|
||||||
destination: None,
|
destination: None,
|
||||||
current_time: 0.,
|
current_time: 0.,
|
||||||
sample_rate,
|
sample_rate,
|
||||||
|
@ -51,6 +57,10 @@ impl BaseAudioContext {
|
||||||
|
|
||||||
context
|
context
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn create_node_engine(&self, node_type: AudioNodeType) -> usize {
|
||||||
|
self.audio_graph.create_node(node_type)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BaseAudioContextMethods for BaseAudioContext {
|
impl BaseAudioContextMethods for BaseAudioContext {
|
||||||
|
|
|
@ -80,6 +80,7 @@ use offscreen_gl_context::GLLimits;
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use profile_traits::mem::ProfilerChan as MemProfilerChan;
|
use profile_traits::mem::ProfilerChan as MemProfilerChan;
|
||||||
use profile_traits::time::ProfilerChan as TimeProfilerChan;
|
use profile_traits::time::ProfilerChan as TimeProfilerChan;
|
||||||
|
use servo_media::AudioGraph;
|
||||||
use script_layout_interface::OpaqueStyleAndLayoutData;
|
use script_layout_interface::OpaqueStyleAndLayoutData;
|
||||||
use script_layout_interface::reporter::CSSErrorReporter;
|
use script_layout_interface::reporter::CSSErrorReporter;
|
||||||
use script_layout_interface::rpc::LayoutRPC;
|
use script_layout_interface::rpc::LayoutRPC;
|
||||||
|
@ -429,6 +430,7 @@ unsafe_no_jsmanaged_fields!(InteractiveMetrics);
|
||||||
unsafe_no_jsmanaged_fields!(InteractiveWindow);
|
unsafe_no_jsmanaged_fields!(InteractiveWindow);
|
||||||
unsafe_no_jsmanaged_fields!(CanvasId);
|
unsafe_no_jsmanaged_fields!(CanvasId);
|
||||||
unsafe_no_jsmanaged_fields!(SourceSet);
|
unsafe_no_jsmanaged_fields!(SourceSet);
|
||||||
|
unsafe_no_jsmanaged_fields!(AudioGraph);
|
||||||
|
|
||||||
unsafe impl<'a> JSTraceable for &'a str {
|
unsafe impl<'a> JSTraceable for &'a str {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -6,18 +6,20 @@ use dom::audioscheduledsourcenode::AudioScheduledSourceNode;
|
||||||
use dom::baseaudiocontext::BaseAudioContext;
|
use dom::baseaudiocontext::BaseAudioContext;
|
||||||
use dom::bindings::codegen::Bindings::AudioNodeBinding::AudioNodeOptions;
|
use dom::bindings::codegen::Bindings::AudioNodeBinding::AudioNodeOptions;
|
||||||
use dom::bindings::codegen::Bindings::AudioNodeBinding::{ChannelCountMode, ChannelInterpretation};
|
use dom::bindings::codegen::Bindings::AudioNodeBinding::{ChannelCountMode, ChannelInterpretation};
|
||||||
use dom::bindings::codegen::Bindings::OscillatorNodeBinding;
|
use dom::bindings::codegen::Bindings::OscillatorNodeBinding::{self, OscillatorOptions, OscillatorType};
|
||||||
use dom::bindings::codegen::Bindings::OscillatorNodeBinding::OscillatorOptions;
|
|
||||||
use dom::bindings::error::Fallible;
|
use dom::bindings::error::Fallible;
|
||||||
use dom::bindings::reflector::reflect_dom_object;
|
use dom::bindings::reflector::reflect_dom_object;
|
||||||
use dom::bindings::root::DomRoot;
|
use dom::bindings::root::DomRoot;
|
||||||
use dom::window::Window;
|
use dom::window::Window;
|
||||||
use dom_struct::dom_struct;
|
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]
|
#[dom_struct]
|
||||||
pub struct OscillatorNode {
|
pub struct OscillatorNode {
|
||||||
node: AudioScheduledSourceNode,
|
node: AudioScheduledSourceNode,
|
||||||
// oscillator_type: OscillatorType,
|
oscillator_type: OscillatorType,
|
||||||
// frequency: AudioParam,
|
// frequency: AudioParam,
|
||||||
// detune: AudioParam,
|
// detune: AudioParam,
|
||||||
}
|
}
|
||||||
|
@ -28,18 +30,21 @@ impl OscillatorNode {
|
||||||
pub fn new_inherited(
|
pub fn new_inherited(
|
||||||
window: &Window,
|
window: &Window,
|
||||||
context: &BaseAudioContext,
|
context: &BaseAudioContext,
|
||||||
|
oscillator_options: &OscillatorOptions,
|
||||||
) -> OscillatorNode {
|
) -> OscillatorNode {
|
||||||
let mut options = unsafe { AudioNodeOptions::empty(window.get_cx()) };
|
let mut node_options = unsafe { AudioNodeOptions::empty(window.get_cx()) };
|
||||||
options.channelCount = Some(2);
|
node_options.channelCount = Some(2);
|
||||||
options.channelCountMode = Some(ChannelCountMode::Max);
|
node_options.channelCountMode = Some(ChannelCountMode::Max);
|
||||||
options.channelInterpretation = Some(ChannelInterpretation::Speakers);
|
node_options.channelInterpretation = Some(ChannelInterpretation::Speakers);
|
||||||
OscillatorNode {
|
OscillatorNode {
|
||||||
node: AudioScheduledSourceNode::new_inherited(
|
node: AudioScheduledSourceNode::new_inherited(
|
||||||
|
AudioNodeType::OscillatorNode(oscillator_options.into()),
|
||||||
context,
|
context,
|
||||||
&options,
|
&node_options,
|
||||||
0, /* inputs */
|
0, /* inputs */
|
||||||
1, /* outputs */
|
1, /* outputs */
|
||||||
),
|
),
|
||||||
|
oscillator_type: oscillator_options.type_,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,9 +52,9 @@ impl OscillatorNode {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
window: &Window,
|
window: &Window,
|
||||||
context: &BaseAudioContext,
|
context: &BaseAudioContext,
|
||||||
_options: &OscillatorOptions,
|
options: &OscillatorOptions,
|
||||||
) -> DomRoot<OscillatorNode> {
|
) -> DomRoot<OscillatorNode> {
|
||||||
let node = OscillatorNode::new_inherited(window, context);
|
let node = OscillatorNode::new_inherited(window, context, options);
|
||||||
reflect_dom_object(Box::new(node), window, OscillatorNodeBinding::Wrap)
|
reflect_dom_object(Box::new(node), window, OscillatorNodeBinding::Wrap)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,3 +84,26 @@ impl OscillatorNode {
|
||||||
DomRoot::from_ref(&self.detune)
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue