Skip to main content

gstreamer_net/auto/
ptp_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;
7use glib::{
8    prelude::*,
9    signal::{SignalHandlerId, connect_raw},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    /// GstPtpClock implements a PTP (IEEE1588:2008) ordinary clock in slave-only
16    /// mode, that allows a GStreamer pipeline to synchronize to a PTP network
17    /// clock in some specific domain.
18    ///
19    /// The PTP subsystem can be initialized with `gst_ptp_init()`, which then starts
20    /// a helper process to do the actual communication via the PTP ports. This is
21    /// required as PTP listens on ports < 1024 and thus requires special
22    /// privileges. Once this helper process is started, the main process will
23    /// synchronize to all PTP domains that are detected on the selected
24    /// interfaces.
25    ///
26    /// [`new()`][Self::new()] then allows to create a GstClock that provides the PTP
27    /// time from a master clock inside a specific PTP domain. This clock will only
28    /// return valid timestamps once the timestamps in the PTP domain are known. To
29    /// check this, you can use [`ClockExtManual::wait_for_sync()`][crate::gst::prelude::ClockExtManual::wait_for_sync()], the GstClock::synced
30    /// signal and [`ClockExtManual::is_synced()`][crate::gst::prelude::ClockExtManual::is_synced()].
31    ///
32    /// To gather statistics about the PTP clock synchronization,
33    /// `gst_ptp_statistics_callback_add()` can be used. This gives the application
34    /// the possibility to collect all kinds of statistics from the clock
35    /// synchronization.
36    ///
37    /// ## Properties
38    ///
39    ///
40    /// #### `domain`
41    ///  Readable | Writeable | Construct Only
42    ///
43    ///
44    /// #### `grandmaster-clock-id`
45    ///  Readable
46    ///
47    ///
48    /// #### `internal-clock`
49    ///  Readable
50    ///
51    ///
52    /// #### `master-clock-id`
53    ///  Readable
54    /// <details><summary><h4>SystemClock</h4></summary>
55    ///
56    ///
57    /// #### `clock-type`
58    ///  Readable | Writeable
59    /// </details>
60    /// <details><summary><h4>Clock</h4></summary>
61    ///
62    ///
63    /// #### `timeout`
64    ///  Readable | Writeable
65    ///
66    ///
67    /// #### `window-size`
68    ///  Readable | Writeable
69    ///
70    ///
71    /// #### `window-threshold`
72    ///  Readable | Writeable
73    /// </details>
74    /// <details><summary><h4>Object</h4></summary>
75    ///
76    ///
77    /// #### `name`
78    ///  Readable | Writeable | Construct
79    ///
80    ///
81    /// #### `parent`
82    ///  The parent of the object. Please note, that when changing the 'parent'
83    /// property, we don't emit [`notify`][struct@crate::glib::Object#notify] and [`deep-notify`][struct@crate::gst::Object#deep-notify]
84    /// signals due to locking issues. In some cases one can use
85    /// `GstBin::element-added` or `GstBin::element-removed` signals on the parent to
86    /// achieve a similar effect.
87    ///
88    /// Readable | Writeable
89    /// </details>
90    ///
91    /// # Implements
92    ///
93    /// [`trait@gst::prelude::ClockExt`], [`trait@gst::prelude::ObjectExt`], [`trait@glib::ObjectExt`]
94    #[doc(alias = "GstPtpClock")]
95    pub struct PtpClock(Object<ffi::GstPtpClock, ffi::GstPtpClockClass>) @extends gst::Clock, gst::Object;
96
97    match fn {
98        type_ => || ffi::gst_ptp_clock_get_type(),
99    }
100}
101
102impl PtpClock {
103    /// Creates a new PTP clock instance that exports the PTP time of the master
104    /// clock in `domain`. This clock can be slaved to other clocks as needed.
105    ///
106    /// If `gst_ptp_init()` was not called before, this will call `gst_ptp_init()` with
107    /// default parameters.
108    ///
109    /// This clock only returns valid timestamps after it received the first
110    /// times from the PTP master clock on the network. Once this happens the
111    /// GstPtpClock::internal-clock property will become non-NULL. You can
112    /// check this with [`ClockExtManual::wait_for_sync()`][crate::gst::prelude::ClockExtManual::wait_for_sync()], the GstClock::synced signal and
113    /// [`ClockExtManual::is_synced()`][crate::gst::prelude::ClockExtManual::is_synced()].
114    /// ## `name`
115    /// Name of the clock
116    /// ## `domain`
117    /// PTP domain
118    ///
119    /// # Returns
120    ///
121    /// A new [`gst::Clock`][crate::gst::Clock]
122    #[doc(alias = "gst_ptp_clock_new")]
123    pub fn new(name: Option<&str>, domain: u32) -> Result<PtpClock, glib::BoolError> {
124        assert_initialized_main_thread!();
125        unsafe {
126            Option::<gst::Clock>::from_glib_full(ffi::gst_ptp_clock_new(
127                name.to_glib_none().0,
128                domain,
129            ))
130            .map(|o| o.unsafe_cast())
131            .ok_or_else(|| glib::bool_error!("Can't create gst::PtpClock"))
132        }
133    }
134
135    pub fn domain(&self) -> u32 {
136        ObjectExt::property(self, "domain")
137    }
138
139    #[doc(alias = "grandmaster-clock-id")]
140    pub fn grandmaster_clock_id(&self) -> u64 {
141        ObjectExt::property(self, "grandmaster-clock-id")
142    }
143
144    #[doc(alias = "internal-clock")]
145    pub fn internal_clock(&self) -> Option<gst::Clock> {
146        ObjectExt::property(self, "internal-clock")
147    }
148
149    #[doc(alias = "master-clock-id")]
150    pub fn master_clock_id(&self) -> u64 {
151        ObjectExt::property(self, "master-clock-id")
152    }
153
154    #[doc(alias = "grandmaster-clock-id")]
155    pub fn connect_grandmaster_clock_id_notify<F: Fn(&Self) + Send + Sync + 'static>(
156        &self,
157        f: F,
158    ) -> SignalHandlerId {
159        unsafe extern "C" fn notify_grandmaster_clock_id_trampoline<
160            F: Fn(&PtpClock) + Send + Sync + 'static,
161        >(
162            this: *mut ffi::GstPtpClock,
163            _param_spec: glib::ffi::gpointer,
164            f: glib::ffi::gpointer,
165        ) {
166            unsafe {
167                let f: &F = &*(f as *const F);
168                f(&from_glib_borrow(this))
169            }
170        }
171        unsafe {
172            let f: Box_<F> = Box_::new(f);
173            connect_raw(
174                self.as_ptr() as *mut _,
175                c"notify::grandmaster-clock-id".as_ptr(),
176                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
177                    notify_grandmaster_clock_id_trampoline::<F> as *const (),
178                )),
179                Box_::into_raw(f),
180            )
181        }
182    }
183
184    #[doc(alias = "internal-clock")]
185    pub fn connect_internal_clock_notify<F: Fn(&Self) + Send + Sync + 'static>(
186        &self,
187        f: F,
188    ) -> SignalHandlerId {
189        unsafe extern "C" fn notify_internal_clock_trampoline<
190            F: Fn(&PtpClock) + Send + Sync + 'static,
191        >(
192            this: *mut ffi::GstPtpClock,
193            _param_spec: glib::ffi::gpointer,
194            f: glib::ffi::gpointer,
195        ) {
196            unsafe {
197                let f: &F = &*(f as *const F);
198                f(&from_glib_borrow(this))
199            }
200        }
201        unsafe {
202            let f: Box_<F> = Box_::new(f);
203            connect_raw(
204                self.as_ptr() as *mut _,
205                c"notify::internal-clock".as_ptr(),
206                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
207                    notify_internal_clock_trampoline::<F> as *const (),
208                )),
209                Box_::into_raw(f),
210            )
211        }
212    }
213
214    #[doc(alias = "master-clock-id")]
215    pub fn connect_master_clock_id_notify<F: Fn(&Self) + Send + Sync + 'static>(
216        &self,
217        f: F,
218    ) -> SignalHandlerId {
219        unsafe extern "C" fn notify_master_clock_id_trampoline<
220            F: Fn(&PtpClock) + Send + Sync + 'static,
221        >(
222            this: *mut ffi::GstPtpClock,
223            _param_spec: glib::ffi::gpointer,
224            f: glib::ffi::gpointer,
225        ) {
226            unsafe {
227                let f: &F = &*(f as *const F);
228                f(&from_glib_borrow(this))
229            }
230        }
231        unsafe {
232            let f: Box_<F> = Box_::new(f);
233            connect_raw(
234                self.as_ptr() as *mut _,
235                c"notify::master-clock-id".as_ptr(),
236                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
237                    notify_master_clock_id_trampoline::<F> as *const (),
238                )),
239                Box_::into_raw(f),
240            )
241        }
242    }
243}
244
245unsafe impl Send for PtpClock {}
246unsafe impl Sync for PtpClock {}