Skip to main content

gstreamer/
system_clock.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3#[cfg(feature = "v1_30")]
4use glib::{prelude::*, translate::*};
5
6#[cfg(feature = "v1_30")]
7use crate::{Clock, ffi};
8use crate::{ClockType, SystemClock};
9
10impl SystemClock {
11    /// Creates a new instance of the system clock. Unlike [`obtain()`][Self::obtain()]
12    /// this allows to apply custom calibration to it via
13    /// [`ClockExtManual::set_calibration()`][crate::prelude::ClockExtManual::set_calibration()], set a master clock via [`ClockExt::set_master()`][crate::prelude::ClockExt::set_master()] or
14    /// change the `clock-type` property without changing the behaviour of the
15    /// default system clock for the whole process.
16    /// ## `name`
17    /// name of the new clock
18    /// ## `clock_type`
19    /// [`ClockType`][crate::ClockType] for the new clock
20    ///
21    /// # Returns
22    ///
23    /// the new system clock instance.
24    #[cfg(feature = "v1_30")]
25    #[doc(alias = "gst_system_clock_new")]
26    pub fn new(name: Option<&str>, clock_type: ClockType) -> SystemClock {
27        assert_initialized_main_thread!();
28        unsafe {
29            Clock::from_glib_full(ffi::gst_system_clock_new(
30                name.to_glib_none().0,
31                clock_type.into_glib(),
32            ))
33            .unsafe_cast()
34        }
35    }
36
37    #[cfg(not(feature = "v1_30"))]
38    #[doc(alias = "gst_system_clock_new")]
39    pub fn new(name: Option<&str>, clock_type: ClockType) -> SystemClock {
40        assert_initialized_main_thread!();
41        glib::Object::builder::<SystemClock>()
42            .property("name", name)
43            .property("clock-type", clock_type)
44            .build()
45    }
46}