diff options
author | Fernando Jiménez Moreno <ferjmoreno@gmail.com> | 2017-11-07 20:57:30 +0100 |
---|---|---|
committer | Fernando Jiménez Moreno <ferjmoreno@gmail.com> | 2018-07-30 14:21:36 +0200 |
commit | 7ee42e4223dc970aeffc56ecddec2738c8340f8c (patch) | |
tree | 1f53a3dc650992ab7b84c9a9e0e748d11ca97a7d /components/script/dom/audiocontext.rs | |
parent | de48f25d0b0b5ecaf0499030f8617a3d37b3fde2 (diff) | |
download | servo-7ee42e4223dc970aeffc56ecddec2738c8340f8c.tar.gz servo-7ee42e4223dc970aeffc56ecddec2738c8340f8c.zip |
Initial WebAudio API stubs
Diffstat (limited to 'components/script/dom/audiocontext.rs')
-rw-r--r-- | components/script/dom/audiocontext.rs | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/components/script/dom/audiocontext.rs b/components/script/dom/audiocontext.rs new file mode 100644 index 00000000000..9b767a6da05 --- /dev/null +++ b/components/script/dom/audiocontext.rs @@ -0,0 +1,81 @@ +/* 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::baseaudiocontext::BaseAudioContext; +use dom::bindings::codegen::Bindings::AudioContextBinding; +use dom::bindings::codegen::Bindings::AudioContextBinding::AudioContextMethods; +use dom::bindings::codegen::Bindings::AudioContextBinding::{AudioContextOptions, AudioTimestamp}; +use dom::bindings::error::Fallible; +use dom::bindings::inheritance::Castable; +use dom::bindings::num::Finite; +use dom::bindings::reflector::{DomObject, reflect_dom_object}; +use dom::bindings::root::DomRoot; +use dom::globalscope::GlobalScope; +use dom::promise::Promise; +use dom::window::Window; +use dom_struct::dom_struct; +use std::rc::Rc; + +#[dom_struct] +pub struct AudioContext { + context: BaseAudioContext, + base_latency: f64, + output_latency: f64, +} + +impl AudioContext { + fn new_inherited(global: &GlobalScope, sample_rate: f32) -> AudioContext { + AudioContext { + context: BaseAudioContext::new_inherited(global, 2 /* channel_count */, sample_rate), + base_latency: 0., // TODO + output_latency: 0., // TODO + } + } + + #[allow(unrooted_must_root)] + pub fn new(global: &GlobalScope, + options: &AudioContextOptions) -> DomRoot<AudioContext> { + let context = AudioContext::new_inherited( + global, + *options.sampleRate.unwrap_or(Finite::wrap(0.)), + ); // TODO + reflect_dom_object(Box::new(context), global, AudioContextBinding::Wrap) + } + + pub fn Constructor(window: &Window, + options: &AudioContextOptions) -> Fallible<DomRoot<AudioContext>> { + let global = window.upcast::<GlobalScope>(); + Ok(AudioContext::new(global, options)) + } +} + +impl AudioContextMethods for AudioContext { + fn BaseLatency(&self) -> Finite<f64> { + Finite::wrap(self.base_latency) + } + + fn OutputLatency(&self) -> Finite<f64> { + Finite::wrap(self.output_latency) + } + + fn GetOutputTimestamp(&self) -> AudioTimestamp { + // TODO + AudioTimestamp { + contextTime: Some(Finite::wrap(0.)), + performanceTime: Some(Finite::wrap(0.)), + } + } + + #[allow(unrooted_must_root)] + fn Suspend(&self) -> Rc<Promise> { + // TODO + Promise::new(&self.global()) + } + + #[allow(unrooted_must_root)] + fn Close(&self) -> Rc<Promise> { + // TODO + Promise::new(&self.global()) + } +} |