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::{ffi, Clock, ClockType, Object};
7use glib::{
8    prelude::*,
9    signal::{connect_raw, SignalHandlerId},
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 | Writeable
30    /// <details><summary><h4>Clock</h4></summary>
31    ///
32    ///
33    /// #### `timeout`
34    ///  Readable | Writeable
35    ///
36    ///
37    /// #### `window-size`
38    ///  Readable | Writeable
39    ///
40    ///
41    /// #### `window-threshold`
42    ///  Readable | Writeable
43    /// </details>
44    /// <details><summary><h4>Object</h4></summary>
45    ///
46    ///
47    /// #### `name`
48    ///  Readable | Writeable | 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 | Writeable
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]
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    /// # Returns
80    ///
81    /// the default clock.
82    ///
83    /// MT safe.
84    #[doc(alias = "gst_system_clock_obtain")]
85    pub fn obtain() -> Clock {
86        assert_initialized_main_thread!();
87        unsafe { from_glib_full(ffi::gst_system_clock_obtain()) }
88    }
89
90    /// Sets the default system clock that can be obtained with
91    /// [`obtain()`][Self::obtain()].
92    ///
93    /// This is mostly used for testing and debugging purposes when you
94    /// want to have control over the time reported by the default system
95    /// clock.
96    ///
97    /// MT safe.
98    /// ## `new_clock`
99    /// a [`Clock`][crate::Clock]
100    #[doc(alias = "gst_system_clock_set_default")]
101    pub fn set_default(new_clock: Option<&impl IsA<Clock>>) {
102        assert_initialized_main_thread!();
103        unsafe {
104            ffi::gst_system_clock_set_default(new_clock.map(|p| p.as_ref()).to_glib_none().0);
105        }
106    }
107}
108
109unsafe impl Send for SystemClock {}
110unsafe impl Sync for SystemClock {}
111
112/// Trait containing all [`struct@SystemClock`] methods.
113///
114/// # Implementors
115///
116/// [`SystemClock`][struct@crate::SystemClock]
117pub trait SystemClockExt: IsA<SystemClock> + 'static {
118    #[doc(alias = "clock-type")]
119    fn clock_type(&self) -> ClockType {
120        ObjectExt::property(self.as_ref(), "clock-type")
121    }
122
123    #[doc(alias = "clock-type")]
124    fn set_clock_type(&self, clock_type: ClockType) {
125        ObjectExt::set_property(self.as_ref(), "clock-type", clock_type)
126    }
127
128    #[doc(alias = "clock-type")]
129    fn connect_clock_type_notify<F: Fn(&Self) + Send + Sync + 'static>(
130        &self,
131        f: F,
132    ) -> SignalHandlerId {
133        unsafe extern "C" fn notify_clock_type_trampoline<
134            P: IsA<SystemClock>,
135            F: Fn(&P) + Send + Sync + 'static,
136        >(
137            this: *mut ffi::GstSystemClock,
138            _param_spec: glib::ffi::gpointer,
139            f: glib::ffi::gpointer,
140        ) {
141            let f: &F = &*(f as *const F);
142            f(SystemClock::from_glib_borrow(this).unsafe_cast_ref())
143        }
144        unsafe {
145            let f: Box_<F> = Box_::new(f);
146            connect_raw(
147                self.as_ptr() as *mut _,
148                c"notify::clock-type".as_ptr() as *const _,
149                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
150                    notify_clock_type_trampoline::<Self, F> as *const (),
151                )),
152                Box_::into_raw(f),
153            )
154        }
155    }
156}
157
158impl<O: IsA<SystemClock>> SystemClockExt for O {}