gstreamer_play/
play_signal_adapter.rs
1use std::{boxed::Box as Box_, mem::transmute};
4
5use glib::{
6 prelude::*,
7 signal::{connect_raw, SignalHandlerId},
8 translate::*,
9};
10
11use crate::{ffi, PlaySignalAdapter};
12
13impl PlaySignalAdapter {
14 #[doc(alias = "duration-changed")]
15 pub fn connect_duration_changed<
16 F: Fn(&PlaySignalAdapter, Option<gst::ClockTime>) + Send + 'static,
17 >(
18 &self,
19 f: F,
20 ) -> SignalHandlerId {
21 unsafe extern "C" fn duration_changed_trampoline<
22 F: Fn(&PlaySignalAdapter, Option<gst::ClockTime>) + Send + 'static,
23 >(
24 this: *mut ffi::GstPlaySignalAdapter,
25 object: u64,
26 f: glib::ffi::gpointer,
27 ) {
28 let f: &F = &*(f as *const F);
29 f(&from_glib_borrow(this), FromGlib::from_glib(object))
30 }
31 #[allow(clippy::cast_ptr_alignment)]
32 unsafe {
33 let f: Box_<F> = Box_::new(f);
34 connect_raw(
35 self.as_ptr() as *mut _,
36 b"duration-changed\0".as_ptr() as *const _,
37 Some(transmute::<*const (), unsafe extern "C" fn()>(
38 duration_changed_trampoline::<F> as *const (),
39 )),
40 Box_::into_raw(f),
41 )
42 }
43 }
44
45 #[doc(alias = "position-updated")]
46 pub fn connect_position_updated<
47 F: Fn(&PlaySignalAdapter, Option<gst::ClockTime>) + Send + 'static,
48 >(
49 &self,
50 f: F,
51 ) -> SignalHandlerId {
52 unsafe extern "C" fn position_updated_trampoline<
53 F: Fn(&PlaySignalAdapter, Option<gst::ClockTime>) + Send + 'static,
54 >(
55 this: *mut ffi::GstPlaySignalAdapter,
56 object: u64,
57 f: glib::ffi::gpointer,
58 ) {
59 let f: &F = &*(f as *const F);
60 f(&from_glib_borrow(this), FromGlib::from_glib(object))
61 }
62 #[allow(clippy::cast_ptr_alignment)]
63 unsafe {
64 let f: Box_<F> = Box_::new(f);
65 connect_raw(
66 self.as_ptr() as *mut _,
67 b"position-updated\0".as_ptr() as *const _,
68 Some(transmute::<*const (), unsafe extern "C" fn()>(
69 position_updated_trampoline::<F> as *const (),
70 )),
71 Box_::into_raw(f),
72 )
73 }
74 }
75
76 #[doc(alias = "seek-done")]
77 pub fn connect_seek_done<F: Fn(&PlaySignalAdapter, gst::ClockTime) + Send + 'static>(
78 &self,
79 f: F,
80 ) -> SignalHandlerId {
81 unsafe extern "C" fn seek_done_trampoline<
82 F: Fn(&PlaySignalAdapter, gst::ClockTime) + Send + 'static,
83 >(
84 this: *mut ffi::GstPlaySignalAdapter,
85 object: u64,
86 f: glib::ffi::gpointer,
87 ) {
88 let f: &F = &*(f as *const F);
89 f(
90 &from_glib_borrow(this),
91 try_from_glib(object).expect("undefined seek position"),
92 )
93 }
94 #[allow(clippy::cast_ptr_alignment)]
95 unsafe {
96 let f: Box_<F> = Box_::new(f);
97 connect_raw(
98 self.as_ptr() as *mut _,
99 b"seek-done\0".as_ptr() as *const _,
100 Some(transmute::<*const (), unsafe extern "C" fn()>(
101 seek_done_trampoline::<F> as *const (),
102 )),
103 Box_::into_raw(f),
104 )
105 }
106 }
107}