mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
AudioNode connection
This commit is contained in:
parent
aed57252b1
commit
9eebcb31c5
2 changed files with 25 additions and 11 deletions
|
@ -11,7 +11,7 @@ use dom::bindings::root::DomRoot;
|
||||||
use dom::audioparam::AudioParam;
|
use dom::audioparam::AudioParam;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
use servo_media::audio::graph::NodeId;
|
use servo_media::audio::graph::NodeId;
|
||||||
use servo_media::audio::node::AudioNodeType;
|
use servo_media::audio::node::{AudioNodeMessage, AudioNodeType};
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
|
||||||
// 32 is the minimum required by the spec for createBuffer() and the deprecated
|
// 32 is the minimum required by the spec for createBuffer() and the deprecated
|
||||||
|
@ -40,7 +40,7 @@ impl AudioNode {
|
||||||
number_of_outputs: u32) -> AudioNode {
|
number_of_outputs: u32) -> AudioNode {
|
||||||
AudioNode {
|
AudioNode {
|
||||||
reflector_: Reflector::new(),
|
reflector_: Reflector::new(),
|
||||||
node_id: context.create_node_engine(node_type),
|
node_id: context.audio_context_impl().create_node(node_type),
|
||||||
context: DomRoot::from_ref(context),
|
context: DomRoot::from_ref(context),
|
||||||
number_of_inputs,
|
number_of_inputs,
|
||||||
number_of_outputs,
|
number_of_outputs,
|
||||||
|
@ -49,15 +49,35 @@ impl AudioNode {
|
||||||
channel_interpretation: Cell::new(options.channelInterpretation.unwrap_or_default()),
|
channel_interpretation: Cell::new(options.channelInterpretation.unwrap_or_default()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn message(&self, message: AudioNodeMessage) {
|
||||||
|
self.context.audio_context_impl().message_node(self.node_id, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn node(&self) -> NodeId {
|
||||||
|
self.node_id
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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,
|
||||||
destination: &AudioNode,
|
destination: &AudioNode,
|
||||||
_output: u32,
|
output: u32,
|
||||||
_input: u32) -> Fallible<DomRoot<AudioNode>> {
|
input: u32) -> Fallible<DomRoot<AudioNode>> {
|
||||||
// TODO
|
if self.context != destination.Context() {
|
||||||
|
return Err(Error::InvalidAccess);
|
||||||
|
}
|
||||||
|
|
||||||
|
if output >= self.NumberOfOutputs() ||
|
||||||
|
input >= destination.NumberOfInputs() {
|
||||||
|
return Err(Error::IndexSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
self.context.audio_context_impl().connect_ports(
|
||||||
|
self.node().output(output), destination.node().input(input)
|
||||||
|
);
|
||||||
|
|
||||||
Ok(DomRoot::from_ref(destination))
|
Ok(DomRoot::from_ref(destination))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,8 +23,6 @@ use dom_struct::dom_struct;
|
||||||
use servo_media::ServoMedia;
|
use servo_media::ServoMedia;
|
||||||
use servo_media::audio::context::{AudioContext, ProcessingState};
|
use servo_media::audio::context::{AudioContext, ProcessingState};
|
||||||
use servo_media::audio::context::{OfflineAudioContextOptions, RealTimeAudioContextOptions};
|
use servo_media::audio::context::{OfflineAudioContextOptions, RealTimeAudioContextOptions};
|
||||||
use servo_media::audio::graph::NodeId;
|
|
||||||
use servo_media::audio::node::AudioNodeType;
|
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
@ -97,10 +95,6 @@ impl BaseAudioContext {
|
||||||
&self.audio_context_impl
|
&self.audio_context_impl
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_node_engine(&self, node_type: AudioNodeType) -> NodeId {
|
|
||||||
self.audio_context_impl.create_node(node_type)
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://webaudio.github.io/web-audio-api/#allowed-to-start
|
// https://webaudio.github.io/web-audio-api/#allowed-to-start
|
||||||
pub fn is_allowed_to_start(&self) -> bool {
|
pub fn is_allowed_to_start(&self) -> bool {
|
||||||
self.state.get() == AudioContextState::Suspended
|
self.state.get() == AudioContextState::Suspended
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue