gstreamer/auto/system_clock.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
4// DO NOT EDIT
5
6use crate::{Clock, ClockType, Object, ffi};
7use glib::{
8 prelude::*,
9 signal::{SignalHandlerId, connect_raw},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 /// The GStreamer core provides a GstSystemClock based on the system time.
16 /// Asynchronous callbacks are scheduled from an internal thread.
17 ///
18 /// Clock implementors are encouraged to subclass this systemclock as it
19 /// implements the async notification.
20 ///
21 /// Subclasses can however override all of the important methods for sync and
22 /// async notifications to implement their own callback methods or blocking
23 /// wait operations.
24 ///
25 /// ## Properties
26 ///
27 ///
28 /// #### `clock-type`
29 /// Readable | Writable
30 /// <details><summary><h4>Clock</h4></summary>
31 ///
32 ///
33 /// #### `timeout`
34 /// Readable | Writable
35 ///
36 ///
37 /// #### `window-size`
38 /// Readable | Writable
39 ///
40 ///
41 /// #### `window-threshold`
42 /// Readable | Writable
43 /// </details>
44 /// <details><summary><h4>Object</h4></summary>
45 ///
46 ///
47 /// #### `name`
48 /// Readable | Writable | Construct
49 ///
50 ///
51 /// #### `parent`
52 /// The parent of the object. Please note, that when changing the 'parent'
53 /// property, we don't emit [`notify`][struct@crate::glib::Object#notify] and [`deep-notify`][struct@crate::Object#deep-notify]
54 /// signals due to locking issues. In some cases one can use
55 /// [`element-added`][struct@crate::Bin#element-added] or [`element-removed`][struct@crate::Bin#element-removed] signals on the parent to
56 /// achieve a similar effect.
57 ///
58 /// Readable | Writable
59 /// </details>
60 ///
61 /// # Implements
62 ///
63 /// [`SystemClockExt`][trait@crate::prelude::SystemClockExt], [`ClockExt`][trait@crate::prelude::ClockExt], [`GstObjectExt`][trait@crate::prelude::GstObjectExt], [`trait@glib::ObjectExt`], [`ClockExtManual`][trait@crate::prelude::ClockExtManual], [`GstObjectExtManual`][trait@crate::prelude::GstObjectExtManual]
64 #[doc(alias = "GstSystemClock")]
65 pub struct SystemClock(Object<ffi::GstSystemClock, ffi::GstSystemClockClass>) @extends Clock, Object;
66
67 match fn {
68 type_ => || ffi::gst_system_clock_get_type(),
69 }
70}
71
72impl SystemClock {
73 pub const NONE: Option<&'static SystemClock> = None;
74
75 /// Get a handle to the default system clock. The refcount of the
76 /// clock will be increased so you need to unref the clock after
77 /// usage.
78 ///
79 /// Changing the calibration via [`ClockExtManual::set_calibration()`][crate::prelude::ClockExtManual::set_calibration()], setting a master
80 /// clock via [`ClockExt::set_master()`][crate::prelude::ClockExt::set_master()] or changing the `clock-type` property on the
81 /// returned clock will change the behaviour for the whole process.
82 ///
83 /// # Returns
84 ///
85 /// the default clock.
86 ///
87 /// MT safe.
88 #[doc(alias = "gst_system_clock_obtain")]
89 pub fn obtain() -> Clock {
90 assert_initialized_main_thread!();
91 unsafe { from_glib_full(ffi::gst_system_clock_obtain()) }
92 }
93
94 /// Sets the default system clock that can be obtained with
95 /// [`obtain()`][Self::obtain()].
96 ///
97 /// This is mostly used for testing and debugging purposes when you
98 /// want to have control over the time reported by the default system
99 /// clock.
100 ///
101 /// MT safe.
102 /// ## `new_clock`
103 /// a [`Clock`][crate::Clock]
104 #[doc(alias = "gst_system_clock_set_default")]
105 pub fn set_default(new_clock: Option<&impl IsA<Clock>>) {
106 assert_initialized_main_thread!();
107 unsafe {
108 ffi::gst_system_clock_set_default(new_clock.map(|p| p.as_ref()).to_glib_none().0);
109 }
110 }
111}
112
113unsafe impl Send for SystemClock {}
114unsafe impl Sync for SystemClock {}
115
116/// Trait containing all [`struct@SystemClock`] methods.
117///
118/// # Implementors
119///
120/// [`SystemClock`][struct@crate::SystemClock]
121pub trait SystemClockExt: IsA<SystemClock> + 'static {
122 #[doc(alias = "clock-type")]
123 fn clock_type(&self) -> ClockType {
124 ObjectExt::property(self.as_ref(), "clock-type")
125 }
126
127 #[doc(alias = "clock-type")]
128 fn set_clock_type(&self, clock_type: ClockType) {
129 ObjectExt::set_property(self.as_ref(), "clock-type", clock_type)
130 }
131
132 #[doc(alias = "clock-type")]
133 fn connect_clock_type_notify<F: Fn(&Self) + Send + Sync + 'static>(
134 &self,
135 f: F,
136 ) -> SignalHandlerId {
137 unsafe extern "C" fn notify_clock_type_trampoline<
138 P: IsA<SystemClock>,
139 F: Fn(&P) + Send + Sync + 'static,
140 >(
141 this: *mut ffi::GstSystemClock,
142 _param_spec: glib::ffi::gpointer,
143 f: glib::ffi::gpointer,
144 ) {
145 unsafe {
146 let f: &F = &*(f as *const F);
147 f(SystemClock::from_glib_borrow(this).unsafe_cast_ref())
148 }
149 }
150 unsafe {
151 let f: Box_<F> = Box_::new(f);
152 connect_raw(
153 self.as_ptr() as *mut _,
154 c"notify::clock-type".as_ptr(),
155 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
156 notify_clock_type_trampoline::<Self, F> as *const (),
157 )),
158 Box_::into_raw(f),
159 )
160 }
161 }
162}
163
164impl<O: IsA<SystemClock>> SystemClockExt for O {}