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::{ffi, TestClock};
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 {
53                from_glib_full(id)
54            } else {
55                None
56            }
57        }
58    }
59
60    /// Processes and releases the pending ID.
61    ///
62    /// MT safe.
63    /// ## `pending_id`
64    /// `GstClockID`
65    #[cfg(feature = "v1_18")]
66    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
67    #[doc(alias = "gst_test_clock_process_id")]
68    pub fn process_id(&self, pending_id: &gst::ClockId) -> bool {
69        unsafe {
70            from_glib(ffi::gst_test_clock_process_id(
71                self.to_glib_none().0,
72                pending_id.to_glib_none().0,
73            ))
74        }
75    }
76
77    /// Processes and releases the pending IDs in the list.
78    ///
79    /// MT safe.
80    /// ## `pending_list`
81    /// List
82    ///  of pending `GstClockIDs`
83    #[doc(alias = "gst_test_clock_process_id_list")]
84    pub fn process_id_list(&self, pending_list: &[&gst::ClockId]) -> u32 {
85        unsafe {
86            ffi::gst_test_clock_process_id_list(
87                self.to_glib_none().0,
88                pending_list.to_glib_none().0,
89            )
90        }
91    }
92
93    /// MT safe.
94    ///
95    /// # Returns
96    ///
97    /// a `GstClockID` containing the next pending clock
98    /// notification.
99    #[doc(alias = "gst_test_clock_process_next_clock_id")]
100    pub fn process_next_clock_id(&self) -> Option<gst::ClockId> {
101        unsafe {
102            from_glib_full(ffi::gst_test_clock_process_next_clock_id(
103                self.to_glib_none().0,
104            ))
105        }
106    }
107
108    /// Blocks until at least `count` clock notifications have been requested from
109    /// `self`. There is no timeout for this wait, see the main description of
110    /// [`TestClock`][crate::TestClock].
111    ///
112    /// MT safe.
113    /// ## `count`
114    /// the number of pending clock notifications to wait for
115    ///
116    /// # Returns
117    ///
118    ///
119    /// ## `pending_list`
120    /// Address
121    ///  of a `GList` pointer variable to store the list of pending `GstClockIDs`
122    ///  that expired, or [`None`]
123    #[doc(alias = "gst_test_clock_wait_for_multiple_pending_ids")]
124    pub fn wait_for_multiple_pending_ids(&self, count: u32) -> Vec<gst::ClockId> {
125        unsafe {
126            let mut pending_list = ptr::null_mut();
127            ffi::gst_test_clock_wait_for_multiple_pending_ids(
128                self.to_glib_none().0,
129                count,
130                &mut pending_list,
131            );
132            FromGlibPtrContainer::from_glib_full(pending_list)
133        }
134    }
135
136    /// Waits until a clock notification is requested from `self`. There is no
137    /// timeout for this wait, see the main description of [`TestClock`][crate::TestClock]. A reference
138    /// to the pending clock notification is stored in `pending_id`.
139    ///
140    /// MT safe.
141    ///
142    /// # Returns
143    ///
144    ///
145    /// ## `pending_id`
146    /// `GstClockID`
147    /// with information about the pending clock notification
148    #[doc(alias = "gst_test_clock_wait_for_next_pending_id")]
149    pub fn wait_for_next_pending_id(&self) -> gst::ClockId {
150        unsafe {
151            let mut id = ptr::null_mut();
152            ffi::gst_test_clock_wait_for_next_pending_id(self.to_glib_none().0, &mut id);
153            from_glib_full(id)
154        }
155    }
156
157    /// Blocks until at least `count` clock notifications have been requested from
158    /// `self`, or the timeout expires.
159    ///
160    /// MT safe.
161    /// ## `count`
162    /// the number of pending clock notifications to wait for
163    /// ## `timeout_ms`
164    /// the timeout in milliseconds
165    ///
166    /// # Returns
167    ///
168    /// a `gboolean` [`true`] if the waits have been registered, [`false`] if not.
169    /// (Could be that it timed out waiting or that more waits than waits was found)
170    ///
171    /// ## `pending_list`
172    /// Address
173    ///  of a `GList` pointer variable to store the list of pending `GstClockIDs`
174    ///  that expired, or [`None`]
175    #[cfg(feature = "v1_16")]
176    #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
177    #[doc(alias = "gst_test_clock_timed_wait_for_multiple_pending_ids")]
178    pub fn timed_wait_for_multiple_pending_ids(
179        &self,
180        count: u32,
181        timeout_ms: u32,
182    ) -> (bool, Vec<gst::ClockId>) {
183        unsafe {
184            let mut pending_list = ptr::null_mut();
185            let res = ffi::gst_test_clock_timed_wait_for_multiple_pending_ids(
186                self.to_glib_none().0,
187                count,
188                timeout_ms,
189                &mut pending_list,
190            );
191            (
192                from_glib(res),
193                FromGlibPtrContainer::from_glib_full(pending_list),
194            )
195        }
196    }
197}