Test OscillatorNode with servo_media

This commit is contained in:
Fernando Jiménez Moreno 2018-03-26 19:04:33 +02:00
parent e9c40665ba
commit d8365111c9
5 changed files with 26 additions and 2 deletions

View file

@ -7,6 +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;
#[dom_struct]
pub struct AudioScheduledSourceNode {
@ -30,6 +31,18 @@ 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

View file

@ -7,11 +7,13 @@ use dom::bindings::codegen::Bindings::AudioNodeBinding::AudioNodeOptions;
use dom::bindings::codegen::Bindings::AudioNodeBinding::{ChannelCountMode, ChannelInterpretation};
use dom::bindings::codegen::Bindings::BaseAudioContextBinding::BaseAudioContextMethods;
use dom::bindings::codegen::Bindings::BaseAudioContextBinding::AudioContextState;
use dom::bindings::codegen::Bindings::OscillatorNodeBinding::OscillatorOptions;
use dom::bindings::num::Finite;
use dom::bindings::reflector::{DomObject, Reflector};
use dom::bindings::root::DomRoot;
use dom::globalscope::GlobalScope;
use dom::promise::Promise;
use dom::oscillatornode::OscillatorNode;
use dom_struct::dom_struct;
use std::rc::Rc;
@ -76,4 +78,12 @@ impl BaseAudioContextMethods for BaseAudioContext {
// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-onstatechange
event_handler!(statechange, GetOnstatechange, SetOnstatechange);
#[allow(unsafe_code)]
fn CreateOscillator(&self) -> DomRoot<OscillatorNode> {
let global = self.global();
let window = global.as_window();
let options = unsafe { OscillatorOptions::empty(window.get_cx()) };
OscillatorNode::new(&window, &self, &options)
}
}

View file

@ -48,7 +48,7 @@ interface BaseAudioContext : EventTarget {
// ChannelSplitterNode createChannelSplitter(optional unsigned long numberOfOutputs = 6);
// ChannelMergerNode createChannelMerger(optional unsigned long numberOfInputs = 6);
// DynamicsCompressorNode createDynamicsCompressor();
// OscillatorNode createOscillator();
OscillatorNode createOscillator();
// PeriodicWave createPeriodicWave(sequence<float> real,
// sequence<float> imag,
// optional PeriodicWaveConstraints constraints);