Skip to content
Permalink
Browse files

Add stream types to tracks, add MediaStreamTrack.id and MediaStreamTr…

…ack.kind
  • Loading branch information...
Manishearth committed May 7, 2019
1 parent a9ab13b commit 36abbca0a64d1886bf813e801aad3d3dec66a434
@@ -105,6 +105,7 @@ use servo_media::audio::panner_node::{DistanceModel, PanningModel};
use servo_media::audio::param::ParamType;
use servo_media::player::Player;
use servo_media::streams::registry::MediaStreamId;
use servo_media::streams::MediaStreamType;
use servo_media::webrtc::WebRtcController;
use servo_url::{ImmutableOrigin, MutableOrigin, ServoUrl};
use smallvec::SmallVec;
@@ -490,7 +491,7 @@ unsafe_no_jsmanaged_fields!(NodeId);
unsafe_no_jsmanaged_fields!(AnalysisEngine, DistanceModel, PanningModel, ParamType);
unsafe_no_jsmanaged_fields!(dyn Player);
unsafe_no_jsmanaged_fields!(WebRtcController);
unsafe_no_jsmanaged_fields!(MediaStreamId);
unsafe_no_jsmanaged_fields!(MediaStreamId, MediaStreamType);
unsafe_no_jsmanaged_fields!(Mutex<MediaFrameRenderer>);
unsafe_no_jsmanaged_fields!(RenderApiSender);
unsafe_no_jsmanaged_fields!(ResourceFetchTiming);
@@ -18,6 +18,7 @@ use crate::dom::mediastreamtrack::MediaStreamTrack;
use crate::dom::promise::Promise;
use dom_struct::dom_struct;
use servo_media::streams::capture::{Constrain, ConstrainRange, MediaTrackConstraintSet};
use servo_media::streams::MediaStreamType;
use servo_media::ServoMedia;
use std::rc::Rc;

@@ -55,13 +56,13 @@ impl MediaDevicesMethods for MediaDevices {
let stream = MediaStream::new(&self.global());
if let Some(constraints) = convert_constraints(&constraints.audio) {
if let Some(audio) = media.create_audioinput_stream(constraints) {
let track = MediaStreamTrack::new(&self.global(), audio);
let track = MediaStreamTrack::new(&self.global(), audio, MediaStreamType::Audio);
stream.add_track(&track);
}
}
if let Some(constraints) = convert_constraints(&constraints.video) {
if let Some(video) = media.create_videoinput_stream(constraints) {
let track = MediaStreamTrack::new(&self.global(), video);
let track = MediaStreamTrack::new(&self.global(), video, MediaStreamType::Video);
stream.add_track(&track);
}
}
@@ -2,32 +2,43 @@
* 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::bindings::codegen::Bindings::MediaStreamTrackBinding;
use crate::dom::bindings::codegen::Bindings::MediaStreamTrackBinding::{
self, MediaStreamTrackMethods,
};
use crate::dom::bindings::reflector::reflect_dom_object;
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::dom::eventtarget::EventTarget;
use crate::dom::globalscope::GlobalScope;
use dom_struct::dom_struct;
use servo_media::streams::registry::MediaStreamId;
use servo_media::streams::MediaStreamType;

#[dom_struct]
pub struct MediaStreamTrack {
eventtarget: EventTarget,
#[ignore_malloc_size_of = "defined in servo-media"]
id: MediaStreamId,
#[ignore_malloc_size_of = "defined in servo-media"]
ty: MediaStreamType,
}

impl MediaStreamTrack {
pub fn new_inherited(id: MediaStreamId) -> MediaStreamTrack {
pub fn new_inherited(id: MediaStreamId, ty: MediaStreamType) -> MediaStreamTrack {
MediaStreamTrack {
eventtarget: EventTarget::new_inherited(),
id,
ty,
}
}

pub fn new(global: &GlobalScope, id: MediaStreamId) -> DomRoot<MediaStreamTrack> {
pub fn new(
global: &GlobalScope,
id: MediaStreamId,
ty: MediaStreamType,
) -> DomRoot<MediaStreamTrack> {
reflect_dom_object(
Box::new(MediaStreamTrack::new_inherited(id)),
Box::new(MediaStreamTrack::new_inherited(id, ty)),
global,
MediaStreamTrackBinding::Wrap,
)
@@ -36,4 +47,23 @@ impl MediaStreamTrack {
pub fn id(&self) -> MediaStreamId {
self.id
}

pub fn ty(&self) -> MediaStreamType {
self.ty
}
}

impl MediaStreamTrackMethods for MediaStreamTrack {
/// https://w3c.github.io/mediacapture-main/#dom-mediastreamtrack-kind
fn Kind(&self) -> DOMString {
match self.ty {
MediaStreamType::Video => "video".into(),
MediaStreamType::Audio => "audio".into(),
}
}

/// https://w3c.github.io/mediacapture-main/#dom-mediastreamtrack-id
fn Id(&self) -> DOMString {
self.id.id().to_string().into()
}
}
@@ -6,8 +6,8 @@

[Exposed=Window, Pref="dom.webrtc.enabled"]
interface MediaStreamTrack : EventTarget {
// readonly attribute DOMString kind;
// readonly attribute DOMString id;
readonly attribute DOMString kind;
readonly attribute DOMString id;
// readonly attribute DOMString label;
// attribute boolean enabled;
// readonly attribute boolean muted;

0 comments on commit 36abbca

Please sign in to comment.
You can’t perform that action at this time.