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