MediaElementAudioSourceNode implementation

This commit is contained in:
Fernando Jiménez Moreno 2019-11-07 16:45:34 +01:00
parent ea054871bf
commit 03485d730f
4 changed files with 103 additions and 0 deletions

View file

@ -97,6 +97,10 @@ impl AudioContext {
self.context.resume();
}
}
pub fn base(&self) -> DomRoot<BaseAudioContext> {
DomRoot::from_ref(&self.context)
}
}
impl AudioContextMethods for AudioContext {

View file

@ -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)
}
}

View file

@ -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;

View file

@ -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;
};