diff options
author | Fernando Jiménez Moreno <ferjmoreno@gmail.com> | 2019-11-07 16:45:34 +0100 |
---|---|---|
committer | Fernando Jiménez Moreno <ferjmoreno@gmail.com> | 2019-11-18 17:14:51 +0100 |
commit | 03485d730ffc3b5c3b9e2c66c2d985c83ccb5665 (patch) | |
tree | fd663a09062b480178b9999bbb982adb7a771a82 /components/script | |
parent | ea054871bf5157561d7cb28cb202e36046a328fd (diff) | |
download | servo-03485d730ffc3b5c3b9e2c66c2d985c83ccb5665.tar.gz servo-03485d730ffc3b5c3b9e2c66c2d985c83ccb5665.zip |
MediaElementAudioSourceNode implementation
Diffstat (limited to 'components/script')
-rw-r--r-- | components/script/dom/audiocontext.rs | 4 | ||||
-rw-r--r-- | components/script/dom/mediaelementaudiosourcenode.rs | 81 | ||||
-rw-r--r-- | components/script/dom/mod.rs | 1 | ||||
-rw-r--r-- | components/script/dom/webidls/MediaElementAudioSourceNode.webidl | 17 |
4 files changed, 103 insertions, 0 deletions
diff --git a/components/script/dom/audiocontext.rs b/components/script/dom/audiocontext.rs index 2b6f04b421b..033ac49ed11 100644 --- a/components/script/dom/audiocontext.rs +++ b/components/script/dom/audiocontext.rs @@ -97,6 +97,10 @@ impl AudioContext { self.context.resume(); } } + + pub fn base(&self) -> DomRoot<BaseAudioContext> { + DomRoot::from_ref(&self.context) + } } impl AudioContextMethods for AudioContext { diff --git a/components/script/dom/mediaelementaudiosourcenode.rs b/components/script/dom/mediaelementaudiosourcenode.rs new file mode 100644 index 00000000000..8ec25026bc1 --- /dev/null +++ b/components/script/dom/mediaelementaudiosourcenode.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 https://mozilla.org/MPL/2.0/. */ + +use crate::dom::audiocontext::AudioContext; +use crate::dom::audionode::AudioNode; +use crate::dom::bindings::codegen::Bindings::MediaElementAudioSourceNodeBinding; +use crate::dom::bindings::codegen::Bindings::MediaElementAudioSourceNodeBinding::MediaElementAudioSourceNodeMethods; +use crate::dom::bindings::codegen::Bindings::MediaElementAudioSourceNodeBinding::MediaElementAudioSourceOptions; +use crate::dom::bindings::error::Fallible; +use crate::dom::bindings::reflector::reflect_dom_object; +use crate::dom::bindings::root::{Dom, DomRoot}; +use crate::dom::htmlmediaelement::HTMLMediaElement; +use crate::dom::window::Window; +use dom_struct::dom_struct; +use servo_media::audio::media_element_source_node::MediaElementSourceNodeMessage; +use servo_media::audio::node::{AudioNodeInit, AudioNodeMessage}; +use std::sync::mpsc; + +#[dom_struct] +pub struct MediaElementAudioSourceNode { + node: AudioNode, + media_element: Dom<HTMLMediaElement>, +} + +impl MediaElementAudioSourceNode { + #[allow(unrooted_must_root)] + fn new_inherited( + window: &Window, + context: &AudioContext, + options: &MediaElementAudioSourceOptions, + ) -> Fallible<MediaElementAudioSourceNode> { + let node = AudioNode::new_inherited( + AudioNodeInit::MediaElementSourceNode, + &*context.base(), + Default::default(), + 0, + 1, + )?; + let (sender, receiver) = mpsc::channel(); + node.message(AudioNodeMessage::MediaElementSourceNode( + MediaElementSourceNodeMessage::GetAudioRenderer(sender), + )); + let audio_renderer = receiver.recv().unwrap(); + // XXX set audio renderer in player. + let media_element = &options.mediaElement; + let media_element = Dom::from_ref(&**media_element); + Ok(MediaElementAudioSourceNode { + node, + media_element, + }) + } + + #[allow(unrooted_must_root)] + pub fn new( + window: &Window, + context: &AudioContext, + options: &MediaElementAudioSourceOptions, + ) -> Fallible<DomRoot<MediaElementAudioSourceNode>> { + let node = MediaElementAudioSourceNode::new_inherited(window, context, options)?; + Ok(reflect_dom_object( + Box::new(node), + window, + MediaElementAudioSourceNodeBinding::Wrap, + )) + } + + pub fn Constructor( + window: &Window, + context: &AudioContext, + options: &MediaElementAudioSourceOptions, + ) -> Fallible<DomRoot<MediaElementAudioSourceNode>> { + MediaElementAudioSourceNode::new(window, context, options) + } +} + +impl MediaElementAudioSourceNodeMethods for MediaElementAudioSourceNode { + fn MediaElement(&self) -> DomRoot<HTMLMediaElement> { + DomRoot::from_ref(&*self.media_element) + } +} diff --git a/components/script/dom/mod.rs b/components/script/dom/mod.rs index 16d2c6fb686..fbc4d457482 100644 --- a/components/script/dom/mod.rs +++ b/components/script/dom/mod.rs @@ -394,6 +394,7 @@ pub mod inputevent; pub mod keyboardevent; pub mod location; pub mod mediadevices; +pub mod mediaelementaudiosourcenode; pub mod mediaerror; pub mod mediafragmentparser; pub mod medialist; diff --git a/components/script/dom/webidls/MediaElementAudioSourceNode.webidl b/components/script/dom/webidls/MediaElementAudioSourceNode.webidl new file mode 100644 index 00000000000..5afe7775caa --- /dev/null +++ b/components/script/dom/webidls/MediaElementAudioSourceNode.webidl @@ -0,0 +1,17 @@ +/* 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 https://mozilla.org/MPL/2.0/. */ +/* + * The origin of this IDL file is + * https://webaudio.github.io/web-audio-api/#mediaelementaudiosourcenode + */ + +dictionary MediaElementAudioSourceOptions { + required HTMLMediaElement mediaElement; +}; + +[Exposed=Window] +interface MediaElementAudioSourceNode : AudioNode { + [Throws] constructor (AudioContext context, MediaElementAudioSourceOptions options); + [SameObject] readonly attribute HTMLMediaElement mediaElement; +}; |