Skip to content

Commit

Permalink
Use correct webrtc sink and payloads
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Mar 2, 2019
1 parent b76b8a0 commit f0e7554
Show file tree
Hide file tree
Showing 9 changed files with 251 additions and 53 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion backends/dummy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl WebRtcControllerBackend for DummyWebRtcController {
fn add_ice_candidate(&mut self, _: IceCandidate) {}
fn create_offer(&mut self, _: SendBoxFnOnce<'static, (SessionDescription,)>) {}
fn create_answer(&mut self, _: SendBoxFnOnce<'static, (SessionDescription,)>) {}
fn add_stream(&mut self, _: &mut MediaStream) {}
fn add_stream(&mut self, _: Box<MediaStream>) {}
fn internal_event(&mut self, _: thread::InternalEvent) {}
fn quit(&mut self) {}
}
3 changes: 3 additions & 0 deletions backends/gstreamer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ version = "0.8"
[dependencies.gstreamer-sys]
version = "0.7"

[dependencies.gstreamer-sdp-sys]
version = "0.7"

[dependencies.gstreamer]
version = "0.13"
features = ["subclassing"]
Expand Down
2 changes: 0 additions & 2 deletions backends/gstreamer/src/media_capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,12 @@ impl GstMediaDevices {
("audio/x-raw", "Audio/Source")
};
let caps = into_caps(constraints, format)?;
println!("requesting {:?}", caps);
let f = self.monitor.add_filter(filter, &caps);
let devices = self.monitor.get_devices();
if let Some(f) = f {
let _ = self.monitor.remove_filter(f);
}
if let Some(d) = devices.get(0) {
println!("{:?}", d.get_caps());
let element = d.create_element(None)?;
Some(GstMediaTrack { element })
} else {
Expand Down
53 changes: 39 additions & 14 deletions backends/gstreamer/src/media_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ lazy_static! {
&[
("media", &"audio"),
("encoding-name", &"OPUS"),
("payload", &(97i32)),
],
)
};
Expand All @@ -21,7 +20,6 @@ lazy_static! {
&[
("media", &"video"),
("encoding-name", &"VP8"),
("payload", &(96i32)),
],
)
};
Expand Down Expand Up @@ -50,20 +48,47 @@ impl MediaStream for GStreamerMediaStream {
}

impl GStreamerMediaStream {
pub fn attach_to_webrtc(&mut self, pipeline: &gst::Pipeline, webrtcbin: &gst::Element) {
println!("atttaching a {:?} stream", self.type_);
self.attach_to_pipeline(pipeline);

let caps = match self.type_ {
pub fn caps(&self) -> &gst::Caps {
match self.type_ {
StreamType::Audio => &*RTP_CAPS_OPUS,
StreamType::Video => &*RTP_CAPS_VP8,
};
self.elements
.last()
.as_ref()
.unwrap()
.link_filtered(webrtcbin, caps)
.unwrap();
}
}

pub fn caps_with_payload(&self, payload: i32) -> gst::Caps {
match self.type_ {
StreamType::Audio => {
gst::Caps::new_simple(
"application/x-rtp",
&[
("media", &"audio"),
("encoding-name", &"OPUS"),
("payload", &(payload)),
],
)
}
StreamType::Video => {
gst::Caps::new_simple(
"application/x-rtp",
&[
("media", &"video"),
("encoding-name", &"VP8"),
("payload", &(payload)),
],
)
}
}
}

pub fn insert_capsfilter(&mut self) {
assert!(self.pipeline.is_none());
let capsfilter = gst::ElementFactory::make("capsfilter", None).unwrap();
capsfilter.set_property("caps", self.caps()).unwrap();
self.elements.push(capsfilter);
}

pub fn src_element(&self) -> gst::Element {
self.elements.last().unwrap().clone()
}

pub fn attach_to_pipeline(&mut self, pipeline: &gst::Pipeline) {
Expand Down
Loading

0 comments on commit f0e7554

Please sign in to comment.