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
211/// Trait containing all [`struct@Clock`] methods.
212///
213/// # Implementors
214///
215/// [`Clock`][struct@crate::Clock], [`SystemClock`][struct@crate::SystemClock]
216pub trait ClockExt: IsA<Clock> + 'static {
217    /// The time `observation_external` of the external or master clock and the time
218    /// `observation_internal` of the internal or slave clock are added to the list of
219    /// observations. If enough observations are available, a linear regression
220    /// algorithm is run on the observations and `self` is recalibrated.
221    ///
222    /// If this functions returns [`true`], `r_squared` will contain the
223    /// correlation coefficient of the interpolation. A value of 1.0
224    /// means a perfect regression was performed. This value can
225    /// be used to control the sampling frequency of the master and slave
226    /// clocks.
227    /// ## `observation_internal`
228    /// a time on the internal clock
229    /// ## `observation_external`
230    /// a time on the external clock
231    ///
232    /// # Returns
233    ///
234    /// [`true`] if enough observations were added to run the
235    /// regression algorithm.
236    ///
237    /// ## `r_squared`
238    /// a pointer to hold the result
239    #[doc(alias = "gst_clock_add_observation")]
240    fn add_observation(
241        &self,
242        observation_internal: ClockTime,
243        observation_external: ClockTime,
244    ) -> Option<f64> {
245        unsafe {
246            let mut r_squared = std::mem::MaybeUninit::uninit();
247            let ret = from_glib(ffi::gst_clock_add_observation(
248                self.as_ref().to_glib_none().0,
249                observation_internal.into_glib(),
250                observation_external.into_glib(),
251                r_squared.as_mut_ptr(),
252            ));
253            if ret {
254                Some(r_squared.assume_init())
255            } else {
256                None
257            }
258        }
259    }
260
261    /// Add a clock observation to the internal slaving algorithm the same as
262    /// [`add_observation()`][Self::add_observation()], and return the result of the external or master
263    /// clock estimation, without updating the internal calibration.
264    ///
265    /// The caller can then take the results and call [`ClockExtManual::set_calibration()`][crate::prelude::ClockExtManual::set_calibration()]
266    /// with the values, or some modified version of them.
267    /// ## `observation_internal`
268    /// a time on the internal clock
269    /// ## `observation_external`
270    /// a time on the external clock
271    ///
272    /// # Returns
273    ///
274    /// [`true`] if enough observations were added to run the
275    /// regression algorithm.
276    ///
277    /// ## `r_squared`
278    /// a pointer to hold the result
279    ///
280    /// ## `internal`
281    /// a location to store the internal time
282    ///
283    /// ## `external`
284    /// a location to store the external time
285    ///
286    /// ## `rate_num`
287    /// a location to store the rate numerator
288    ///
289    /// ## `rate_denom`
290    /// a location to store the rate denominator
291    #[doc(alias = "gst_clock_add_observation_unapplied")]
292    fn add_observation_unapplied(
293        &self,
294        observation_internal: ClockTime,
295        observation_external: ClockTime,
296    ) -> Option<(f64, ClockTime, ClockTime, ClockTime, ClockTime)> {
297        unsafe {
298            let mut r_squared = std::mem::MaybeUninit::uninit();
299            let mut internal = std::mem::MaybeUninit::uninit();
300            let mut external = std::mem::MaybeUninit::uninit();
301            let mut rate_num = std::mem::MaybeUninit::uninit();
302            let mut rate_denom = std::mem::MaybeUninit::uninit();
303            let ret = from_glib(ffi::gst_clock_add_observation_unapplied(
304                self.as_ref().to_glib_none().0,
305                observation_internal.into_glib(),
306                observation_external.into_glib(),
307                r_squared.as_mut_ptr(),
308                internal.as_mut_ptr(),
309                external.as_mut_ptr(),
310                rate_num.as_mut_ptr(),
311                rate_denom.as_mut_ptr(),
312            ));
313            if ret {
314                Some((
315                    r_squared.assume_init(),
316                    try_from_glib(internal.assume_init()).expect("mandatory glib value is None"),
317                    try_from_glib(external.assume_init()).expect("mandatory glib value is None"),
318                    try_from_glib(rate_num.assume_init()).expect("mandatory glib value is None"),
319                    try_from_glib(rate_denom.assume_init()).expect("mandatory glib value is None"),
320                ))
321            } else {
322                None
323            }
324        }
325    }
326
327    /// Converts the given `internal` clock time to the external time, adjusting for the
328    /// rate and reference time set with [`ClockExtManual::set_calibration()`][crate::prelude::ClockExtManual::set_calibration()] and making sure
329    /// that the returned time is increasing. This function should be called with the
330    /// clock's OBJECT_LOCK held and is mainly used by clock subclasses.
331    ///
332    /// This function is the reverse of [`unadjust_unlocked()`][Self::unadjust_unlocked()].
333    /// ## `internal`
334    /// a clock time
335    ///
336    /// # Returns
337    ///
338    /// the converted time of the clock.
339    #[doc(alias = "gst_clock_adjust_unlocked")]
340    fn adjust_unlocked(&self, internal: ClockTime) -> ClockTime {
341        unsafe {
342            try_from_glib(ffi::gst_clock_adjust_unlocked(
343                self.as_ref().to_glib_none().0,
344                internal.into_glib(),
345            ))
346            .expect("mandatory glib value is None")
347        }
348    }
349
350    /// Gets the current internal time of the given clock. The time is returned
351    /// unadjusted for the offset and the rate.
352    ///
353    /// # Returns
354    ///
355    /// the internal time of the clock. Or `GST_CLOCK_TIME_NONE` when
356    /// given invalid input.
357    #[doc(alias = "gst_clock_get_internal_time")]
358    #[doc(alias = "get_internal_time")]
359    fn internal_time(&self) -> ClockTime {
360        unsafe {
361            try_from_glib(ffi::gst_clock_get_internal_time(
362                self.as_ref().to_glib_none().0,
363            ))
364            .expect("mandatory glib value is None")
365        }
366    }
367
368    /// Gets the master clock that `self` is slaved to or [`None`] when the clock is
369    /// not slaved to any master clock.
370    ///
371    /// # Returns
372    ///
373    /// a master [`Clock`][crate::Clock] or [`None`]
374    ///  when this clock is not slaved to a master clock.
375    #[doc(alias = "gst_clock_get_master")]
376    #[doc(alias = "get_master")]
377    #[must_use]
378    fn master(&self) -> Option<Clock> {
379        unsafe { from_glib_full(ffi::gst_clock_get_master(self.as_ref().to_glib_none().0)) }
380    }
381
382    /// Gets the accuracy of the clock. The accuracy of the clock is the granularity
383    /// of the values returned by [`time()`][Self::time()].
384    ///
385    /// # Returns
386    ///
387    /// the resolution of the clock in units of `GstClockTime`.
388    #[doc(alias = "gst_clock_get_resolution")]
389    #[doc(alias = "get_resolution")]
390    fn resolution(&self) -> ClockTime {
391        unsafe {
392            try_from_glib(ffi::gst_clock_get_resolution(
393                self.as_ref().to_glib_none().0,
394            ))
395            .expect("mandatory glib value is None")
396        }
397    }
398
399    /// Gets the current time of the given clock. The time is always
400    /// monotonically increasing and adjusted according to the current
401    /// offset and rate.
402    ///
403    /// # Returns
404    ///
405    /// the time of the clock. Or `GST_CLOCK_TIME_NONE` when
406    /// given invalid input.
407    #[doc(alias = "gst_clock_get_time")]
408    #[doc(alias = "get_time")]
409    fn time(&self) -> ClockTime {
410        unsafe {
411            try_from_glib(ffi::gst_clock_get_time(self.as_ref().to_glib_none().0))
412                .expect("mandatory glib value is None")
413        }
414    }
415
416    /// Gets the amount of time that master and slave clocks are sampled.
417    ///
418    /// # Returns
419    ///
420    /// the interval between samples.
421    #[doc(alias = "gst_clock_get_timeout")]
422    #[doc(alias = "get_timeout")]
423    fn timeout(&self) -> Option<ClockTime> {
424        unsafe { from_glib(ffi::gst_clock_get_timeout(self.as_ref().to_glib_none().0)) }
425    }
426
427    /// Checks if the clock is currently synced, by looking at whether
428    /// [`ClockFlags::NEEDS_STARTUP_SYNC`][crate::ClockFlags::NEEDS_STARTUP_SYNC] is set.
429    ///
430    /// # Returns
431    ///
432    /// [`true`] if the clock is currently synced
433    #[doc(alias = "gst_clock_is_synced")]
434    fn is_synced(&self) -> bool {
435        unsafe { from_glib(ffi::gst_clock_is_synced(self.as_ref().to_glib_none().0)) }
436    }
437
438    /// Sets `master` as the master clock for `self`. `self` will be automatically
439    /// calibrated so that [`time()`][Self::time()] reports the same time as the
440    /// master clock.
441    ///
442    /// A clock provider that slaves its clock to a master can get the current
443    /// calibration values with [`ClockExtManual::calibration()`][crate::prelude::ClockExtManual::calibration()].
444    ///
445    /// `master` can be [`None`] in which case `self` will not be slaved anymore. It will
446    /// however keep reporting its time adjusted with the last configured rate
447    /// and time offsets.
448    /// ## `master`
449    /// a master [`Clock`][crate::Clock]
450    ///
451    /// # Returns
452    ///
453    /// [`true`] if the clock is capable of being slaved to a master clock.
454    /// Trying to set a master on a clock without the
455    /// [`ClockFlags::CAN_SET_MASTER`][crate::ClockFlags::CAN_SET_MASTER] flag will make this function return [`false`].
456    #[doc(alias = "gst_clock_set_master")]
457    fn set_master(&self, master: Option<&impl IsA<Clock>>) -> Result<(), glib::error::BoolError> {
458        unsafe {
459            glib::result_from_gboolean!(
460                ffi::gst_clock_set_master(
461                    self.as_ref().to_glib_none().0,
462                    master.map(|p| p.as_ref()).to_glib_none().0
463                ),
464                "Failed to set master clock"
465            )
466        }
467    }
468
469    /// Sets the accuracy of the clock. Some clocks have the possibility to operate
470    /// with different accuracy at the expense of more resource usage. There is
471    /// normally no need to change the default resolution of a clock. The resolution
472    /// of a clock can only be changed if the clock has the
473    /// [`ClockFlags::CAN_SET_RESOLUTION`][crate::ClockFlags::CAN_SET_RESOLUTION] flag set.
474    /// ## `resolution`
475    /// The resolution to set
476    ///
477    /// # Returns
478    ///
479    /// the new resolution of the clock.
480    #[doc(alias = "gst_clock_set_resolution")]
481    fn set_resolution(&self, resolution: ClockTime) -> ClockTime {
482        unsafe {
483            try_from_glib(ffi::gst_clock_set_resolution(
484                self.as_ref().to_glib_none().0,
485                resolution.into_glib(),
486            ))
487            .expect("mandatory glib value is None")
488        }
489    }
490
491    /// Sets `self` to synced and emits the [`synced`][struct@crate::Clock#synced] signal, and wakes up any
492    /// thread waiting in [`wait_for_sync()`][Self::wait_for_sync()].
493    ///
494    /// This function must only be called if [`ClockFlags::NEEDS_STARTUP_SYNC`][crate::ClockFlags::NEEDS_STARTUP_SYNC]
495    /// is set on the clock, and is intended to be called by subclasses only.
496    /// ## `synced`
497    /// if the clock is synced
498    #[doc(alias = "gst_clock_set_synced")]
499    fn set_synced(&self, synced: bool) {
500        unsafe {
501            ffi::gst_clock_set_synced(self.as_ref().to_glib_none().0, synced.into_glib());
502        }
503    }
504
505    /// Sets the amount of time, in nanoseconds, to sample master and slave
506    /// clocks
507    /// ## `timeout`
508    /// a timeout
509    #[doc(alias = "gst_clock_set_timeout")]
510    #[doc(alias = "timeout")]
511    fn set_timeout(&self, timeout: impl Into<Option<ClockTime>>) {
512        unsafe {
513            ffi::gst_clock_set_timeout(self.as_ref().to_glib_none().0, timeout.into().into_glib());
514        }
515    }
516
517    /// Converts the given `external` clock time to the internal time of `self`,
518    /// using the rate and reference time set with [`ClockExtManual::set_calibration()`][crate::prelude::ClockExtManual::set_calibration()].
519    /// This function should be called with the clock's OBJECT_LOCK held and
520    /// is mainly used by clock subclasses.
521    ///
522    /// This function is the reverse of [`adjust_unlocked()`][Self::adjust_unlocked()].
523    /// ## `external`
524    /// an external clock time
525    ///
526    /// # Returns
527    ///
528    /// the internal time of the clock corresponding to `external`.
529    #[doc(alias = "gst_clock_unadjust_unlocked")]
530    fn unadjust_unlocked(&self, external: ClockTime) -> ClockTime {
531        unsafe {
532            try_from_glib(ffi::gst_clock_unadjust_unlocked(
533                self.as_ref().to_glib_none().0,
534                external.into_glib(),
535            ))
536            .expect("mandatory glib value is None")
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                c"synced".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                c"notify::timeout".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                c"notify::window-size".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                c"notify::window-threshold".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 {}