mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Auto merge of #27143 - Manishearth:streamnodes, r=ferjm
Implement MediaStreamAudioDestinationNode, MediaStreamAudioSourceNode, MediaStreamTrackAudioSourceNode Progress in https://github.com/servo/servo/issues/26097 This is a draft since we need the data channels stuff to land first (also I need to make sure we're passing WPT)
This commit is contained in:
commit
4504eebdc3
21 changed files with 348 additions and 213 deletions
|
@ -9,6 +9,7 @@ use crate::dom::bindings::codegen::Bindings::AudioContextBinding::{
|
|||
use crate::dom::bindings::codegen::Bindings::AudioContextBinding::{
|
||||
AudioContextOptions, AudioTimestamp,
|
||||
};
|
||||
use crate::dom::bindings::codegen::Bindings::AudioNodeBinding::AudioNodeOptions;
|
||||
use crate::dom::bindings::codegen::Bindings::BaseAudioContextBinding::AudioContextState;
|
||||
use crate::dom::bindings::codegen::Bindings::BaseAudioContextBinding::BaseAudioContextBinding::BaseAudioContextMethods;
|
||||
use crate::dom::bindings::codegen::UnionTypes::AudioContextLatencyCategoryOrDouble;
|
||||
|
@ -20,6 +21,11 @@ use crate::dom::bindings::reflector::{reflect_dom_object, DomObject};
|
|||
use crate::dom::bindings::root::DomRoot;
|
||||
use crate::dom::htmlmediaelement::HTMLMediaElement;
|
||||
use crate::dom::mediaelementaudiosourcenode::MediaElementAudioSourceNode;
|
||||
use crate::dom::mediastream::MediaStream;
|
||||
use crate::dom::mediastreamaudiodestinationnode::MediaStreamAudioDestinationNode;
|
||||
use crate::dom::mediastreamaudiosourcenode::MediaStreamAudioSourceNode;
|
||||
use crate::dom::mediastreamtrack::MediaStreamTrack;
|
||||
use crate::dom::mediastreamtrackaudiosourcenode::MediaStreamTrackAudioSourceNode;
|
||||
use crate::dom::promise::Promise;
|
||||
use crate::dom::window::Window;
|
||||
use crate::realms::InRealm;
|
||||
|
@ -254,6 +260,33 @@ impl AudioContextMethods for AudioContext {
|
|||
let window = global.as_window();
|
||||
MediaElementAudioSourceNode::new(window, self, media_element)
|
||||
}
|
||||
|
||||
/// https://webaudio.github.io/web-audio-api/#dom-audiocontext-createmediastreamsource
|
||||
fn CreateMediaStreamSource(
|
||||
&self,
|
||||
stream: &MediaStream,
|
||||
) -> Fallible<DomRoot<MediaStreamAudioSourceNode>> {
|
||||
let global = self.global();
|
||||
let window = global.as_window();
|
||||
MediaStreamAudioSourceNode::new(window, self, stream)
|
||||
}
|
||||
|
||||
/// https://webaudio.github.io/web-audio-api/#dom-audiocontext-createmediastreamtracksource
|
||||
fn CreateMediaStreamTrackSource(
|
||||
&self,
|
||||
track: &MediaStreamTrack,
|
||||
) -> Fallible<DomRoot<MediaStreamTrackAudioSourceNode>> {
|
||||
let global = self.global();
|
||||
let window = global.as_window();
|
||||
MediaStreamTrackAudioSourceNode::new(window, self, track)
|
||||
}
|
||||
|
||||
/// https://webaudio.github.io/web-audio-api/#dom-audiocontext-createmediastreamdestination
|
||||
fn CreateMediaStreamDestination(&self) -> Fallible<DomRoot<MediaStreamAudioDestinationNode>> {
|
||||
let global = self.global();
|
||||
let window = global.as_window();
|
||||
MediaStreamAudioDestinationNode::new(window, self, &AudioNodeOptions::empty())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<AudioContextLatencyCategory> for LatencyCategory {
|
||||
|
|
|
@ -13,6 +13,7 @@ use crate::dom::globalscope::GlobalScope;
|
|||
use crate::dom::mediastreamtrack::MediaStreamTrack;
|
||||
use crate::dom::window::Window;
|
||||
use dom_struct::dom_struct;
|
||||
use servo_media::streams::registry::MediaStreamId;
|
||||
use servo_media::streams::MediaStreamType;
|
||||
|
||||
#[dom_struct]
|
||||
|
@ -34,6 +35,17 @@ impl MediaStream {
|
|||
reflect_dom_object(Box::new(MediaStream::new_inherited()), global)
|
||||
}
|
||||
|
||||
pub fn new_single(
|
||||
global: &GlobalScope,
|
||||
id: MediaStreamId,
|
||||
ty: MediaStreamType,
|
||||
) -> DomRoot<MediaStream> {
|
||||
let this = Self::new(global);
|
||||
let track = MediaStreamTrack::new(global, id, ty);
|
||||
this.AddTrack(&track);
|
||||
this
|
||||
}
|
||||
|
||||
pub fn Constructor(global: &Window) -> Fallible<DomRoot<MediaStream>> {
|
||||
Ok(MediaStream::new(&global.global()))
|
||||
}
|
||||
|
|
81
components/script/dom/mediastreamaudiodestinationnode.rs
Normal file
81
components/script/dom/mediastreamaudiodestinationnode.rs
Normal 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::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, 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;
|
||||
use servo_media::streams::MediaStreamType;
|
||||
use servo_media::ServoMedia;
|
||||
|
||||
#[dom_struct]
|
||||
pub struct MediaStreamAudioDestinationNode {
|
||||
node: AudioNode,
|
||||
stream: Dom<MediaStream>,
|
||||
}
|
||||
|
||||
impl MediaStreamAudioDestinationNode {
|
||||
#[allow(unrooted_must_root)]
|
||||
pub fn new_inherited(
|
||||
context: &AudioContext,
|
||||
options: &AudioNodeOptions,
|
||||
) -> Fallible<MediaStreamAudioDestinationNode> {
|
||||
let media = ServoMedia::get().unwrap();
|
||||
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,
|
||||
ChannelInterpretation::Speakers,
|
||||
);
|
||||
let node = AudioNode::new_inherited(
|
||||
AudioNodeInit::MediaStreamDestinationNode(socket),
|
||||
&context.upcast(),
|
||||
node_options,
|
||||
1, // inputs
|
||||
0, // outputs
|
||||
)?;
|
||||
Ok(MediaStreamAudioDestinationNode {
|
||||
node,
|
||||
stream: Dom::from_ref(&stream),
|
||||
})
|
||||
}
|
||||
|
||||
#[allow(unrooted_must_root)]
|
||||
pub fn new(
|
||||
window: &Window,
|
||||
context: &AudioContext,
|
||||
options: &AudioNodeOptions,
|
||||
) -> Fallible<DomRoot<MediaStreamAudioDestinationNode>> {
|
||||
let node = MediaStreamAudioDestinationNode::new_inherited(context, options)?;
|
||||
Ok(reflect_dom_object(Box::new(node), window))
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
pub fn Constructor(
|
||||
window: &Window,
|
||||
context: &AudioContext,
|
||||
options: &AudioNodeOptions,
|
||||
) -> Fallible<DomRoot<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)
|
||||
}
|
||||
}
|
76
components/script/dom/mediastreamaudiosourcenode.rs
Normal file
76
components/script/dom/mediastreamaudiosourcenode.rs
Normal file
|
@ -0,0 +1,76 @@
|
|||
/* 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::MediaStreamAudioSourceNodeBinding::{
|
||||
MediaStreamAudioSourceNodeMethods, MediaStreamAudioSourceOptions,
|
||||
};
|
||||
use crate::dom::bindings::error::{Error, Fallible};
|
||||
use crate::dom::bindings::inheritance::Castable;
|
||||
use crate::dom::bindings::reflector::reflect_dom_object;
|
||||
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;
|
||||
use servo_media::streams::MediaStreamType;
|
||||
|
||||
#[dom_struct]
|
||||
pub struct MediaStreamAudioSourceNode {
|
||||
node: AudioNode,
|
||||
stream: Dom<MediaStream>,
|
||||
}
|
||||
|
||||
impl MediaStreamAudioSourceNode {
|
||||
#[allow(unrooted_must_root)]
|
||||
pub fn new_inherited(
|
||||
context: &AudioContext,
|
||||
stream: &MediaStream,
|
||||
) -> Fallible<MediaStreamAudioSourceNode> {
|
||||
let track = stream
|
||||
.get_tracks()
|
||||
.iter()
|
||||
.find(|t| t.ty() == MediaStreamType::Audio)
|
||||
.ok_or(Error::InvalidState)?
|
||||
.id();
|
||||
let node = AudioNode::new_inherited(
|
||||
AudioNodeInit::MediaStreamSourceNode(track),
|
||||
&context.upcast(),
|
||||
Default::default(),
|
||||
0, // inputs
|
||||
1, // outputs
|
||||
)?;
|
||||
Ok(MediaStreamAudioSourceNode {
|
||||
node,
|
||||
stream: Dom::from_ref(&stream),
|
||||
})
|
||||
}
|
||||
|
||||
#[allow(unrooted_must_root)]
|
||||
pub fn new(
|
||||
window: &Window,
|
||||
context: &AudioContext,
|
||||
stream: &MediaStream,
|
||||
) -> Fallible<DomRoot<MediaStreamAudioSourceNode>> {
|
||||
let node = MediaStreamAudioSourceNode::new_inherited(context, stream)?;
|
||||
Ok(reflect_dom_object(Box::new(node), window))
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
pub fn Constructor(
|
||||
window: &Window,
|
||||
context: &AudioContext,
|
||||
options: &MediaStreamAudioSourceOptions,
|
||||
) -> Fallible<DomRoot<MediaStreamAudioSourceNode>> {
|
||||
MediaStreamAudioSourceNode::new(window, context, &options.mediaStream)
|
||||
}
|
||||
}
|
||||
|
||||
impl MediaStreamAudioSourceNodeMethods for MediaStreamAudioSourceNode {
|
||||
/// https://webaudio.github.io/web-audio-api/#dom-MediaStreamAudioSourceNode-stream
|
||||
fn MediaStream(&self) -> DomRoot<MediaStream> {
|
||||
DomRoot::from_ref(&self.stream)
|
||||
}
|
||||
}
|
60
components/script/dom/mediastreamtrackaudiosourcenode.rs
Normal file
60
components/script/dom/mediastreamtrackaudiosourcenode.rs
Normal file
|
@ -0,0 +1,60 @@
|
|||
/* 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::MediaStreamTrackAudioSourceNodeBinding::MediaStreamTrackAudioSourceOptions;
|
||||
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::{Dom, DomRoot};
|
||||
use crate::dom::mediastreamtrack::MediaStreamTrack;
|
||||
use crate::dom::window::Window;
|
||||
use dom_struct::dom_struct;
|
||||
use servo_media::audio::node::AudioNodeInit;
|
||||
|
||||
#[dom_struct]
|
||||
pub struct MediaStreamTrackAudioSourceNode {
|
||||
node: AudioNode,
|
||||
track: Dom<MediaStreamTrack>,
|
||||
}
|
||||
|
||||
impl MediaStreamTrackAudioSourceNode {
|
||||
#[allow(unrooted_must_root)]
|
||||
pub fn new_inherited(
|
||||
context: &AudioContext,
|
||||
track: &MediaStreamTrack,
|
||||
) -> Fallible<MediaStreamTrackAudioSourceNode> {
|
||||
let node = AudioNode::new_inherited(
|
||||
AudioNodeInit::MediaStreamSourceNode(track.id()),
|
||||
&context.upcast(),
|
||||
Default::default(),
|
||||
0, // inputs
|
||||
1, // outputs
|
||||
)?;
|
||||
Ok(MediaStreamTrackAudioSourceNode {
|
||||
node,
|
||||
track: Dom::from_ref(&track),
|
||||
})
|
||||
}
|
||||
|
||||
#[allow(unrooted_must_root)]
|
||||
pub fn new(
|
||||
window: &Window,
|
||||
context: &AudioContext,
|
||||
track: &MediaStreamTrack,
|
||||
) -> Fallible<DomRoot<MediaStreamTrackAudioSourceNode>> {
|
||||
let node = MediaStreamTrackAudioSourceNode::new_inherited(context, track)?;
|
||||
Ok(reflect_dom_object(Box::new(node), window))
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
pub fn Constructor(
|
||||
window: &Window,
|
||||
context: &AudioContext,
|
||||
options: &MediaStreamTrackAudioSourceOptions,
|
||||
) -> Fallible<DomRoot<MediaStreamTrackAudioSourceNode>> {
|
||||
MediaStreamTrackAudioSourceNode::new(window, context, &options.mediaStreamTrack)
|
||||
}
|
||||
}
|
|
@ -435,7 +435,10 @@ pub mod mediaquerylist;
|
|||
pub mod mediaquerylistevent;
|
||||
pub mod mediasession;
|
||||
pub mod mediastream;
|
||||
pub mod mediastreamaudiodestinationnode;
|
||||
pub mod mediastreamaudiosourcenode;
|
||||
pub mod mediastreamtrack;
|
||||
pub mod mediastreamtrackaudiosourcenode;
|
||||
pub mod messagechannel;
|
||||
pub mod messageevent;
|
||||
pub mod messageport;
|
||||
|
|
|
@ -34,7 +34,7 @@ interface AudioContext : BaseAudioContext {
|
|||
Promise<void> close();
|
||||
|
||||
[Throws] MediaElementAudioSourceNode createMediaElementSource(HTMLMediaElement mediaElement);
|
||||
// MediaStreamAudioSourceNode createMediaStreamSource(MediaStream mediaStream);
|
||||
// MediaStreamTrackAudioSourceNode createMediaStreamTrackSource(MediaStreamTrack mediaStreamTrack);
|
||||
// MediaStreamAudioDestinationNode createMediaStreamDestination();
|
||||
[Throws] MediaStreamAudioSourceNode createMediaStreamSource(MediaStream mediaStream);
|
||||
[Throws] MediaStreamTrackAudioSourceNode createMediaStreamTrackSource(MediaStreamTrack mediaStreamTrack);
|
||||
[Throws] MediaStreamAudioDestinationNode createMediaStreamDestination();
|
||||
};
|
||||
|
|
|
@ -4,8 +4,7 @@
|
|||
|
||||
// https://w3c.github.io/mediacapture-main/#dom-mediastream
|
||||
|
||||
[Exposed=Window,
|
||||
Pref="dom.webrtc.enabled"]
|
||||
[Exposed=Window]
|
||||
interface MediaStream : EventTarget {
|
||||
[Throws] constructor();
|
||||
[Throws] constructor(MediaStream stream);
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
/* 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/#mediastreamaudiodestinationnode
|
||||
*/
|
||||
|
||||
[Exposed=Window]
|
||||
interface MediaStreamAudioDestinationNode : AudioNode {
|
||||
[Throws] constructor (AudioContext context, optional AudioNodeOptions options = {});
|
||||
readonly attribute MediaStream stream;
|
||||
};
|
|
@ -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/#mediastreamaudiosourcenode
|
||||
*/
|
||||
|
||||
dictionary MediaStreamAudioSourceOptions {
|
||||
required MediaStream mediaStream;
|
||||
};
|
||||
|
||||
[Exposed=Window]
|
||||
interface MediaStreamAudioSourceNode : AudioNode {
|
||||
[Throws] constructor (AudioContext context, MediaStreamAudioSourceOptions options);
|
||||
[SameObject] readonly attribute MediaStream mediaStream;
|
||||
};
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
// https://w3c.github.io/mediacapture-main/#dom-mediastreamtrack
|
||||
|
||||
[Exposed=Window, Pref="dom.webrtc.enabled"]
|
||||
[Exposed=Window]
|
||||
interface MediaStreamTrack : EventTarget {
|
||||
readonly attribute DOMString kind;
|
||||
readonly attribute DOMString id;
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
/* 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/#mediastreamtrackaudiosourcenode
|
||||
*/
|
||||
|
||||
dictionary MediaStreamTrackAudioSourceOptions {
|
||||
required MediaStreamTrack mediaStreamTrack;
|
||||
};
|
||||
|
||||
[Exposed=Window]
|
||||
interface MediaStreamTrackAudioSourceNode : AudioNode {
|
||||
[Throws] constructor (AudioContext context, MediaStreamTrackAudioSourceOptions options);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue