Get rid of fragile dependency and use GLib API instead

This commit is contained in:
Sebastian Dröge 2022-01-24 19:33:15 +02:00
parent 13eb483444
commit 06cf5de45f
4 changed files with 7 additions and 9 deletions

View file

@ -23,7 +23,6 @@ gst = { package = "gstreamer", path = "../gstreamer" }
gst-base = { package = "gstreamer-base", path = "../gstreamer-base" }
once_cell = "1.0"
futures-channel = "0.3"
fragile = "1"
serde = { version = "1.0", optional = true, features = ["derive"] }
[dev-dependencies]

View file

@ -58,7 +58,7 @@ pub fn convert_sample_async_local<F>(
.acquire()
.expect("thread default main context already acquired by another thread");
let func = fragile::Fragile::new(func);
let func = glib::thread_guard::ThreadGuard::new(func);
convert_sample_async_unsafe(sample, caps, timeout, move |res| (func.into_inner())(res))
}

View file

@ -32,7 +32,6 @@ serde_bytes = { version = "0.11", optional = true }
paste = "1.0"
pretty-hex = "0.2"
thiserror = "1"
fragile = "1"
[dev-dependencies]
ron = "0.7"

View file

@ -13,8 +13,6 @@ use std::mem::transmute;
use std::pin::Pin;
use std::task::{Context, Poll};
use fragile::Fragile;
use crate::Bus;
use crate::BusSyncReply;
use crate::Message;
@ -48,20 +46,22 @@ unsafe extern "C" fn trampoline_watch_local<F: FnMut(&Bus, &Message) -> Continue
msg: *mut ffi::GstMessage,
func: gpointer,
) -> gboolean {
let func: &Fragile<RefCell<F>> = &*(func as *const Fragile<RefCell<F>>);
(&mut *func.get().borrow_mut())(&from_glib_borrow(bus), &Message::from_glib_borrow(msg))
let func: &glib::thread_guard::ThreadGuard<RefCell<F>> =
&*(func as *const glib::thread_guard::ThreadGuard<RefCell<F>>);
(&mut *func.get_ref().borrow_mut())(&from_glib_borrow(bus), &Message::from_glib_borrow(msg))
.into_glib()
}
unsafe extern "C" fn destroy_closure_watch_local<F: FnMut(&Bus, &Message) -> Continue + 'static>(
ptr: gpointer,
) {
Box::<Fragile<RefCell<F>>>::from_raw(ptr as *mut _);
Box::<glib::thread_guard::ThreadGuard<RefCell<F>>>::from_raw(ptr as *mut _);
}
fn into_raw_watch_local<F: FnMut(&Bus, &Message) -> Continue + 'static>(func: F) -> gpointer {
#[allow(clippy::type_complexity)]
let func: Box<Fragile<RefCell<F>>> = Box::new(Fragile::new(RefCell::new(func)));
let func: Box<glib::thread_guard::ThreadGuard<RefCell<F>>> =
Box::new(glib::thread_guard::ThreadGuard::new(RefCell::new(func)));
Box::into_raw(func) as gpointer
}