webrtc sendrecv rust: Port to bindings 0.17 version

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1332>
This commit is contained in:
Olivier Crête 2021-11-09 15:04:47 -06:00 committed by GStreamer Marge Bot
parent 9abac91c96
commit 93032b2ecc
3 changed files with 102 additions and 96 deletions

View file

@ -1,5 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "anyhow"
version = "1.0.34"
@ -210,6 +212,15 @@ version = "1.0.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95752358c8f7552394baf48cd82695b345628ad3f170d607de3ca03b8dacca15"
[[package]]
name = "cfg-expr"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b412e83326147c2bb881f8b40edfbf9905b9b8abaebd0e47ca190ba62fda8f0e"
dependencies = [
"smallvec",
]
[[package]]
name = "cfg-if"
version = "0.1.10"
@ -476,32 +487,31 @@ dependencies = [
[[package]]
name = "glib"
version = "0.10.3"
version = "0.14.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c685013b7515e668f1b57a165b009d4d28cb139a8a989bbd699c10dad29d0c5"
checksum = "7c515f1e62bf151ef6635f528d05b02c11506de986e43b34a5c920ef0b3796a4"
dependencies = [
"bitflags",
"futures-channel",
"futures-core",
"futures-executor",
"futures-task",
"futures-util",
"glib-macros",
"glib-sys",
"gobject-sys",
"libc",
"once_cell",
"smallvec",
]
[[package]]
name = "glib-macros"
version = "0.10.1"
version = "0.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41486a26d1366a8032b160b59065a59fb528530a46a49f627e7048fb8c064039"
checksum = "2aad66361f66796bfc73f530c51ef123970eb895ffba991a234fcf7bea89e518"
dependencies = [
"anyhow",
"heck",
"itertools",
"proc-macro-crate",
"proc-macro-error",
"proc-macro2",
@ -511,9 +521,9 @@ dependencies = [
[[package]]
name = "glib-sys"
version = "0.10.1"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7e9b997a66e9a23d073f2b1abb4dbfc3925e0b8952f67efd8d9b6e168e4cdc1"
checksum = "1c1d60554a212445e2a858e42a0e48cece1bd57b311a19a9468f70376cf554ae"
dependencies = [
"libc",
"system-deps",
@ -534,9 +544,9 @@ dependencies = [
[[package]]
name = "gobject-sys"
version = "0.10.0"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "952133b60c318a62bf82ee75b93acc7e84028a093e06b9e27981c2b6fe68218c"
checksum = "aa92cae29759dae34ab5921d73fff5ad54b3d794ab842c117e36cafc7994c3f5"
dependencies = [
"glib-sys",
"libc",
@ -545,9 +555,9 @@ dependencies = [
[[package]]
name = "gstreamer"
version = "0.16.5"
version = "0.17.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d50f822055923f1cbede233aa5dfd4ee957cf328fb3076e330886094e11d6cf"
checksum = "c6a255f142048ba2c4a4dce39106db1965abe355d23f4b5335edea43a553faa4"
dependencies = [
"bitflags",
"cfg-if 1.0.0",
@ -555,11 +565,10 @@ dependencies = [
"futures-core",
"futures-util",
"glib",
"glib-sys",
"gobject-sys",
"gstreamer-sys",
"libc",
"muldiv",
"num-integer",
"num-rational",
"once_cell",
"paste",
@ -569,26 +578,22 @@ dependencies = [
[[package]]
name = "gstreamer-sdp"
version = "0.16.5"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36832b09858102a4def30d2eb0d599043914ef83674609d578feb80a0e6bd3f2"
checksum = "4fb915df42663a982c64d65c36e7de7963c96733ea591338c648cc124fc0b5c9"
dependencies = [
"glib",
"glib-sys",
"gobject-sys",
"gstreamer",
"gstreamer-sdp-sys",
"gstreamer-sys",
]
[[package]]
name = "gstreamer-sdp-sys"
version = "0.9.1"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "405adf64f61c427c1c3cd6d928f0ca891bde2614b7bd31c3b3670ae0da3ac79a"
checksum = "e37750f58494510976ac50e6c2ba1757e2270aca1086239bf02f576d63496201"
dependencies = [
"glib-sys",
"gobject-sys",
"gstreamer-sys",
"libc",
"system-deps",
@ -596,9 +601,9 @@ dependencies = [
[[package]]
name = "gstreamer-sys"
version = "0.9.1"
version = "0.17.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc1f154082d01af5718c5f8a8eb4f565a4ea5586ad8833a8fc2c2aa6844b601d"
checksum = "a81704feeb3e8599913bdd1e738455c2991a01ff4a1780cb62200993e454cc3e"
dependencies = [
"glib-sys",
"gobject-sys",
@ -608,30 +613,25 @@ dependencies = [
[[package]]
name = "gstreamer-webrtc"
version = "0.16.5"
version = "0.17.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b3077f2f250f493da8da786e8cfc160896963ec853219453748a88009768eeb"
checksum = "12beabc4ac72936ec1e91502633771d163b322e4cb76dc51f203eb80ce1c2f05"
dependencies = [
"glib",
"glib-sys",
"gobject-sys",
"gstreamer",
"gstreamer-sdp",
"gstreamer-sys",
"gstreamer-webrtc-sys",
"libc",
]
[[package]]
name = "gstreamer-webrtc-sys"
version = "0.9.1"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67f294eea3e1421c524e3067364ea2c750159df9395c6c93324fb8cab089bffd"
checksum = "96274f366e272fab68599907fc0f54ba91e8cd15ebdd6554ee5c7c10cd02d6ab"
dependencies = [
"glib-sys",
"gobject-sys",
"gstreamer-sdp-sys",
"gstreamer-sys",
"libc",
"system-deps",
]
@ -702,9 +702,9 @@ dependencies = [
[[package]]
name = "itertools"
version = "0.9.0"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b"
checksum = "69ddb889f9d0d08a67338271fa9b62996bc788c7796a5c18cf057420aaed5eaf"
dependencies = [
"either",
]
@ -768,9 +768,9 @@ checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525"
[[package]]
name = "muldiv"
version = "0.2.1"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0419348c027fa7be448d2ae7ea0e4e04c2334c31dc4e74ab29f00a2a7ca69204"
checksum = "b5136edda114182728ccdedb9f5eda882781f35fa6e80cc360af12a8932507f3"
[[package]]
name = "native-tls"
@ -812,9 +812,9 @@ dependencies = [
[[package]]
name = "num-rational"
version = "0.3.2"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12ac428b1cb17fce6f731001d307d351ec70a6d202fc2e60f7d4c5e42d8f4f07"
checksum = "d41702bd167c2df5520b384281bc111a4b5efcf7fbc4c9c222c815b07e0a6a6a"
dependencies = [
"autocfg",
"num-integer",
@ -968,10 +968,11 @@ checksum = "bc5c99d529f0d30937f6f4b8a86d988047327bb88d04d2c4afc356de74722131"
[[package]]
name = "proc-macro-crate"
version = "0.1.5"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d6ea3c4595b96363c13943497db34af4460fb474a95c43f4446ad341b8c9785"
checksum = "1ebace6889caf889b4d3f76becee12e90353f2b8c7d875534a71e5742f8f6f83"
dependencies = [
"thiserror",
"toml",
]
@ -1171,6 +1172,12 @@ version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
[[package]]
name = "smallvec"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ecab6c735a6bb4139c0caafd0cc3635748bbb3acf4550e8138122099251f309"
[[package]]
name = "structopt"
version = "0.3.20"
@ -1197,15 +1204,15 @@ dependencies = [
[[package]]
name = "strum"
version = "0.18.0"
version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57bd81eb48f4c437cadc685403cad539345bf703d78e63707418431cecd4522b"
checksum = "aaf86bbcfd1fa9670b7a129f64fc0c9fcbbfe4f1bc4210e9e98fe71ffc12cde2"
[[package]]
name = "strum_macros"
version = "0.18.0"
version = "0.21.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87c85aa3f8ea653bfd3ddf25f7ee357ee4d204731f6aa9ad04002306f6e2774c"
checksum = "d06aaeeee809dbc59eb4556183dd927df67db1540de5be8d3ec0b6636358a5ec"
dependencies = [
"heck",
"proc-macro2",
@ -1226,11 +1233,14 @@ dependencies = [
[[package]]
name = "system-deps"
version = "1.3.2"
version = "3.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f3ecc17269a19353b3558b313bba738b25d82993e30d62a18406a24aba4649b"
checksum = "480c269f870722b3b08d2f13053ce0c2ab722839f472863c3e2d61ff3a1c2fa6"
dependencies = [
"anyhow",
"cfg-expr",
"heck",
"itertools",
"pkg-config",
"strum",
"strum_macros",
@ -1264,18 +1274,18 @@ dependencies = [
[[package]]
name = "thiserror"
version = "1.0.22"
version = "1.0.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e9ae34b84616eedaaf1e9dd6026dbe00dcafa92aa0c8077cb69df1fcfe5e53e"
checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.22"
version = "1.0.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ba20f23e85b10754cd195504aebf6a27e2e6cbe28c17778a0c930724628dd56"
checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b"
dependencies = [
"proc-macro2",
"quote",
@ -1399,9 +1409,9 @@ checksum = "eafc1b9b2dfc6f5529177b62cf806484db55b32dc7c9658a118e11bbeb33061d"
[[package]]
name = "version-compare"
version = "0.0.10"
version = "0.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d63556a25bae6ea31b52e640d7c41d1ab27faba4ccb600013837a3d0b3994ca1"
checksum = "1c18c859eead79d8b95d09e4678566e8d70105c4e7b251f707a03df32442661b"
[[package]]
name = "version_check"

View file

@ -11,9 +11,9 @@ structopt = { version = "0.3", default-features = false }
anyhow = "1"
rand = "0.7"
async-tungstenite = { version = "0.10", features = ["async-std-runtime", "async-native-tls"] }
gst = { package = "gstreamer", version = "0.16", features = ["v1_14"] }
gst-webrtc = { package = "gstreamer-webrtc", version = "0.16" }
gst-sdp = { package = "gstreamer-sdp", version = "0.16", features = ["v1_14"] }
gst = { package = "gstreamer", version = "0.17", features = ["v1_14"] }
gst-webrtc = { package = "gstreamer-webrtc", version = "0.17" }
gst-sdp = { package = "gstreamer-sdp", version = "0.17", features = ["v1_14"] }
serde = "1"
serde_derive = "1"
serde_json = "1"

View file

@ -16,7 +16,6 @@ use async_tungstenite::tungstenite;
use tungstenite::Error as WsError;
use tungstenite::Message as WsMessage;
use gst::gst_element_error;
use gst::prelude::*;
use serde_derive::{Deserialize, Serialize};
@ -127,7 +126,7 @@ impl App {
// Get access to the webrtcbin by name
let webrtcbin = pipeline
.get_by_name("webrtcbin")
.by_name("webrtcbin")
.expect("can't find webrtcbin");
// Set some properties on webrtcbin
@ -136,7 +135,7 @@ impl App {
webrtcbin.set_property_from_str("bundle-policy", "max-bundle");
// Create a stream for handling the GStreamer message asynchronously
let bus = pipeline.get_bus().unwrap();
let bus = pipeline.bus().unwrap();
let send_gst_msg_rx = bus.stream();
// Channel for outgoing WebSocket messages from other threads
@ -158,7 +157,7 @@ impl App {
let app = upgrade_weak!(app_clone, None);
if let Err(err) = app.on_negotiation_needed() {
gst_element_error!(
gst::element_error!(
app.pipeline,
gst::LibraryError::Failed,
("Failed to negotiate: {:?}", err)
@ -175,16 +174,15 @@ impl App {
app.webrtcbin
.connect("on-ice-candidate", false, move |values| {
let _webrtc = values[0].get::<gst::Element>().expect("Invalid argument");
let mlineindex = values[1].get_some::<u32>().expect("Invalid argument");
let mlineindex = values[1].get::<u32>().expect("Invalid argument");
let candidate = values[2]
.get::<String>()
.expect("Invalid argument")
.unwrap();
.expect("Invalid argument");
let app = upgrade_weak!(app_clone, None);
if let Err(err) = app.on_ice_candidate(mlineindex, candidate) {
gst_element_error!(
gst::element_error!(
app.pipeline,
gst::LibraryError::Failed,
("Failed to send ICE candidate: {:?}", err)
@ -201,7 +199,7 @@ impl App {
let app = upgrade_weak!(app_clone);
if let Err(err) = app.on_incoming_stream(pad) {
gst_element_error!(
gst::element_error!(
app.pipeline,
gst::LibraryError::Failed,
("Failed to handle incoming stream: {:?}", err)
@ -213,7 +211,7 @@ impl App {
app.pipeline.call_async(|pipeline| {
// If this fails, post an error on the bus so we exit
if pipeline.set_state(gst::State::Playing).is_err() {
gst_element_error!(
gst::element_error!(
pipeline,
gst::LibraryError::Failed,
("Failed to set pipeline to Playing")
@ -255,14 +253,14 @@ impl App {
match message.view() {
MessageView::Error(err) => bail!(
"Error from element {}: {} ({})",
err.get_src()
.map(|s| String::from(s.get_path_string()))
err.src()
.map(|s| String::from(s.path_string()))
.unwrap_or_else(|| String::from("None")),
err.get_error(),
err.get_debug().unwrap_or_else(|| String::from("None")),
err.error(),
err.debug().unwrap_or_else(|| String::from("None")),
),
MessageView::Warning(warning) => {
println!("Warning: \"{}\"", warning.get_debug().unwrap());
println!("Warning: \"{}\"", warning.debug().unwrap());
}
_ => (),
}
@ -281,7 +279,7 @@ impl App {
let app = upgrade_weak!(app_clone);
if let Err(err) = app.on_offer_created(reply) {
gst_element_error!(
gst::element_error!(
app.pipeline,
gst::LibraryError::Failed,
("Failed to send SDP offer: {:?}", err)
@ -290,7 +288,7 @@ impl App {
});
self.webrtcbin
.emit("create-offer", &[&None::<gst::Structure>, &promise])
.emit_by_name("create-offer", &[&None::<gst::Structure>, &promise])
.unwrap();
Ok(())
@ -313,23 +311,22 @@ impl App {
};
let offer = reply
.get_value("offer")
.value("offer")
.unwrap()
.get::<gst_webrtc::WebRTCSessionDescription>()
.expect("Invalid argument")
.unwrap();
.expect("Invalid argument");
self.webrtcbin
.emit("set-local-description", &[&offer, &None::<gst::Promise>])
.emit_by_name("set-local-description", &[&offer, &None::<gst::Promise>])
.unwrap();
println!(
"sending SDP offer to peer: {}",
offer.get_sdp().as_text().unwrap()
offer.sdp().as_text().unwrap()
);
let message = serde_json::to_string(&JsonMsg::Sdp {
type_: "offer".to_string(),
sdp: offer.get_sdp().as_text().unwrap(),
sdp: offer.sdp().as_text().unwrap(),
})
.unwrap();
@ -359,23 +356,22 @@ impl App {
};
let answer = reply
.get_value("answer")
.value("answer")
.unwrap()
.get::<gst_webrtc::WebRTCSessionDescription>()
.expect("Invalid argument")
.unwrap();
.expect("Invalid argument");
self.webrtcbin
.emit("set-local-description", &[&answer, &None::<gst::Promise>])
.emit_by_name("set-local-description", &[&answer, &None::<gst::Promise>])
.unwrap();
println!(
"sending SDP answer to peer: {}",
answer.get_sdp().as_text().unwrap()
answer.sdp().as_text().unwrap()
);
let message = serde_json::to_string(&JsonMsg::Sdp {
type_: "answer".to_string(),
sdp: answer.get_sdp().as_text().unwrap(),
sdp: answer.sdp().as_text().unwrap(),
})
.unwrap();
@ -399,7 +395,7 @@ impl App {
gst_webrtc::WebRTCSessionDescription::new(gst_webrtc::WebRTCSDPType::Answer, ret);
self.webrtcbin
.emit("set-remote-description", &[&answer, &None::<gst::Promise>])
.emit_by_name("set-remote-description", &[&answer, &None::<gst::Promise>])
.unwrap();
Ok(())
@ -422,7 +418,7 @@ impl App {
app.0
.webrtcbin
.emit("set-remote-description", &[&offer, &None::<gst::Promise>])
.emit_by_name("set-remote-description", &[&offer, &None::<gst::Promise>])
.unwrap();
let app_clone = app.downgrade();
@ -430,7 +426,7 @@ impl App {
let app = upgrade_weak!(app_clone);
if let Err(err) = app.on_answer_created(reply) {
gst_element_error!(
gst::element_error!(
app.pipeline,
gst::LibraryError::Failed,
("Failed to send SDP answer: {:?}", err)
@ -440,7 +436,7 @@ impl App {
app.0
.webrtcbin
.emit("create-answer", &[&None::<gst::Structure>, &promise])
.emit_by_name("create-answer", &[&None::<gst::Structure>, &promise])
.unwrap();
});
@ -453,7 +449,7 @@ impl App {
// Handle incoming ICE candidates from the peer by passing them to webrtcbin
fn handle_ice(&self, sdp_mline_index: u32, candidate: &str) -> Result<(), anyhow::Error> {
self.webrtcbin
.emit("add-ice-candidate", &[&sdp_mline_index, &candidate])
.emit_by_name("add-ice-candidate", &[&sdp_mline_index, &candidate])
.unwrap();
Ok(())
@ -480,7 +476,7 @@ impl App {
// Whenever there's a new incoming, encoded stream from the peer create a new decodebin
fn on_incoming_stream(&self, pad: &gst::Pad) -> Result<(), anyhow::Error> {
// Early return for the source pads we're adding ourselves
if pad.get_direction() != gst::PadDirection::Src {
if pad.direction() != gst::PadDirection::Src {
return Ok(());
}
@ -490,7 +486,7 @@ impl App {
let app = upgrade_weak!(app_clone);
if let Err(err) = app.on_incoming_decodebin_stream(pad) {
gst_element_error!(
gst::element_error!(
app.pipeline,
gst::LibraryError::Failed,
("Failed to handle decoded stream: {:?}", err)
@ -501,7 +497,7 @@ impl App {
self.pipeline.add(&decodebin).unwrap();
decodebin.sync_state_with_parent().unwrap();
let sinkpad = decodebin.get_static_pad("sink").unwrap();
let sinkpad = decodebin.static_pad("sink").unwrap();
pad.link(&sinkpad).unwrap();
Ok(())
@ -510,8 +506,8 @@ impl App {
// Handle a newly decoded decodebin stream and depending on its type, create the relevant
// elements or simply ignore it
fn on_incoming_decodebin_stream(&self, pad: &gst::Pad) -> Result<(), anyhow::Error> {
let caps = pad.get_current_caps().unwrap();
let name = caps.get_structure(0).unwrap().get_name();
let caps = pad.current_caps().unwrap();
let name = caps.structure(0).unwrap().name();
let sink = if name.starts_with("video/") {
gst::parse_bin_from_description(
@ -532,7 +528,7 @@ impl App {
sink.sync_state_with_parent()
.with_context(|| format!("can't start sink for stream {:?}", caps))?;
let sinkpad = sink.get_static_pad("sink").unwrap();
let sinkpad = sink.static_pad("sink").unwrap();
pad.link(&sinkpad)
.with_context(|| format!("can't link sink for stream {:?}", caps))?;