gstreamer/auto/
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, ClockTime, Object};
7use glib::{
8    object::ObjectType as _,
9    prelude::*,
10    signal::{connect_raw, SignalHandlerId},
11    translate::*,
12};
13use std::boxed::Box as Box_;
14
15glib::wrapper! {
16    /// GStreamer uses a global clock to synchronize the plugins in a pipeline.
17    /// Different clock implementations are possible by implementing this abstract
18    /// base class or, more conveniently, by subclassing [`SystemClock`][crate::SystemClock].
19    ///
20    /// The [`Clock`][crate::Clock] returns a monotonically increasing time with the method
21    /// [`ClockExt::time()`][crate::prelude::ClockExt::time()]. Its accuracy and base time depend on the specific
22    /// clock implementation but time is always expressed in nanoseconds. Since the
23    /// baseline of the clock is undefined, the clock time returned is not
24    /// meaningful in itself, what matters are the deltas between two clock times.
25    /// The time returned by a clock is called the absolute time.
26    ///
27    /// The pipeline uses the clock to calculate the running time. Usually all
28    /// renderers synchronize to the global clock using the buffer timestamps, the
29    /// [`EventType::Segment`][crate::EventType::Segment] events and the element's base time, see [`Pipeline`][crate::Pipeline].
30    ///
31    /// A clock implementation can support periodic and single shot clock
32    /// notifications both synchronous and asynchronous.
33    ///
34    /// One first needs to create a `GstClockID` for the periodic or single shot
35    /// notification using [`ClockExtManual::new_single_shot_id()`][crate::prelude::ClockExtManual::new_single_shot_id()] or
36    /// [`ClockExtManual::new_periodic_id()`][crate::prelude::ClockExtManual::new_periodic_id()].
37    ///
38    /// To perform a blocking wait for the specific time of the `GstClockID` use
39    /// `gst_clock_id_wait()`. To receive a callback when the specific time is reached
40    /// in the clock use `gst_clock_id_wait_async()`. Both these calls can be
41    /// interrupted with the `gst_clock_id_unschedule()` call. If the blocking wait is
42    /// unscheduled a return value of [`ClockReturn::Unscheduled`][crate::ClockReturn::Unscheduled] is returned.
43    ///
44    /// Periodic callbacks scheduled async will be repeatedly called automatically
45    /// until they are unscheduled. To schedule a sync periodic callback,
46    /// `gst_clock_id_wait()` should be called repeatedly.
47    ///
48    /// The async callbacks can happen from any thread, either provided by the core
49    /// or from a streaming thread. The application should be prepared for this.
50    ///
51    /// A `GstClockID` that has been unscheduled cannot be used again for any wait
52    /// operation, a new `GstClockID` should be created and the old unscheduled one
53    /// should be destroyed with `gst_clock_id_unref()`.
54    ///
55    /// It is possible to perform a blocking wait on the same `GstClockID` from
56    /// multiple threads. However, registering the same `GstClockID` for multiple
57    /// async notifications is not possible, the callback will only be called for
58    /// the thread registering the entry last.
59    ///
60    /// None of the wait operations unref the `GstClockID`, the owner is responsible
61    /// for unreffing the ids itself. This holds for both periodic and single shot
62    /// notifications. The reason being that the owner of the `GstClockID` has to
63    /// keep a handle to the `GstClockID` to unblock the wait on FLUSHING events or
64    /// state changes and if the entry would be unreffed automatically, the handle
65    /// might become invalid without any notification.
66    ///
67    /// These clock operations do not operate on the running time, so the callbacks
68    /// will also occur when not in PLAYING state as if the clock just keeps on
69    /// running. Some clocks however do not progress when the element that provided
70    /// the clock is not PLAYING.
71    ///
72    /// When a clock has the [`ClockFlags::CAN_SET_MASTER`][crate::ClockFlags::CAN_SET_MASTER] flag set, it can be
73    /// slaved to another [`Clock`][crate::Clock] with [`ClockExt::set_master()`][crate::prelude::ClockExt::set_master()]. The clock will
74    /// then automatically be synchronized to this master clock by repeatedly
75    /// sampling the master clock and the slave clock and recalibrating the slave
76    /// clock with [`ClockExtManual::set_calibration()`][crate::prelude::ClockExtManual::set_calibration()]. This feature is mostly useful for
77    /// plugins that have an internal clock but must operate with another clock
78    /// selected by the [`Pipeline`][crate::Pipeline]. They can track the offset and rate difference
79    /// of their internal clock relative to the master clock by using the
80    /// [`ClockExtManual::calibration()`][crate::prelude::ClockExtManual::calibration()] function.
81    ///
82    /// The master/slave synchronisation can be tuned with the [`timeout`][struct@crate::Clock#timeout],
83    /// [`window-size`][struct@crate::Clock#window-size] and [`window-threshold`][struct@crate::Clock#window-threshold] properties.
84    /// The [`timeout`][struct@crate::Clock#timeout] property defines the interval to sample the master
85    /// clock and run the calibration functions. [`window-size`][struct@crate::Clock#window-size] defines the
86    /// number of samples to use when calibrating and [`window-threshold`][struct@crate::Clock#window-threshold]
87    /// defines the minimum number of samples before the calibration is performed.
88    ///
89    /// This is an Abstract Base Class, you cannot instantiate it.
90    ///
91    /// ## Properties
92    ///
93    ///
94    /// #### `timeout`
95    ///  Readable | Writeable
96    ///
97    ///
98    /// #### `window-size`
99    ///  Readable | Writeable
100    ///
101    ///
102    /// #### `window-threshold`
103    ///  Readable | Writeable
104    /// <details><summary><h4>Object</h4></summary>
105    ///
106    ///
107    /// #### `name`
108    ///  Readable | Writeable | Construct
109    ///
110    ///
111    /// #### `parent`
112    ///  The parent of the object. Please note, that when changing the 'parent'
113    /// property, we don't emit [`notify`][struct@crate::glib::Object#notify] and [`deep-notify`][struct@crate::Object#deep-notify]
114    /// signals due to locking issues. In some cases one can use
115    /// [`element-added`][struct@crate::Bin#element-added] or [`element-removed`][struct@crate::Bin#element-removed] signals on the parent to
116    /// achieve a similar effect.
117    ///
118    /// Readable | Writeable
119    /// </details>
120    ///
121    /// ## Signals
122    ///
123    ///
124    /// #### `synced`
125    ///  Signaled on clocks with [`ClockFlags::NEEDS_STARTUP_SYNC`][crate::ClockFlags::NEEDS_STARTUP_SYNC] set once
126    /// the clock is synchronized, or when it completely lost synchronization.
127    /// This signal will not be emitted on clocks without the flag.
128    ///
129    /// This signal will be emitted from an arbitrary thread, most likely not
130    /// the application's main thread.
131    ///
132    ///
133    /// <details><summary><h4>Object</h4></summary>
134    ///
135    ///
136    /// #### `deep-notify`
137    ///  The deep notify signal is used to be notified of property changes. It is
138    /// typically attached to the toplevel bin to receive notifications from all
139    /// the elements contained in that bin.
140    ///
141    /// Detailed
142    /// </details>
143    ///
144    /// # Implements
145    ///
146    /// [`ClockExt`][trait@crate::prelude::ClockExt], [`GstObjectExt`][trait@crate::prelude::GstObjectExt], [`trait@glib::ObjectExt`], [`ClockExtManual`][trait@crate::prelude::ClockExtManual]
147    #[doc(alias = "GstClock")]
148    pub struct Clock(Object<ffi::GstClock, ffi::GstClockClass>) @extends Object;
149
150    match fn {
151        type_ => || ffi::gst_clock_get_type(),
152    }
153}
154
155impl Clock {
156    pub const NONE: Option<&'static Clock> = None;
157
158    //#[doc(alias = "gst_clock_id_compare_func")]
159    //pub fn id_compare_func(id1: /*Unimplemented*/Option<Basic: Pointer>, id2: /*Unimplemented*/Option<Basic: Pointer>) -> i32 {
160    //    unsafe { TODO: call ffi:gst_clock_id_compare_func() }
161    //}
162
163    //#[cfg(feature = "v1_16")]
164    //#[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
165    //#[doc(alias = "gst_clock_id_get_clock")]
166    //pub fn id_get_clock(id: /*Unimplemented*/ClockID) -> Option<Clock> {
167    //    unsafe { TODO: call ffi:gst_clock_id_get_clock() }
168    //}
169
170    //#[doc(alias = "gst_clock_id_get_time")]
171    //pub fn id_get_time(id: /*Unimplemented*/ClockID) -> Option<ClockTime> {
172    //    unsafe { TODO: call ffi:gst_clock_id_get_time() }
173    //}
174
175    //#[doc(alias = "gst_clock_id_ref")]
176    //pub fn id_ref(id: /*Unimplemented*/ClockID) -> /*Unimplemented*/ClockID {
177    //    unsafe { TODO: call ffi:gst_clock_id_ref() }
178    //}
179
180    //#[doc(alias = "gst_clock_id_unref")]
181    //pub fn id_unref(id: /*Unimplemented*/ClockID) {
182    //    unsafe { TODO: call ffi:gst_clock_id_unref() }
183    //}
184
185    //#[doc(alias = "gst_clock_id_unschedule")]
186    //pub fn id_unschedule(id: /*Unimplemented*/ClockID) {
187    //    unsafe { TODO: call ffi:gst_clock_id_unschedule() }
188    //}
189
190    //#[cfg(feature = "v1_16")]
191    //#[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
192    //#[doc(alias = "gst_clock_id_uses_clock")]
193    //pub fn id_uses_clock(id: /*Unimplemented*/ClockID, clock: &impl IsA<Clock>) -> bool {
194    //    unsafe { TODO: call ffi:gst_clock_id_uses_clock() }
195    //}
196
197    //#[doc(alias = "gst_clock_id_wait")]
198    //pub fn id_wait(id: /*Unimplemented*/ClockID) -> (Result<ClockSuccess, ClockError>, ClockTimeDiff) {
199    //    unsafe { TODO: call ffi:gst_clock_id_wait() }
200    //}
201
202    //#[doc(alias = "gst_clock_id_wait_async")]
203    //pub fn id_wait_async(id: /*Unimplemented*/ClockID, func: /*Unimplemented*/Fn(&Clock, impl Into<Option<ClockTime>>, /*Unimplemented*/ClockID) -> bool, user_data: /*Unimplemented*/Option<Basic: Pointer>) -> Result<ClockSuccess, ClockError> {
204    //    unsafe { TODO: call ffi:gst_clock_id_wait_async() }
205    //}
206}
207
208unsafe impl Send for Clock {}
209unsafe impl Sync for Clock {}
210
211mod sealed {
212    pub trait Sealed {}
213    impl<T: super::IsA<super::Clock>> Sealed for T {}
214}
215
216/// Trait containing all [`struct@Clock`] methods.
217///
218/// # Implementors
219///
220/// [`Clock`][struct@crate::Clock], [`SystemClock`][struct@crate::SystemClock]
221pub trait ClockExt: IsA<Clock> + sealed::Sealed + 'static {
222    /// The time `observation_external` of the external or master clock and the time
223    /// `observation_internal` of the internal or slave clock are added to the list of
224    /// observations. If enough observations are available, a linear regression
225    /// algorithm is run on the observations and `self` is recalibrated.
226    ///
227    /// If this functions returns [`true`], `r_squared` will contain the
228    /// correlation coefficient of the interpolation. A value of 1.0
229    /// means a perfect regression was performed. This value can
230    /// be used to control the sampling frequency of the master and slave
231    /// clocks.
232    /// ## `observation_internal`
233    /// a time on the internal clock
234    /// ## `observation_external`
235    /// a time on the external clock
236    ///
237    /// # Returns
238    ///
239    /// [`true`] if enough observations were added to run the
240    /// regression algorithm.
241    ///
242    /// ## `r_squared`
243    /// a pointer to hold the result
244    #[doc(alias = "gst_clock_add_observation")]
245    fn add_observation(
246        &self,
247        observation_internal: ClockTime,
248        observation_external: ClockTime,
249    ) -> Option<f64> {
250        unsafe {
251            let mut r_squared = std::mem::MaybeUninit::uninit();
252            let ret = from_glib(ffi::gst_clock_add_observation(
253                self.as_ref().to_glib_none().0,
254                observation_internal.into_glib(),
255                observation_external.into_glib(),
256                r_squared.as_mut_ptr(),
257            ));
258            if ret {
259                Some(r_squared.assume_init())
260            } else {
261                None
262            }
263        }
264    }
265
266    /// Add a clock observation to the internal slaving algorithm the same as
267    /// [`add_observation()`][Self::add_observation()], and return the result of the external or master
268    /// clock estimation, without updating the internal calibration.
269    ///
270    /// The caller can then take the results and call [`ClockExtManual::set_calibration()`][crate::prelude::ClockExtManual::set_calibration()]
271    /// with the values, or some modified version of them.
272    /// ## `observation_internal`
273    /// a time on the internal clock
274    /// ## `observation_external`
275    /// a time on the external clock
276    ///
277    /// # Returns
278    ///
279    /// [`true`] if enough observations were added to run the
280    /// regression algorithm.
281    ///
282    /// ## `r_squared`
283    /// a pointer to hold the result
284    ///
285    /// ## `internal`
286    /// a location to store the internal time
287    ///
288    /// ## `external`
289    /// a location to store the external time
290    ///
291    /// ## `rate_num`
292    /// a location to store the rate numerator
293    ///
294    /// ## `rate_denom`
295    /// a location to store the rate denominator
296    #[doc(alias = "gst_clock_add_observation_unapplied")]
297    fn add_observation_unapplied(
298        &self,
299        observation_internal: ClockTime,
300        observation_external: ClockTime,
301    ) -> Option<(f64, ClockTime, ClockTime, ClockTime, ClockTime)> {
302        unsafe {
303            let mut r_squared = std::mem::MaybeUninit::uninit();
304            let mut internal = std::mem::MaybeUninit::uninit();
305            let mut external = std::mem::MaybeUninit::uninit();
306            let mut rate_num = std::mem::MaybeUninit::uninit();
307            let mut rate_denom = std::mem::MaybeUninit::uninit();
308            let ret = from_glib(ffi::gst_clock_add_observation_unapplied(
309                self.as_ref().to_glib_none().0,
310                observation_internal.into_glib(),
311                observation_external.into_glib(),
312                r_squared.as_mut_ptr(),
313                internal.as_mut_ptr(),
314                external.as_mut_ptr(),
315                rate_num.as_mut_ptr(),
316                rate_denom.as_mut_ptr(),
317            ));
318            if ret {
319                Some((
320                    r_squared.assume_init(),
321                    try_from_glib(internal.assume_init()).expect("mandatory glib value is None"),
322                    try_from_glib(external.assume_init()).expect("mandatory glib value is None"),
323                    try_from_glib(rate_num.assume_init()).expect("mandatory glib value is None"),
324                    try_from_glib(rate_denom.assume_init()).expect("mandatory glib value is None"),
325                ))
326            } else {
327                None
328            }
329        }
330    }
331
332    /// Converts the given `internal` clock time to the external time, adjusting for the
333    /// rate and reference time set with [`ClockExtManual::set_calibration()`][crate::prelude::ClockExtManual::set_calibration()] and making sure
334    /// that the returned time is increasing. This function should be called with the
335    /// clock's OBJECT_LOCK held and is mainly used by clock subclasses.
336    ///
337    /// This function is the reverse of [`unadjust_unlocked()`][Self::unadjust_unlocked()].
338    /// ## `internal`
339    /// a clock time
340    ///
341    /// # Returns
342    ///
343    /// the converted time of the clock.
344    #[doc(alias = "gst_clock_adjust_unlocked")]
345    fn adjust_unlocked(&self, internal: ClockTime) -> Option<ClockTime> {
346        unsafe {
347            from_glib(ffi::gst_clock_adjust_unlocked(
348                self.as_ref().to_glib_none().0,
349                internal.into_glib(),
350            ))
351        }
352    }
353
354    /// Gets the current internal time of the given clock. The time is returned
355    /// unadjusted for the offset and the rate.
356    ///
357    /// # Returns
358    ///
359    /// the internal time of the clock. Or `GST_CLOCK_TIME_NONE` when
360    /// given invalid input.
361    #[doc(alias = "gst_clock_get_internal_time")]
362    #[doc(alias = "get_internal_time")]
363    fn internal_time(&self) -> ClockTime {
364        unsafe {
365            try_from_glib(ffi::gst_clock_get_internal_time(
366                self.as_ref().to_glib_none().0,
367            ))
368            .expect("mandatory glib value is None")
369        }
370    }
371
372    /// Gets the master clock that `self` is slaved to or [`None`] when the clock is
373    /// not slaved to any master clock.
374    ///
375    /// # Returns
376    ///
377    /// a master [`Clock`][crate::Clock] or [`None`]
378    ///  when this clock is not slaved to a master clock.
379    #[doc(alias = "gst_clock_get_master")]
380    #[doc(alias = "get_master")]
381    #[must_use]
382    fn master(&self) -> Option<Clock> {
383        unsafe { from_glib_full(ffi::gst_clock_get_master(self.as_ref().to_glib_none().0)) }
384    }
385
386    /// Gets the accuracy of the clock. The accuracy of the clock is the granularity
387    /// of the values returned by [`time()`][Self::time()].
388    ///
389    /// # Returns
390    ///
391    /// the resolution of the clock in units of `GstClockTime`.
392    #[doc(alias = "gst_clock_get_resolution")]
393    #[doc(alias = "get_resolution")]
394    fn resolution(&self) -> ClockTime {
395        unsafe {
396            try_from_glib(ffi::gst_clock_get_resolution(
397                self.as_ref().to_glib_none().0,
398            ))
399            .expect("mandatory glib value is None")
400        }
401    }
402
403    /// Gets the current time of the given clock. The time is always
404    /// monotonically increasing and adjusted according to the current
405    /// offset and rate.
406    ///
407    /// # Returns
408    ///
409    /// the time of the clock. Or `GST_CLOCK_TIME_NONE` when
410    /// given invalid input.
411    #[doc(alias = "gst_clock_get_time")]
412    #[doc(alias = "get_time")]
413    fn time(&self) -> Option<ClockTime> {
414        unsafe { from_glib(ffi::gst_clock_get_time(self.as_ref().to_glib_none().0)) }
415    }
416
417    /// Gets the amount of time that master and slave clocks are sampled.
418    ///
419    /// # Returns
420    ///
421    /// the interval between samples.
422    #[doc(alias = "gst_clock_get_timeout")]
423    #[doc(alias = "get_timeout")]
424    fn timeout(&self) -> Option<ClockTime> {
425        unsafe { from_glib(ffi::gst_clock_get_timeout(self.as_ref().to_glib_none().0)) }
426    }
427
428    /// Checks if the clock is currently synced, by looking at whether
429    /// [`ClockFlags::NEEDS_STARTUP_SYNC`][crate::ClockFlags::NEEDS_STARTUP_SYNC] is set.
430    ///
431    /// # Returns
432    ///
433    /// [`true`] if the clock is currently synced
434    #[doc(alias = "gst_clock_is_synced")]
435    fn is_synced(&self) -> bool {
436        unsafe { from_glib(ffi::gst_clock_is_synced(self.as_ref().to_glib_none().0)) }
437    }
438
439    /// Sets `master` as the master clock for `self`. `self` will be automatically
440    /// calibrated so that [`time()`][Self::time()] reports the same time as the
441    /// master clock.
442    ///
443    /// A clock provider that slaves its clock to a master can get the current
444    /// calibration values with [`ClockExtManual::calibration()`][crate::prelude::ClockExtManual::calibration()].
445    ///
446    /// `master` can be [`None`] in which case `self` will not be slaved anymore. It will
447    /// however keep reporting its time adjusted with the last configured rate
448    /// and time offsets.
449    /// ## `master`
450    /// a master [`Clock`][crate::Clock]
451    ///
452    /// # Returns
453    ///
454    /// [`true`] if the clock is capable of being slaved to a master clock.
455    /// Trying to set a master on a clock without the
456    /// [`ClockFlags::CAN_SET_MASTER`][crate::ClockFlags::CAN_SET_MASTER] flag will make this function return [`false`].
457    #[doc(alias = "gst_clock_set_master")]
458    fn set_master(&self, master: Option<&impl IsA<Clock>>) -> Result<(), glib::error::BoolError> {
459        unsafe {
460            glib::result_from_gboolean!(
461                ffi::gst_clock_set_master(
462                    self.as_ref().to_glib_none().0,
463                    master.map(|p| p.as_ref()).to_glib_none().0
464                ),
465                "Failed to set master clock"
466            )
467        }
468    }
469
470    /// Sets the accuracy of the clock. Some clocks have the possibility to operate
471    /// with different accuracy at the expense of more resource usage. There is
472    /// normally no need to change the default resolution of a clock. The resolution
473    /// of a clock can only be changed if the clock has the
474    /// [`ClockFlags::CAN_SET_RESOLUTION`][crate::ClockFlags::CAN_SET_RESOLUTION] flag set.
475    /// ## `resolution`
476    /// The resolution to set
477    ///
478    /// # Returns
479    ///
480    /// the new resolution of the clock.
481    #[doc(alias = "gst_clock_set_resolution")]
482    fn set_resolution(&self, resolution: ClockTime) -> ClockTime {
483        unsafe {
484            try_from_glib(ffi::gst_clock_set_resolution(
485                self.as_ref().to_glib_none().0,
486                resolution.into_glib(),
487            ))
488            .expect("mandatory glib value is None")
489        }
490    }
491
492    /// Sets `self` to synced and emits the [`synced`][struct@crate::Clock#synced] signal, and wakes up any
493    /// thread waiting in [`wait_for_sync()`][Self::wait_for_sync()].
494    ///
495    /// This function must only be called if [`ClockFlags::NEEDS_STARTUP_SYNC`][crate::ClockFlags::NEEDS_STARTUP_SYNC]
496    /// is set on the clock, and is intended to be called by subclasses only.
497    /// ## `synced`
498    /// if the clock is synced
499    #[doc(alias = "gst_clock_set_synced")]
500    fn set_synced(&self, synced: bool) {
501        unsafe {
502            ffi::gst_clock_set_synced(self.as_ref().to_glib_none().0, synced.into_glib());
503        }
504    }
505
506    /// Sets the amount of time, in nanoseconds, to sample master and slave
507    /// clocks
508    /// ## `timeout`
509    /// a timeout
510    #[doc(alias = "gst_clock_set_timeout")]
511    #[doc(alias = "timeout")]
512    fn set_timeout(&self, timeout: impl Into<Option<ClockTime>>) {
513        unsafe {
514            ffi::gst_clock_set_timeout(self.as_ref().to_glib_none().0, timeout.into().into_glib());
515        }
516    }
517
518    /// Converts the given `external` clock time to the internal time of `self`,
519    /// using the rate and reference time set with [`ClockExtManual::set_calibration()`][crate::prelude::ClockExtManual::set_calibration()].
520    /// This function should be called with the clock's OBJECT_LOCK held and
521    /// is mainly used by clock subclasses.
522    ///
523    /// This function is the reverse of [`adjust_unlocked()`][Self::adjust_unlocked()].
524    /// ## `external`
525    /// an external clock time
526    ///
527    /// # Returns
528    ///
529    /// the internal time of the clock corresponding to `external`.
530    #[doc(alias = "gst_clock_unadjust_unlocked")]
531    fn unadjust_unlocked(&self, external: ClockTime) -> Option<ClockTime> {
532        unsafe {
533            from_glib(ffi::gst_clock_unadjust_unlocked(
534                self.as_ref().to_glib_none().0,
535                external.into_glib(),
536            ))
537        }
538    }
539
540    /// Waits until `self` is synced for reporting the current time. If `timeout`
541    /// is `GST_CLOCK_TIME_NONE` it will wait forever, otherwise it will time out
542    /// after `timeout` nanoseconds.
543    ///
544    /// For asynchronous waiting, the [`synced`][struct@crate::Clock#synced] signal can be used.
545    ///
546    /// This returns immediately with [`true`] if [`ClockFlags::NEEDS_STARTUP_SYNC`][crate::ClockFlags::NEEDS_STARTUP_SYNC]
547    /// is not set on the clock, or if the clock is already synced.
548    /// ## `timeout`
549    /// timeout for waiting or `GST_CLOCK_TIME_NONE`
550    ///
551    /// # Returns
552    ///
553    /// [`true`] if waiting was successful, or [`false`] on timeout
554    #[doc(alias = "gst_clock_wait_for_sync")]
555    fn wait_for_sync(
556        &self,
557        timeout: impl Into<Option<ClockTime>>,
558    ) -> Result<(), glib::error::BoolError> {
559        unsafe {
560            glib::result_from_gboolean!(
561                ffi::gst_clock_wait_for_sync(
562                    self.as_ref().to_glib_none().0,
563                    timeout.into().into_glib()
564                ),
565                "Timed out waiting for sync"
566            )
567        }
568    }
569
570    #[doc(alias = "window-size")]
571    fn window_size(&self) -> i32 {
572        ObjectExt::property(self.as_ref(), "window-size")
573    }
574
575    #[doc(alias = "window-size")]
576    fn set_window_size(&self, window_size: i32) {
577        ObjectExt::set_property(self.as_ref(), "window-size", window_size)
578    }
579
580    #[doc(alias = "window-threshold")]
581    fn window_threshold(&self) -> i32 {
582        ObjectExt::property(self.as_ref(), "window-threshold")
583    }
584
585    #[doc(alias = "window-threshold")]
586    fn set_window_threshold(&self, window_threshold: i32) {
587        ObjectExt::set_property(self.as_ref(), "window-threshold", window_threshold)
588    }
589
590    /// Signaled on clocks with [`ClockFlags::NEEDS_STARTUP_SYNC`][crate::ClockFlags::NEEDS_STARTUP_SYNC] set once
591    /// the clock is synchronized, or when it completely lost synchronization.
592    /// This signal will not be emitted on clocks without the flag.
593    ///
594    /// This signal will be emitted from an arbitrary thread, most likely not
595    /// the application's main thread.
596    /// ## `synced`
597    /// if the clock is synced now
598    #[doc(alias = "synced")]
599    fn connect_synced<F: Fn(&Self, bool) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
600        unsafe extern "C" fn synced_trampoline<
601            P: IsA<Clock>,
602            F: Fn(&P, bool) + Send + Sync + 'static,
603        >(
604            this: *mut ffi::GstClock,
605            synced: glib::ffi::gboolean,
606            f: glib::ffi::gpointer,
607        ) {
608            let f: &F = &*(f as *const F);
609            f(
610                Clock::from_glib_borrow(this).unsafe_cast_ref(),
611                from_glib(synced),
612            )
613        }
614        unsafe {
615            let f: Box_<F> = Box_::new(f);
616            connect_raw(
617                self.as_ptr() as *mut _,
618                b"synced\0".as_ptr() as *const _,
619                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
620                    synced_trampoline::<Self, F> as *const (),
621                )),
622                Box_::into_raw(f),
623            )
624        }
625    }
626
627    #[doc(alias = "timeout")]
628    fn connect_timeout_notify<F: Fn(&Self) + Send + Sync + 'static>(
629        &self,
630        f: F,
631    ) -> SignalHandlerId {
632        unsafe extern "C" fn notify_timeout_trampoline<
633            P: IsA<Clock>,
634            F: Fn(&P) + Send + Sync + 'static,
635        >(
636            this: *mut ffi::GstClock,
637            _param_spec: glib::ffi::gpointer,
638            f: glib::ffi::gpointer,
639        ) {
640            let f: &F = &*(f as *const F);
641            f(Clock::from_glib_borrow(this).unsafe_cast_ref())
642        }
643        unsafe {
644            let f: Box_<F> = Box_::new(f);
645            connect_raw(
646                self.as_ptr() as *mut _,
647                b"notify::timeout\0".as_ptr() as *const _,
648                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
649                    notify_timeout_trampoline::<Self, F> as *const (),
650                )),
651                Box_::into_raw(f),
652            )
653        }
654    }
655
656    #[doc(alias = "window-size")]
657    fn connect_window_size_notify<F: Fn(&Self) + Send + Sync + 'static>(
658        &self,
659        f: F,
660    ) -> SignalHandlerId {
661        unsafe extern "C" fn notify_window_size_trampoline<
662            P: IsA<Clock>,
663            F: Fn(&P) + Send + Sync + 'static,
664        >(
665            this: *mut ffi::GstClock,
666            _param_spec: glib::ffi::gpointer,
667            f: glib::ffi::gpointer,
668        ) {
669            let f: &F = &*(f as *const F);
670            f(Clock::from_glib_borrow(this).unsafe_cast_ref())
671        }
672        unsafe {
673            let f: Box_<F> = Box_::new(f);
674            connect_raw(
675                self.as_ptr() as *mut _,
676                b"notify::window-size\0".as_ptr() as *const _,
677                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
678                    notify_window_size_trampoline::<Self, F> as *const (),
679                )),
680                Box_::into_raw(f),
681            )
682        }
683    }
684
685    #[doc(alias = "window-threshold")]
686    fn connect_window_threshold_notify<F: Fn(&Self) + Send + Sync + 'static>(
687        &self,
688        f: F,
689    ) -> SignalHandlerId {
690        unsafe extern "C" fn notify_window_threshold_trampoline<
691            P: IsA<Clock>,
692            F: Fn(&P) + Send + Sync + 'static,
693        >(
694            this: *mut ffi::GstClock,
695            _param_spec: glib::ffi::gpointer,
696            f: glib::ffi::gpointer,
697        ) {
698            let f: &F = &*(f as *const F);
699            f(Clock::from_glib_borrow(this).unsafe_cast_ref())
700        }
701        unsafe {
702            let f: Box_<F> = Box_::new(f);
703            connect_raw(
704                self.as_ptr() as *mut _,
705                b"notify::window-threshold\0".as_ptr() as *const _,
706                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
707                    notify_window_threshold_trampoline::<Self, F> as *const (),
708                )),
709                Box_::into_raw(f),
710            )
711        }
712    }
713}
714
715impl<O: IsA<Clock>> ClockExt for O {}