From d3d503cea65055d06adcb97c1c51d5398bbde324 Mon Sep 17 00:00:00 2001 From: Mathieu Duponchelle Date: Sat, 31 Aug 2019 00:08:07 +0200 Subject: [PATCH] subclass/element: expose set_clock and provide_clock vmethods --- gstreamer/src/subclass/element.rs | 77 +++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/gstreamer/src/subclass/element.rs b/gstreamer/src/subclass/element.rs index 89552f6ab..e61ef407c 100644 --- a/gstreamer/src/subclass/element.rs +++ b/gstreamer/src/subclass/element.rs @@ -62,6 +62,14 @@ pub trait ElementImpl: ElementImplExt + ObjectImpl + Send + Sync + 'static { fn set_context(&self, element: &::Element, context: &::Context) { self.parent_set_context(element, context) } + + fn set_clock(&self, element: &::Element, clock: Option<&::Clock>) -> bool { + self.parent_set_clock(element, clock) + } + + fn provide_clock(&self, element: &::Element) -> Option<::Clock> { + self.parent_provide_clock(element) + } } pub trait ElementImplExt { @@ -87,6 +95,10 @@ pub trait ElementImplExt { fn parent_set_context(&self, element: &::Element, context: &::Context); + fn parent_set_clock(&self, element: &::Element, clock: Option<&::Clock>) -> bool; + + fn parent_provide_clock(&self, element: &::Element) -> Option<::Clock>; + fn catch_panic< R, F: FnOnce(&Self) -> R, @@ -200,6 +212,30 @@ where } } + fn parent_set_clock(&self, element: &::Element, clock: Option<&::Clock>) -> bool { + unsafe { + let data = self.get_type_data(); + let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstElementClass; + + (*parent_class) + .set_clock + .map(|f| from_glib(f(element.to_glib_none().0, clock.to_glib_none().0))) + .unwrap_or(false) + } + } + + fn parent_provide_clock(&self, element: &::Element) -> Option<::Clock> { + unsafe { + let data = self.get_type_data(); + let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstElementClass; + + (*parent_class) + .provide_clock + .map(|f| from_glib_none(f(element.to_glib_none().0))) + .unwrap_or(None) + } + } + fn catch_panic< R, F: FnOnce(&Self) -> R, @@ -288,6 +324,8 @@ where klass.send_event = Some(element_send_event::); klass.query = Some(element_query::); klass.set_context = Some(element_set_context::); + klass.set_clock = Some(element_set_clock::); + klass.provide_clock = Some(element_provide_clock::); } } } @@ -433,6 +471,45 @@ unsafe extern "C" fn element_set_context( }) } +unsafe extern "C" fn element_set_clock( + ptr: *mut gst_sys::GstElement, + clock: *mut gst_sys::GstClock, +) -> glib_sys::gboolean +where + T: ElementImpl, + T::Instance: PanicPoison, +{ + glib_floating_reference_guard!(ptr); + let instance = &*(ptr as *mut T::Instance); + let imp = instance.get_impl(); + let wrap: Element = from_glib_borrow(ptr); + + let clock = Option::<::Clock>::from_glib_borrow(clock); + + gst_panic_to_error!(&wrap, &instance.panicked(), false, { + imp.set_clock(&wrap, clock.as_ref()) + }) + .to_glib() +} + +unsafe extern "C" fn element_provide_clock( + ptr: *mut gst_sys::GstElement, +) -> *mut gst_sys::GstClock +where + T: ElementImpl, + T::Instance: PanicPoison, +{ + glib_floating_reference_guard!(ptr); + let instance = &*(ptr as *mut T::Instance); + let imp = instance.get_impl(); + let wrap: Element = from_glib_borrow(ptr); + + gst_panic_to_error!(&wrap, &instance.panicked(), None, { + imp.provide_clock(&wrap) + }) + .to_glib_full() +} + #[cfg(test)] mod tests { use super::*;