Skip to main content

gstreamer_check/
test_clock.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::ptr;
4
5use glib::translate::*;
6
7use crate::{TestClock, ffi};
8
9impl TestClock {
10    /// Checks whether `self` was requested to provide the clock notification
11    /// given by `id`.
12    ///
13    /// MT safe.
14    /// ## `id`
15    /// a `GstClockID` clock notification
16    ///
17    /// # Returns
18    ///
19    /// [`true`] if the clock has been asked to provide the given clock
20    /// notification, [`false`] otherwise.
21    #[doc(alias = "gst_test_clock_has_id")]
22    pub fn has_id(&self, id: &gst::ClockId) -> bool {
23        unsafe {
24            from_glib(ffi::gst_test_clock_has_id(
25                self.to_glib_none().0,
26                id.to_glib_none().0,
27            ))
28        }
29    }
30
31    /// Determines if the `pending_id` is the next clock notification scheduled to
32    /// be triggered given the current time of the `self`.
33    ///
34    /// MT safe.
35    ///
36    /// # Returns
37    ///
38    /// [`true`] if `pending_id` is the next clock notification to be
39    /// triggered, [`false`] otherwise.
40    ///
41    /// ## `pending_id`
42    /// a `GstClockID` clock
43    /// notification to look for
44    #[doc(alias = "gst_test_clock_peek_next_pending_id")]
45    pub fn peek_next_pending_id(&self) -> Option<gst::ClockId> {
46        unsafe {
47            let mut id = ptr::null_mut();
48            let ret: bool = from_glib(ffi::gst_test_clock_peek_next_pending_id(
49                self.to_glib_none().0,
50                &mut id,
51            ));
52            if ret { from_glib_full(id) } else { None }
53        }
54    }
55
56    /// Processes and releases the pending ID.
57    ///
58    /// MT safe.
59    /// ## `pending_id`
60    /// `GstClockID`
61    #[cfg(feature = "v1_18")]
62    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
63    #[doc(alias = "gst_test_clock_process_id")]
64    pub fn process_id(&self, pending_id: &gst::ClockId) -> bool {
65        unsafe {
66            from_glib(ffi::gst_test_clock_process_id(
67                self.to_glib_none().0,
68                pending_id.to_glib_none().0,
69            ))
70        }
71    }
72
73    /// Processes and releases the pending IDs in the list.
74    ///
75    /// MT safe.
76    /// ## `pending_list`
77    /// List
78    ///  of pending `GstClockIDs`
79    #[doc(alias = "gst_test_clock_process_id_list")]
80    pub fn process_id_list(&self, pending_list: &[&gst::ClockId]) -> u32 {
81        unsafe {
82            ffi::gst_test_clock_process_id_list(
83                self.to_glib_none().0,
84                pending_list.to_glib_none().0,
85            )
86        }
87    }
88
89    /// MT safe.
90    ///
91    /// # Returns
92    ///
93    /// a `GstClockID` containing the next pending clock
94    /// notification.
95    #[doc(alias = "gst_test_clock_process_next_clock_id")]
96    pub fn process_next_clock_id(&self) -> Option<gst::ClockId> {
97        unsafe {
98            from_glib_full(ffi::gst_test_clock_process_next_clock_id(
99                self.to_glib_none().0,
100            ))
101        }
102    }
103
104    /// Blocks until at least `count` clock notifications have been requested from
105    /// `self`. There is no timeout for this wait, see the main description of
106    /// [`TestClock`][crate::TestClock].
107    ///
108    /// MT safe.
109    /// ## `count`
110    /// the number of pending clock notifications to wait for
111    ///
112    /// # Returns
113    ///
114    ///
115    /// ## `pending_list`
116    /// Address
117    ///  of a `GList` pointer variable to store the list of pending `GstClockIDs`
118    ///  that expired, or [`None`]
119    #[doc(alias = "gst_test_clock_wait_for_multiple_pending_ids")]
120    pub fn wait_for_multiple_pending_ids(&self, count: u32) -> Vec<gst::ClockId> {
121        unsafe {
122            let mut pending_list = ptr::null_mut();
123            ffi::gst_test_clock_wait_for_multiple_pending_ids(
124                self.to_glib_none().0,
125                count,
126                &mut pending_list,
127            );
128            FromGlibPtrContainer::from_glib_full(pending_list)
129        }
130    }
131
132    /// Waits until a clock notification is requested from `self`. There is no
133    /// timeout for this wait, see the main description of [`TestClock`][crate::TestClock]. A reference
134    /// to the pending clock notification is stored in `pending_id`.
135    ///
136    /// MT safe.
137    ///
138    /// # Returns
139    ///
140    ///
141    /// ## `pending_id`
142    /// `GstClockID`
143    /// with information about the pending clock notification
144    #[doc(alias = "gst_test_clock_wait_for_next_pending_id")]
145    pub fn wait_for_next_pending_id(&self) -> gst::ClockId {
146        unsafe {
147            let mut id = ptr::null_mut();
148            ffi::gst_test_clock_wait_for_next_pending_id(self.to_glib_none().0, &mut id);
149            from_glib_full(id)
150        }
151    }
152
153    /// Blocks until at least `count` clock notifications have been requested from
154    /// `self`, or the timeout expires.
155    ///
156    /// MT safe.
157    /// ## `count`
158    /// the number of pending clock notifications to wait for
159    /// ## `timeout_ms`
160    /// the timeout in milliseconds
161    ///
162    /// # Returns
163    ///
164    /// a `gboolean` [`true`] if the waits have been registered, [`false`] if not.
165    /// (Could be that it timed out waiting or that more waits than waits was found)
166    ///
167    /// ## `pending_list`
168    /// Address
169    ///  of a `GList` pointer variable to store the list of pending `GstClockIDs`
170    ///  that expired, or [`None`]
171    #[cfg(feature = "v1_16")]
172    #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
173    #[doc(alias = "gst_test_clock_timed_wait_for_multiple_pending_ids")]
174    pub fn timed_wait_for_multiple_pending_ids(
175        &self,
176        count: u32,
177        timeout_ms: u32,
178    ) -> (bool, Vec<gst::ClockId>) {
179        unsafe {
180            let mut pending_list = ptr::null_mut();
181            let res = ffi::gst_test_clock_timed_wait_for_multiple_pending_ids(
182                self.to_glib_none().0,
183                count,
184                timeout_ms,
185                &mut pending_list,
186            );
187            (
188                from_glib(res),
189                FromGlibPtrContainer::from_glib_full(pending_list),
190            )
191        }
192    }
193}