gstreamer_video/subclass/
navigation.rs1use glib::{prelude::*, subclass::prelude::*, translate::*};
4
5use crate::{ffi, Navigation};
6
7pub trait NavigationImpl: ObjectImpl + ObjectSubclass<Type: IsA<Navigation>> {
8 fn send_event(&self, structure: gst::Structure);
9
10 #[cfg(feature = "v1_22")]
11 #[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
12 fn send_event_simple(&self, event: gst::Event) {
13 if let Some(structure) = event.structure() {
14 self.send_event(structure.to_owned());
15 }
16 }
17}
18
19pub trait NavigationImplExt: NavigationImpl {
20 fn parent_send_event(&self, structure: gst::Structure) {
21 unsafe {
22 let type_data = Self::type_data();
23 let parent_iface = type_data.as_ref().parent_interface::<Navigation>()
24 as *const ffi::GstNavigationInterface;
25
26 let func = match (*parent_iface).send_event {
27 Some(func) => func,
28 None => return,
29 };
30
31 func(
32 self.obj().unsafe_cast_ref::<Navigation>().to_glib_none().0,
33 structure.into_glib_ptr(),
34 );
35 }
36 }
37
38 #[cfg(feature = "v1_22")]
39 #[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
40 fn parent_send_event_simple(&self, event: gst::Event) {
41 unsafe {
42 let type_data = Self::type_data();
43 let parent_iface = type_data.as_ref().parent_interface::<Navigation>()
44 as *const ffi::GstNavigationInterface;
45
46 let func = match (*parent_iface).send_event_simple {
47 Some(func) => func,
48 None => return,
49 };
50
51 func(
52 self.obj().unsafe_cast_ref::<Navigation>().to_glib_none().0,
53 event.into_glib_ptr(),
54 );
55 }
56 }
57}
58
59impl<T: NavigationImpl> NavigationImplExt for T {}
60
61unsafe impl<T: NavigationImpl> IsImplementable<T> for Navigation {
62 #[cfg(not(any(feature = "v1_22", docsrs)))]
63 fn interface_init(iface: &mut glib::Interface<Self>) {
64 let iface = iface.as_mut();
65
66 iface.send_event = Some(navigation_send_event::<T>);
67 }
68
69 #[cfg(feature = "v1_22")]
70 #[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
71 fn interface_init(iface: &mut glib::Interface<Self>) {
72 let iface = iface.as_mut();
73
74 iface.send_event = Some(navigation_send_event::<T>);
75 iface.send_event_simple = Some(navigation_send_event_simple::<T>);
76 }
77}
78
79unsafe extern "C" fn navigation_send_event<T: NavigationImpl>(
80 nav: *mut ffi::GstNavigation,
81 structure: *mut gst::ffi::GstStructure,
82) {
83 let instance = &*(nav as *mut T::Instance);
84 let imp = instance.imp();
85
86 imp.send_event(from_glib_full(structure));
87}
88
89#[cfg(feature = "v1_22")]
90#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
91unsafe extern "C" fn navigation_send_event_simple<T: NavigationImpl>(
92 nav: *mut ffi::GstNavigation,
93 event: *mut gst::ffi::GstEvent,
94) {
95 let instance = &*(nav as *mut T::Instance);
96 let imp = instance.imp();
97
98 imp.send_event_simple(from_glib_full(event));
99}