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) -> Option<ClockTime> {
341 unsafe {
342 from_glib(ffi::gst_clock_adjust_unlocked(
343 self.as_ref().to_glib_none().0,
344 internal.into_glib(),
345 ))
346 }
347 }
348
349 /// Gets the current internal time of the given clock. The time is returned
350 /// unadjusted for the offset and the rate.
351 ///
352 /// # Returns
353 ///
354 /// the internal time of the clock. Or `GST_CLOCK_TIME_NONE` when
355 /// given invalid input.
356 #[doc(alias = "gst_clock_get_internal_time")]
357 #[doc(alias = "get_internal_time")]
358 fn internal_time(&self) -> ClockTime {
359 unsafe {
360 try_from_glib(ffi::gst_clock_get_internal_time(
361 self.as_ref().to_glib_none().0,
362 ))
363 .expect("mandatory glib value is None")
364 }
365 }
366
367 /// Gets the master clock that `self` is slaved to or [`None`] when the clock is
368 /// not slaved to any master clock.
369 ///
370 /// # Returns
371 ///
372 /// a master [`Clock`][crate::Clock] or [`None`]
373 /// when this clock is not slaved to a master clock.
374 #[doc(alias = "gst_clock_get_master")]
375 #[doc(alias = "get_master")]
376 #[must_use]
377 fn master(&self) -> Option<Clock> {
378 unsafe { from_glib_full(ffi::gst_clock_get_master(self.as_ref().to_glib_none().0)) }
379 }
380
381 /// Gets the accuracy of the clock. The accuracy of the clock is the granularity
382 /// of the values returned by [`time()`][Self::time()].
383 ///
384 /// # Returns
385 ///
386 /// the resolution of the clock in units of `GstClockTime`.
387 #[doc(alias = "gst_clock_get_resolution")]
388 #[doc(alias = "get_resolution")]
389 fn resolution(&self) -> ClockTime {
390 unsafe {
391 try_from_glib(ffi::gst_clock_get_resolution(
392 self.as_ref().to_glib_none().0,
393 ))
394 .expect("mandatory glib value is None")
395 }
396 }
397
398 /// Gets the current time of the given clock. The time is always
399 /// monotonically increasing and adjusted according to the current
400 /// offset and rate.
401 ///
402 /// # Returns
403 ///
404 /// the time of the clock. Or `GST_CLOCK_TIME_NONE` when
405 /// given invalid input.
406 #[doc(alias = "gst_clock_get_time")]
407 #[doc(alias = "get_time")]
408 fn time(&self) -> Option<ClockTime> {
409 unsafe { from_glib(ffi::gst_clock_get_time(self.as_ref().to_glib_none().0)) }
410 }
411
412 /// Gets the amount of time that master and slave clocks are sampled.
413 ///
414 /// # Returns
415 ///
416 /// the interval between samples.
417 #[doc(alias = "gst_clock_get_timeout")]
418 #[doc(alias = "get_timeout")]
419 fn timeout(&self) -> Option<ClockTime> {
420 unsafe { from_glib(ffi::gst_clock_get_timeout(self.as_ref().to_glib_none().0)) }
421 }
422
423 /// Checks if the clock is currently synced, by looking at whether
424 /// [`ClockFlags::NEEDS_STARTUP_SYNC`][crate::ClockFlags::NEEDS_STARTUP_SYNC] is set.
425 ///
426 /// # Returns
427 ///
428 /// [`true`] if the clock is currently synced
429 #[doc(alias = "gst_clock_is_synced")]
430 fn is_synced(&self) -> bool {
431 unsafe { from_glib(ffi::gst_clock_is_synced(self.as_ref().to_glib_none().0)) }
432 }
433
434 /// Sets `master` as the master clock for `self`. `self` will be automatically
435 /// calibrated so that [`time()`][Self::time()] reports the same time as the
436 /// master clock.
437 ///
438 /// A clock provider that slaves its clock to a master can get the current
439 /// calibration values with [`ClockExtManual::calibration()`][crate::prelude::ClockExtManual::calibration()].
440 ///
441 /// `master` can be [`None`] in which case `self` will not be slaved anymore. It will
442 /// however keep reporting its time adjusted with the last configured rate
443 /// and time offsets.
444 /// ## `master`
445 /// a master [`Clock`][crate::Clock]
446 ///
447 /// # Returns
448 ///
449 /// [`true`] if the clock is capable of being slaved to a master clock.
450 /// Trying to set a master on a clock without the
451 /// [`ClockFlags::CAN_SET_MASTER`][crate::ClockFlags::CAN_SET_MASTER] flag will make this function return [`false`].
452 #[doc(alias = "gst_clock_set_master")]
453 fn set_master(&self, master: Option<&impl IsA<Clock>>) -> Result<(), glib::error::BoolError> {
454 unsafe {
455 glib::result_from_gboolean!(
456 ffi::gst_clock_set_master(
457 self.as_ref().to_glib_none().0,
458 master.map(|p| p.as_ref()).to_glib_none().0
459 ),
460 "Failed to set master clock"
461 )
462 }
463 }
464
465 /// Sets the accuracy of the clock. Some clocks have the possibility to operate
466 /// with different accuracy at the expense of more resource usage. There is
467 /// normally no need to change the default resolution of a clock. The resolution
468 /// of a clock can only be changed if the clock has the
469 /// [`ClockFlags::CAN_SET_RESOLUTION`][crate::ClockFlags::CAN_SET_RESOLUTION] flag set.
470 /// ## `resolution`
471 /// The resolution to set
472 ///
473 /// # Returns
474 ///
475 /// the new resolution of the clock.
476 #[doc(alias = "gst_clock_set_resolution")]
477 fn set_resolution(&self, resolution: ClockTime) -> ClockTime {
478 unsafe {
479 try_from_glib(ffi::gst_clock_set_resolution(
480 self.as_ref().to_glib_none().0,
481 resolution.into_glib(),
482 ))
483 .expect("mandatory glib value is None")
484 }
485 }
486
487 /// Sets `self` to synced and emits the [`synced`][struct@crate::Clock#synced] signal, and wakes up any
488 /// thread waiting in [`wait_for_sync()`][Self::wait_for_sync()].
489 ///
490 /// This function must only be called if [`ClockFlags::NEEDS_STARTUP_SYNC`][crate::ClockFlags::NEEDS_STARTUP_SYNC]
491 /// is set on the clock, and is intended to be called by subclasses only.
492 /// ## `synced`
493 /// if the clock is synced
494 #[doc(alias = "gst_clock_set_synced")]
495 fn set_synced(&self, synced: bool) {
496 unsafe {
497 ffi::gst_clock_set_synced(self.as_ref().to_glib_none().0, synced.into_glib());
498 }
499 }
500
501 /// Sets the amount of time, in nanoseconds, to sample master and slave
502 /// clocks
503 /// ## `timeout`
504 /// a timeout
505 #[doc(alias = "gst_clock_set_timeout")]
506 #[doc(alias = "timeout")]
507 fn set_timeout(&self, timeout: impl Into<Option<ClockTime>>) {
508 unsafe {
509 ffi::gst_clock_set_timeout(self.as_ref().to_glib_none().0, timeout.into().into_glib());
510 }
511 }
512
513 /// Converts the given `external` clock time to the internal time of `self`,
514 /// using the rate and reference time set with [`ClockExtManual::set_calibration()`][crate::prelude::ClockExtManual::set_calibration()].
515 /// This function should be called with the clock's OBJECT_LOCK held and
516 /// is mainly used by clock subclasses.
517 ///
518 /// This function is the reverse of [`adjust_unlocked()`][Self::adjust_unlocked()].
519 /// ## `external`
520 /// an external clock time
521 ///
522 /// # Returns
523 ///
524 /// the internal time of the clock corresponding to `external`.
525 #[doc(alias = "gst_clock_unadjust_unlocked")]
526 fn unadjust_unlocked(&self, external: ClockTime) -> Option<ClockTime> {
527 unsafe {
528 from_glib(ffi::gst_clock_unadjust_unlocked(
529 self.as_ref().to_glib_none().0,
530 external.into_glib(),
531 ))
532 }
533 }
534
535 /// Waits until `self` is synced for reporting the current time. If `timeout`
536 /// is `GST_CLOCK_TIME_NONE` it will wait forever, otherwise it will time out
537 /// after `timeout` nanoseconds.
538 ///
539 /// For asynchronous waiting, the [`synced`][struct@crate::Clock#synced] signal can be used.
540 ///
541 /// This returns immediately with [`true`] if [`ClockFlags::NEEDS_STARTUP_SYNC`][crate::ClockFlags::NEEDS_STARTUP_SYNC]
542 /// is not set on the clock, or if the clock is already synced.
543 /// ## `timeout`
544 /// timeout for waiting or `GST_CLOCK_TIME_NONE`
545 ///
546 /// # Returns
547 ///
548 /// [`true`] if waiting was successful, or [`false`] on timeout
549 #[doc(alias = "gst_clock_wait_for_sync")]
550 fn wait_for_sync(
551 &self,
552 timeout: impl Into<Option<ClockTime>>,
553 ) -> Result<(), glib::error::BoolError> {
554 unsafe {
555 glib::result_from_gboolean!(
556 ffi::gst_clock_wait_for_sync(
557 self.as_ref().to_glib_none().0,
558 timeout.into().into_glib()
559 ),
560 "Timed out waiting for sync"
561 )
562 }
563 }
564
565 #[doc(alias = "window-size")]
566 fn window_size(&self) -> i32 {
567 ObjectExt::property(self.as_ref(), "window-size")
568 }
569
570 #[doc(alias = "window-size")]
571 fn set_window_size(&self, window_size: i32) {
572 ObjectExt::set_property(self.as_ref(), "window-size", window_size)
573 }
574
575 #[doc(alias = "window-threshold")]
576 fn window_threshold(&self) -> i32 {
577 ObjectExt::property(self.as_ref(), "window-threshold")
578 }
579
580 #[doc(alias = "window-threshold")]
581 fn set_window_threshold(&self, window_threshold: i32) {
582 ObjectExt::set_property(self.as_ref(), "window-threshold", window_threshold)
583 }
584
585 /// Signaled on clocks with [`ClockFlags::NEEDS_STARTUP_SYNC`][crate::ClockFlags::NEEDS_STARTUP_SYNC] set once
586 /// the clock is synchronized, or when it completely lost synchronization.
587 /// This signal will not be emitted on clocks without the flag.
588 ///
589 /// This signal will be emitted from an arbitrary thread, most likely not
590 /// the application's main thread.
591 /// ## `synced`
592 /// if the clock is synced now
593 #[doc(alias = "synced")]
594 fn connect_synced<F: Fn(&Self, bool) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
595 unsafe extern "C" fn synced_trampoline<
596 P: IsA<Clock>,
597 F: Fn(&P, bool) + Send + Sync + 'static,
598 >(
599 this: *mut ffi::GstClock,
600 synced: glib::ffi::gboolean,
601 f: glib::ffi::gpointer,
602 ) {
603 let f: &F = &*(f as *const F);
604 f(
605 Clock::from_glib_borrow(this).unsafe_cast_ref(),
606 from_glib(synced),
607 )
608 }
609 unsafe {
610 let f: Box_<F> = Box_::new(f);
611 connect_raw(
612 self.as_ptr() as *mut _,
613 c"synced".as_ptr() as *const _,
614 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
615 synced_trampoline::<Self, F> as *const (),
616 )),
617 Box_::into_raw(f),
618 )
619 }
620 }
621
622 #[doc(alias = "timeout")]
623 fn connect_timeout_notify<F: Fn(&Self) + Send + Sync + 'static>(
624 &self,
625 f: F,
626 ) -> SignalHandlerId {
627 unsafe extern "C" fn notify_timeout_trampoline<
628 P: IsA<Clock>,
629 F: Fn(&P) + Send + Sync + 'static,
630 >(
631 this: *mut ffi::GstClock,
632 _param_spec: glib::ffi::gpointer,
633 f: glib::ffi::gpointer,
634 ) {
635 let f: &F = &*(f as *const F);
636 f(Clock::from_glib_borrow(this).unsafe_cast_ref())
637 }
638 unsafe {
639 let f: Box_<F> = Box_::new(f);
640 connect_raw(
641 self.as_ptr() as *mut _,
642 c"notify::timeout".as_ptr() as *const _,
643 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
644 notify_timeout_trampoline::<Self, F> as *const (),
645 )),
646 Box_::into_raw(f),
647 )
648 }
649 }
650
651 #[doc(alias = "window-size")]
652 fn connect_window_size_notify<F: Fn(&Self) + Send + Sync + 'static>(
653 &self,
654 f: F,
655 ) -> SignalHandlerId {
656 unsafe extern "C" fn notify_window_size_trampoline<
657 P: IsA<Clock>,
658 F: Fn(&P) + Send + Sync + 'static,
659 >(
660 this: *mut ffi::GstClock,
661 _param_spec: glib::ffi::gpointer,
662 f: glib::ffi::gpointer,
663 ) {
664 let f: &F = &*(f as *const F);
665 f(Clock::from_glib_borrow(this).unsafe_cast_ref())
666 }
667 unsafe {
668 let f: Box_<F> = Box_::new(f);
669 connect_raw(
670 self.as_ptr() as *mut _,
671 c"notify::window-size".as_ptr() as *const _,
672 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
673 notify_window_size_trampoline::<Self, F> as *const (),
674 )),
675 Box_::into_raw(f),
676 )
677 }
678 }
679
680 #[doc(alias = "window-threshold")]
681 fn connect_window_threshold_notify<F: Fn(&Self) + Send + Sync + 'static>(
682 &self,
683 f: F,
684 ) -> SignalHandlerId {
685 unsafe extern "C" fn notify_window_threshold_trampoline<
686 P: IsA<Clock>,
687 F: Fn(&P) + Send + Sync + 'static,
688 >(
689 this: *mut ffi::GstClock,
690 _param_spec: glib::ffi::gpointer,
691 f: glib::ffi::gpointer,
692 ) {
693 let f: &F = &*(f as *const F);
694 f(Clock::from_glib_borrow(this).unsafe_cast_ref())
695 }
696 unsafe {
697 let f: Box_<F> = Box_::new(f);
698 connect_raw(
699 self.as_ptr() as *mut _,
700 c"notify::window-threshold".as_ptr() as *const _,
701 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
702 notify_window_threshold_trampoline::<Self, F> as *const (),
703 )),
704 Box_::into_raw(f),
705 )
706 }
707 }
708}
709
710impl<O: IsA<Clock>> ClockExt for O {}