forked from mirrors/gstreamer-rs
Don't box closures twice for signal callback closures
This commit is contained in:
parent
d8085a5d79
commit
1adb063fbc
4 changed files with 46 additions and 55 deletions
|
@ -182,19 +182,12 @@ impl AppSink {
|
||||||
f: F,
|
f: F,
|
||||||
) -> SignalHandlerId {
|
) -> SignalHandlerId {
|
||||||
unsafe {
|
unsafe {
|
||||||
let f: Box_<
|
let f: Box_<F> = Box_::new(f);
|
||||||
Box_<
|
|
||||||
Fn(&AppSink) -> Result<gst::FlowSuccess, gst::FlowError>
|
|
||||||
+ Send
|
|
||||||
+ Sync
|
|
||||||
+ 'static,
|
|
||||||
>,
|
|
||||||
> = Box_::new(Box_::new(f));
|
|
||||||
connect_raw(
|
connect_raw(
|
||||||
self.as_ptr() as *mut _,
|
self.as_ptr() as *mut _,
|
||||||
b"new-sample\0".as_ptr() as *const _,
|
b"new-sample\0".as_ptr() as *const _,
|
||||||
transmute(new_sample_trampoline as usize),
|
Some(transmute(new_sample_trampoline::<F> as usize)),
|
||||||
Box_::into_raw(f) as *mut _,
|
Box_::into_raw(f),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -206,40 +199,35 @@ impl AppSink {
|
||||||
f: F,
|
f: F,
|
||||||
) -> SignalHandlerId {
|
) -> SignalHandlerId {
|
||||||
unsafe {
|
unsafe {
|
||||||
let f: Box_<
|
let f: Box_<F> = Box_::new(f);
|
||||||
Box_<
|
|
||||||
Fn(&AppSink) -> Result<gst::FlowSuccess, gst::FlowError>
|
|
||||||
+ Send
|
|
||||||
+ Sync
|
|
||||||
+ 'static,
|
|
||||||
>,
|
|
||||||
> = Box_::new(Box_::new(f));
|
|
||||||
connect_raw(
|
connect_raw(
|
||||||
self.as_ptr() as *mut _,
|
self.as_ptr() as *mut _,
|
||||||
b"new-preroll\0".as_ptr() as *const _,
|
b"new-preroll\0".as_ptr() as *const _,
|
||||||
transmute(new_preroll_trampoline as usize),
|
Some(transmute(new_preroll_trampoline::<F> as usize)),
|
||||||
Box_::into_raw(f) as *mut _,
|
Box_::into_raw(f),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn new_sample_trampoline(
|
unsafe extern "C" fn new_sample_trampoline<
|
||||||
|
F: Fn(&AppSink) -> Result<gst::FlowSuccess, gst::FlowError> + Send + Sync + 'static,
|
||||||
|
>(
|
||||||
this: *mut ffi::GstAppSink,
|
this: *mut ffi::GstAppSink,
|
||||||
f: glib_ffi::gpointer,
|
f: glib_ffi::gpointer,
|
||||||
) -> gst_ffi::GstFlowReturn {
|
) -> gst_ffi::GstFlowReturn {
|
||||||
let f: &&(Fn(&AppSink) -> Result<gst::FlowSuccess, gst::FlowError> + Send + Sync + 'static) =
|
let f: &F = transmute(f);
|
||||||
transmute(f);
|
|
||||||
let ret: gst::FlowReturn = f(&from_glib_borrow(this)).into();
|
let ret: gst::FlowReturn = f(&from_glib_borrow(this)).into();
|
||||||
ret.to_glib()
|
ret.to_glib()
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn new_preroll_trampoline(
|
unsafe extern "C" fn new_preroll_trampoline<
|
||||||
|
F: Fn(&AppSink) -> Result<gst::FlowSuccess, gst::FlowError> + Send + Sync + 'static,
|
||||||
|
>(
|
||||||
this: *mut ffi::GstAppSink,
|
this: *mut ffi::GstAppSink,
|
||||||
f: glib_ffi::gpointer,
|
f: glib_ffi::gpointer,
|
||||||
) -> gst_ffi::GstFlowReturn {
|
) -> gst_ffi::GstFlowReturn {
|
||||||
let f: &&(Fn(&AppSink) -> Result<gst::FlowSuccess, gst::FlowError> + Send + Sync + 'static) =
|
let f: &F = transmute(f);
|
||||||
transmute(f);
|
|
||||||
let ret: gst::FlowReturn = f(&from_glib_borrow(this)).into();
|
let ret: gst::FlowReturn = f(&from_glib_borrow(this)).into();
|
||||||
ret.to_glib()
|
ret.to_glib()
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,18 +53,18 @@ impl Discoverer {
|
||||||
f: F,
|
f: F,
|
||||||
) -> SignalHandlerId {
|
) -> SignalHandlerId {
|
||||||
unsafe {
|
unsafe {
|
||||||
let f: Box_<Box_<Fn(&Self) + Send + Sync + 'static>> = Box_::new(Box_::new(f));
|
let f: Box_<F> = Box_::new(f);
|
||||||
connect_raw(
|
connect_raw(
|
||||||
self.as_ptr() as *mut _,
|
self.as_ptr() as *mut _,
|
||||||
b"notify::timeout\0".as_ptr() as *const _,
|
b"notify::timeout\0".as_ptr() as *const _,
|
||||||
transmute(notify_timeout_trampoline::<Self> as usize),
|
Some(transmute(notify_timeout_trampoline::<Self, F> as usize)),
|
||||||
Box_::into_raw(f) as *mut _,
|
Box_::into_raw(f),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn notify_timeout_trampoline<P>(
|
unsafe extern "C" fn notify_timeout_trampoline<P, F: Fn(&P) + Send + Sync + 'static>(
|
||||||
this: *mut ffi::GstDiscoverer,
|
this: *mut ffi::GstDiscoverer,
|
||||||
_param_spec: glib_ffi::gpointer,
|
_param_spec: glib_ffi::gpointer,
|
||||||
f: glib_ffi::gpointer,
|
f: glib_ffi::gpointer,
|
||||||
|
@ -72,6 +72,6 @@ unsafe extern "C" fn notify_timeout_trampoline<P>(
|
||||||
P: IsA<Discoverer>,
|
P: IsA<Discoverer>,
|
||||||
{
|
{
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
||||||
let f: &&(Fn(&P) + Send + Sync + 'static) = transmute(f);
|
let f: &F = transmute(f);
|
||||||
f(&Discoverer::from_glib_borrow(this).unsafe_cast())
|
f(&Discoverer::from_glib_borrow(this).unsafe_cast())
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,13 +57,12 @@ impl Player {
|
||||||
f: F,
|
f: F,
|
||||||
) -> SignalHandlerId {
|
) -> SignalHandlerId {
|
||||||
unsafe {
|
unsafe {
|
||||||
let f: Box_<Box_<Fn(&Player, gst::ClockTime) + Send + 'static>> =
|
let f: Box_<F> = Box_::new(f);
|
||||||
Box_::new(Box_::new(f));
|
|
||||||
connect_raw(
|
connect_raw(
|
||||||
self.as_ptr() as *mut _,
|
self.as_ptr() as *mut _,
|
||||||
b"duration-changed\0".as_ptr() as *const _,
|
b"duration-changed\0".as_ptr() as *const _,
|
||||||
transmute(duration_changed_trampoline as usize),
|
Some(transmute(duration_changed_trampoline::<F> as usize)),
|
||||||
Box_::into_raw(f) as *mut _,
|
Box_::into_raw(f),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,13 +72,12 @@ impl Player {
|
||||||
f: F,
|
f: F,
|
||||||
) -> SignalHandlerId {
|
) -> SignalHandlerId {
|
||||||
unsafe {
|
unsafe {
|
||||||
let f: Box_<Box_<Fn(&Player, gst::ClockTime) + Send + 'static>> =
|
let f: Box_<F> = Box_::new(f);
|
||||||
Box_::new(Box_::new(f));
|
|
||||||
connect_raw(
|
connect_raw(
|
||||||
self.as_ptr() as *mut _,
|
self.as_ptr() as *mut _,
|
||||||
b"position-updated\0".as_ptr() as *const _,
|
b"position-updated\0".as_ptr() as *const _,
|
||||||
transmute(position_updated_trampoline as usize),
|
Some(transmute(position_updated_trampoline::<F> as usize)),
|
||||||
Box_::into_raw(f) as *mut _,
|
Box_::into_raw(f),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,44 +87,47 @@ impl Player {
|
||||||
f: F,
|
f: F,
|
||||||
) -> SignalHandlerId {
|
) -> SignalHandlerId {
|
||||||
unsafe {
|
unsafe {
|
||||||
let f: Box_<Box_<Fn(&Player, gst::ClockTime) + Send + 'static>> =
|
let f: Box_<F> = Box_::new(f);
|
||||||
Box_::new(Box_::new(f));
|
|
||||||
connect_raw(
|
connect_raw(
|
||||||
self.as_ptr() as *mut _,
|
self.as_ptr() as *mut _,
|
||||||
b"seek-done\0".as_ptr() as *const _,
|
b"seek-done\0".as_ptr() as *const _,
|
||||||
transmute(seek_done_trampoline as usize),
|
Some(transmute(seek_done_trampoline::<F> as usize)),
|
||||||
Box_::into_raw(f) as *mut _,
|
Box_::into_raw(f),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn duration_changed_trampoline(
|
unsafe extern "C" fn duration_changed_trampoline<
|
||||||
|
F: Fn(&Player, gst::ClockTime) + Send + 'static,
|
||||||
|
>(
|
||||||
this: *mut ffi::GstPlayer,
|
this: *mut ffi::GstPlayer,
|
||||||
object: u64,
|
object: u64,
|
||||||
f: glib_ffi::gpointer,
|
f: glib_ffi::gpointer,
|
||||||
) {
|
) {
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
||||||
let f: &&(Fn(&Player, gst::ClockTime) + Send + 'static) = transmute(f);
|
let f: &F = transmute(f);
|
||||||
f(&from_glib_borrow(this), gst::ClockTime(Some(object)))
|
f(&from_glib_borrow(this), gst::ClockTime(Some(object)))
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn position_updated_trampoline(
|
unsafe extern "C" fn position_updated_trampoline<
|
||||||
|
F: Fn(&Player, gst::ClockTime) + Send + 'static,
|
||||||
|
>(
|
||||||
this: *mut ffi::GstPlayer,
|
this: *mut ffi::GstPlayer,
|
||||||
object: u64,
|
object: u64,
|
||||||
f: glib_ffi::gpointer,
|
f: glib_ffi::gpointer,
|
||||||
) {
|
) {
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
||||||
let f: &&(Fn(&Player, gst::ClockTime) + Send + Sync + 'static) = transmute(f);
|
let f: &F = transmute(f);
|
||||||
f(&from_glib_borrow(this), gst::ClockTime(Some(object)))
|
f(&from_glib_borrow(this), gst::ClockTime(Some(object)))
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn seek_done_trampoline(
|
unsafe extern "C" fn seek_done_trampoline<F: Fn(&Player, gst::ClockTime) + Send + 'static>(
|
||||||
this: *mut ffi::GstPlayer,
|
this: *mut ffi::GstPlayer,
|
||||||
object: u64,
|
object: u64,
|
||||||
f: glib_ffi::gpointer,
|
f: glib_ffi::gpointer,
|
||||||
) {
|
) {
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
||||||
let f: &&(Fn(&Player, gst::ClockTime) + Send + 'static) = transmute(f);
|
let f: &F = transmute(f);
|
||||||
f(&from_glib_borrow(this), gst::ClockTime(Some(object)))
|
f(&from_glib_borrow(this), gst::ClockTime(Some(object)))
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,13 +85,12 @@ impl<O: IsA<Bin>> GstBinExtManual for O {
|
||||||
f: F,
|
f: F,
|
||||||
) -> SignalHandlerId {
|
) -> SignalHandlerId {
|
||||||
unsafe {
|
unsafe {
|
||||||
let f: Box_<Box_<Fn(&Self) -> Result<(), LoggableError> + Send + Sync + 'static>> =
|
let f: Box_<F> = Box_::new(f);
|
||||||
Box_::new(Box_::new(f));
|
|
||||||
connect_raw(
|
connect_raw(
|
||||||
self.as_ptr() as *mut _,
|
self.as_ptr() as *mut _,
|
||||||
b"do-latency\0".as_ptr() as *const _,
|
b"do-latency\0".as_ptr() as *const _,
|
||||||
transmute(do_latency_trampoline::<Self> as usize),
|
Some(transmute(do_latency_trampoline::<Self, F> as usize)),
|
||||||
Box_::into_raw(f) as *mut _,
|
Box_::into_raw(f),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -154,14 +153,17 @@ impl<O: IsA<Bin>> GstBinExtManual for O {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn do_latency_trampoline<P>(
|
unsafe extern "C" fn do_latency_trampoline<
|
||||||
|
P,
|
||||||
|
F: Fn(&P) -> Result<(), LoggableError> + Send + Sync + 'static,
|
||||||
|
>(
|
||||||
this: *mut ffi::GstBin,
|
this: *mut ffi::GstBin,
|
||||||
f: glib_ffi::gpointer,
|
f: glib_ffi::gpointer,
|
||||||
) -> glib_ffi::gboolean
|
) -> glib_ffi::gboolean
|
||||||
where
|
where
|
||||||
P: IsA<Bin>,
|
P: IsA<Bin>,
|
||||||
{
|
{
|
||||||
let f: &&(Fn(&P) -> Result<(), LoggableError> + Send + Sync + 'static) = transmute(f);
|
let f: &F = transmute(f);
|
||||||
match f(&Bin::from_glib_borrow(this).unsafe_cast()) {
|
match f(&Bin::from_glib_borrow(this).unsafe_cast()) {
|
||||||
Ok(()) => true,
|
Ok(()) => true,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|
Loading…
Reference in a new issue