From 0d70950821f136eae5eeec5ab69a0c72dbc2c506 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Mon, 13 Aug 2018 19:58:30 +0300 Subject: [PATCH] Implement Pad::sticky_events_foreach() --- gstreamer/src/pad.rs | 49 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/gstreamer/src/pad.rs b/gstreamer/src/pad.rs index 5c314d3d9..cddffc1ff 100644 --- a/gstreamer/src/pad.rs +++ b/gstreamer/src/pad.rs @@ -226,6 +226,11 @@ pub trait PadExtManual { fn query_position_generic(&self, format: Format) -> Option; fn get_mode(&self) -> ::PadMode; + + fn sticky_events_foreach Result, Option>>( + &self, + func: F, + ); } impl> PadExtManual for O { @@ -868,6 +873,50 @@ impl> PadExtManual for O { from_glib(ptr.mode) } } + + fn sticky_events_foreach Result, Option>>( + &self, + func: F, + ) { + unsafe extern "C" fn trampoline( + _pad: *mut ffi::GstPad, + event: *mut *mut ffi::GstEvent, + user_data: glib_ffi::gpointer, + ) -> glib_ffi::gboolean { + let func = + user_data as *mut &mut (FnMut(Event) -> Result, Option>); + let res = (*func)(from_glib_full(*event)); + + match res { + Ok(Some(ev)) => { + *event = ev.into_ptr(); + glib_ffi::GTRUE + } + Err(Some(ev)) => { + *event = ev.into_ptr(); + glib_ffi::GFALSE + } + Ok(None) => { + *event = ptr::null_mut(); + glib_ffi::GTRUE + } + Err(None) => { + *event = ptr::null_mut(); + glib_ffi::GFALSE + } + } + } + + unsafe { + let mut func = func; + let func_obj: &mut (FnMut(Event) -> Result, Option>) = &mut func; + let func_ptr = &func_obj + as *const &mut (FnMut(Event) -> Result, Option>) + as glib_ffi::gpointer; + + ffi::gst_pad_sticky_events_foreach(self.to_glib_none().0, Some(trampoline), func_ptr); + } + } } unsafe extern "C" fn trampoline_pad_probe(