Skip to main content

gstreamer_check/auto/
test_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    /// pending_id);
16    ///  GST_INFO ("Advance past 7ms beyond the requested time of the clock notification\n");
17    ///  gst_test_clock_advance_time (test_clock, latency + 7 * GST_MSECOND);
18    ///  GST_INFO ("Release the next blocking wait and make sure it is the one from element\n");
19    ///  processed_id = gst_test_clock_process_next_clock_id (test_clock);
20    ///  g_assert (processed_id == pending_id);
21    ///  g_assert_cmpint (GST_CLOCK_ENTRY_STATUS (processed_id), ==, GST_CLOCK_OK);
22    ///  gst_clock_id_unref (pending_id);
23    ///  gst_clock_id_unref (processed_id);
24    ///
25    ///  GST_INFO ("Validate that element produced an output buffer and check its timestamp\n");
26    ///  g_assert_cmpint (get_number_of_output_buffer (...), ==, 1);
27    ///  buf = get_buffer_pushed_by_element (element, ...);
28    ///  g_assert_cmpint (GST_BUFFER_TIMESTAMP (buf), ==,
29    ///  10 * GST_SECOND + latency + 7 * GST_MSECOND);
30    ///  gst_buffer_unref (buf);
31    ///  GST_INFO ("Check that element does not wait for any clock notification\n");
32    ///  g_assert (!gst_test_clock_peek_next_pending_id (test_clock, NULL));
33    ///  ...
34    /// ]|
35    ///
36    /// Since [`TestClock`][crate::TestClock] is only supposed to be used in unit tests it calls
37    /// `g_assert()`, `g_assert_cmpint()` or `g_assert_cmpuint()` to validate all function
38    /// arguments. This will highlight any issues with the unit test code itself.
39    ///
40    /// ## Properties
41    ///
42    ///
43    /// #### `clock-type`
44    ///  Readable | Writable
45    ///
46    ///
47    /// #### `start-time`
48    ///  When a [`TestClock`][crate::TestClock] is constructed it will have a certain start time set.
49    /// If the clock was created using [`TestClock::with_start_time()`][crate::TestClock::with_start_time()] then
50    /// this property contains the value of the `start_time` argument. If
51    /// [`TestClock::new()`][crate::TestClock::new()] was called the clock started at time zero, and thus
52    /// this property contains the value 0.
53    ///
54    /// Readable | Writable | Construct Only
55    /// <details><summary><h4>Clock</h4></summary>
56    ///
57    ///
58    /// #### `timeout`
59    ///  Readable | Writable
60    ///
61    ///
62    /// #### `window-size`
63    ///  Readable | Writable
64    ///
65    ///
66    /// #### `window-threshold`
67    ///  Readable | Writable
68    /// </details>
69    /// <details><summary><h4>Object</h4></summary>
70    ///
71    ///
72    /// #### `name`
73    ///  Readable | Writable | Construct
74    ///
75    ///
76    /// #### `parent`
77    ///  The parent of the object. Please note, that when changing the 'parent'
78    /// property, we don't emit [`notify`][struct@crate::glib::Object#notify] and [`deep-notify`][struct@crate::gst::Object#deep-notify]
79    /// signals due to locking issues. In some cases one can use
80    /// [`element-added`][struct@crate::gst::Bin#element-added] or [`element-removed`][struct@crate::gst::Bin#element-removed] signals on the parent to
81    /// achieve a similar effect.
82    ///
83    /// Readable | Writable
84    /// </details>
85    ///
86    /// # Implements
87    ///
88    /// [`trait@gst::prelude::ClockExt`], [`trait@gst::prelude::ObjectExt`], [`trait@glib::ObjectExt`]
89    #[doc(alias = "GstTestClock")]
90    pub struct TestClock(Object<ffi::GstTestClock, ffi::GstTestClockClass>) @extends gst::Clock, gst::Object;
91
92    match fn {
93        type_ => || ffi::gst_test_clock_get_type(),
94    }
95}
96
97impl TestClock {
98    /// Creates a new test clock with its time set to zero.
99    ///
100    /// MT safe.
101    ///
102    /// # Returns
103    ///
104    /// a [`TestClock`][crate::TestClock] cast to [`gst::Clock`][crate::gst::Clock].
105    #[doc(alias = "gst_test_clock_new")]
106    pub fn new() -> TestClock {
107        assert_initialized_main_thread!();
108        unsafe { gst::Clock::from_glib_full(ffi::gst_test_clock_new()).unsafe_cast() }
109    }
110
111    /// Creates a new test clock with its time set to the specified time.
112    ///
113    /// MT safe.
114    /// ## `start_time`
115    /// a `GstClockTime` set to the desired start time of the clock.
116    ///
117    /// # Returns
118    ///
119    /// a [`TestClock`][crate::TestClock] cast to [`gst::Clock`][crate::gst::Clock].
120    #[doc(alias = "gst_test_clock_new_with_start_time")]
121    #[doc(alias = "new_with_start_time")]
122    pub fn with_start_time(start_time: gst::ClockTime) -> TestClock {
123        assert_initialized_main_thread!();
124        unsafe {
125            gst::Clock::from_glib_full(ffi::gst_test_clock_new_with_start_time(
126                start_time.into_glib(),
127            ))
128            .unsafe_cast()
129        }
130    }
131
132    /// Advances the time of the `self` by the amount given by `delta`. The
133    /// time of `self` is monotonically increasing, therefore providing a
134    /// `delta` which is negative or zero is a programming error.
135    ///
136    /// MT safe.
137    /// ## `delta`
138    /// a positive `GstClockTimeDiff` to be added to the time of the clock
139    #[doc(alias = "gst_test_clock_advance_time")]
140    pub fn advance_time(&self, delta: gst::ClockTimeDiff) {
141        unsafe {
142            ffi::gst_test_clock_advance_time(self.to_glib_none().0, delta);
143        }
144    }
145
146    /// A "crank" consists of three steps:
147    /// 1: Wait for a `GstClockID` to be registered with the [`TestClock`][crate::TestClock].
148    /// 2: Advance the [`TestClock`][crate::TestClock] to the time the `GstClockID` is waiting, unless
149    ///  the clock time is already passed the clock id (Since: 1.18).
150    /// 3: Release the `GstClockID` wait.
151    /// A "crank" can be though of as the notion of
152    /// manually driving the clock forward to its next logical step.
153    ///
154    /// # Returns
155    ///
156    /// [`true`] if the crank was successful, [`false`] otherwise.
157    ///
158    /// MT safe.
159    #[doc(alias = "gst_test_clock_crank")]
160    pub fn crank(&self) -> bool {
161        unsafe { from_glib(ffi::gst_test_clock_crank(self.to_glib_none().0)) }
162    }
163
164    /// Retrieve the requested time for the next pending clock notification.
165    ///
166    /// MT safe.
167    ///
168    /// # Returns
169    ///
170    /// a `GstClockTime` set to the time of the next pending clock
171    /// notification. If no clock notifications have been requested
172    /// `GST_CLOCK_TIME_NONE` will be returned.
173    #[doc(alias = "gst_test_clock_get_next_entry_time")]
174    #[doc(alias = "get_next_entry_time")]
175    pub fn next_entry_time(&self) -> Option<gst::ClockTime> {
176        unsafe {
177            from_glib(ffi::gst_test_clock_get_next_entry_time(
178                self.to_glib_none().0,
179            ))
180        }
181    }
182
183    /// Determine the number of pending clock notifications that have been
184    /// requested from the `self`.
185    ///
186    /// MT safe.
187    ///
188    /// # Returns
189    ///
190    /// the number of pending clock notifications.
191    #[doc(alias = "gst_test_clock_peek_id_count")]
192    pub fn peek_id_count(&self) -> u32 {
193        unsafe { ffi::gst_test_clock_peek_id_count(self.to_glib_none().0) }
194    }
195
196    /// Sets the time of `self` to the time given by `new_time`. The time of
197    /// `self` is monotonically increasing, therefore providing a `new_time`
198    /// which is earlier or equal to the time of the clock as given by
199    /// [`ClockExtManual::time()`][crate::gst::prelude::ClockExtManual::time()] is a programming error.
200    ///
201    /// MT safe.
202    /// ## `new_time`
203    /// a `GstClockTime` later than that returned by [`ClockExtManual::time()`][crate::gst::prelude::ClockExtManual::time()]
204    #[doc(alias = "gst_test_clock_set_time")]
205    pub fn set_time(&self, new_time: gst::ClockTime) {
206        unsafe {
207            ffi::gst_test_clock_set_time(self.to_glib_none().0, new_time.into_glib());
208        }
209    }
210
211    /// Blocks until at least `count` clock notifications have been requested from
212    /// `self`. There is no timeout for this wait, see the main description of
213    /// [`TestClock`][crate::TestClock].
214    ///
215    /// # Deprecated
216    ///
217    /// use [`wait_for_multiple_pending_ids()`][Self::wait_for_multiple_pending_ids()] instead.
218    /// ## `count`
219    /// the number of pending clock notifications to wait for
220    #[doc(alias = "gst_test_clock_wait_for_pending_id_count")]
221    pub fn wait_for_pending_id_count(&self, count: u32) {
222        unsafe {
223            ffi::gst_test_clock_wait_for_pending_id_count(self.to_glib_none().0, count);
224        }
225    }
226
227    #[doc(alias = "clock-type")]
228    pub fn clock_type(&self) -> gst::ClockType {
229        ObjectExt::property(self, "clock-type")
230    }
231
232    #[doc(alias = "clock-type")]
233    pub fn set_clock_type(&self, clock_type: gst::ClockType) {
234        ObjectExt::set_property(self, "clock-type", clock_type)
235    }
236
237    /// When a [`TestClock`][crate::TestClock] is constructed it will have a certain start time set.
238    /// If the clock was created using [`with_start_time()`][Self::with_start_time()] then
239    /// this property contains the value of the `start_time` argument. If
240    /// [`new()`][Self::new()] was called the clock started at time zero, and thus
241    /// this property contains the value 0.
242    #[doc(alias = "start-time")]
243    pub fn start_time(&self) -> u64 {
244        ObjectExt::property(self, "start-time")
245    }
246
247    //#[doc(alias = "gst_test_clock_id_list_get_latest_time")]
248    //pub fn id_list_get_latest_time(pending_list: /*Unimplemented*/&[&gst::ClockID]) -> Option<gst::ClockTime> {
249    //    unsafe { TODO: call ffi:gst_test_clock_id_list_get_latest_time() }
250    //}
251
252    #[doc(alias = "clock-type")]
253    pub fn connect_clock_type_notify<F: Fn(&Self) + Send + Sync + 'static>(
254        &self,
255        f: F,
256    ) -> SignalHandlerId {
257        unsafe extern "C" fn notify_clock_type_trampoline<
258            F: Fn(&TestClock) + Send + Sync + 'static,
259        >(
260            this: *mut ffi::GstTestClock,
261            _param_spec: glib::ffi::gpointer,
262            f: glib::ffi::gpointer,
263        ) {
264            unsafe {
265                let f: &F = &*(f as *const F);
266                f(&from_glib_borrow(this))
267            }
268        }
269        unsafe {
270            let f: Box_<F> = Box_::new(f);
271            connect_raw(
272                self.as_ptr() as *mut _,
273                c"notify::clock-type".as_ptr(),
274                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
275                    notify_clock_type_trampoline::<F> as *const (),
276                )),
277                Box_::into_raw(f),
278            )
279        }
280    }
281}
282
283impl Default for TestClock {
284    fn default() -> Self {
285        Self::new()
286    }
287}
288
289unsafe impl Send for TestClock {}
290unsafe impl Sync for TestClock {}