forked from mirrors/gstreamer-rs
Get rid of double-boxing for some other closures
This commit is contained in:
parent
1adb063fbc
commit
42a8b9e505
9 changed files with 308 additions and 298 deletions
|
@ -9,25 +9,26 @@ use std::cell::RefCell;
|
||||||
use std::mem::transmute;
|
use std::mem::transmute;
|
||||||
use RTSPSessionPool;
|
use RTSPSessionPool;
|
||||||
|
|
||||||
unsafe extern "C" fn trampoline_watch(
|
unsafe extern "C" fn trampoline_watch<F: FnMut(&RTSPSessionPool) -> Continue + Send + 'static>(
|
||||||
pool: *mut ffi::GstRTSPSessionPool,
|
pool: *mut ffi::GstRTSPSessionPool,
|
||||||
func: gpointer,
|
func: gpointer,
|
||||||
) -> gboolean {
|
) -> gboolean {
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
||||||
let func: &RefCell<Box<FnMut(&RTSPSessionPool) -> Continue + Send + 'static>> = transmute(func);
|
let func: &RefCell<F> = transmute(func);
|
||||||
(&mut *func.borrow_mut())(&from_glib_borrow(pool)).to_glib()
|
(&mut *func.borrow_mut())(&from_glib_borrow(pool)).to_glib()
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn destroy_closure_watch(ptr: gpointer) {
|
unsafe extern "C" fn destroy_closure_watch<
|
||||||
Box::<RefCell<Box<FnMut(&RTSPSessionPool) -> Continue + Send + 'static>>>::from_raw(
|
F: FnMut(&RTSPSessionPool) -> Continue + Send + 'static,
|
||||||
ptr as *mut _,
|
>(
|
||||||
);
|
ptr: gpointer,
|
||||||
|
) {
|
||||||
|
Box::<RefCell<F>>::from_raw(ptr as *mut _);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn into_raw_watch<F: FnMut(&RTSPSessionPool) -> Continue + Send + 'static>(func: F) -> gpointer {
|
fn into_raw_watch<F: FnMut(&RTSPSessionPool) -> Continue + Send + 'static>(func: F) -> gpointer {
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
|
#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
|
||||||
let func: Box<RefCell<Box<FnMut(&RTSPSessionPool) -> Continue + Send + 'static>>> =
|
let func: Box<RefCell<F>> = Box::new(RefCell::new(func));
|
||||||
Box::new(RefCell::new(Box::new(func)));
|
|
||||||
Box::into_raw(func) as gpointer
|
Box::into_raw(func) as gpointer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,12 +56,11 @@ impl<O: IsA<RTSPSessionPool>> RTSPSessionPoolExtManual for O {
|
||||||
skip_assert_initialized!();
|
skip_assert_initialized!();
|
||||||
unsafe {
|
unsafe {
|
||||||
let source = ffi::gst_rtsp_session_pool_create_watch(self.as_ref().to_glib_none().0);
|
let source = ffi::gst_rtsp_session_pool_create_watch(self.as_ref().to_glib_none().0);
|
||||||
let trampoline = trampoline_watch as gpointer;
|
|
||||||
glib_ffi::g_source_set_callback(
|
glib_ffi::g_source_set_callback(
|
||||||
source,
|
source,
|
||||||
Some(transmute(trampoline)),
|
Some(transmute(trampoline_watch::<F> as usize)),
|
||||||
into_raw_watch(func),
|
into_raw_watch(func),
|
||||||
Some(destroy_closure_watch),
|
Some(destroy_closure_watch::<F>),
|
||||||
);
|
);
|
||||||
glib_ffi::g_source_set_priority(source, priority.to_glib());
|
glib_ffi::g_source_set_priority(source, priority.to_glib());
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ pub fn convert_sample_async<F>(
|
||||||
F: FnOnce(Result<gst::Sample, glib::Error>) + Send + 'static,
|
F: FnOnce(Result<gst::Sample, glib::Error>) + Send + 'static,
|
||||||
{
|
{
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
||||||
let callback: &mut Option<Box<F>> = mem::transmute(user_data);
|
let callback: &mut Option<F> = mem::transmute(user_data);
|
||||||
let callback = callback.take().unwrap();
|
let callback = callback.take().unwrap();
|
||||||
|
|
||||||
if error.is_null() {
|
if error.is_null() {
|
||||||
|
@ -68,11 +68,11 @@ pub fn convert_sample_async<F>(
|
||||||
where
|
where
|
||||||
F: FnOnce(Result<gst::Sample, glib::Error>) + Send + 'static,
|
F: FnOnce(Result<gst::Sample, glib::Error>) + Send + 'static,
|
||||||
{
|
{
|
||||||
let _: Box<Option<Box<F>>> = Box::from_raw(user_data as *mut _);
|
let _: Box<Option<F>> = Box::from_raw(user_data as *mut _);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let user_data: Box<Option<Box<F>>> = Box::new(Some(Box::new(func)));
|
let user_data: Box<Option<F>> = Box::new(Some(func));
|
||||||
|
|
||||||
ffi::gst_video_convert_sample_async(
|
ffi::gst_video_convert_sample_async(
|
||||||
sample.to_glib_none().0,
|
sample.to_glib_none().0,
|
||||||
|
|
|
@ -20,36 +20,39 @@ use Bus;
|
||||||
use BusSyncReply;
|
use BusSyncReply;
|
||||||
use Message;
|
use Message;
|
||||||
|
|
||||||
unsafe extern "C" fn trampoline_watch(
|
unsafe extern "C" fn trampoline_watch<F: FnMut(&Bus, &Message) -> Continue + Send + 'static>(
|
||||||
bus: *mut ffi::GstBus,
|
bus: *mut ffi::GstBus,
|
||||||
msg: *mut ffi::GstMessage,
|
msg: *mut ffi::GstMessage,
|
||||||
func: gpointer,
|
func: gpointer,
|
||||||
) -> gboolean {
|
) -> gboolean {
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
||||||
let func: &RefCell<Box<FnMut(&Bus, &Message) -> Continue + Send + 'static>> = transmute(func);
|
let func: &RefCell<F> = transmute(func);
|
||||||
(&mut *func.borrow_mut())(&from_glib_borrow(bus), &Message::from_glib_borrow(msg)).to_glib()
|
(&mut *func.borrow_mut())(&from_glib_borrow(bus), &Message::from_glib_borrow(msg)).to_glib()
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn destroy_closure_watch(ptr: gpointer) {
|
unsafe extern "C" fn destroy_closure_watch<
|
||||||
Box::<RefCell<Box<FnMut(&Bus, &Message) -> Continue + Send + 'static>>>::from_raw(
|
F: FnMut(&Bus, &Message) -> Continue + Send + 'static,
|
||||||
ptr as *mut _,
|
>(
|
||||||
);
|
ptr: gpointer,
|
||||||
|
) {
|
||||||
|
Box::<RefCell<F>>::from_raw(ptr as *mut _);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn into_raw_watch<F: FnMut(&Bus, &Message) -> Continue + Send + 'static>(func: F) -> gpointer {
|
fn into_raw_watch<F: FnMut(&Bus, &Message) -> Continue + Send + 'static>(func: F) -> gpointer {
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
|
#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
|
||||||
let func: Box<RefCell<Box<FnMut(&Bus, &Message) -> Continue + Send + 'static>>> =
|
let func: Box<RefCell<F>> = Box::new(RefCell::new(func));
|
||||||
Box::new(RefCell::new(Box::new(func)));
|
|
||||||
Box::into_raw(func) as gpointer
|
Box::into_raw(func) as gpointer
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn trampoline_sync(
|
unsafe extern "C" fn trampoline_sync<
|
||||||
|
F: Fn(&Bus, &Message) -> BusSyncReply + Send + Sync + 'static,
|
||||||
|
>(
|
||||||
bus: *mut ffi::GstBus,
|
bus: *mut ffi::GstBus,
|
||||||
msg: *mut ffi::GstMessage,
|
msg: *mut ffi::GstMessage,
|
||||||
func: gpointer,
|
func: gpointer,
|
||||||
) -> ffi::GstBusSyncReply {
|
) -> ffi::GstBusSyncReply {
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
||||||
let f: &&(Fn(&Bus, &Message) -> BusSyncReply + Send + Sync + 'static) = transmute(func);
|
let f: &F = transmute(func);
|
||||||
let res = f(&from_glib_borrow(bus), &Message::from_glib_borrow(msg)).to_glib();
|
let res = f(&from_glib_borrow(bus), &Message::from_glib_borrow(msg)).to_glib();
|
||||||
|
|
||||||
if res == ffi::GST_BUS_DROP {
|
if res == ffi::GST_BUS_DROP {
|
||||||
|
@ -59,15 +62,18 @@ unsafe extern "C" fn trampoline_sync(
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn destroy_closure_sync(ptr: gpointer) {
|
unsafe extern "C" fn destroy_closure_sync<
|
||||||
Box::<Box<Fn(&Bus, &Message) -> BusSyncReply + Send + Sync + 'static>>::from_raw(ptr as *mut _);
|
F: Fn(&Bus, &Message) -> BusSyncReply + Send + Sync + 'static,
|
||||||
|
>(
|
||||||
|
ptr: gpointer,
|
||||||
|
) {
|
||||||
|
Box::<F>::from_raw(ptr as *mut _);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn into_raw_sync<F: Fn(&Bus, &Message) -> BusSyncReply + Send + Sync + 'static>(
|
fn into_raw_sync<F: Fn(&Bus, &Message) -> BusSyncReply + Send + Sync + 'static>(
|
||||||
func: F,
|
func: F,
|
||||||
) -> gpointer {
|
) -> gpointer {
|
||||||
let func: Box<Box<Fn(&Bus, &Message) -> BusSyncReply + Send + Sync + 'static>> =
|
let func: Box<F> = Box::new(func);
|
||||||
Box::new(Box::new(func));
|
|
||||||
Box::into_raw(func) as gpointer
|
Box::into_raw(func) as gpointer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,12 +96,11 @@ impl Bus {
|
||||||
skip_assert_initialized!();
|
skip_assert_initialized!();
|
||||||
unsafe {
|
unsafe {
|
||||||
let source = ffi::gst_bus_create_watch(self.to_glib_none().0);
|
let source = ffi::gst_bus_create_watch(self.to_glib_none().0);
|
||||||
let trampoline = trampoline_watch as gpointer;
|
|
||||||
glib_ffi::g_source_set_callback(
|
glib_ffi::g_source_set_callback(
|
||||||
source,
|
source,
|
||||||
Some(transmute(trampoline)),
|
Some(transmute(trampoline_watch::<F> as usize)),
|
||||||
into_raw_watch(func),
|
into_raw_watch(func),
|
||||||
Some(destroy_closure_watch),
|
Some(destroy_closure_watch::<F>),
|
||||||
);
|
);
|
||||||
glib_ffi::g_source_set_priority(source, priority.to_glib());
|
glib_ffi::g_source_set_priority(source, priority.to_glib());
|
||||||
|
|
||||||
|
@ -116,9 +121,9 @@ impl Bus {
|
||||||
from_glib(ffi::gst_bus_add_watch_full(
|
from_glib(ffi::gst_bus_add_watch_full(
|
||||||
self.to_glib_none().0,
|
self.to_glib_none().0,
|
||||||
glib_ffi::G_PRIORITY_DEFAULT,
|
glib_ffi::G_PRIORITY_DEFAULT,
|
||||||
Some(trampoline_watch),
|
Some(trampoline_watch::<F>),
|
||||||
into_raw_watch(func),
|
into_raw_watch(func),
|
||||||
Some(destroy_closure_watch),
|
Some(destroy_closure_watch::<F>),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,9 +135,9 @@ impl Bus {
|
||||||
unsafe {
|
unsafe {
|
||||||
ffi::gst_bus_set_sync_handler(
|
ffi::gst_bus_set_sync_handler(
|
||||||
self.to_glib_none().0,
|
self.to_glib_none().0,
|
||||||
Some(trampoline_sync),
|
Some(trampoline_sync::<F>),
|
||||||
into_raw_sync(func),
|
into_raw_sync(func),
|
||||||
Some(destroy_closure_sync),
|
Some(destroy_closure_sync::<F>),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,14 +33,14 @@ glib_wrapper! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn trampoline_wait_async(
|
unsafe extern "C" fn trampoline_wait_async<F: Fn(&Clock, ClockTime, &ClockId) + Send + 'static>(
|
||||||
clock: *mut ffi::GstClock,
|
clock: *mut ffi::GstClock,
|
||||||
time: ffi::GstClockTime,
|
time: ffi::GstClockTime,
|
||||||
id: gpointer,
|
id: gpointer,
|
||||||
func: gpointer,
|
func: gpointer,
|
||||||
) -> gboolean {
|
) -> gboolean {
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
||||||
let f: &&(Fn(&Clock, ClockTime, &ClockId) + Send + 'static) = transmute(func);
|
let f: &F = transmute(func);
|
||||||
f(
|
f(
|
||||||
&from_glib_borrow(clock),
|
&from_glib_borrow(clock),
|
||||||
from_glib(time),
|
from_glib(time),
|
||||||
|
@ -49,13 +49,17 @@ unsafe extern "C" fn trampoline_wait_async(
|
||||||
glib_ffi::GTRUE
|
glib_ffi::GTRUE
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn destroy_closure_wait_async(ptr: gpointer) {
|
unsafe extern "C" fn destroy_closure_wait_async<
|
||||||
Box::<Box<Fn(&Clock, ClockTime, &ClockId) + Send + 'static>>::from_raw(ptr as *mut _);
|
F: Fn(&Clock, ClockTime, &ClockId) + Send + 'static,
|
||||||
|
>(
|
||||||
|
ptr: gpointer,
|
||||||
|
) {
|
||||||
|
Box::<F>::from_raw(ptr as *mut _);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn into_raw_wait_async<F: Fn(&Clock, ClockTime, &ClockId) + Send + 'static>(func: F) -> gpointer {
|
fn into_raw_wait_async<F: Fn(&Clock, ClockTime, &ClockId) + Send + 'static>(func: F) -> gpointer {
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
|
#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
|
||||||
let func: Box<Box<Fn(&Clock, ClockTime, &ClockId) + Send + 'static>> = Box::new(Box::new(func));
|
let func: Box<F> = Box::new(func);
|
||||||
Box::into_raw(func) as gpointer
|
Box::into_raw(func) as gpointer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,9 +88,9 @@ impl ClockId {
|
||||||
let ret: ClockReturn = unsafe {
|
let ret: ClockReturn = unsafe {
|
||||||
from_glib(ffi::gst_clock_id_wait_async(
|
from_glib(ffi::gst_clock_id_wait_async(
|
||||||
self.to_glib_none().0,
|
self.to_glib_none().0,
|
||||||
Some(trampoline_wait_async),
|
Some(trampoline_wait_async::<F>),
|
||||||
into_raw_wait_async(func),
|
into_raw_wait_async(func),
|
||||||
Some(destroy_closure_wait_async),
|
Some(destroy_closure_wait_async::<F>),
|
||||||
))
|
))
|
||||||
};
|
};
|
||||||
ret.into_result()
|
ret.into_result()
|
||||||
|
|
|
@ -652,13 +652,13 @@ impl<O: IsA<Element>> ElementExtManual for O {
|
||||||
where
|
where
|
||||||
F: FnOnce(&Self) + Send + 'static,
|
F: FnOnce(&Self) + Send + 'static,
|
||||||
{
|
{
|
||||||
let user_data: Box<Option<Box<F>>> = Box::new(Some(Box::new(func)));
|
let user_data: Box<Option<F>> = Box::new(Some(func));
|
||||||
|
|
||||||
unsafe extern "C" fn trampoline<O: IsA<Element>, F: FnOnce(&O) + Send + 'static>(
|
unsafe extern "C" fn trampoline<O: IsA<Element>, F: FnOnce(&O) + Send + 'static>(
|
||||||
element: *mut ffi::GstElement,
|
element: *mut ffi::GstElement,
|
||||||
user_data: glib_ffi::gpointer,
|
user_data: glib_ffi::gpointer,
|
||||||
) {
|
) {
|
||||||
let user_data: &mut Option<Box<F>> = &mut *(user_data as *mut _);
|
let user_data: &mut Option<F> = &mut *(user_data as *mut _);
|
||||||
let callback = user_data.take().unwrap();
|
let callback = user_data.take().unwrap();
|
||||||
|
|
||||||
callback(&Element::from_glib_borrow(element).unsafe_cast());
|
callback(&Element::from_glib_borrow(element).unsafe_cast());
|
||||||
|
@ -667,17 +667,15 @@ impl<O: IsA<Element>> ElementExtManual for O {
|
||||||
unsafe extern "C" fn free_user_data<O: IsA<Element>, F: FnOnce(&O) + Send + 'static>(
|
unsafe extern "C" fn free_user_data<O: IsA<Element>, F: FnOnce(&O) + Send + 'static>(
|
||||||
user_data: glib_ffi::gpointer,
|
user_data: glib_ffi::gpointer,
|
||||||
) {
|
) {
|
||||||
let _: Box<Option<Box<F>>> = Box::from_raw(user_data as *mut _);
|
let _: Box<Option<F>> = Box::from_raw(user_data as *mut _);
|
||||||
}
|
}
|
||||||
|
|
||||||
let trampoline = trampoline::<Self, F>;
|
|
||||||
let free_user_data = free_user_data::<Self, F>;
|
|
||||||
unsafe {
|
unsafe {
|
||||||
ffi::gst_element_call_async(
|
ffi::gst_element_call_async(
|
||||||
self.as_ref().to_glib_none().0,
|
self.as_ref().to_glib_none().0,
|
||||||
Some(trampoline),
|
Some(trampoline::<Self, F>),
|
||||||
Box::into_raw(user_data) as *mut _,
|
Box::into_raw(user_data) as *mut _,
|
||||||
Some(free_user_data),
|
Some(free_user_data::<Self, F>),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,12 +90,7 @@ where
|
||||||
mem::forget(self);
|
mem::forget(self);
|
||||||
|
|
||||||
let func_box: Box<Fn(T) -> bool + Send + Sync + 'static> = Box::new(func);
|
let func_box: Box<Fn(T) -> bool + Send + Sync + 'static> = Box::new(func);
|
||||||
// FIXME: Use Value::from_type once we depend on new enough GLib
|
let mut closure_value = glib::Value::from_type(from_glib(filter_boxed_get_type::<T>()));
|
||||||
let mut closure_value = glib::Value::uninitialized();
|
|
||||||
gobject_ffi::g_value_init(
|
|
||||||
closure_value.to_glib_none_mut().0,
|
|
||||||
filter_boxed_get_type::<T>(),
|
|
||||||
);
|
|
||||||
gobject_ffi::g_value_set_boxed(
|
gobject_ffi::g_value_set_boxed(
|
||||||
closure_value.to_glib_none_mut().0,
|
closure_value.to_glib_none_mut().0,
|
||||||
Arc::into_raw(Arc::new(func_box)) as gpointer,
|
Arc::into_raw(Arc::new(func_box)) as gpointer,
|
||||||
|
@ -117,12 +112,11 @@ where
|
||||||
let mut elem = glib::Value::uninitialized();
|
let mut elem = glib::Value::uninitialized();
|
||||||
|
|
||||||
let mut func = func;
|
let mut func = func;
|
||||||
let func_obj: &mut (FnMut(T) -> bool) = &mut func;
|
let func_ptr = &mut func as *mut F as gpointer;
|
||||||
let func_ptr = &func_obj as *const &mut (FnMut(T) -> bool) as gpointer;
|
|
||||||
|
|
||||||
let res = from_glib(ffi::gst_iterator_find_custom(
|
let res = from_glib(ffi::gst_iterator_find_custom(
|
||||||
self.to_glib_none_mut().0,
|
self.to_glib_none_mut().0,
|
||||||
Some(find_trampoline::<T>),
|
Some(find_trampoline::<T, F>),
|
||||||
elem.to_glib_none_mut().0,
|
elem.to_glib_none_mut().0,
|
||||||
func_ptr,
|
func_ptr,
|
||||||
));
|
));
|
||||||
|
@ -140,12 +134,11 @@ where
|
||||||
{
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut func = func;
|
let mut func = func;
|
||||||
let func_obj: &mut (FnMut(T)) = &mut func;
|
let func_ptr = &mut func as *mut F as gpointer;
|
||||||
let func_ptr = &func_obj as *const &mut (FnMut(T)) as gpointer;
|
|
||||||
|
|
||||||
let res = ffi::gst_iterator_foreach(
|
let res = ffi::gst_iterator_foreach(
|
||||||
self.to_glib_none_mut().0,
|
self.to_glib_none_mut().0,
|
||||||
Some(foreach_trampoline::<T>),
|
Some(foreach_trampoline::<T, F>),
|
||||||
func_ptr,
|
func_ptr,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -163,13 +156,10 @@ where
|
||||||
{
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut func = func;
|
let mut func = func;
|
||||||
let func_obj: &mut (FnMut(U, T) -> Result<U, U>) = &mut func;
|
let func_ptr = &mut func as *mut F as gpointer;
|
||||||
let func_ptr = &func_obj as *const &mut (FnMut(U, T) -> Result<U, U>) as gpointer;
|
|
||||||
|
|
||||||
let mut accum = Some(init);
|
let mut accum = Some(init);
|
||||||
// FIXME: Use Value::from_type once we depend on new enough GLib
|
let mut ret = glib::Value::from_type(glib::Type::Pointer);
|
||||||
let mut ret = glib::Value::uninitialized();
|
|
||||||
gobject_ffi::g_value_init(ret.to_glib_none_mut().0, gobject_ffi::G_TYPE_POINTER);
|
|
||||||
gobject_ffi::g_value_set_pointer(
|
gobject_ffi::g_value_set_pointer(
|
||||||
ret.to_glib_none_mut().0,
|
ret.to_glib_none_mut().0,
|
||||||
&mut accum as *mut _ as gpointer,
|
&mut accum as *mut _ as gpointer,
|
||||||
|
@ -177,7 +167,7 @@ where
|
||||||
|
|
||||||
let res = ffi::gst_iterator_fold(
|
let res = ffi::gst_iterator_fold(
|
||||||
self.to_glib_none_mut().0,
|
self.to_glib_none_mut().0,
|
||||||
Some(fold_trampoline::<T, U>),
|
Some(fold_trampoline::<T, U, F>),
|
||||||
ret.to_glib_none_mut().0,
|
ret.to_glib_none_mut().0,
|
||||||
func_ptr,
|
func_ptr,
|
||||||
);
|
);
|
||||||
|
@ -405,13 +395,16 @@ unsafe extern "C" fn filter_boxed_get_type<T: StaticType + 'static>() -> glib_ff
|
||||||
TYPE
|
TYPE
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn find_trampoline<T>(value: gconstpointer, func: gconstpointer) -> i32
|
unsafe extern "C" fn find_trampoline<T, F: FnMut(T) -> bool>(
|
||||||
|
value: gconstpointer,
|
||||||
|
func: gconstpointer,
|
||||||
|
) -> i32
|
||||||
where
|
where
|
||||||
for<'a> T: FromValueOptional<'a> + 'static,
|
for<'a> T: FromValueOptional<'a> + 'static,
|
||||||
{
|
{
|
||||||
let value = value as *const gobject_ffi::GValue;
|
let value = value as *const gobject_ffi::GValue;
|
||||||
|
|
||||||
let func = func as *mut &mut (FnMut(T) -> bool);
|
let func = func as *mut F;
|
||||||
let value = &*(value as *const glib::Value);
|
let value = &*(value as *const glib::Value);
|
||||||
let value = value.get::<T>().unwrap();
|
let value = value.get::<T>().unwrap();
|
||||||
|
|
||||||
|
@ -422,18 +415,20 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn foreach_trampoline<T>(value: *const gobject_ffi::GValue, func: gpointer)
|
unsafe extern "C" fn foreach_trampoline<T, F: FnMut(T)>(
|
||||||
where
|
value: *const gobject_ffi::GValue,
|
||||||
|
func: gpointer,
|
||||||
|
) where
|
||||||
for<'a> T: FromValueOptional<'a> + 'static,
|
for<'a> T: FromValueOptional<'a> + 'static,
|
||||||
{
|
{
|
||||||
let func = func as *mut &mut (FnMut(T));
|
let func = func as *mut F;
|
||||||
let value = &*(value as *const glib::Value);
|
let value = &*(value as *const glib::Value);
|
||||||
let value = value.get::<T>().unwrap();
|
let value = value.get::<T>().unwrap();
|
||||||
|
|
||||||
(*func)(value);
|
(*func)(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn fold_trampoline<T, U>(
|
unsafe extern "C" fn fold_trampoline<T, U, F: FnMut(U, T) -> Result<U, U>>(
|
||||||
value: *const gobject_ffi::GValue,
|
value: *const gobject_ffi::GValue,
|
||||||
ret: *mut gobject_ffi::GValue,
|
ret: *mut gobject_ffi::GValue,
|
||||||
func: gpointer,
|
func: gpointer,
|
||||||
|
@ -441,7 +436,7 @@ unsafe extern "C" fn fold_trampoline<T, U>(
|
||||||
where
|
where
|
||||||
for<'a> T: FromValueOptional<'a> + 'static,
|
for<'a> T: FromValueOptional<'a> + 'static,
|
||||||
{
|
{
|
||||||
let func = func as *mut &mut (FnMut(U, T) -> Result<U, U>);
|
let func = func as *mut F;
|
||||||
let value = &*(value as *const glib::Value);
|
let value = &*(value as *const glib::Value);
|
||||||
let value = value.get::<T>().unwrap();
|
let value = value.get::<T>().unwrap();
|
||||||
|
|
||||||
|
|
|
@ -35,10 +35,10 @@ use std::mem::transmute;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
||||||
use glib;
|
use glib;
|
||||||
use glib::object::IsA;
|
use glib::object::{Cast, IsA};
|
||||||
use glib::translate::{
|
use glib::translate::{
|
||||||
from_glib, from_glib_borrow, from_glib_full, from_glib_none, mut_override, FromGlib, ToGlib,
|
from_glib, from_glib_borrow, from_glib_full, from_glib_none, mut_override, FromGlib,
|
||||||
ToGlibPtr,
|
FromGlibPtrBorrow, ToGlib, ToGlibPtr,
|
||||||
};
|
};
|
||||||
use glib::StaticType;
|
use glib::StaticType;
|
||||||
use glib_ffi;
|
use glib_ffi;
|
||||||
|
@ -116,7 +116,7 @@ impl Drop for StreamLock {
|
||||||
pub trait PadExtManual: 'static {
|
pub trait PadExtManual: 'static {
|
||||||
fn add_probe<F>(&self, mask: PadProbeType, func: F) -> Option<PadProbeId>
|
fn add_probe<F>(&self, mask: PadProbeType, func: F) -> Option<PadProbeId>
|
||||||
where
|
where
|
||||||
F: Fn(&Pad, &mut PadProbeInfo) -> PadProbeReturn + Send + Sync + 'static;
|
F: Fn(&Self, &mut PadProbeInfo) -> PadProbeReturn + Send + Sync + 'static;
|
||||||
fn remove_probe(&self, id: PadProbeId);
|
fn remove_probe(&self, id: PadProbeId);
|
||||||
|
|
||||||
fn chain(&self, buffer: Buffer) -> Result<FlowSuccess, FlowError>;
|
fn chain(&self, buffer: Buffer) -> Result<FlowSuccess, FlowError>;
|
||||||
|
@ -165,65 +165,65 @@ pub trait PadExtManual: 'static {
|
||||||
|
|
||||||
fn set_activate_function<F>(&self, func: F)
|
fn set_activate_function<F>(&self, func: F)
|
||||||
where
|
where
|
||||||
F: Fn(&Pad, &Option<::Object>) -> Result<(), LoggableError> + Send + Sync + 'static;
|
F: Fn(&Self, &Option<::Object>) -> Result<(), LoggableError> + Send + Sync + 'static;
|
||||||
|
|
||||||
fn set_activatemode_function<F>(&self, func: F)
|
fn set_activatemode_function<F>(&self, func: F)
|
||||||
where
|
where
|
||||||
F: Fn(&Pad, &Option<::Object>, ::PadMode, bool) -> Result<(), LoggableError>
|
F: Fn(&Self, &Option<::Object>, ::PadMode, bool) -> Result<(), LoggableError>
|
||||||
+ Send
|
+ Send
|
||||||
+ Sync
|
+ Sync
|
||||||
+ 'static;
|
+ 'static;
|
||||||
|
|
||||||
fn set_chain_function<F>(&self, func: F)
|
fn set_chain_function<F>(&self, func: F)
|
||||||
where
|
where
|
||||||
F: Fn(&Pad, &Option<::Object>, ::Buffer) -> Result<FlowSuccess, FlowError>
|
F: Fn(&Self, &Option<::Object>, ::Buffer) -> Result<FlowSuccess, FlowError>
|
||||||
+ Send
|
+ Send
|
||||||
+ Sync
|
+ Sync
|
||||||
+ 'static;
|
+ 'static;
|
||||||
|
|
||||||
fn set_chain_list_function<F>(&self, func: F)
|
fn set_chain_list_function<F>(&self, func: F)
|
||||||
where
|
where
|
||||||
F: Fn(&Pad, &Option<::Object>, ::BufferList) -> Result<FlowSuccess, FlowError>
|
F: Fn(&Self, &Option<::Object>, ::BufferList) -> Result<FlowSuccess, FlowError>
|
||||||
+ Send
|
+ Send
|
||||||
+ Sync
|
+ Sync
|
||||||
+ 'static;
|
+ 'static;
|
||||||
|
|
||||||
fn set_event_function<F>(&self, func: F)
|
fn set_event_function<F>(&self, func: F)
|
||||||
where
|
where
|
||||||
F: Fn(&Pad, &Option<::Object>, ::Event) -> bool + Send + Sync + 'static;
|
F: Fn(&Self, &Option<::Object>, ::Event) -> bool + Send + Sync + 'static;
|
||||||
|
|
||||||
fn set_event_full_function<F>(&self, func: F)
|
fn set_event_full_function<F>(&self, func: F)
|
||||||
where
|
where
|
||||||
F: Fn(&Pad, &Option<::Object>, ::Event) -> Result<FlowSuccess, FlowError>
|
F: Fn(&Self, &Option<::Object>, ::Event) -> Result<FlowSuccess, FlowError>
|
||||||
+ Send
|
+ Send
|
||||||
+ Sync
|
+ Sync
|
||||||
+ 'static;
|
+ 'static;
|
||||||
|
|
||||||
fn set_getrange_function<F>(&self, func: F)
|
fn set_getrange_function<F>(&self, func: F)
|
||||||
where
|
where
|
||||||
F: Fn(&Pad, &Option<::Object>, u64, u32) -> Result<::Buffer, ::FlowError>
|
F: Fn(&Self, &Option<::Object>, u64, u32) -> Result<::Buffer, ::FlowError>
|
||||||
+ Send
|
+ Send
|
||||||
+ Sync
|
+ Sync
|
||||||
+ 'static;
|
+ 'static;
|
||||||
|
|
||||||
fn set_iterate_internal_links_function<F>(&self, func: F)
|
fn set_iterate_internal_links_function<F>(&self, func: F)
|
||||||
where
|
where
|
||||||
F: Fn(&Pad, &Option<::Object>) -> ::Iterator<Pad> + Send + Sync + 'static;
|
F: Fn(&Self, &Option<::Object>) -> ::Iterator<Pad> + Send + Sync + 'static;
|
||||||
|
|
||||||
fn set_link_function<F>(&self, func: F)
|
fn set_link_function<F>(&self, func: F)
|
||||||
where
|
where
|
||||||
F: Fn(&Pad, &Option<::Object>, &Pad) -> Result<::PadLinkSuccess, ::PadLinkError>
|
F: Fn(&Self, &Option<::Object>, &Pad) -> Result<::PadLinkSuccess, ::PadLinkError>
|
||||||
+ Send
|
+ Send
|
||||||
+ Sync
|
+ Sync
|
||||||
+ 'static;
|
+ 'static;
|
||||||
|
|
||||||
fn set_query_function<F>(&self, func: F)
|
fn set_query_function<F>(&self, func: F)
|
||||||
where
|
where
|
||||||
F: Fn(&Pad, &Option<::Object>, &mut ::QueryRef) -> bool + Send + Sync + 'static;
|
F: Fn(&Self, &Option<::Object>, &mut ::QueryRef) -> bool + Send + Sync + 'static;
|
||||||
|
|
||||||
fn set_unlink_function<F>(&self, func: F)
|
fn set_unlink_function<F>(&self, func: F)
|
||||||
where
|
where
|
||||||
F: Fn(&Pad, &Option<::Object>) + Send + Sync + 'static;
|
F: Fn(&Self, &Option<::Object>) + Send + Sync + 'static;
|
||||||
|
|
||||||
fn start_task<F: FnMut() + Send + 'static>(&self, func: F) -> Result<(), glib::BoolError>;
|
fn start_task<F: FnMut() + Send + 'static>(&self, func: F) -> Result<(), glib::BoolError>;
|
||||||
|
|
||||||
|
@ -272,18 +272,16 @@ pub trait PadExtManual: 'static {
|
||||||
impl<O: IsA<Pad>> PadExtManual for O {
|
impl<O: IsA<Pad>> PadExtManual for O {
|
||||||
fn add_probe<F>(&self, mask: PadProbeType, func: F) -> Option<PadProbeId>
|
fn add_probe<F>(&self, mask: PadProbeType, func: F) -> Option<PadProbeId>
|
||||||
where
|
where
|
||||||
F: Fn(&Pad, &mut PadProbeInfo) -> PadProbeReturn + Send + Sync + 'static,
|
F: Fn(&Self, &mut PadProbeInfo) -> PadProbeReturn + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
let func_box: Box<
|
let func_box: Box<F> = Box::new(func);
|
||||||
Fn(&Pad, &mut PadProbeInfo) -> PadProbeReturn + Send + Sync + 'static,
|
|
||||||
> = Box::new(func);
|
|
||||||
let id = ffi::gst_pad_add_probe(
|
let id = ffi::gst_pad_add_probe(
|
||||||
self.as_ref().to_glib_none().0,
|
self.as_ref().to_glib_none().0,
|
||||||
mask.to_glib(),
|
mask.to_glib(),
|
||||||
Some(trampoline_pad_probe),
|
Some(trampoline_pad_probe::<Self, F>),
|
||||||
Box::into_raw(Box::new(func_box)) as gpointer,
|
Box::into_raw(func_box) as gpointer,
|
||||||
Some(destroy_closure),
|
Some(destroy_closure::<F>),
|
||||||
);
|
);
|
||||||
|
|
||||||
if id == 0 {
|
if id == 0 {
|
||||||
|
@ -517,224 +515,185 @@ impl<O: IsA<Pad>> PadExtManual for O {
|
||||||
|
|
||||||
fn set_activate_function<F>(&self, func: F)
|
fn set_activate_function<F>(&self, func: F)
|
||||||
where
|
where
|
||||||
F: Fn(&Pad, &Option<::Object>) -> Result<(), LoggableError> + Send + Sync + 'static,
|
F: Fn(&Self, &Option<::Object>) -> Result<(), LoggableError> + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
|
#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
|
||||||
unsafe {
|
unsafe {
|
||||||
let func_box: Box<
|
let func_box: Box<F> = Box::new(func);
|
||||||
Fn(&Pad, &Option<::Object>) -> Result<(), LoggableError> + Send + Sync + 'static,
|
|
||||||
> = Box::new(func);
|
|
||||||
ffi::gst_pad_set_activate_function_full(
|
ffi::gst_pad_set_activate_function_full(
|
||||||
self.as_ref().to_glib_none().0,
|
self.as_ref().to_glib_none().0,
|
||||||
Some(trampoline_activate_function),
|
Some(trampoline_activate_function::<Self, F>),
|
||||||
Box::into_raw(Box::new(func_box)) as gpointer,
|
Box::into_raw(func_box) as gpointer,
|
||||||
Some(destroy_closure),
|
Some(destroy_closure::<F>),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_activatemode_function<F>(&self, func: F)
|
fn set_activatemode_function<F>(&self, func: F)
|
||||||
where
|
where
|
||||||
F: Fn(&Pad, &Option<::Object>, ::PadMode, bool) -> Result<(), LoggableError>
|
F: Fn(&Self, &Option<::Object>, ::PadMode, bool) -> Result<(), LoggableError>
|
||||||
+ Send
|
+ Send
|
||||||
+ Sync
|
+ Sync
|
||||||
+ 'static,
|
+ 'static,
|
||||||
{
|
{
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
|
#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
|
||||||
unsafe {
|
unsafe {
|
||||||
let func_box: Box<
|
let func_box: Box<F> = Box::new(func);
|
||||||
Fn(&Pad, &Option<::Object>, ::PadMode, bool) -> Result<(), LoggableError>
|
|
||||||
+ Send
|
|
||||||
+ Sync
|
|
||||||
+ 'static,
|
|
||||||
> = Box::new(func);
|
|
||||||
ffi::gst_pad_set_activatemode_function_full(
|
ffi::gst_pad_set_activatemode_function_full(
|
||||||
self.as_ref().to_glib_none().0,
|
self.as_ref().to_glib_none().0,
|
||||||
Some(trampoline_activatemode_function),
|
Some(trampoline_activatemode_function::<Self, F>),
|
||||||
Box::into_raw(Box::new(func_box)) as gpointer,
|
Box::into_raw(func_box) as gpointer,
|
||||||
Some(destroy_closure),
|
Some(destroy_closure::<F>),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_chain_function<F>(&self, func: F)
|
fn set_chain_function<F>(&self, func: F)
|
||||||
where
|
where
|
||||||
F: Fn(&Pad, &Option<::Object>, ::Buffer) -> Result<FlowSuccess, FlowError>
|
F: Fn(&Self, &Option<::Object>, ::Buffer) -> Result<FlowSuccess, FlowError>
|
||||||
+ Send
|
+ Send
|
||||||
+ Sync
|
+ Sync
|
||||||
+ 'static,
|
+ 'static,
|
||||||
{
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
let func_box: Box<
|
let func_box: Box<F> = Box::new(func);
|
||||||
Fn(&Pad, &Option<::Object>, ::Buffer) -> Result<FlowSuccess, FlowError>
|
|
||||||
+ Send
|
|
||||||
+ Sync
|
|
||||||
+ 'static,
|
|
||||||
> = Box::new(func);
|
|
||||||
ffi::gst_pad_set_chain_function_full(
|
ffi::gst_pad_set_chain_function_full(
|
||||||
self.as_ref().to_glib_none().0,
|
self.as_ref().to_glib_none().0,
|
||||||
Some(trampoline_chain_function),
|
Some(trampoline_chain_function::<Self, F>),
|
||||||
Box::into_raw(Box::new(func_box)) as gpointer,
|
Box::into_raw(func_box) as gpointer,
|
||||||
Some(destroy_closure),
|
Some(destroy_closure::<F>),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_chain_list_function<F>(&self, func: F)
|
fn set_chain_list_function<F>(&self, func: F)
|
||||||
where
|
where
|
||||||
F: Fn(&Pad, &Option<::Object>, ::BufferList) -> Result<FlowSuccess, FlowError>
|
F: Fn(&Self, &Option<::Object>, ::BufferList) -> Result<FlowSuccess, FlowError>
|
||||||
+ Send
|
+ Send
|
||||||
+ Sync
|
+ Sync
|
||||||
+ 'static,
|
+ 'static,
|
||||||
{
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
let func_box: Box<
|
let func_box: Box<F> = Box::new(func);
|
||||||
Fn(&Pad, &Option<::Object>, ::BufferList) -> Result<FlowSuccess, FlowError>
|
|
||||||
+ Send
|
|
||||||
+ Sync
|
|
||||||
+ 'static,
|
|
||||||
> = Box::new(func);
|
|
||||||
ffi::gst_pad_set_chain_list_function_full(
|
ffi::gst_pad_set_chain_list_function_full(
|
||||||
self.as_ref().to_glib_none().0,
|
self.as_ref().to_glib_none().0,
|
||||||
Some(trampoline_chain_list_function),
|
Some(trampoline_chain_list_function::<Self, F>),
|
||||||
Box::into_raw(Box::new(func_box)) as gpointer,
|
Box::into_raw(func_box) as gpointer,
|
||||||
Some(destroy_closure),
|
Some(destroy_closure::<F>),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_event_function<F>(&self, func: F)
|
fn set_event_function<F>(&self, func: F)
|
||||||
where
|
where
|
||||||
F: Fn(&Pad, &Option<::Object>, ::Event) -> bool + Send + Sync + 'static,
|
F: Fn(&Self, &Option<::Object>, ::Event) -> bool + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
let func_box: Box<
|
let func_box: Box<F> = Box::new(func);
|
||||||
Fn(&Pad, &Option<::Object>, ::Event) -> bool + Send + Sync + 'static,
|
|
||||||
> = Box::new(func);
|
|
||||||
ffi::gst_pad_set_event_function_full(
|
ffi::gst_pad_set_event_function_full(
|
||||||
self.as_ref().to_glib_none().0,
|
self.as_ref().to_glib_none().0,
|
||||||
Some(trampoline_event_function),
|
Some(trampoline_event_function::<Self, F>),
|
||||||
Box::into_raw(Box::new(func_box)) as gpointer,
|
Box::into_raw(func_box) as gpointer,
|
||||||
Some(destroy_closure),
|
Some(destroy_closure::<F>),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_event_full_function<F>(&self, func: F)
|
fn set_event_full_function<F>(&self, func: F)
|
||||||
where
|
where
|
||||||
F: Fn(&Pad, &Option<::Object>, ::Event) -> Result<FlowSuccess, FlowError>
|
F: Fn(&Self, &Option<::Object>, ::Event) -> Result<FlowSuccess, FlowError>
|
||||||
+ Send
|
+ Send
|
||||||
+ Sync
|
+ Sync
|
||||||
+ 'static,
|
+ 'static,
|
||||||
{
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
let func_box: Box<
|
let func_box: Box<F> = Box::new(func);
|
||||||
Fn(&Pad, &Option<::Object>, ::Event) -> Result<FlowSuccess, FlowError>
|
|
||||||
+ Send
|
|
||||||
+ Sync
|
|
||||||
+ 'static,
|
|
||||||
> = Box::new(func);
|
|
||||||
ffi::gst_pad_set_event_full_function_full(
|
ffi::gst_pad_set_event_full_function_full(
|
||||||
self.as_ref().to_glib_none().0,
|
self.as_ref().to_glib_none().0,
|
||||||
Some(trampoline_event_full_function),
|
Some(trampoline_event_full_function::<Self, F>),
|
||||||
Box::into_raw(Box::new(func_box)) as gpointer,
|
Box::into_raw(func_box) as gpointer,
|
||||||
Some(destroy_closure),
|
Some(destroy_closure::<F>),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_getrange_function<F>(&self, func: F)
|
fn set_getrange_function<F>(&self, func: F)
|
||||||
where
|
where
|
||||||
F: Fn(&Pad, &Option<::Object>, u64, u32) -> Result<::Buffer, FlowError>
|
F: Fn(&Self, &Option<::Object>, u64, u32) -> Result<::Buffer, FlowError>
|
||||||
+ Send
|
+ Send
|
||||||
+ Sync
|
+ Sync
|
||||||
+ 'static,
|
+ 'static,
|
||||||
{
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
|
let func_box: Box<F> = Box::new(func);
|
||||||
let func_box: Box<
|
|
||||||
Fn(&Pad, &Option<::Object>, u64, u32) -> Result<::Buffer, FlowError>
|
|
||||||
+ Send
|
|
||||||
+ Sync
|
|
||||||
+ 'static,
|
|
||||||
> = Box::new(func);
|
|
||||||
ffi::gst_pad_set_getrange_function_full(
|
ffi::gst_pad_set_getrange_function_full(
|
||||||
self.as_ref().to_glib_none().0,
|
self.as_ref().to_glib_none().0,
|
||||||
Some(trampoline_getrange_function),
|
Some(trampoline_getrange_function::<Self, F>),
|
||||||
Box::into_raw(Box::new(func_box)) as gpointer,
|
Box::into_raw(func_box) as gpointer,
|
||||||
Some(destroy_closure),
|
Some(destroy_closure::<F>),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_iterate_internal_links_function<F>(&self, func: F)
|
fn set_iterate_internal_links_function<F>(&self, func: F)
|
||||||
where
|
where
|
||||||
F: Fn(&Pad, &Option<::Object>) -> ::Iterator<Pad> + Send + Sync + 'static,
|
F: Fn(&Self, &Option<::Object>) -> ::Iterator<Pad> + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
let func_box: Box<
|
let func_box: Box<F> = Box::new(func);
|
||||||
Fn(&Pad, &Option<::Object>) -> ::Iterator<Pad> + Send + Sync + 'static,
|
|
||||||
> = Box::new(func);
|
|
||||||
ffi::gst_pad_set_iterate_internal_links_function_full(
|
ffi::gst_pad_set_iterate_internal_links_function_full(
|
||||||
self.as_ref().to_glib_none().0,
|
self.as_ref().to_glib_none().0,
|
||||||
Some(trampoline_iterate_internal_links_function),
|
Some(trampoline_iterate_internal_links_function::<Self, F>),
|
||||||
Box::into_raw(Box::new(func_box)) as gpointer,
|
Box::into_raw(func_box) as gpointer,
|
||||||
Some(destroy_closure),
|
Some(destroy_closure::<F>),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_link_function<F>(&self, func: F)
|
fn set_link_function<F>(&self, func: F)
|
||||||
where
|
where
|
||||||
F: Fn(&Pad, &Option<::Object>, &Pad) -> Result<::PadLinkSuccess, ::PadLinkError>
|
F: Fn(&Self, &Option<::Object>, &Pad) -> Result<::PadLinkSuccess, ::PadLinkError>
|
||||||
+ Send
|
+ Send
|
||||||
+ Sync
|
+ Sync
|
||||||
+ 'static,
|
+ 'static,
|
||||||
{
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
let func_box: Box<
|
let func_box: Box<F> = Box::new(func);
|
||||||
Fn(&Pad, &Option<::Object>, &Pad) -> Result<::PadLinkSuccess, ::PadLinkError>
|
|
||||||
+ Send
|
|
||||||
+ Sync
|
|
||||||
+ 'static,
|
|
||||||
> = Box::new(func);
|
|
||||||
ffi::gst_pad_set_link_function_full(
|
ffi::gst_pad_set_link_function_full(
|
||||||
self.as_ref().to_glib_none().0,
|
self.as_ref().to_glib_none().0,
|
||||||
Some(trampoline_link_function),
|
Some(trampoline_link_function::<Self, F>),
|
||||||
Box::into_raw(Box::new(func_box)) as gpointer,
|
Box::into_raw(func_box) as gpointer,
|
||||||
Some(destroy_closure),
|
Some(destroy_closure::<F>),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_query_function<F>(&self, func: F)
|
fn set_query_function<F>(&self, func: F)
|
||||||
where
|
where
|
||||||
F: Fn(&Pad, &Option<::Object>, &mut ::QueryRef) -> bool + Send + Sync + 'static,
|
F: Fn(&Self, &Option<::Object>, &mut ::QueryRef) -> bool + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
let func_box: Box<
|
let func_box: Box<F> = Box::new(func);
|
||||||
Fn(&Pad, &Option<::Object>, &mut ::QueryRef) -> bool + Send + Sync + 'static,
|
|
||||||
> = Box::new(func);
|
|
||||||
ffi::gst_pad_set_query_function_full(
|
ffi::gst_pad_set_query_function_full(
|
||||||
self.as_ref().to_glib_none().0,
|
self.as_ref().to_glib_none().0,
|
||||||
Some(trampoline_query_function),
|
Some(trampoline_query_function::<Self, F>),
|
||||||
Box::into_raw(Box::new(func_box)) as gpointer,
|
Box::into_raw(func_box) as gpointer,
|
||||||
Some(destroy_closure),
|
Some(destroy_closure::<F>),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_unlink_function<F>(&self, func: F)
|
fn set_unlink_function<F>(&self, func: F)
|
||||||
where
|
where
|
||||||
F: Fn(&Pad, &Option<::Object>) + Send + Sync + 'static,
|
F: Fn(&Self, &Option<::Object>) + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
let func_box: Box<Fn(&Pad, &Option<::Object>) + Send + Sync + 'static> = Box::new(func);
|
let func_box: Box<F> = Box::new(func);
|
||||||
ffi::gst_pad_set_unlink_function_full(
|
ffi::gst_pad_set_unlink_function_full(
|
||||||
self.as_ref().to_glib_none().0,
|
self.as_ref().to_glib_none().0,
|
||||||
Some(trampoline_unlink_function),
|
Some(trampoline_unlink_function::<Self, F>),
|
||||||
Box::into_raw(Box::new(func_box)) as gpointer,
|
Box::into_raw(func_box) as gpointer,
|
||||||
Some(destroy_closure),
|
Some(destroy_closure::<F>),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -744,9 +703,9 @@ impl<O: IsA<Pad>> PadExtManual for O {
|
||||||
glib_result_from_gboolean!(
|
glib_result_from_gboolean!(
|
||||||
ffi::gst_pad_start_task(
|
ffi::gst_pad_start_task(
|
||||||
self.as_ref().to_glib_none().0,
|
self.as_ref().to_glib_none().0,
|
||||||
Some(trampoline_pad_task),
|
Some(trampoline_pad_task::<F>),
|
||||||
into_raw_pad_task(func),
|
into_raw_pad_task(func),
|
||||||
Some(destroy_closure_pad_task),
|
Some(destroy_closure::<F>),
|
||||||
),
|
),
|
||||||
"Failed to start pad task",
|
"Failed to start pad task",
|
||||||
)
|
)
|
||||||
|
@ -1039,14 +998,19 @@ impl<O: IsA<Pad>> PadExtManual for O {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn trampoline_pad_probe(
|
unsafe extern "C" fn trampoline_pad_probe<
|
||||||
|
T,
|
||||||
|
F: Fn(&T, &mut PadProbeInfo) -> PadProbeReturn + Send + Sync + 'static,
|
||||||
|
>(
|
||||||
pad: *mut ffi::GstPad,
|
pad: *mut ffi::GstPad,
|
||||||
info: *mut ffi::GstPadProbeInfo,
|
info: *mut ffi::GstPadProbeInfo,
|
||||||
func: gpointer,
|
func: gpointer,
|
||||||
) -> ffi::GstPadProbeReturn {
|
) -> ffi::GstPadProbeReturn
|
||||||
|
where
|
||||||
|
T: IsA<Pad>,
|
||||||
|
{
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
||||||
let func: &&(Fn(&Pad, &mut PadProbeInfo) -> PadProbeReturn + Send + Sync + 'static) =
|
let func: &F = transmute(func);
|
||||||
transmute(func);
|
|
||||||
let mut data_type = None;
|
let mut data_type = None;
|
||||||
|
|
||||||
let mut probe_info = PadProbeInfo {
|
let mut probe_info = PadProbeInfo {
|
||||||
|
@ -1085,7 +1049,7 @@ unsafe extern "C" fn trampoline_pad_probe(
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
let ret = func(&from_glib_borrow(pad), &mut probe_info).to_glib();
|
let ret = func(&Pad::from_glib_borrow(pad).unsafe_cast(), &mut probe_info).to_glib();
|
||||||
|
|
||||||
match probe_info.data {
|
match probe_info.data {
|
||||||
Some(PadProbeData::Buffer(buffer)) => {
|
Some(PadProbeData::Buffer(buffer)) => {
|
||||||
|
@ -1115,68 +1079,78 @@ unsafe extern "C" fn trampoline_pad_probe(
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn trampoline_activate_function(
|
unsafe extern "C" fn trampoline_activate_function<
|
||||||
|
T,
|
||||||
|
F: Fn(&T, &Option<::Object>) -> Result<(), LoggableError> + Send + Sync + 'static,
|
||||||
|
>(
|
||||||
pad: *mut ffi::GstPad,
|
pad: *mut ffi::GstPad,
|
||||||
parent: *mut ffi::GstObject,
|
parent: *mut ffi::GstObject,
|
||||||
) -> glib_ffi::gboolean {
|
) -> glib_ffi::gboolean
|
||||||
|
where
|
||||||
|
T: IsA<Pad>,
|
||||||
|
{
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
||||||
let func: &&(Fn(&Pad, &Option<::Object>) -> Result<(), LoggableError>
|
let func: &F = transmute((*pad).activatedata);
|
||||||
+ Send
|
|
||||||
+ Sync
|
|
||||||
+ 'static) = transmute((*pad).activatedata);
|
|
||||||
|
|
||||||
let pad: Pad = from_glib_borrow(pad);
|
match func(
|
||||||
match func(&pad, &from_glib_borrow(parent)) {
|
&Pad::from_glib_borrow(pad).unsafe_cast(),
|
||||||
|
&from_glib_borrow(parent),
|
||||||
|
) {
|
||||||
Ok(()) => true,
|
Ok(()) => true,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
err.log_with_object(&pad);
|
err.log_with_object(&Pad::from_glib_borrow(pad));
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.to_glib()
|
.to_glib()
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn trampoline_activatemode_function(
|
unsafe extern "C" fn trampoline_activatemode_function<
|
||||||
|
T,
|
||||||
|
F: Fn(&T, &Option<::Object>, ::PadMode, bool) -> Result<(), LoggableError> + Send + Sync + 'static,
|
||||||
|
>(
|
||||||
pad: *mut ffi::GstPad,
|
pad: *mut ffi::GstPad,
|
||||||
parent: *mut ffi::GstObject,
|
parent: *mut ffi::GstObject,
|
||||||
mode: ffi::GstPadMode,
|
mode: ffi::GstPadMode,
|
||||||
active: glib_ffi::gboolean,
|
active: glib_ffi::gboolean,
|
||||||
) -> glib_ffi::gboolean {
|
) -> glib_ffi::gboolean
|
||||||
|
where
|
||||||
|
T: IsA<Pad>,
|
||||||
|
{
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
||||||
let func: &&(Fn(&Pad, &Option<::Object>, ::PadMode, bool) -> Result<(), LoggableError>
|
let func: &F = transmute((*pad).activatemodedata);
|
||||||
+ Send
|
|
||||||
+ Sync
|
|
||||||
+ 'static) = transmute((*pad).activatemodedata);
|
|
||||||
|
|
||||||
let pad: Pad = from_glib_borrow(pad);
|
|
||||||
match func(
|
match func(
|
||||||
&pad,
|
&&Pad::from_glib_borrow(pad).unsafe_cast(),
|
||||||
&from_glib_borrow(parent),
|
&from_glib_borrow(parent),
|
||||||
from_glib(mode),
|
from_glib(mode),
|
||||||
from_glib(active),
|
from_glib(active),
|
||||||
) {
|
) {
|
||||||
Ok(()) => true,
|
Ok(()) => true,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
err.log_with_object(&pad);
|
err.log_with_object(&Pad::from_glib_borrow(pad));
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.to_glib()
|
.to_glib()
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn trampoline_chain_function(
|
unsafe extern "C" fn trampoline_chain_function<
|
||||||
|
T,
|
||||||
|
F: Fn(&T, &Option<::Object>, ::Buffer) -> Result<FlowSuccess, FlowError> + Send + Sync + 'static,
|
||||||
|
>(
|
||||||
pad: *mut ffi::GstPad,
|
pad: *mut ffi::GstPad,
|
||||||
parent: *mut ffi::GstObject,
|
parent: *mut ffi::GstObject,
|
||||||
buffer: *mut ffi::GstBuffer,
|
buffer: *mut ffi::GstBuffer,
|
||||||
) -> ffi::GstFlowReturn {
|
) -> ffi::GstFlowReturn
|
||||||
|
where
|
||||||
|
T: IsA<Pad>,
|
||||||
|
{
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
||||||
let func: &&(Fn(&Pad, &Option<::Object>, ::Buffer) -> Result<FlowSuccess, FlowError>
|
let func: &F = transmute((*pad).chaindata);
|
||||||
+ Send
|
|
||||||
+ Sync
|
|
||||||
+ 'static) = transmute((*pad).chaindata);
|
|
||||||
|
|
||||||
let res: FlowReturn = func(
|
let res: FlowReturn = func(
|
||||||
&from_glib_borrow(pad),
|
&Pad::from_glib_borrow(pad).unsafe_cast(),
|
||||||
&from_glib_borrow(parent),
|
&from_glib_borrow(parent),
|
||||||
from_glib_full(buffer),
|
from_glib_full(buffer),
|
||||||
)
|
)
|
||||||
|
@ -1184,19 +1158,25 @@ unsafe extern "C" fn trampoline_chain_function(
|
||||||
res.to_glib()
|
res.to_glib()
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn trampoline_chain_list_function(
|
unsafe extern "C" fn trampoline_chain_list_function<
|
||||||
|
T,
|
||||||
|
F: Fn(&T, &Option<::Object>, ::BufferList) -> Result<FlowSuccess, FlowError>
|
||||||
|
+ Send
|
||||||
|
+ Sync
|
||||||
|
+ 'static,
|
||||||
|
>(
|
||||||
pad: *mut ffi::GstPad,
|
pad: *mut ffi::GstPad,
|
||||||
parent: *mut ffi::GstObject,
|
parent: *mut ffi::GstObject,
|
||||||
list: *mut ffi::GstBufferList,
|
list: *mut ffi::GstBufferList,
|
||||||
) -> ffi::GstFlowReturn {
|
) -> ffi::GstFlowReturn
|
||||||
|
where
|
||||||
|
T: IsA<Pad>,
|
||||||
|
{
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
||||||
let func: &&(Fn(&Pad, &Option<::Object>, ::BufferList) -> Result<FlowSuccess, FlowError>
|
let func: &F = transmute((*pad).chainlistdata);
|
||||||
+ Send
|
|
||||||
+ Sync
|
|
||||||
+ 'static) = transmute((*pad).chainlistdata);
|
|
||||||
|
|
||||||
let res: FlowReturn = func(
|
let res: FlowReturn = func(
|
||||||
&from_glib_borrow(pad),
|
&Pad::from_glib_borrow(pad).unsafe_cast(),
|
||||||
&from_glib_borrow(parent),
|
&from_glib_borrow(parent),
|
||||||
from_glib_full(list),
|
from_glib_full(list),
|
||||||
)
|
)
|
||||||
|
@ -1204,36 +1184,44 @@ unsafe extern "C" fn trampoline_chain_list_function(
|
||||||
res.to_glib()
|
res.to_glib()
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn trampoline_event_function(
|
unsafe extern "C" fn trampoline_event_function<
|
||||||
|
T,
|
||||||
|
F: Fn(&T, &Option<::Object>, ::Event) -> bool + Send + Sync + 'static,
|
||||||
|
>(
|
||||||
pad: *mut ffi::GstPad,
|
pad: *mut ffi::GstPad,
|
||||||
parent: *mut ffi::GstObject,
|
parent: *mut ffi::GstObject,
|
||||||
event: *mut ffi::GstEvent,
|
event: *mut ffi::GstEvent,
|
||||||
) -> glib_ffi::gboolean {
|
) -> glib_ffi::gboolean
|
||||||
|
where
|
||||||
|
T: IsA<Pad>,
|
||||||
|
{
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
||||||
let func: &&(Fn(&Pad, &Option<::Object>, ::Event) -> bool + Send + Sync + 'static) =
|
let func: &F = transmute((*pad).eventdata);
|
||||||
transmute((*pad).eventdata);
|
|
||||||
|
|
||||||
func(
|
func(
|
||||||
&from_glib_borrow(pad),
|
&Pad::from_glib_borrow(pad).unsafe_cast(),
|
||||||
&from_glib_borrow(parent),
|
&from_glib_borrow(parent),
|
||||||
from_glib_full(event),
|
from_glib_full(event),
|
||||||
)
|
)
|
||||||
.to_glib()
|
.to_glib()
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn trampoline_event_full_function(
|
unsafe extern "C" fn trampoline_event_full_function<
|
||||||
|
T,
|
||||||
|
F: Fn(&T, &Option<::Object>, ::Event) -> Result<FlowSuccess, FlowError> + Send + Sync + 'static,
|
||||||
|
>(
|
||||||
pad: *mut ffi::GstPad,
|
pad: *mut ffi::GstPad,
|
||||||
parent: *mut ffi::GstObject,
|
parent: *mut ffi::GstObject,
|
||||||
event: *mut ffi::GstEvent,
|
event: *mut ffi::GstEvent,
|
||||||
) -> ffi::GstFlowReturn {
|
) -> ffi::GstFlowReturn
|
||||||
|
where
|
||||||
|
T: IsA<Pad>,
|
||||||
|
{
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
||||||
let func: &&(Fn(&Pad, &Option<::Object>, ::Event) -> Result<FlowSuccess, FlowError>
|
let func: &F = transmute((*pad).eventdata);
|
||||||
+ Send
|
|
||||||
+ Sync
|
|
||||||
+ 'static) = transmute((*pad).eventdata);
|
|
||||||
|
|
||||||
let res: FlowReturn = func(
|
let res: FlowReturn = func(
|
||||||
&from_glib_borrow(pad),
|
&Pad::from_glib_borrow(pad).unsafe_cast(),
|
||||||
&from_glib_borrow(parent),
|
&from_glib_borrow(parent),
|
||||||
from_glib_full(event),
|
from_glib_full(event),
|
||||||
)
|
)
|
||||||
|
@ -1241,21 +1229,24 @@ unsafe extern "C" fn trampoline_event_full_function(
|
||||||
res.to_glib()
|
res.to_glib()
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn trampoline_getrange_function(
|
unsafe extern "C" fn trampoline_getrange_function<
|
||||||
|
T,
|
||||||
|
F: Fn(&T, &Option<::Object>, u64, u32) -> Result<::Buffer, FlowError> + Send + Sync + 'static,
|
||||||
|
>(
|
||||||
pad: *mut ffi::GstPad,
|
pad: *mut ffi::GstPad,
|
||||||
parent: *mut ffi::GstObject,
|
parent: *mut ffi::GstObject,
|
||||||
offset: u64,
|
offset: u64,
|
||||||
length: u32,
|
length: u32,
|
||||||
buffer: *mut *mut ffi::GstBuffer,
|
buffer: *mut *mut ffi::GstBuffer,
|
||||||
) -> ffi::GstFlowReturn {
|
) -> ffi::GstFlowReturn
|
||||||
|
where
|
||||||
|
T: IsA<Pad>,
|
||||||
|
{
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
||||||
let func: &&(Fn(&Pad, &Option<::Object>, u64, u32) -> Result<::Buffer, FlowError>
|
let func: &F = transmute((*pad).getrangedata);
|
||||||
+ Send
|
|
||||||
+ Sync
|
|
||||||
+ 'static) = transmute((*pad).getrangedata);
|
|
||||||
|
|
||||||
match func(
|
match func(
|
||||||
&from_glib_borrow(pad),
|
&Pad::from_glib_borrow(pad).unsafe_cast(),
|
||||||
&from_glib_borrow(parent),
|
&from_glib_borrow(parent),
|
||||||
offset,
|
offset,
|
||||||
length,
|
length,
|
||||||
|
@ -1268,39 +1259,49 @@ unsafe extern "C" fn trampoline_getrange_function(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn trampoline_iterate_internal_links_function(
|
unsafe extern "C" fn trampoline_iterate_internal_links_function<
|
||||||
|
T,
|
||||||
|
F: Fn(&T, &Option<::Object>) -> ::Iterator<Pad> + Send + Sync + 'static,
|
||||||
|
>(
|
||||||
pad: *mut ffi::GstPad,
|
pad: *mut ffi::GstPad,
|
||||||
parent: *mut ffi::GstObject,
|
parent: *mut ffi::GstObject,
|
||||||
) -> *mut ffi::GstIterator {
|
) -> *mut ffi::GstIterator
|
||||||
|
where
|
||||||
|
T: IsA<Pad>,
|
||||||
|
{
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
||||||
let func: &&(Fn(&Pad, &Option<::Object>) -> ::Iterator<Pad> + Send + Sync + 'static) =
|
let func: &F = transmute((*pad).iterintlinkdata);
|
||||||
transmute((*pad).iterintlinkdata);
|
|
||||||
|
|
||||||
// Steal the iterator and return it
|
// Steal the iterator and return it
|
||||||
let ret = func(&from_glib_borrow(pad), &from_glib_borrow(parent));
|
let ret = func(
|
||||||
|
&Pad::from_glib_borrow(pad).unsafe_cast(),
|
||||||
|
&from_glib_borrow(parent),
|
||||||
|
);
|
||||||
let ptr = ret.to_glib_none().0;
|
let ptr = ret.to_glib_none().0;
|
||||||
mem::forget(ret);
|
mem::forget(ret);
|
||||||
|
|
||||||
ptr as *mut _
|
ptr as *mut _
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn trampoline_link_function(
|
unsafe extern "C" fn trampoline_link_function<
|
||||||
|
T,
|
||||||
|
F: Fn(&T, &Option<::Object>, &::Pad) -> Result<::PadLinkSuccess, ::PadLinkError>
|
||||||
|
+ Send
|
||||||
|
+ Sync
|
||||||
|
+ 'static,
|
||||||
|
>(
|
||||||
pad: *mut ffi::GstPad,
|
pad: *mut ffi::GstPad,
|
||||||
parent: *mut ffi::GstObject,
|
parent: *mut ffi::GstObject,
|
||||||
peer: *mut ffi::GstPad,
|
peer: *mut ffi::GstPad,
|
||||||
) -> ffi::GstPadLinkReturn {
|
) -> ffi::GstPadLinkReturn
|
||||||
|
where
|
||||||
|
T: IsA<Pad>,
|
||||||
|
{
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
||||||
let func: &&(Fn(
|
let func: &F = transmute((*pad).linkdata);
|
||||||
&Pad,
|
|
||||||
&Option<::Object>,
|
|
||||||
&::Pad,
|
|
||||||
) -> Result<::PadLinkSuccess, ::PadLinkError>
|
|
||||||
+ Send
|
|
||||||
+ Sync
|
|
||||||
+ 'static) = transmute((*pad).linkdata);
|
|
||||||
|
|
||||||
let res: ::PadLinkReturn = func(
|
let res: ::PadLinkReturn = func(
|
||||||
&from_glib_borrow(pad),
|
&Pad::from_glib_borrow(pad).unsafe_cast(),
|
||||||
&from_glib_borrow(parent),
|
&from_glib_borrow(parent),
|
||||||
&from_glib_borrow(peer),
|
&from_glib_borrow(peer),
|
||||||
)
|
)
|
||||||
|
@ -1308,51 +1309,59 @@ unsafe extern "C" fn trampoline_link_function(
|
||||||
res.to_glib()
|
res.to_glib()
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn trampoline_query_function(
|
unsafe extern "C" fn trampoline_query_function<
|
||||||
|
T,
|
||||||
|
F: Fn(&T, &Option<::Object>, &mut ::QueryRef) -> bool + Send + Sync + 'static,
|
||||||
|
>(
|
||||||
pad: *mut ffi::GstPad,
|
pad: *mut ffi::GstPad,
|
||||||
parent: *mut ffi::GstObject,
|
parent: *mut ffi::GstObject,
|
||||||
query: *mut ffi::GstQuery,
|
query: *mut ffi::GstQuery,
|
||||||
) -> glib_ffi::gboolean {
|
) -> glib_ffi::gboolean
|
||||||
|
where
|
||||||
|
T: IsA<Pad>,
|
||||||
|
{
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
||||||
let func: &&(Fn(&Pad, &Option<::Object>, &mut ::QueryRef) -> bool + Send + Sync + 'static) =
|
let func: &F = transmute((*pad).querydata);
|
||||||
transmute((*pad).querydata);
|
|
||||||
|
|
||||||
func(
|
func(
|
||||||
&from_glib_borrow(pad),
|
&Pad::from_glib_borrow(pad).unsafe_cast(),
|
||||||
&from_glib_borrow(parent),
|
&from_glib_borrow(parent),
|
||||||
::QueryRef::from_mut_ptr(query),
|
::QueryRef::from_mut_ptr(query),
|
||||||
)
|
)
|
||||||
.to_glib()
|
.to_glib()
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn trampoline_unlink_function(
|
unsafe extern "C" fn trampoline_unlink_function<
|
||||||
|
T,
|
||||||
|
F: Fn(&T, &Option<::Object>) + Send + Sync + 'static,
|
||||||
|
>(
|
||||||
pad: *mut ffi::GstPad,
|
pad: *mut ffi::GstPad,
|
||||||
parent: *mut ffi::GstObject,
|
parent: *mut ffi::GstObject,
|
||||||
) {
|
) where
|
||||||
|
T: IsA<Pad>,
|
||||||
|
{
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
||||||
let func: &&(Fn(&Pad, &Option<::Object>) + Send + Sync + 'static) =
|
let func: &F = transmute((*pad).unlinkdata);
|
||||||
transmute((*pad).unlinkdata);
|
|
||||||
|
|
||||||
func(&from_glib_borrow(pad), &from_glib_borrow(parent))
|
func(
|
||||||
|
&Pad::from_glib_borrow(pad).unsafe_cast(),
|
||||||
|
&from_glib_borrow(parent),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn destroy_closure(ptr: gpointer) {
|
unsafe extern "C" fn destroy_closure<F>(ptr: gpointer) {
|
||||||
Box::<Box<Fn()>>::from_raw(ptr as *mut _);
|
Box::<F>::from_raw(ptr as *mut _);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn trampoline_pad_task(func: gpointer) {
|
unsafe extern "C" fn trampoline_pad_task<F: FnMut() + Send + 'static>(func: gpointer) {
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
||||||
let func: &RefCell<Box<FnMut() + Send + 'static>> = transmute(func);
|
let func: &RefCell<F> = transmute(func);
|
||||||
(&mut *func.borrow_mut())()
|
(&mut *func.borrow_mut())()
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn destroy_closure_pad_task(ptr: gpointer) {
|
|
||||||
Box::<RefCell<Box<FnMut() + Send + 'static>>>::from_raw(ptr as *mut _);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn into_raw_pad_task<F: FnMut() + Send + 'static>(func: F) -> gpointer {
|
fn into_raw_pad_task<F: FnMut() + Send + 'static>(func: F) -> gpointer {
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
|
#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
|
||||||
let func: Box<RefCell<Box<FnMut() + Send + 'static>>> = Box::new(RefCell::new(Box::new(func)));
|
let func: Box<RefCell<F>> = Box::new(RefCell::new(func));
|
||||||
Box::into_raw(func) as gpointer
|
Box::into_raw(func) as gpointer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,13 +36,13 @@ impl Promise {
|
||||||
where
|
where
|
||||||
F: FnOnce(&Promise) + Send + 'static,
|
F: FnOnce(&Promise) + Send + 'static,
|
||||||
{
|
{
|
||||||
let user_data: Box<Option<Box<F>>> = Box::new(Some(Box::new(func)));
|
let user_data: Box<Option<F>> = Box::new(Some(func));
|
||||||
|
|
||||||
unsafe extern "C" fn trampoline<F: FnOnce(&Promise) + Send + 'static>(
|
unsafe extern "C" fn trampoline<F: FnOnce(&Promise) + Send + 'static>(
|
||||||
promise: *mut ffi::GstPromise,
|
promise: *mut ffi::GstPromise,
|
||||||
user_data: glib_ffi::gpointer,
|
user_data: glib_ffi::gpointer,
|
||||||
) {
|
) {
|
||||||
let user_data: &mut Option<Box<F>> = &mut *(user_data as *mut _);
|
let user_data: &mut Option<F> = &mut *(user_data as *mut _);
|
||||||
let callback = user_data.take().unwrap();
|
let callback = user_data.take().unwrap();
|
||||||
|
|
||||||
callback(&from_glib_borrow(promise));
|
callback(&from_glib_borrow(promise));
|
||||||
|
@ -51,16 +51,14 @@ impl Promise {
|
||||||
unsafe extern "C" fn free_user_data<F: FnOnce(&Promise) + Send + 'static>(
|
unsafe extern "C" fn free_user_data<F: FnOnce(&Promise) + Send + 'static>(
|
||||||
user_data: glib_ffi::gpointer,
|
user_data: glib_ffi::gpointer,
|
||||||
) {
|
) {
|
||||||
let _: Box<Option<Box<F>>> = Box::from_raw(user_data as *mut _);
|
let _: Box<Option<F>> = Box::from_raw(user_data as *mut _);
|
||||||
}
|
}
|
||||||
|
|
||||||
let trampoline = trampoline::<F>;
|
|
||||||
let free_user_data = free_user_data::<F>;
|
|
||||||
unsafe {
|
unsafe {
|
||||||
from_glib_full(ffi::gst_promise_new_with_change_func(
|
from_glib_full(ffi::gst_promise_new_with_change_func(
|
||||||
Some(trampoline),
|
Some(trampoline::<F>),
|
||||||
Box::into_raw(user_data) as *mut _,
|
Box::into_raw(user_data) as *mut _,
|
||||||
Some(free_user_data),
|
Some(free_user_data::<F>),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,19 +56,18 @@ impl<'a> TypeFind<'a> {
|
||||||
let extensions = extensions.into();
|
let extensions = extensions.into();
|
||||||
let possible_caps = possible_caps.into();
|
let possible_caps = possible_caps.into();
|
||||||
unsafe {
|
unsafe {
|
||||||
let func: Box<Box<Fn(&mut TypeFind) + Send + Sync + 'static>> =
|
let func: Box<F> = Box::new(func);
|
||||||
Box::new(Box::new(func));
|
|
||||||
let func = Box::into_raw(func);
|
let func = Box::into_raw(func);
|
||||||
|
|
||||||
let res = ffi::gst_type_find_register(
|
let res = ffi::gst_type_find_register(
|
||||||
plugin.to_glib_none().0,
|
plugin.to_glib_none().0,
|
||||||
name.to_glib_none().0,
|
name.to_glib_none().0,
|
||||||
rank,
|
rank,
|
||||||
Some(type_find_trampoline),
|
Some(type_find_trampoline::<F>),
|
||||||
extensions.to_glib_none().0,
|
extensions.to_glib_none().0,
|
||||||
possible_caps.to_glib_none().0,
|
possible_caps.to_glib_none().0,
|
||||||
func as *mut _,
|
func as *mut _,
|
||||||
Some(type_find_closure_drop),
|
Some(type_find_closure_drop::<F>),
|
||||||
);
|
);
|
||||||
|
|
||||||
glib_result_from_gboolean!(res, "Failed to register typefind factory")
|
glib_result_from_gboolean!(res, "Failed to register typefind factory")
|
||||||
|
@ -116,17 +115,19 @@ impl TypeFindFactory {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn type_find_trampoline(
|
unsafe extern "C" fn type_find_trampoline<F: Fn(&mut TypeFind) + Send + Sync + 'static>(
|
||||||
find: *mut ffi::GstTypeFind,
|
find: *mut ffi::GstTypeFind,
|
||||||
user_data: glib_ffi::gpointer,
|
user_data: glib_ffi::gpointer,
|
||||||
) {
|
) {
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
||||||
let func: &&(Fn(&mut TypeFind) + Send + Sync + 'static) = mem::transmute(user_data);
|
let func: &F = mem::transmute(user_data);
|
||||||
func(&mut *(find as *mut TypeFind));
|
func(&mut *(find as *mut TypeFind));
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn type_find_closure_drop(data: glib_ffi::gpointer) {
|
unsafe extern "C" fn type_find_closure_drop<F: Fn(&mut TypeFind) + Send + Sync + 'static>(
|
||||||
Box::<Box<Fn(&mut TypeFind) + Send + Sync + 'static>>::from_raw(data as *mut _);
|
data: glib_ffi::gpointer,
|
||||||
|
) {
|
||||||
|
Box::<F>::from_raw(data as *mut _);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn type_find_peek(data: glib_ffi::gpointer, offset: i64, size: u32) -> *const u8 {
|
unsafe extern "C" fn type_find_peek(data: glib_ffi::gpointer, offset: i64, size: u32) -> *const u8 {
|
||||||
|
|
Loading…
Reference in a new issue