examples: webrtc: rust: Update to gstreamer-rs 0.21

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5181>
This commit is contained in:
Sebastian Dröge 2023-08-14 11:42:43 +03:00 committed by GStreamer Marge Bot
parent f3cd913b3c
commit ae28e1035e
10 changed files with 1383 additions and 1068 deletions

File diff suppressed because it is too large Load diff

View file

@ -11,15 +11,15 @@ clap = { version = "4", features = ["derive"] }
anyhow = "1" anyhow = "1"
url = "2" url = "2"
rand = "0.8" rand = "0.8"
async-tungstenite = { version = "0.20", features = ["gio-runtime"] } async-tungstenite = { version = "0.23", features = ["gio-runtime"] }
gst = { package = "gstreamer", version = "0.20" } gst = { package = "gstreamer", version = "0.21" }
gst-webrtc = { package = "gstreamer-webrtc", version = "0.20" } gst-webrtc = { package = "gstreamer-webrtc", version = "0.21" }
gst-sdp = { package = "gstreamer-sdp", version = "0.20" } gst-sdp = { package = "gstreamer-sdp", version = "0.21" }
serde = "1" serde = "1"
serde_derive = "1" serde_derive = "1"
serde_json = "1.0.53" serde_json = "1.0.53"
http = "0.2" http = "0.2"
glib = "0.17" glib = "0.18"
gio = "0.17" gio = "0.18"
log = "0.4.8" log = "0.4.8"
env_logger = "0.10" env_logger = "0.10"

View file

