Skip to content

Commit

Permalink
Add MedaStreamAudioDestinationNode::stream
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Jul 2, 2020
1 parent bf9614e commit 2a838d9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
22 changes: 18 additions & 4 deletions components/script/dom/mediastreamaudiodestinationnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ use crate::dom::bindings::codegen::Bindings::AudioNodeBinding::AudioNodeOptions;
use crate::dom::bindings::codegen::Bindings::AudioNodeBinding::{
ChannelCountMode, ChannelInterpretation,
};
use crate::dom::bindings::codegen::Bindings::MediaStreamAudioDestinationNodeBinding::MediaStreamAudioDestinationNodeMethods;
use crate::dom::bindings::error::Fallible;
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::reflector::reflect_dom_object;
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject};
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::mediastream::MediaStream;
use crate::dom::window::Window;
use dom_struct::dom_struct;
use servo_media::audio::node::AudioNodeInit;
Expand All @@ -21,6 +23,7 @@ use servo_media::ServoMedia;
#[dom_struct]
pub struct MediaStreamAudioDestinationNode {
node: AudioNode,
stream: Dom<MediaStream>,
}

impl MediaStreamAudioDestinationNode {
Expand All @@ -30,7 +33,8 @@ impl MediaStreamAudioDestinationNode {
options: &AudioNodeOptions,
) -> Fallible<MediaStreamAudioDestinationNode> {
let media = ServoMedia::get().unwrap();
let (socket, _id) = media.create_stream_and_socket(MediaStreamType::Audio);
let (socket, id) = media.create_stream_and_socket(MediaStreamType::Audio);
let stream = MediaStream::new_single(&context.global(), id, MediaStreamType::Audio);
let node_options = options.unwrap_or(
2,
ChannelCountMode::Explicit,
Expand All @@ -43,7 +47,10 @@ impl MediaStreamAudioDestinationNode {
1, // inputs
0, // outputs
)?;
Ok(MediaStreamAudioDestinationNode { node })
Ok(MediaStreamAudioDestinationNode {
node,
stream: Dom::from_ref(&stream),
})
}

#[allow(unrooted_must_root)]
Expand All @@ -65,3 +72,10 @@ impl MediaStreamAudioDestinationNode {
MediaStreamAudioDestinationNode::new(window, context, options)
}
}

impl MediaStreamAudioDestinationNodeMethods for MediaStreamAudioDestinationNode {
/// https://webaudio.github.io/web-audio-api/#dom-mediastreamaudiodestinationnode-stream
fn Stream(&self) -> DomRoot<MediaStream> {
DomRoot::from_ref(&self.stream)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
[Exposed=Window]
interface MediaStreamAudioDestinationNode : AudioNode {
[Throws] constructor (AudioContext context, optional AudioNodeOptions options = {});
// readonly attribute MediaStream stream;
};
readonly attribute MediaStream stream;
};

0 comments on commit 2a838d9

Please sign in to comment.