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::{connect_raw, SignalHandlerId},
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 let f: &F = &*(f as *const F);
167 f(&from_glib_borrow(this))
168 }
169 unsafe {
170 let f: Box_<F> = Box_::new(f);
171 connect_raw(
172 self.as_ptr() as *mut _,
173 c"notify::grandmaster-clock-id".as_ptr() as *const _,
174 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
175 notify_grandmaster_clock_id_trampoline::<F> as *const (),
176 )),
177 Box_::into_raw(f),
178 )
179 }
180 }
181
182 #[doc(alias = "internal-clock")]
183 pub fn connect_internal_clock_notify<F: Fn(&Self) + Send + Sync + 'static>(
184 &self,
185 f: F,
186 ) -> SignalHandlerId {
187 unsafe extern "C" fn notify_internal_clock_trampoline<
188 F: Fn(&PtpClock) + Send + Sync + 'static,
189 >(
190 this: *mut ffi::GstPtpClock,
191 _param_spec: glib::ffi::gpointer,
192 f: glib::ffi::gpointer,
193 ) {
194 let f: &F = &*(f as *const F);
195 f(&from_glib_borrow(this))
196 }
197 unsafe {
198 let f: Box_<F> = Box_::new(f);
199 connect_raw(
200 self.as_ptr() as *mut _,
201 c"notify::internal-clock".as_ptr() as *const _,
202 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
203 notify_internal_clock_trampoline::<F> as *const (),
204 )),
205 Box_::into_raw(f),
206 )
207 }
208 }
209
210 #[doc(alias = "master-clock-id")]
211 pub fn connect_master_clock_id_notify<F: Fn(&Self) + Send + Sync + 'static>(
212 &self,
213 f: F,
214 ) -> SignalHandlerId {
215 unsafe extern "C" fn notify_master_clock_id_trampoline<
216 F: Fn(&PtpClock) + Send + Sync + 'static,
217 >(
218 this: *mut ffi::GstPtpClock,
219 _param_spec: glib::ffi::gpointer,
220 f: glib::ffi::gpointer,
221 ) {
222 let f: &F = &*(f as *const F);
223 f(&from_glib_borrow(this))
224 }
225 unsafe {
226 let f: Box_<F> = Box_::new(f);
227 connect_raw(
228 self.as_ptr() as *mut _,
229 c"notify::master-clock-id".as_ptr() as *const _,
230 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
231 notify_master_clock_id_trampoline::<F> as *const (),
232 )),
233 Box_::into_raw(f),
234 )
235 }
236 }
237}
238
239unsafe impl Send for PtpClock {}
240unsafe impl Sync for PtpClock {}