@ -503,10 +503,11 @@ impl JanusGateway {
.static_pad("sink") .static_pad("sink")
.expect("Failed to get sink pad from encoder"); .expect("Failed to get sink pad from encoder");
if let Ok(video_ghost_pad) = gst::GhostPad::with_target(Some("video_sink"), &sinkpad) { let video_ghost_pad = gst::GhostPad::builder_with_target(&sinkpad)?
encode_bin.add_pad(&video_ghost_pad)?; .name("video_sink")
srcpad.link(&video_ghost_pad)?; .build();
} encode_bin.add_pad(&video_ghost_pad)?;
srcpad.link(&video_ghost_pad)?;
let sinkpad2 = webrtcbin let sinkpad2 = webrtcbin
.request_pad_simple("sink_%u") .request_pad_simple("sink_%u")
@ -515,11 +516,11 @@ impl JanusGateway {
.by_name("webrtc-vsink") .by_name("webrtc-vsink")
.expect("No webrtc-vsink found"); .expect("No webrtc-vsink found");
let srcpad = vsink.static_pad("src").expect("Element without src pad"); let srcpad = vsink.static_pad("src").expect("Element without src pad");
if let Ok(webrtc_ghost_pad) = gst::GhostPad::with_target(Some("webrtc_video_src"), &srcpad) let webrtc_ghost_pad = gst::GhostPad::builder_with_target(&srcpad)?
{ .name("webrtc_video_src")
encode_bin.add_pad(&webrtc_ghost_pad)?; .build();
webrtc_ghost_pad.link(&sinkpad2)?; encode_bin.add_pad(&webrtc_ghost_pad)?;
} webrtc_ghost_pad.link(&sinkpad2)?;
let transceiver = webrtcbin.emit_by_name::<glib::Object>("get-transceiver", &[&0i32]); let transceiver = webrtcbin.emit_by_name::<glib::Object>("get-transceiver", &[&0i32]);
transceiver.set_property("do-nack", false); transceiver.set_property("do-nack", false);

View file

@ -20,7 +20,7 @@
use anyhow::bail; use anyhow::bail;
use gst::prelude::*; use gst::prelude::*;
use std::sync::{Arc, Weak}; use std::sync::{Arc, Mutex, Weak};
mod janus; mod janus;
@ -36,6 +36,7 @@ struct AppWeak(Weak<AppInner>);
#[derive(Debug)] #[derive(Debug)]
struct AppInner { struct AppInner {
pipeline: gst::Pipeline, pipeline: gst::Pipeline,
bus_watch: Mutex<Option<gst::bus::BusWatchGuard>>,
} }
// To be able to access the App's fields directly // To be able to access the App's fields directly
@ -71,18 +72,24 @@ impl App {
.expect("Couldn't downcast pipeline"); .expect("Couldn't downcast pipeline");
let bus = pipeline.bus().unwrap(); let bus = pipeline.bus().unwrap();
let app = App(Arc::new(AppInner { pipeline })); let app = App(Arc::new(AppInner {
pipeline,
bus_watch: Mutex::default(),
}));
let app_weak = app.downgrade(); let app_weak = app.downgrade();
bus.add_watch_local(move |_bus, msg| { let bus_watch = bus
let app = upgrade_weak!(app_weak, glib::Continue(false)); .add_watch_local(move |_bus, msg| {
let app = upgrade_weak!(app_weak, glib::ControlFlow::Break);
if app.handle_pipeline_message(msg).is_err() {
return glib::ControlFlow::Break;
}
glib::ControlFlow::Continue
})
.expect("Unable to add bus watch");
*app.0.bus_watch.lock().unwrap() = Some(bus_watch);
if app.handle_pipeline_message(msg).is_err() {
return glib::Continue(false);
}
glib::Continue(true)
})
.expect("Unable to add bus watch");
Ok(app) Ok(app)
} }

File diff suppressed because it is too large Load diff

View file

@ -10,13 +10,13 @@ async-std = "1"
clap = { version = "4", features = ["derive"] } clap = { version = "4", features = ["derive"] }
anyhow = "1" anyhow = "1"
rand = "0.8" rand = "0.8"
async-tungstenite = { version = "0.20", features = ["async-std-runtime", "async-native-tls"] } async-tungstenite = { version = "0.23", features = ["async-std-runtime", "async-native-tls"] }
gst = { package = "gstreamer", version = "0.20" } gst = { package = "gstreamer", version = "0.21" }
gst-webrtc = { package = "gstreamer-webrtc", version = "0.20" } gst-webrtc = { package = "gstreamer-webrtc", version = "0.21" }
gst-sdp = { package = "gstreamer-sdp", version = "0.20" } gst-sdp = { package = "gstreamer-sdp", version = "0.21" }
serde = "1" serde = "1"
serde_derive = "1" serde_derive = "1"
serde_json = "1" serde_json = "1"
[target.'cfg(target_os = "macos")'.dependencies] [target.'cfg(target_os = "macos")'.dependencies]
cocoa = "0.24" cocoa = "0.25"

View file

@ -321,21 +321,21 @@ impl App {
let audio_queue = peer_bin let audio_queue = peer_bin
.by_name("audio-queue") .by_name("audio-queue")
.expect("can't find audio-queue"); .expect("can't find audio-queue");
let audio_sink_pad = gst::GhostPad::with_target( let audio_sink_pad =
Some("audio_sink"), gst::GhostPad::builder_with_target(&audio_queue.static_pad("sink").unwrap())
&audio_queue.static_pad("sink").unwrap(), .unwrap()
) .name("audio_sink")
.unwrap(); .build();
peer_bin.add_pad(&audio_sink_pad).unwrap(); peer_bin.add_pad(&audio_sink_pad).unwrap();
let video_queue = peer_bin let video_queue = peer_bin
.by_name("video-queue") .by_name("video-queue")
.expect("can't find video-queue"); .expect("can't find video-queue");
let video_sink_pad = gst::GhostPad::with_target( let video_sink_pad =
Some("video_sink"), gst::GhostPad::builder_with_target(&video_queue.static_pad("sink").unwrap())
&video_queue.static_pad("sink").unwrap(), .unwrap()
) .name("video_sink")
.unwrap(); .build();
peer_bin.add_pad(&video_sink_pad).unwrap(); peer_bin.add_pad(&video_sink_pad).unwrap();
let peer = Peer(Arc::new(PeerInner { let peer = Peer(Arc::new(PeerInner {
@ -837,14 +837,12 @@ impl Peer {
// Add a ghost pad on our conv bin that proxies the sink pad of the decodebin // Add a ghost pad on our conv bin that proxies the sink pad of the decodebin
let dbin = conv.by_name("dbin").unwrap(); let dbin = conv.by_name("dbin").unwrap();
let sinkpad = let sinkpad = gst::GhostPad::with_target(&dbin.static_pad("sink").unwrap()).unwrap();
gst::GhostPad::with_target(Some("sink"), &dbin.static_pad("sink").unwrap()).unwrap();
conv.add_pad(&sinkpad).unwrap(); conv.add_pad(&sinkpad).unwrap();
// And another one that proxies the source pad of the last element // And another one that proxies the source pad of the last element
let src = conv.by_name("src").unwrap(); let src = conv.by_name("src").unwrap();
let srcpad = let srcpad = gst::GhostPad::with_target(&src.static_pad("src").unwrap()).unwrap();
gst::GhostPad::with_target(Some("src"), &src.static_pad("src").unwrap()).unwrap();
conv.add_pad(&srcpad).unwrap(); conv.add_pad(&srcpad).unwrap();
self.bin.add(&conv).unwrap(); self.bin.add(&conv).unwrap();
@ -856,11 +854,17 @@ impl Peer {
// And then add a new ghost pad to the peer bin that proxies the source pad we added above // And then add a new ghost pad to the peer bin that proxies the source pad we added above
if media_type == "video" { if media_type == "video" {
let srcpad = gst::GhostPad::with_target(Some("video_src"), &srcpad).unwrap(); let srcpad = gst::GhostPad::builder_with_target(&srcpad)
.unwrap()
.name("video_src")
.build();
srcpad.set_active(true).unwrap(); srcpad.set_active(true).unwrap();
self.bin.add_pad(&srcpad).unwrap(); self.bin.add_pad(&srcpad).unwrap();
} else if media_type == "audio" { } else if media_type == "audio" {
let srcpad = gst::GhostPad::with_target(Some("audio_src"), &srcpad).unwrap(); let srcpad = gst::GhostPad::builder_with_target(&srcpad)
.unwrap()
.name("audio_src")
.build();
srcpad.set_active(true).unwrap(); srcpad.set_active(true).unwrap();
self.bin.add_pad(&srcpad).unwrap(); self.bin.add_pad(&srcpad).unwrap();
} }

File diff suppressed because it is too large Load diff

View file

@ -10,14 +10,14 @@ async-std = "1"
clap = { version = "4", features = ["derive"] } clap = { version = "4", features = ["derive"] }
anyhow = "1" anyhow = "1"
rand = "0.8" rand = "0.8"
async-tungstenite = { version = "0.20", features = ["async-std-runtime", "async-native-tls"] } async-tungstenite = { version = "0.23", features = ["async-std-runtime", "async-native-tls"] }
gst = { package = "gstreamer", version = "0.20" } gst = { package = "gstreamer", version = "0.21" }
gst-rtp = { package = "gstreamer-rtp", version = "0.20", features = ["v1_20"] } gst-rtp = { package = "gstreamer-rtp", version = "0.21", features = ["v1_20"] }
gst-webrtc = { package = "gstreamer-webrtc", version = "0.20" } gst-webrtc = { package = "gstreamer-webrtc", version = "0.21" }
gst-sdp = { package = "gstreamer-sdp", version = "0.20" } gst-sdp = { package = "gstreamer-sdp", version = "0.21" }
serde = "1" serde = "1"
serde_derive = "1" serde_derive = "1"
serde_json = "1" serde_json = "1"
[target.'cfg(target_os = "macos")'.dependencies] [target.'cfg(target_os = "macos")'.dependencies]
cocoa = "0.24" cocoa = "0.25"

View file

@ -377,7 +377,7 @@ impl App {
bail!("Answer creation future got no response"); bail!("Answer creation future got no response");
} }
Err(err) => { Err(err) => {
bail!("Answer creation future got error response: {err:?}", err); bail!("Answer creation future got error response: {err:?}");
} }
}; };