subclass/element: expose set_clock and provide_clock vmethods

This commit is contained in:
Mathieu Duponchelle 2019-08-31 00:08:07 +02:00
parent 1367becfaf
commit d3d503cea6

View file

@ -62,6 +62,14 @@ pub trait ElementImpl: ElementImplExt + ObjectImpl + Send + Sync + 'static {
fn set_context(&self, element: &::Element, context: &::Context) { fn set_context(&self, element: &::Element, context: &::Context) {
self.parent_set_context(element, 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 { pub trait ElementImplExt {
@ -87,6 +95,10 @@ pub trait ElementImplExt {
fn parent_set_context(&self, element: &::Element, context: &::Context); 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< fn catch_panic<
R, R,
F: FnOnce(&Self) -> 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< fn catch_panic<
R, R,
F: FnOnce(&Self) -> R, F: FnOnce(&Self) -> R,
@ -288,6 +324,8 @@ where
klass.send_event = Some(element_send_event::<T>); klass.send_event = Some(element_send_event::<T>);
klass.query = Some(element_query::<T>); klass.query = Some(element_query::<T>);
klass.set_context = Some(element_set_context::<T>); klass.set_context = Some(element_set_context::<T>);
klass.set_clock = Some(element_set_clock::<T>);
klass.provide_clock = Some(element_provide_clock::<T>);
} }
} }
} }
@ -433,6 +471,45 @@ unsafe extern "C" fn element_set_context<T: ObjectSubclass>(
}) })
} }
unsafe extern "C" fn element_set_clock<T: ObjectSubclass>(
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<T: ObjectSubclass>(
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)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;