mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-14 13:21:28 +00:00
sendrecv/rust: Port from tokio to async-std and use async/await
This commit is contained in:
parent
3d2b63615a
commit
9a46977a4c
4 changed files with 1227 additions and 1471 deletions
1420
webrtc/sendrecv/gst-rust/Cargo.lock
generated
1420
webrtc/sendrecv/gst-rust/Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -1,19 +1,20 @@
|
||||||
[package]
|
[package]
|
||||||
name = "gst-rust"
|
name = "webrtc-app"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["maxmcd <max.t.mcdonnell@gmail.com>"]
|
authors = ["Sebastian Dröge <sebastian@centricular.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = "2.31.2"
|
futures = "0.3"
|
||||||
failure = "0.1.1"
|
async-std = "1"
|
||||||
glib = "0.8"
|
structopt = { version = "0.3", default-features = false }
|
||||||
gstreamer = "0.14"
|
anyhow = "1"
|
||||||
gstreamer-sdp = "0.14"
|
url = "2"
|
||||||
gstreamer-webrtc = "0.14"
|
|
||||||
lazy_static = "1.0"
|
|
||||||
rand = "0.7"
|
rand = "0.7"
|
||||||
serde = "1.0.66"
|
async-tungstenite = "0.2"
|
||||||
serde_derive = "1.0.66"
|
gst = { package = "gstreamer", version = "0.14", features = ["v1_14"] }
|
||||||
serde_json = "1.0.19"
|
gst-webrtc = { package = "gstreamer-webrtc", version = "0.14" }
|
||||||
websocket = "0.23"
|
gst-sdp = { package = "gstreamer-sdp", version = "0.14", features = ["v1_14"] }
|
||||||
tokio = "0.1"
|
serde = "1"
|
||||||
|
serde_derive = "1"
|
||||||
|
serde_json = "1"
|
||||||
|
|
67
webrtc/sendrecv/gst-rust/src/macos_workaround.rs
Normal file
67
webrtc/sendrecv/gst-rust/src/macos_workaround.rs
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
/// macOS has a specific requirement that there must be a run loop running
|
||||||
|
/// on the main thread in order to open windows and use OpenGL.
|
||||||
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
mod runloop {
|
||||||
|
use std::os::raw::c_void;
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct CFRunLoop(*mut c_void);
|
||||||
|
|
||||||
|
#[link(name = "foundation", kind = "framework")]
|
||||||
|
extern "C" {
|
||||||
|
fn CFRunLoopRun();
|
||||||
|
fn CFRunLoopGetMain() -> *mut c_void;
|
||||||
|
fn CFRunLoopStop(l: *mut c_void);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CFRunLoop {
|
||||||
|
pub fn run() {
|
||||||
|
unsafe {
|
||||||
|
CFRunLoopRun();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_main() -> CFRunLoop {
|
||||||
|
unsafe {
|
||||||
|
let r = CFRunLoopGetMain();
|
||||||
|
assert!(!r.is_null());
|
||||||
|
CFRunLoop(r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn stop(&self) {
|
||||||
|
unsafe { CFRunLoopStop(self.0) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe impl Send for CFRunLoop {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// On macOS this launches the callback function on a thread.
|
||||||
|
/// On other platforms it's just executed immediately.
|
||||||
|
#[cfg(not(target_os = "macos"))]
|
||||||
|
pub fn run<T, F: FnOnce() -> T + Send + 'static>(main: F) -> T
|
||||||
|
where
|
||||||
|
T: Send + 'static,
|
||||||
|
{
|
||||||
|
main()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
pub fn run<T, F: FnOnce() -> T + Send + 'static>(main: F) -> T
|
||||||
|
where
|
||||||
|
T: Send + 'static,
|
||||||
|
{
|
||||||
|
use std::thread;
|
||||||
|
|
||||||
|
let l = runloop::CFRunLoop::get_main();
|
||||||
|
let t = thread::spawn(move || {
|
||||||
|
let res = main();
|
||||||
|
l.stop();
|
||||||
|
res
|
||||||
|
});
|
||||||
|
|
||||||
|
runloop::CFRunLoop::run();
|
||||||
|
|
||||||
|
t.join().unwrap()
|
||||||
|
}
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue