webrtc: Update dependencies of the Rust examples

And also clean up code a bit while updating to new APIs.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2016>
This commit is contained in:
Sebastian Dröge 2022-03-24 12:05:29 +02:00
parent 1440ca2157
commit d2ecce5862
10 changed files with 718 additions and 908 deletions

View file

@ -13,15 +13,15 @@ dependencies = [
[[package]] [[package]]
name = "anyhow" name = "anyhow"
version = "1.0.45" version = "1.0.56"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee10e43ae4a853c0a3591d4e2ada1719e553be18199d9da9d4a83f5927c2f5c7" checksum = "4361135be9122e0870de935d7c439aef945b9f9ddd4199a553b5270b49c82a27"
[[package]] [[package]]
name = "async-tungstenite" name = "async-tungstenite"
version = "0.16.0" version = "0.17.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a0d06e9a20f1c0d64b6067ef6aa9fdf59e194ecde93575591fb4c78063692324" checksum = "a1b71b31561643aa8e7df3effe284fa83ab1a840e52294c5f4bd7bfd8b2becbb"
dependencies = [ dependencies = [
"futures-io", "futures-io",
"futures-util", "futures-util",
@ -45,9 +45,9 @@ dependencies = [
[[package]] [[package]]
name = "autocfg" name = "autocfg"
version = "1.0.1" version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]] [[package]]
name = "base64" name = "base64"
@ -63,9 +63,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]] [[package]]
name = "block-buffer" name = "block-buffer"
version = "0.9.0" version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" checksum = "0bf7fe51849ea569fd452f37822f606a5cabb684dc918707a0193fd4664ff324"
dependencies = [ dependencies = [
"generic-array", "generic-array",
] ]
@ -84,9 +84,9 @@ checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8"
[[package]] [[package]]
name = "cfg-expr" name = "cfg-expr"
version = "0.8.1" version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b412e83326147c2bb881f8b40edfbf9905b9b8abaebd0e47ca190ba62fda8f0e" checksum = "5e068cb2806bbc15b439846dc16c5f89f8599f2c3e4d73d4449d38f9b2f0b6c5"
dependencies = [ dependencies = [
"smallvec", "smallvec",
] ]
@ -99,9 +99,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]] [[package]]
name = "clap" name = "clap"
version = "2.33.3" version = "2.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"textwrap", "textwrap",
@ -110,27 +110,32 @@ dependencies = [
[[package]] [[package]]
name = "cpufeatures" name = "cpufeatures"
version = "0.2.1" version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95059428f66df56b63431fdb4e1947ed2190586af5c5a8a8b71122bdf5a7f469" checksum = "59a6001667ab124aebae2a495118e11d30984c3a653e99d86d58971708cf5e4b"
dependencies = [ dependencies = [
"libc", "libc",
] ]
[[package]] [[package]]
name = "digest" name = "crypto-common"
version = "0.9.0" version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" checksum = "57952ca27b5e3606ff4dd79b0020231aaf9d6aa76dc05fd30137538c50bd3ce8"
dependencies = [ dependencies = [
"generic-array", "generic-array",
"typenum",
] ]
[[package]] [[package]]
name = "either" name = "digest"
version = "1.6.1" version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506"
dependencies = [
"block-buffer",
"crypto-common",
]
[[package]] [[package]]
name = "env_logger" name = "env_logger"
@ -163,9 +168,9 @@ dependencies = [
[[package]] [[package]]
name = "futures" name = "futures"
version = "0.3.17" version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a12aa0eb539080d55c3f2d45a67c3b58b6b0773c1a3ca2dfec66d58c97fd66ca" checksum = "f73fe65f54d1e12b726f517d3e2135ca3125a437b6d998caf1962961f7172d9e"
dependencies = [ dependencies = [
"futures-channel", "futures-channel",
"futures-core", "futures-core",
@ -178,9 +183,9 @@ dependencies = [
[[package]] [[package]]
name = "futures-channel" name = "futures-channel"
version = "0.3.17" version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5da6ba8c3bb3c165d3c7319fc1cc8304facf1fb8db99c5de877183c08a273888" checksum = "c3083ce4b914124575708913bca19bfe887522d6e2e6d0952943f5eac4a74010"
dependencies = [ dependencies = [
"futures-core", "futures-core",
"futures-sink", "futures-sink",
@ -188,15 +193,15 @@ dependencies = [
[[package]] [[package]]
name = "futures-core" name = "futures-core"
version = "0.3.17" version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88d1c26957f23603395cd326b0ffe64124b818f4449552f960d815cfba83a53d" checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3"
[[package]] [[package]]
name = "futures-executor" name = "futures-executor"
version = "0.3.17" version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "45025be030969d763025784f7f355043dc6bc74093e4ecc5000ca4dc50d8745c" checksum = "9420b90cfa29e327d0429f19be13e7ddb68fa1cccb09d65e5706b8c7a749b8a6"
dependencies = [ dependencies = [
"futures-core", "futures-core",
"futures-task", "futures-task",
@ -205,18 +210,16 @@ dependencies = [
[[package]] [[package]]
name = "futures-io" name = "futures-io"
version = "0.3.17" version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "522de2a0fe3e380f1bc577ba0474108faf3f6b18321dbf60b3b9c39a75073377" checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b"
[[package]] [[package]]
name = "futures-macro" name = "futures-macro"
version = "0.3.17" version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18e4a4b95cea4b4ccbcf1c5675ca7c4ee4e9e75eb79944d07defde18068f79bb" checksum = "33c1e13800337f4d4d7a316bf45a567dbcb6ffe087f16424852d97e97a91f512"
dependencies = [ dependencies = [
"autocfg",
"proc-macro-hack",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn",
@ -224,23 +227,22 @@ dependencies = [
[[package]] [[package]]
name = "futures-sink" name = "futures-sink"
version = "0.3.17" version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36ea153c13024fe480590b3e3d4cad89a0cfacecc24577b68f86c6ced9c2bc11" checksum = "21163e139fa306126e6eedaf49ecdb4588f939600f0b1e770f4205ee4b7fa868"
[[package]] [[package]]
name = "futures-task" name = "futures-task"
version = "0.3.17" version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d3d00f4eddb73e498a54394f228cd55853bdf059259e8e7bc6e69d408892e99" checksum = "57c66a976bf5909d801bbef33416c41372779507e7a6b3a5e25e4749c58f776a"
[[package]] [[package]]
name = "futures-util" name = "futures-util"
version = "0.3.17" version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36568465210a3a6ee45e1f165136d68671471a501e632e9a98d96872222b5481" checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a"
dependencies = [ dependencies = [
"autocfg",
"futures-channel", "futures-channel",
"futures-core", "futures-core",
"futures-io", "futures-io",
@ -250,16 +252,14 @@ dependencies = [
"memchr", "memchr",
"pin-project-lite", "pin-project-lite",
"pin-utils", "pin-utils",
"proc-macro-hack",
"proc-macro-nested",
"slab", "slab",
] ]
[[package]] [[package]]
name = "generic-array" name = "generic-array"
version = "0.14.4" version = "0.14.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" checksum = "fd48d33ec7f05fbfa152300fdad764757cbded343c1aa1cff2fbaf4134851803"
dependencies = [ dependencies = [
"typenum", "typenum",
"version_check", "version_check",
@ -267,9 +267,9 @@ dependencies = [
[[package]] [[package]]
name = "getrandom" name = "getrandom"
version = "0.2.3" version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" checksum = "d39cd93900197114fa1fcb7ae84ca742095eed9442088988ae74fa744e930e77"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"libc", "libc",
@ -278,9 +278,9 @@ dependencies = [
[[package]] [[package]]
name = "gio" name = "gio"
version = "0.14.8" version = "0.15.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "711c3632b3ebd095578a9c091418d10fed492da9443f58ebc8f45efbeb215cb0" checksum = "76cd21a7a674ea811749661012512b0ba5237ba404ccbcab2850db5537549b64"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"futures-channel", "futures-channel",
@ -295,9 +295,9 @@ dependencies = [
[[package]] [[package]]
name = "gio-sys" name = "gio-sys"
version = "0.14.0" version = "0.15.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0a41df66e57fcc287c4bcf74fc26b884f31901ea9792ec75607289b456f48fa" checksum = "32157a475271e2c4a023382e9cab31c4584ee30a97da41d3c4e9fdd605abcf8d"
dependencies = [ dependencies = [
"glib-sys", "glib-sys",
"gobject-sys", "gobject-sys",
@ -308,9 +308,9 @@ dependencies = [
[[package]] [[package]]
name = "glib" name = "glib"
version = "0.14.8" version = "0.15.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c515f1e62bf151ef6635f528d05b02c11506de986e43b34a5c920ef0b3796a4" checksum = "a826fad715b57834920839d7a594c3b5e416358c7d790bdaba847a40d7c1d96d"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"futures-channel", "futures-channel",
@ -323,16 +323,17 @@ dependencies = [
"libc", "libc",
"once_cell", "once_cell",
"smallvec", "smallvec",
"thiserror",
] ]
[[package]] [[package]]
name = "glib-macros" name = "glib-macros"
version = "0.14.1" version = "0.15.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2aad66361f66796bfc73f530c51ef123970eb895ffba991a234fcf7bea89e518" checksum = "dac4d47c544af67747652ab1865ace0ffa1155709723ac4f32e97587dd4735b2"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"heck", "heck 0.4.0",
"proc-macro-crate", "proc-macro-crate",
"proc-macro-error", "proc-macro-error",
"proc-macro2", "proc-macro2",
@ -342,9 +343,9 @@ dependencies = [
[[package]] [[package]]
name = "glib-sys" name = "glib-sys"
version = "0.14.0" version = "0.15.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c1d60554a212445e2a858e42a0e48cece1bd57b311a19a9468f70376cf554ae" checksum = "ef4b192f8e65e9cf76cbf4ea71fa8e3be4a0e18ffe3d68b8da6836974cc5bad4"
dependencies = [ dependencies = [
"libc", "libc",
"system-deps", "system-deps",
@ -352,9 +353,9 @@ dependencies = [
[[package]] [[package]]
name = "gobject-sys" name = "gobject-sys"
version = "0.14.0" version = "0.15.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa92cae29759dae34ab5921d73fff5ad54b3d794ab842c117e36cafc7994c3f5" checksum = "0d57ce44246becd17153bd035ab4d32cfee096a657fc01f2231c9278378d1e0a"
dependencies = [ dependencies = [
"glib-sys", "glib-sys",
"libc", "libc",
@ -363,9 +364,9 @@ dependencies = [
[[package]] [[package]]
name = "gstreamer" name = "gstreamer"
version = "0.17.4" version = "0.18.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6a255f142048ba2c4a4dce39106db1965abe355d23f4b5335edea43a553faa4" checksum = "5c1545fac08d7a28f8707101298cbf99d1bc72529698ff2d1fec87cc30a3fb9a"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"cfg-if", "cfg-if",
@ -379,6 +380,7 @@ dependencies = [
"num-integer", "num-integer",
"num-rational", "num-rational",
"once_cell", "once_cell",
"option-operations",
"paste", "paste",
"pretty-hex", "pretty-hex",
"thiserror", "thiserror",
@ -386,9 +388,9 @@ dependencies = [
[[package]] [[package]]
name = "gstreamer-sdp" name = "gstreamer-sdp"
version = "0.17.0" version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fb915df42663a982c64d65c36e7de7963c96733ea591338c648cc124fc0b5c9" checksum = "c8a0db444f6281489f03c7b23bc379dbe0e3cffa55c839c192976190bb298c78"
dependencies = [ dependencies = [
"glib", "glib",
"gstreamer", "gstreamer",
@ -397,9 +399,9 @@ dependencies = [
[[package]] [[package]]
name = "gstreamer-sdp-sys" name = "gstreamer-sdp-sys"
version = "0.17.0" version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e37750f58494510976ac50e6c2ba1757e2270aca1086239bf02f576d63496201" checksum = "67ed8f02e2a2c6b50d27987115401418c4172b14959d562757737a4e7b280d6c"
dependencies = [ dependencies = [
"glib-sys", "glib-sys",
"gstreamer-sys", "gstreamer-sys",
@ -409,9 +411,9 @@ dependencies = [
[[package]] [[package]]
name = "gstreamer-sys" name = "gstreamer-sys"
version = "0.17.3" version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a81704feeb3e8599913bdd1e738455c2991a01ff4a1780cb62200993e454cc3e" checksum = "e3517a65d3c2e6f8905b456eba5d53bda158d664863aef960b44f651cb7d33e2"
dependencies = [ dependencies = [
"glib-sys", "glib-sys",
"gobject-sys", "gobject-sys",
@ -421,9 +423,9 @@ dependencies = [
[[package]] [[package]]
name = "gstreamer-webrtc" name = "gstreamer-webrtc"
version = "0.17.2" version = "0.18.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12beabc4ac72936ec1e91502633771d163b322e4cb76dc51f203eb80ce1c2f05" checksum = "66be30e56113bcdf5acc151bd098fae4916a41f57dc99b570e14e4112111b723"
dependencies = [ dependencies = [
"glib", "glib",
"gstreamer", "gstreamer",
@ -434,9 +436,9 @@ dependencies = [
[[package]] [[package]]
name = "gstreamer-webrtc-sys" name = "gstreamer-webrtc-sys"
version = "0.17.0" version = "0.18.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96274f366e272fab68599907fc0f54ba91e8cd15ebdd6554ee5c7c10cd02d6ab" checksum = "1ea5f3bab2859f0b279edab6ea2620700259fd1bf91cf82185fe10a0fc5e96cc"
dependencies = [ dependencies = [
"glib-sys", "glib-sys",
"gstreamer-sdp-sys", "gstreamer-sdp-sys",
@ -453,6 +455,12 @@ dependencies = [
"unicode-segmentation", "unicode-segmentation",
] ]
[[package]]
name = "heck"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"
[[package]] [[package]]
name = "hermit-abi" name = "hermit-abi"
version = "0.1.19" version = "0.1.19"
@ -464,9 +472,9 @@ dependencies = [
[[package]] [[package]]
name = "http" name = "http"
version = "0.2.5" version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1323096b05d41827dadeaee54c9981958c0f94e670bc94ed80037d1a7b8b186b" checksum = "31f4c6746584866f0feabcc69893c5b51beef3831656a968ed7ae254cdc4fd03"
dependencies = [ dependencies = [
"bytes", "bytes",
"fnv", "fnv",
@ -475,9 +483,9 @@ dependencies = [
[[package]] [[package]]
name = "httparse" name = "httparse"
version = "1.5.1" version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acd94fdbe1d4ff688b67b04eee2e17bd50995534a61539e45adfefb45e5e5503" checksum = "9100414882e15fb7feccb4897e5f0ff0ff1ca7d1a86a23208ada4d7a18e6c6c4"
[[package]] [[package]]
name = "humantime" name = "humantime"
@ -496,20 +504,11 @@ dependencies = [
"unicode-normalization", "unicode-normalization",
] ]
[[package]]
name = "itertools"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69ddb889f9d0d08a67338271fa9b62996bc788c7796a5c18cf057420aaed5eaf"
dependencies = [
"either",
]
[[package]] [[package]]
name = "itoa" name = "itoa"
version = "0.4.8" version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35"
[[package]] [[package]]
name = "janus-video-room" name = "janus-video-room"
@ -542,15 +541,15 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.107" version = "0.2.121"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbe5e23404da5b4f555ef85ebed98fb4083e55a00c317800bc2a50ede9f3d219" checksum = "efaa7b300f3b5fe8eb6bf21ce3895e1751d9665086af2d64b42f19701015ff4f"
[[package]] [[package]]
name = "log" name = "log"
version = "0.4.14" version = "0.4.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" checksum = "6389c490849ff5bc16be905ae24bc913a9c8892e19b2341dbc175e14c341c2b8"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
] ]
@ -605,15 +604,18 @@ dependencies = [
[[package]] [[package]]
name = "once_cell" name = "once_cell"
version = "1.8.0" version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9"
[[package]] [[package]]
name = "opaque-debug" name = "option-operations"
version = "0.3.0" version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" checksum = "95d6113415f41b268f1195907427519769e40ee6f28cbb053795098a2c16f447"
dependencies = [
"paste",
]
[[package]] [[package]]
name = "paste" name = "paste"
@ -629,9 +631,9 @@ checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
[[package]] [[package]]
name = "pin-project-lite" name = "pin-project-lite"
version = "0.2.7" version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443" checksum = "e280fbe77cc62c91527259e9442153f4688736748d24660126286329742b4c6c"
[[package]] [[package]]
name = "pin-utils" name = "pin-utils"
@ -641,15 +643,15 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]] [[package]]
name = "pkg-config" name = "pkg-config"
version = "0.3.22" version = "0.3.24"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12295df4f294471248581bc09bef3c38a5e46f1e36d6a37353621a0c6c357e1f" checksum = "58893f751c9b0412871a09abd62ecd2a00298c6c83befa223ef98c52aef40cbe"
[[package]] [[package]]
name = "ppv-lite86" name = "ppv-lite86"
version = "0.2.15" version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed0cfbc8191465bed66e1718596ee0b0b35d5ee1f41c5df2189d0fe8bde535ba" checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
[[package]] [[package]]
name = "pretty-hex" name = "pretty-hex"
@ -659,9 +661,9 @@ checksum = "bc5c99d529f0d30937f6f4b8a86d988047327bb88d04d2c4afc356de74722131"
[[package]] [[package]]
name = "proc-macro-crate" name = "proc-macro-crate"
version = "1.1.0" version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ebace6889caf889b4d3f76becee12e90353f2b8c7d875534a71e5742f8f6f83" checksum = "e17d47ce914bf4de440332250b0edd23ce48c005f59fab39d3335866b114f11a"
dependencies = [ dependencies = [
"thiserror", "thiserror",
"toml", "toml",
@ -691,46 +693,33 @@ dependencies = [
"version_check", "version_check",
] ]
[[package]]
name = "proc-macro-hack"
version = "0.5.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5"
[[package]]
name = "proc-macro-nested"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086"
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.32" version = "1.0.36"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba508cc11742c0dc5c1659771673afbab7a0efab23aa17e854cbab0837ed0b43" checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029"
dependencies = [ dependencies = [
"unicode-xid", "unicode-xid",
] ]
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.10" version = "1.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05" checksum = "b4af2ec4714533fcdf07e886f17025ace8b997b9ce51204ee69b6da831c3da57"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
] ]
[[package]] [[package]]
name = "rand" name = "rand"
version = "0.8.4" version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [ dependencies = [
"libc", "libc",
"rand_chacha", "rand_chacha",
"rand_core", "rand_core",
"rand_hc",
] ]
[[package]] [[package]]
@ -752,20 +741,11 @@ dependencies = [
"getrandom", "getrandom",
] ]
[[package]]
name = "rand_hc"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7"
dependencies = [
"rand_core",
]
[[package]] [[package]]
name = "regex" name = "regex"
version = "1.5.4" version = "1.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" checksum = "1a11647b6b25ff05a515cb92c365cec08801e83423a235b51e231e1808747286"
dependencies = [ dependencies = [
"aho-corasick", "aho-corasick",
"memchr", "memchr",
@ -780,21 +760,21 @@ checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
[[package]] [[package]]
name = "ryu" name = "ryu"
version = "1.0.5" version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f"
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.130" version = "1.0.136"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913" checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789"
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.130" version = "1.0.136"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b" checksum = "08597e7152fcd306f41838ed3e37be9eaeed2b61c42e2117266a554fab4662f9"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -803,9 +783,9 @@ dependencies = [
[[package]] [[package]]
name = "serde_json" name = "serde_json"
version = "1.0.69" version = "1.0.79"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e466864e431129c7e0d3476b92f20458e5879919a0596c6472738d9fa2d342f8" checksum = "8e8d9fa5c3b304765ce1fd9c4c8a3de2c8db365a5b91be52f186efc675681d95"
dependencies = [ dependencies = [
"itoa", "itoa",
"ryu", "ryu",
@ -814,15 +794,13 @@ dependencies = [
[[package]] [[package]]
name = "sha-1" name = "sha-1"
version = "0.9.8" version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99cd6713db3cf16b6c84e06321e049a9b9f699826e16096d23bbcc44d15d51a6" checksum = "028f48d513f9678cda28f6e4064755b3fbb2af6acd672f2c209b62323f7aea0f"
dependencies = [ dependencies = [
"block-buffer",
"cfg-if", "cfg-if",
"cpufeatures", "cpufeatures",
"digest", "digest",
"opaque-debug",
] ]
[[package]] [[package]]
@ -833,15 +811,15 @@ checksum = "9def91fd1e018fe007022791f865d0ccc9b3a0d5001e01aabb8b40e46000afb5"
[[package]] [[package]]
name = "smallvec" name = "smallvec"
version = "1.7.0" version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ecab6c735a6bb4139c0caafd0cc3635748bbb3acf4550e8138122099251f309" checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83"
[[package]] [[package]]
name = "structopt" name = "structopt"
version = "0.3.25" version = "0.3.26"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40b9788f4202aa75c240ecc9c15c65185e6a39ccdeb0fd5d008b98825464c87c" checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10"
dependencies = [ dependencies = [
"clap", "clap",
"lazy_static", "lazy_static",
@ -854,36 +832,18 @@ version = "0.4.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0" checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0"
dependencies = [ dependencies = [
"heck", "heck 0.3.3",
"proc-macro-error", "proc-macro-error",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn",
] ]
[[package]]
name = "strum"
version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aaf86bbcfd1fa9670b7a129f64fc0c9fcbbfe4f1bc4210e9e98fe71ffc12cde2"
[[package]]
name = "strum_macros"
version = "0.21.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d06aaeeee809dbc59eb4556183dd927df67db1540de5be8d3ec0b6636358a5ec"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.81" version = "1.0.89"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2afee18b8beb5a596ecb4a2dce128c719b4ba399d34126b9e4396e3f9860966" checksum = "ea297be220d52398dcc07ce15a209fce436d361735ac1db700cab3b6cdfb9f54"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -892,27 +852,22 @@ dependencies = [
[[package]] [[package]]
name = "system-deps" name = "system-deps"
version = "3.2.0" version = "6.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "480c269f870722b3b08d2f13053ce0c2ab722839f472863c3e2d61ff3a1c2fa6" checksum = "a1a45a1c4c9015217e12347f2a411b57ce2c4fc543913b14b6fe40483328e709"
dependencies = [ dependencies = [
"anyhow",
"cfg-expr", "cfg-expr",
"heck", "heck 0.4.0",
"itertools",
"pkg-config", "pkg-config",
"strum",
"strum_macros",
"thiserror",
"toml", "toml",
"version-compare", "version-compare",
] ]
[[package]] [[package]]
name = "termcolor" name = "termcolor"
version = "1.1.2" version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
dependencies = [ dependencies = [
"winapi-util", "winapi-util",
] ]
@ -972,9 +927,9 @@ dependencies = [
[[package]] [[package]]
name = "tungstenite" name = "tungstenite"
version = "0.16.0" version = "0.17.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ad3713a14ae247f22a728a0456a545df14acf3867f905adff84be99e23b3ad1" checksum = "d96a2dea40e7570482f28eb57afbe42d97551905da6a9400acc5c328d24004f5"
dependencies = [ dependencies = [
"base64", "base64",
"byteorder", "byteorder",
@ -991,9 +946,9 @@ dependencies = [
[[package]] [[package]]
name = "typenum" name = "typenum"
version = "1.14.0" version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b63708a265f51345575b27fe43f9500ad611579e764c79edbc2037b1121959ec" checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987"
[[package]] [[package]]
name = "unicode-bidi" name = "unicode-bidi"
@ -1012,9 +967,9 @@ dependencies = [
[[package]] [[package]]
name = "unicode-segmentation" name = "unicode-segmentation"
version = "1.8.0" version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99"
[[package]] [[package]]
name = "unicode-width" name = "unicode-width"
@ -1048,15 +1003,15 @@ checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
[[package]] [[package]]
name = "version-compare" name = "version-compare"
version = "0.0.11" version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c18c859eead79d8b95d09e4678566e8d70105c4e7b251f707a03df32442661b" checksum = "fe88247b92c1df6b6de80ddc290f3976dbdf2f5f5d3fd049a9fb598c6dd5ca73"
[[package]] [[package]]
name = "version_check" name = "version_check"
version = "0.9.3" version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]] [[package]]
name = "wasi" name = "wasi"

View file

@ -11,15 +11,15 @@ structopt = { version = "0.3", default-features = false }
anyhow = "1" anyhow = "1"
url = "2" url = "2"
rand = "0.8" rand = "0.8"
async-tungstenite = { version = "0.16", features = ["gio-runtime"] } async-tungstenite = { version = "0.17", features = ["gio-runtime"] }
gst = { package = "gstreamer", version = "0.17", features = ["v1_14"] } gst = { package = "gstreamer", version = "0.18", features = ["v1_14"] }
gst-webrtc = { package = "gstreamer-webrtc", version = "0.17" } gst-webrtc = { package = "gstreamer-webrtc", version = "0.18" }
gst-sdp = { package = "gstreamer-sdp", version = "0.17", features = ["v1_14"] } gst-sdp = { package = "gstreamer-sdp", version = "0.18", features = ["v1_14"] }
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.14" glib = "0.15"
gio = "0.14" gio = "0.15"
log = "0.4.8" log = "0.4.8"
env_logger = "0.9" env_logger = "0.9"

View file

@ -27,6 +27,7 @@ use {
futures::stream::{Stream, StreamExt}, futures::stream::{Stream, StreamExt},
gst::prelude::*, gst::prelude::*,
http::Request, http::Request,
log::{debug, error, info, trace},
rand::prelude::*, rand::prelude::*,
serde_derive::{Deserialize, Serialize}, serde_derive::{Deserialize, Serialize},
serde_json::json, serde_json::json,
@ -153,10 +154,10 @@ struct JsonReply {
fn transaction_id() -> String { fn transaction_id() -> String {
thread_rng() thread_rng()
.sample_iter(&rand::distributions::Alphanumeric) .sample_iter(&rand::distributions::Alphanumeric)
.map(char::from) .map(char::from)
.take(30) .take(30)
.collect() .collect()
} }
// Strong reference to the state of one peer // Strong reference to the state of one peer
@ -225,7 +226,7 @@ impl Peer {
}); });
self.webrtcbin self.webrtcbin
.emit_by_name("create-offer", &[&None::<gst::Structure>, &promise])?; .emit_by_name::<()>("create-offer", &[&None::<gst::Structure>, &promise]);
Ok(()) Ok(())
} }
@ -237,7 +238,7 @@ impl Peer {
.get::<gst_webrtc::WebRTCSessionDescription>("offer") .get::<gst_webrtc::WebRTCSessionDescription>("offer")
.expect("Invalid argument"); .expect("Invalid argument");
self.webrtcbin self.webrtcbin
.emit_by_name("set-local-description", &[&offer, &None::<gst::Promise>])?; .emit_by_name::<()>("set-local-description", &[&offer, &None::<gst::Promise>]);
info!("sending SDP offer to peer: {:?}", offer.sdp().as_text()); info!("sending SDP offer to peer: {:?}", offer.sdp().as_text());
@ -266,7 +267,7 @@ impl Peer {
.lock() .lock()
.expect("Invalid message sender") .expect("Invalid message sender")
.unbounded_send(msg) .unbounded_send(msg)
.with_context(|| "Failed to send SDP offer".to_string())?; .context("Failed to send SDP offer")?;
Ok(()) Ok(())
} }
@ -278,12 +279,9 @@ impl Peer {
.get::<gst_webrtc::WebRTCSessionDescription>("answer") .get::<gst_webrtc::WebRTCSessionDescription>("answer")
.expect("Invalid answer"); .expect("Invalid answer");
self.webrtcbin self.webrtcbin
.emit_by_name("set-local-description", &[&answer, &None::<gst::Promise>])?; .emit_by_name::<()>("set-local-description", &[&answer, &None::<gst::Promise>]);
info!( info!("sending SDP answer to peer: {:?}", answer.sdp().as_text());
"sending SDP answer to peer: {:?}",
answer.sdp().as_text()
);
Ok(()) Ok(())
} }
@ -299,7 +297,7 @@ impl Peer {
gst_webrtc::WebRTCSessionDescription::new(gst_webrtc::WebRTCSDPType::Answer, ret); gst_webrtc::WebRTCSessionDescription::new(gst_webrtc::WebRTCSDPType::Answer, ret);
self.webrtcbin self.webrtcbin
.emit_by_name("set-remote-description", &[&answer, &None::<gst::Promise>])?; .emit_by_name::<()>("set-remote-description", &[&answer, &None::<gst::Promise>]);
Ok(()) Ok(())
} else if type_ == "offer" { } else if type_ == "offer" {
@ -321,8 +319,7 @@ impl Peer {
peer.0 peer.0
.webrtcbin .webrtcbin
.emit_by_name("set-remote-description", &[&offer, &None::<gst::Promise>]) .emit_by_name::<()>("set-remote-description", &[&offer, &None::<gst::Promise>]);
.expect("Unable to set remote description");
let peer_clone = peer.downgrade(); let peer_clone = peer.downgrade();
let promise = gst::Promise::with_change_func(move |reply| { let promise = gst::Promise::with_change_func(move |reply| {
@ -340,8 +337,7 @@ impl Peer {
peer.0 peer.0
.webrtcbin .webrtcbin
.emit_by_name("create-answer", &[&None::<gst::Structure>, &promise]) .emit_by_name::<()>("create-answer", &[&None::<gst::Structure>, &promise]);
.expect("Unable to create answer");
}); });
Ok(()) Ok(())
@ -357,14 +353,14 @@ impl Peer {
sdp_mline_index, candidate sdp_mline_index, candidate
); );
self.webrtcbin self.webrtcbin
.emit_by_name("add-ice-candidate", &[&sdp_mline_index, &candidate])?; .emit_by_name::<()>("add-ice-candidate", &[&sdp_mline_index, &candidate]);
Ok(()) Ok(())
} }
// Asynchronously send ICE candidates to the peer via the WebSocket connection as a JSON // Asynchronously send ICE candidates to the peer via the WebSocket connection as a JSON
// message // message
fn on_ice_candidate(&self, mlineindex: u32, candidate: String) -> Result<(), anyhow::Error> { fn on_ice_candidate(&self, mlineindex: u32, candidate: &str) -> Result<(), anyhow::Error> {
let transaction = transaction_id(); let transaction = transaction_id();
info!("Sending ICE {} {}", mlineindex, &candidate); info!("Sending ICE {} {}", mlineindex, &candidate);
let msg = WsMessage::Text( let msg = WsMessage::Text(
@ -384,7 +380,7 @@ impl Peer {
.lock() .lock()
.expect("Invalid message sender") .expect("Invalid message sender")
.unbounded_send(msg) .unbounded_send(msg)
.with_context(|| "Failed to send ICE candidate".to_string())?; .context("Failed to send ICE candidate")?;
Ok(()) Ok(())
} }
@ -479,9 +475,7 @@ impl JanusGateway {
); );
ws.send(msg).await?; ws.send(msg).await?;
let webrtcbin = pipeline let webrtcbin = pipeline.by_name("webrtcbin").expect("can't find webrtcbin");
.by_name("webrtcbin")
.expect("can't find webrtcbin");
let webrtc_codec = &args.webrtc_video_codec; let webrtc_codec = &args.webrtc_video_codec;
let bin_description = &format!( let bin_description = &format!(
@ -516,18 +510,15 @@ impl JanusGateway {
let vsink = encode_bin let vsink = encode_bin
.by_name("webrtc-vsink") .by_name("webrtc-vsink")
.expect("No webrtc-vsink found"); .expect("No webrtc-vsink found");
let srcpad = vsink let srcpad = vsink.static_pad("src").expect("Element without src pad");
.static_pad("src")
.expect("Element without src pad");
if let Ok(webrtc_ghost_pad) = gst::GhostPad::with_target(Some("webrtc_video_src"), &srcpad) if let Ok(webrtc_ghost_pad) = gst::GhostPad::with_target(Some("webrtc_video_src"), &srcpad)
{ {
encode_bin.add_pad(&webrtc_ghost_pad)?; encode_bin.add_pad(&webrtc_ghost_pad)?;
webrtc_ghost_pad.link(&sinkpad2)?; webrtc_ghost_pad.link(&sinkpad2)?;
} }
if let Some(transceiver) = webrtcbin.emit_by_name("get-transceiver", &[&0.to_value()]).unwrap().and_then(|val| val.get::<glib::Object>().ok()) { let transceiver = webrtcbin.emit_by_name::<glib::Object>("get-transceiver", &[&0i32]);
transceiver.set_property("do-nack", &false.to_value())?; transceiver.set_property("do-nack", false);
}
let (send_ws_msg_tx, send_ws_msg_rx) = mpsc::unbounded::<WsMessage>(); let (send_ws_msg_tx, send_ws_msg_rx) = mpsc::unbounded::<WsMessage>();
@ -545,9 +536,11 @@ impl JanusGateway {
// Connect to on-negotiation-needed to handle sending an Offer // Connect to on-negotiation-needed to handle sending an Offer
let peer_clone = peer.downgrade(); let peer_clone = peer.downgrade();
peer.webrtcbin peer.webrtcbin.connect_closure(
.connect("on-negotiation-needed", false, move |_| { "on-negotiation-needed",
let peer = upgrade_weak!(peer_clone, None); false,
glib::closure!(move |_webrtcbin: &gst::Element| {
let peer = upgrade_weak!(peer_clone);
if let Err(err) = peer.on_negotiation_needed() { if let Err(err) = peer.on_negotiation_needed() {
gst::element_error!( gst::element_error!(
peer.bin, peer.bin,
@ -555,32 +548,27 @@ impl JanusGateway {
("Failed to negotiate: {:?}", err) ("Failed to negotiate: {:?}", err)
); );
} }
}),
None );
})?;
// Whenever there is a new ICE candidate, send it to the peer // Whenever there is a new ICE candidate, send it to the peer
let peer_clone = peer.downgrade(); let peer_clone = peer.downgrade();
peer.webrtcbin peer.webrtcbin.connect_closure(
.connect("on-ice-candidate", false, move |values| { "on-ice-candidate",
let mlineindex = values[1] false,
.get::<u32>() glib::closure!(
.expect("Invalid type"); move |_webrtcbin: &gst::Element, mlineindex: u32, candidate: &str| {
let candidate = values[2] let peer = upgrade_weak!(peer_clone);
.get::<String>() if let Err(err) = peer.on_ice_candidate(mlineindex, candidate) {
.expect("Invalid type"); gst::element_error!(
peer.bin,
let peer = upgrade_weak!(peer_clone, None); gst::LibraryError::Failed,
if let Err(err) = peer.on_ice_candidate(mlineindex, candidate) { ("Failed to send ICE candidate: {:?}", err)
gst::element_error!( );
peer.bin, }
gst::LibraryError::Failed,
("Failed to send ICE candidate: {:?}", err)
);
} }
),
None );
})?;
// Split the websocket into the Sink and Stream // Split the websocket into the Sink and Stream
let (ws_sink, ws_stream) = ws.split(); let (ws_sink, ws_stream) = ws.split();
@ -628,6 +616,7 @@ impl JanusGateway {
} }
None None
}, },
WsMessage::Frame(_) => unreachable!(),
} }
}, },
// Handle WebSocket messages we created asynchronously // Handle WebSocket messages we created asynchronously

View file

@ -18,15 +18,10 @@
// Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, // Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
// Boston, MA 02110-1301, USA. // Boston, MA 02110-1301, USA.
#![recursion_limit = "256"]
use anyhow::bail; use anyhow::bail;
use gst::prelude::*; use gst::prelude::*;
use std::sync::{Arc, Weak}; use std::sync::{Arc, Weak};
#[macro_use]
extern crate log;
mod janus; mod janus;
// Strong reference to our application state // Strong reference to our application state
@ -67,9 +62,8 @@ impl App {
fn new() -> Result<Self, anyhow::Error> { fn new() -> Result<Self, anyhow::Error> {
let pipeline = gst::parse_launch( let pipeline = gst::parse_launch(
&"webrtcbin name=webrtcbin stun-server=stun://stun.l.google.com:19302 \ "webrtcbin name=webrtcbin stun-server=stun://stun.l.google.com:19302 \
videotestsrc pattern=ball ! videoconvert ! queue name=vqueue" videotestsrc pattern=ball ! videoconvert ! queue name=vqueue",
.to_string(),
)?; )?;
let pipeline = pipeline let pipeline = pipeline

File diff suppressed because it is too large Load diff

View file

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

View file

@ -19,6 +19,7 @@ use async_tungstenite::tungstenite;
use tungstenite::Error as WsError; use tungstenite::Error as WsError;
use tungstenite::Message as WsMessage; use tungstenite::Message as WsMessage;
use gst::glib;
use gst::prelude::*; use gst::prelude::*;
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
@ -79,7 +80,6 @@ struct AppWeak(Weak<AppInner>);
// Actual application state // Actual application state
#[derive(Debug)] #[derive(Debug)]
struct AppInner { struct AppInner {
args: Args,
pipeline: gst::Pipeline, pipeline: gst::Pipeline,
video_tee: gst::Element, video_tee: gst::Element,
audio_tee: gst::Element, audio_tee: gst::Element,
@ -145,7 +145,6 @@ impl App {
} }
fn new( fn new(
args: Args,
initial_peers: &[&str], initial_peers: &[&str],
) -> Result< ) -> Result<
( (
@ -176,12 +175,8 @@ impl App {
.expect("not a pipeline"); .expect("not a pipeline");
// Get access to the tees and mixers by name // Get access to the tees and mixers by name
let video_tee = pipeline let video_tee = pipeline.by_name("video-tee").expect("can't find video-tee");
.by_name("video-tee") let audio_tee = pipeline.by_name("audio-tee").expect("can't find audio-tee");
.expect("can't find video-tee");
let audio_tee = pipeline
.by_name("audio-tee")
.expect("can't find audio-tee");
let video_mixer = pipeline let video_mixer = pipeline
.by_name("video-mixer") .by_name("video-mixer")
@ -205,7 +200,6 @@ impl App {
}); });
let app = App(Arc::new(AppInner { let app = App(Arc::new(AppInner {
args,
pipeline, pipeline,
video_tee, video_tee,
audio_tee, audio_tee,
@ -240,9 +234,9 @@ impl App {
bail!("Got error message: {}", msg); bail!("Got error message: {}", msg);
} }
if msg.starts_with("ROOM_PEER_MSG ") { if let Some(msg) = msg.strip_prefix("ROOM_PEER_MSG ") {
// Parse message and pass to the peer if we know about it let mut split = msg.splitn(2, ' ');
let mut split = msg["ROOM_PEER_MSG ".len()..].splitn(2, ' ');
let peer_id = split let peer_id = split
.next() .next()
.and_then(|s| str::parse::<u32>(s).ok()) .and_then(|s| str::parse::<u32>(s).ok())
@ -268,15 +262,15 @@ impl App {
candidate, candidate,
} => peer.handle_ice(sdp_mline_index, &candidate), } => peer.handle_ice(sdp_mline_index, &candidate),
} }
} else if msg.starts_with("ROOM_PEER_JOINED ") { } else if let Some(msg) = msg.strip_prefix("ROOM_PEER_JOINED ") {
// Parse message and add the new peer // Parse message and add the new peer
let mut split = msg["ROOM_PEER_JOINED ".len()..].splitn(2, ' '); let mut split = msg.splitn(2, ' ');
let peer_id = split.next().ok_or_else(|| anyhow!("Can't parse peer id"))?; let peer_id = split.next().ok_or_else(|| anyhow!("Can't parse peer id"))?;
self.add_peer(peer_id, false) self.add_peer(peer_id, false)
} else if msg.starts_with("ROOM_PEER_LEFT ") { } else if let Some(msg) = msg.strip_prefix("ROOM_PEER_LEFT ") {
// Parse message and add the new peer // Parse message and add the new peer
let mut split = msg["ROOM_PEER_LEFT ".len()..].splitn(2, ' '); let mut split = msg.splitn(2, ' ');
let peer_id = split.next().ok_or_else(|| anyhow!("Can't parse peer id"))?; let peer_id = split.next().ok_or_else(|| anyhow!("Can't parse peer id"))?;
self.remove_peer(peer_id) self.remove_peer(peer_id)
@ -310,7 +304,7 @@ impl App {
// Add this new peer and if requested, send the offer to it // Add this new peer and if requested, send the offer to it
fn add_peer(&self, peer: &str, offer: bool) -> Result<(), anyhow::Error> { fn add_peer(&self, peer: &str, offer: bool) -> Result<(), anyhow::Error> {
println!("Adding peer {}", peer); println!("Adding peer {}", peer);
let peer_id = str::parse::<u32>(peer).with_context(|| format!("Can't parse peer id"))?; let peer_id = str::parse::<u32>(peer).context("Can't parse peer id")?;
let mut peers = self.peers.lock().unwrap(); let mut peers = self.peers.lock().unwrap();
if peers.contains_key(&peer_id) { if peers.contains_key(&peer_id) {
bail!("Peer {} already called", peer_id); bail!("Peer {} already called", peer_id);
@ -324,9 +318,7 @@ impl App {
)?; )?;
// Get access to the webrtcbin by name // Get access to the webrtcbin by name
let webrtcbin = peer_bin let webrtcbin = peer_bin.by_name("webrtcbin").expect("can't find webrtcbin");
.by_name("webrtcbin")
.expect("can't find webrtcbin");
// Set some properties on webrtcbin // Set some properties on webrtcbin
webrtcbin.set_property_from_str("stun-server", STUN_SERVER); webrtcbin.set_property_from_str("stun-server", STUN_SERVER);
@ -372,11 +364,11 @@ impl App {
if offer { if offer {
// Connect to on-negotiation-needed to handle sending an Offer // Connect to on-negotiation-needed to handle sending an Offer
let peer_clone = peer.downgrade(); let peer_clone = peer.downgrade();
peer.webrtcbin peer.webrtcbin.connect_closure(
.connect("on-negotiation-needed", false, move |values| { "on-negotiation-needed",
let _webrtc = values[0].get::<gst::Element>().unwrap(); false,
glib::closure!(move |_webrtcbin: &gst::Element| {
let peer = upgrade_weak!(peer_clone, None); let peer = upgrade_weak!(peer_clone);
if let Err(err) = peer.on_negotiation_needed() { if let Err(err) = peer.on_negotiation_needed() {
gst::element_error!( gst::element_error!(
peer.bin, peer.bin,
@ -384,35 +376,29 @@ impl App {
("Failed to negotiate: {:?}", err) ("Failed to negotiate: {:?}", err)
); );
} }
}),
None );
})
.unwrap();
} }
// Whenever there is a new ICE candidate, send it to the peer // Whenever there is a new ICE candidate, send it to the peer
let peer_clone = peer.downgrade(); let peer_clone = peer.downgrade();
peer.webrtcbin peer.webrtcbin.connect_closure(
.connect("on-ice-candidate", false, move |values| { "on-ice-candidate",
let _webrtc = values[0].get::<gst::Element>().expect("Invalid argument"); false,
let mlineindex = values[1].get::<u32>().expect("Invalid argument"); glib::closure!(
let candidate = values[2] move |_webrtcbin: &gst::Element, mlineindex: u32, candidate: &str| {
.get::<String>() let peer = upgrade_weak!(peer_clone);
.expect("Invalid argument");
let peer = upgrade_weak!(peer_clone, None); if let Err(err) = peer.on_ice_candidate(mlineindex, candidate) {
gst::element_error!(
if let Err(err) = peer.on_ice_candidate(mlineindex, candidate) { peer.bin,
gst::element_error!( gst::LibraryError::Failed,
peer.bin, ("Failed to send ICE candidate: {:?}", err)
gst::LibraryError::Failed, );
("Failed to send ICE candidate: {:?}", err) }
);
} }
),
None );
})
.unwrap();
// Whenever there is a new stream incoming from the peer, handle it // Whenever there is a new stream incoming from the peer, handle it
let peer_clone = peer.downgrade(); let peer_clone = peer.downgrade();
@ -513,7 +499,7 @@ impl App {
// Remove this peer // Remove this peer
fn remove_peer(&self, peer: &str) -> Result<(), anyhow::Error> { fn remove_peer(&self, peer: &str) -> Result<(), anyhow::Error> {
println!("Removing peer {}", peer); println!("Removing peer {}", peer);
let peer_id = str::parse::<u32>(peer).with_context(|| format!("Can't parse peer id"))?; let peer_id = str::parse::<u32>(peer).context("Can't parse peer id")?;
let mut peers = self.peers.lock().unwrap(); let mut peers = self.peers.lock().unwrap();
if let Some(peer) = peers.remove(&peer_id) { if let Some(peer) = peers.remove(&peer_id) {
drop(peers); drop(peers);
@ -592,10 +578,10 @@ impl App {
let h = VIDEO_HEIGHT as i32 / height; let h = VIDEO_HEIGHT as i32 / height;
for pad in pads { for pad in pads {
pad.set_property("xpos", &x).unwrap(); pad.set_property("xpos", x);
pad.set_property("ypos", &y).unwrap(); pad.set_property("ypos", y);
pad.set_property("width", &w).unwrap(); pad.set_property("width", w);
pad.set_property("height", &h).unwrap(); pad.set_property("height", h);
x += w; x += w;
if x >= VIDEO_WIDTH as i32 { if x >= VIDEO_WIDTH as i32 {
@ -640,8 +626,7 @@ impl Peer {
}); });
self.webrtcbin self.webrtcbin
.emit_by_name("create-offer", &[&None::<gst::Structure>, &promise]) .emit_by_name::<()>("create-offer", &[&None::<gst::Structure>, &promise]);
.unwrap();
Ok(()) Ok(())
} }
@ -668,8 +653,7 @@ impl Peer {
.get::<gst_webrtc::WebRTCSessionDescription>() .get::<gst_webrtc::WebRTCSessionDescription>()
.expect("Invalid argument"); .expect("Invalid argument");
self.webrtcbin self.webrtcbin
.emit_by_name("set-local-description", &[&offer, &None::<gst::Promise>]) .emit_by_name::<()>("set-local-description", &[&offer, &None::<gst::Promise>]);
.unwrap();
println!( println!(
"sending SDP offer to peer: {}", "sending SDP offer to peer: {}",
@ -689,7 +673,7 @@ impl Peer {
"ROOM_PEER_MSG {} {}", "ROOM_PEER_MSG {} {}",
self.peer_id, message self.peer_id, message
))) )))
.with_context(|| format!("Failed to send SDP offer"))?; .context("Failed to send SDP offer")?;
Ok(()) Ok(())
} }
@ -716,8 +700,7 @@ impl Peer {
.get::<gst_webrtc::WebRTCSessionDescription>() .get::<gst_webrtc::WebRTCSessionDescription>()
.expect("Invalid argument"); .expect("Invalid argument");
self.webrtcbin self.webrtcbin
.emit_by_name("set-local-description", &[&answer, &None::<gst::Promise>]) .emit_by_name::<()>("set-local-description", &[&answer, &None::<gst::Promise>]);
.unwrap();
println!( println!(
"sending SDP answer to peer: {}", "sending SDP answer to peer: {}",
@ -737,7 +720,7 @@ impl Peer {
"ROOM_PEER_MSG {} {}", "ROOM_PEER_MSG {} {}",
self.peer_id, message self.peer_id, message
))) )))
.with_context(|| format!("Failed to send SDP answer"))?; .context("Failed to send SDP answer")?;
Ok(()) Ok(())
} }
@ -753,8 +736,7 @@ impl Peer {
gst_webrtc::WebRTCSessionDescription::new(gst_webrtc::WebRTCSDPType::Answer, ret); gst_webrtc::WebRTCSessionDescription::new(gst_webrtc::WebRTCSDPType::Answer, ret);
self.webrtcbin self.webrtcbin
.emit_by_name("set-remote-description", &[&answer, &None::<gst::Promise>]) .emit_by_name::<()>("set-remote-description", &[&answer, &None::<gst::Promise>]);
.unwrap();
Ok(()) Ok(())
} else if type_ == "offer" { } else if type_ == "offer" {
@ -776,8 +758,7 @@ impl Peer {
peer.0 peer.0
.webrtcbin .webrtcbin
.emit_by_name("set-remote-description", &[&offer, &None::<gst::Promise>]) .emit_by_name::<()>("set-remote-description", &[&offer, &None::<gst::Promise>]);
.unwrap();
let peer_clone = peer.downgrade(); let peer_clone = peer.downgrade();
let promise = gst::Promise::with_change_func(move |reply| { let promise = gst::Promise::with_change_func(move |reply| {
@ -794,8 +775,7 @@ impl Peer {
peer.0 peer.0
.webrtcbin .webrtcbin
.emit_by_name("create-answer", &[&None::<gst::Structure>, &promise]) .emit_by_name::<()>("create-answer", &[&None::<gst::Structure>, &promise]);
.unwrap();
}); });
Ok(()) Ok(())
@ -807,17 +787,16 @@ impl Peer {
// Handle incoming ICE candidates from the peer by passing them to webrtcbin // 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> { fn handle_ice(&self, sdp_mline_index: u32, candidate: &str) -> Result<(), anyhow::Error> {
self.webrtcbin self.webrtcbin
.emit_by_name("add-ice-candidate", &[&sdp_mline_index, &candidate]) .emit_by_name::<()>("add-ice-candidate", &[&sdp_mline_index, &candidate]);
.unwrap();
Ok(()) Ok(())
} }
// Asynchronously send ICE candidates to the peer via the WebSocket connection as a JSON // Asynchronously send ICE candidates to the peer via the WebSocket connection as a JSON
// message // message
fn on_ice_candidate(&self, mlineindex: u32, candidate: String) -> Result<(), anyhow::Error> { fn on_ice_candidate(&self, mlineindex: u32, candidate: &str) -> Result<(), anyhow::Error> {
let message = serde_json::to_string(&JsonMsg::Ice { let message = serde_json::to_string(&JsonMsg::Ice {
candidate, candidate: candidate.to_string(),
sdp_mline_index: mlineindex, sdp_mline_index: mlineindex,
}) })
.unwrap(); .unwrap();
@ -829,7 +808,7 @@ impl Peer {
"ROOM_PEER_MSG {} {}", "ROOM_PEER_MSG {} {}",
self.peer_id, message self.peer_id, message
))) )))
.with_context(|| format!("Failed to send ICE candidate"))?; .context("Failed to send ICE candidate")?;
Ok(()) Ok(())
} }
@ -871,8 +850,7 @@ 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(Some("sink"), &dbin.static_pad("sink").unwrap()) gst::GhostPad::with_target(Some("sink"), &dbin.static_pad("sink").unwrap()).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
@ -911,7 +889,6 @@ impl Drop for PeerInner {
} }
async fn run( async fn run(
args: Args,
initial_peers: &[&str], initial_peers: &[&str],
ws: impl Sink<WsMessage, Error = WsError> + Stream<Item = Result<WsMessage, WsError>>, ws: impl Sink<WsMessage, Error = WsError> + Stream<Item = Result<WsMessage, WsError>>,
) -> Result<(), anyhow::Error> { ) -> Result<(), anyhow::Error> {
@ -921,7 +898,7 @@ async fn run(
let mut ws_stream = ws_stream.fuse(); let mut ws_stream = ws_stream.fuse();
// Create our application state // Create our application state
let (app, send_gst_msg_rx, send_ws_msg_rx) = App::new(args, initial_peers)?; let (app, send_gst_msg_rx, send_ws_msg_rx) = App::new(initial_peers)?;
let mut send_gst_msg_rx = send_gst_msg_rx.fuse(); let mut send_gst_msg_rx = send_gst_msg_rx.fuse();
let mut send_ws_msg_rx = send_ws_msg_rx.fuse(); let mut send_ws_msg_rx = send_ws_msg_rx.fuse();
@ -945,6 +922,7 @@ async fn run(
} }
None None
}, },
WsMessage::Frame(_) => unreachable!(),
} }
}, },
// Pass the GStreamer messages to the application control logic // Pass the GStreamer messages to the application control logic
@ -1042,18 +1020,17 @@ async fn async_main() -> Result<(), anyhow::Error> {
.await .await
.ok_or_else(|| anyhow!("didn't receive anything"))??; .ok_or_else(|| anyhow!("didn't receive anything"))??;
let peers_str; let peers_str = if let WsMessage::Text(text) = &msg {
if let WsMessage::Text(text) = &msg {
if !text.starts_with("ROOM_OK") { if !text.starts_with("ROOM_OK") {
bail!("server error: {:?}", text); bail!("server error: {:?}", text);
} }
println!("Joined room {}", args.room_id); println!("Joined room {}", args.room_id);
peers_str = &text["ROOM_OK ".len()..]; &text["ROOM_OK ".len()..]
} else { } else {
bail!("server error: {:?}", msg); bail!("server error: {:?}", msg);
} };
// Collect the ids of already existing peers // Collect the ids of already existing peers
let initial_peers = peers_str let initial_peers = peers_str
@ -1070,7 +1047,7 @@ async fn async_main() -> Result<(), anyhow::Error> {
.collect::<Vec<_>>(); .collect::<Vec<_>>();
// All good, let's run our message loop // All good, let's run our message loop
run(args, &initial_peers, ws).await run(&initial_peers, ws).await
} }
fn main() -> Result<(), anyhow::Error> { fn main() -> Result<(), anyhow::Error> {

File diff suppressed because it is too large Load diff

View file

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

View file

@ -16,6 +16,7 @@ use async_tungstenite::tungstenite;
use tungstenite::Error as WsError; use tungstenite::Error as WsError;
use tungstenite::Message as WsMessage; use tungstenite::Message as WsMessage;
use gst::glib;
use gst::prelude::*; use gst::prelude::*;
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
@ -125,9 +126,7 @@ impl App {
.expect("not a pipeline"); .expect("not a pipeline");
// Get access to the webrtcbin by name // Get access to the webrtcbin by name
let webrtcbin = pipeline let webrtcbin = pipeline.by_name("webrtcbin").expect("can't find webrtcbin");
.by_name("webrtcbin")
.expect("can't find webrtcbin");
// Set some properties on webrtcbin // Set some properties on webrtcbin
webrtcbin.set_property_from_str("stun-server", STUN_SERVER); webrtcbin.set_property_from_str("stun-server", STUN_SERVER);
@ -151,11 +150,11 @@ impl App {
// Connect to on-negotiation-needed to handle sending an Offer // Connect to on-negotiation-needed to handle sending an Offer
if app.args.peer_id.is_some() { if app.args.peer_id.is_some() {
let app_clone = app.downgrade(); let app_clone = app.downgrade();
app.webrtcbin app.webrtcbin.connect_closure(
.connect("on-negotiation-needed", false, move |values| { "on-negotiation-needed",
let _webrtc = values[0].get::<gst::Element>().unwrap(); false,
glib::closure!(move |_webrtcbin: &gst::Element| {
let app = upgrade_weak!(app_clone, None); let app = upgrade_weak!(app_clone);
if let Err(err) = app.on_negotiation_needed() { if let Err(err) = app.on_negotiation_needed() {
gst::element_error!( gst::element_error!(
app.pipeline, app.pipeline,
@ -163,35 +162,29 @@ impl App {
("Failed to negotiate: {:?}", err) ("Failed to negotiate: {:?}", err)
); );
} }
}),
None );
})
.unwrap();
} }
// Whenever there is a new ICE candidate, send it to the peer // Whenever there is a new ICE candidate, send it to the peer
let app_clone = app.downgrade(); let app_clone = app.downgrade();
app.webrtcbin app.webrtcbin.connect_closure(
.connect("on-ice-candidate", false, move |values| { "on-ice-candidate",
let _webrtc = values[0].get::<gst::Element>().expect("Invalid argument"); false,
let mlineindex = values[1].get::<u32>().expect("Invalid argument"); glib::closure!(
let candidate = values[2] move |_webrtcbin: &gst::Element, mlineindex: u32, candidate: &str| {
.get::<String>() let app = upgrade_weak!(app_clone);
.expect("Invalid argument");
let app = upgrade_weak!(app_clone, None); if let Err(err) = app.on_ice_candidate(mlineindex, candidate) {
gst::element_error!(
if let Err(err) = app.on_ice_candidate(mlineindex, candidate) { app.pipeline,
gst::element_error!( gst::LibraryError::Failed,
app.pipeline, ("Failed to send ICE candidate: {:?}", err)
gst::LibraryError::Failed, );
("Failed to send ICE candidate: {:?}", err) }
);
} }
),
None );
})
.unwrap();
// Whenever there is a new stream incoming from the peer, handle it // Whenever there is a new stream incoming from the peer, handle it
let app_clone = app.downgrade(); let app_clone = app.downgrade();
@ -288,8 +281,7 @@ impl App {
}); });
self.webrtcbin self.webrtcbin
.emit_by_name("create-offer", &[&None::<gst::Structure>, &promise]) .emit_by_name::<()>("create-offer", &[&None::<gst::Structure>, &promise]);
.unwrap();
Ok(()) Ok(())
} }
@ -316,8 +308,7 @@ impl App {
.get::<gst_webrtc::WebRTCSessionDescription>() .get::<gst_webrtc::WebRTCSessionDescription>()
.expect("Invalid argument"); .expect("Invalid argument");
self.webrtcbin self.webrtcbin
.emit_by_name("set-local-description", &[&offer, &None::<gst::Promise>]) .emit_by_name::<()>("set-local-description", &[&offer, &None::<gst::Promise>]);
.unwrap();
println!( println!(
"sending SDP offer to peer: {}", "sending SDP offer to peer: {}",
@ -334,7 +325,7 @@ impl App {
.lock() .lock()
.unwrap() .unwrap()
.unbounded_send(WsMessage::Text(message)) .unbounded_send(WsMessage::Text(message))
.with_context(|| format!("Failed to send SDP offer"))?; .context("Failed to send SDP offer")?;
Ok(()) Ok(())
} }
@ -361,8 +352,7 @@ impl App {
.get::<gst_webrtc::WebRTCSessionDescription>() .get::<gst_webrtc::WebRTCSessionDescription>()
.expect("Invalid argument"); .expect("Invalid argument");
self.webrtcbin self.webrtcbin
.emit_by_name("set-local-description", &[&answer, &None::<gst::Promise>]) .emit_by_name::<()>("set-local-description", &[&answer, &None::<gst::Promise>]);
.unwrap();
println!( println!(
"sending SDP answer to peer: {}", "sending SDP answer to peer: {}",
@ -379,7 +369,7 @@ impl App {
.lock() .lock()
.unwrap() .unwrap()
.unbounded_send(WsMessage::Text(message)) .unbounded_send(WsMessage::Text(message))
.with_context(|| format!("Failed to send SDP answer"))?; .context("Failed to send SDP answer")?;
Ok(()) Ok(())
} }
@ -395,8 +385,7 @@ impl App {
gst_webrtc::WebRTCSessionDescription::new(gst_webrtc::WebRTCSDPType::Answer, ret); gst_webrtc::WebRTCSessionDescription::new(gst_webrtc::WebRTCSDPType::Answer, ret);
self.webrtcbin self.webrtcbin
.emit_by_name("set-remote-description", &[&answer, &None::<gst::Promise>]) .emit_by_name::<()>("set-remote-description", &[&answer, &None::<gst::Promise>]);
.unwrap();
Ok(()) Ok(())
} else if type_ == "offer" { } else if type_ == "offer" {
@ -418,8 +407,7 @@ impl App {
app.0 app.0
.webrtcbin .webrtcbin
.emit_by_name("set-remote-description", &[&offer, &None::<gst::Promise>]) .emit_by_name::<()>("set-remote-description", &[&offer, &None::<gst::Promise>]);
.unwrap();
let app_clone = app.downgrade(); let app_clone = app.downgrade();
let promise = gst::Promise::with_change_func(move |reply| { let promise = gst::Promise::with_change_func(move |reply| {
@ -436,8 +424,7 @@ impl App {
app.0 app.0
.webrtcbin .webrtcbin
.emit_by_name("create-answer", &[&None::<gst::Structure>, &promise]) .emit_by_name::<()>("create-answer", &[&None::<gst::Structure>, &promise]);
.unwrap();
}); });
Ok(()) Ok(())
@ -449,17 +436,16 @@ impl App {
// Handle incoming ICE candidates from the peer by passing them to webrtcbin // 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> { fn handle_ice(&self, sdp_mline_index: u32, candidate: &str) -> Result<(), anyhow::Error> {
self.webrtcbin self.webrtcbin
.emit_by_name("add-ice-candidate", &[&sdp_mline_index, &candidate]) .emit_by_name::<()>("add-ice-candidate", &[&sdp_mline_index, &candidate]);
.unwrap();
Ok(()) Ok(())
} }
// Asynchronously send ICE candidates to the peer via the WebSocket connection as a JSON // Asynchronously send ICE candidates to the peer via the WebSocket connection as a JSON
// message // message
fn on_ice_candidate(&self, mlineindex: u32, candidate: String) -> Result<(), anyhow::Error> { fn on_ice_candidate(&self, mlineindex: u32, candidate: &str) -> Result<(), anyhow::Error> {
let message = serde_json::to_string(&JsonMsg::Ice { let message = serde_json::to_string(&JsonMsg::Ice {
candidate, candidate: candidate.to_string(),
sdp_mline_index: mlineindex, sdp_mline_index: mlineindex,
}) })
.unwrap(); .unwrap();
@ -468,7 +454,7 @@ impl App {
.lock() .lock()
.unwrap() .unwrap()
.unbounded_send(WsMessage::Text(message)) .unbounded_send(WsMessage::Text(message))
.with_context(|| format!("Failed to send ICE candidate"))?; .context("Failed to send ICE candidate")?;
Ok(()) Ok(())
} }
@ -576,6 +562,7 @@ async fn run(
app.handle_websocket_message(&text)?; app.handle_websocket_message(&text)?;
None None
}, },
WsMessage::Frame(_) => unreachable!(),
} }
}, },
// Pass the GStreamer messages to the application control logic // Pass the GStreamer messages to the application control logic