1use crate::{DiscovererInfo, ffi};
7use glib::{
8 object::ObjectType as _,
9 prelude::*,
10 signal::{SignalHandlerId, connect_raw},
11 translate::*,
12};
13use std::boxed::Box as Box_;
14
15glib::wrapper! {
16 #[doc(alias = "GstDiscoverer")]
17 pub struct Discoverer(Object<ffi::GstDiscoverer, ffi::GstDiscovererClass>);
18
19 match fn {
20 type_ => || ffi::gst_discoverer_get_type(),
21 }
22}
23
24impl Discoverer {
25 #[doc(alias = "gst_discoverer_new")]
26 pub fn new(timeout: gst::ClockTime) -> Result<Discoverer, glib::Error> {
27 assert_initialized_main_thread!();
28 unsafe {
29 let mut error = std::ptr::null_mut();
30 let ret = ffi::gst_discoverer_new(timeout.into_glib(), &mut error);
31 if error.is_null() {
32 Ok(from_glib_full(ret))
33 } else {
34 Err(from_glib_full(error))
35 }
36 }
37 }
38
39 #[doc(alias = "gst_discoverer_discover_uri")]
40 pub fn discover_uri(&self, uri: &str) -> Result<DiscovererInfo, glib::Error> {
41 unsafe {
42 let mut error = std::ptr::null_mut();
43 let ret = ffi::gst_discoverer_discover_uri(
44 self.to_glib_none().0,
45 uri.to_glib_none().0,
46 &mut error,
47 );
48 if error.is_null() {
49 Ok(from_glib_full(ret))
50 } else {
51 Err(from_glib_full(error))
52 }
53 }
54 }
55
56 #[doc(alias = "gst_discoverer_discover_uri_async")]
57 pub fn discover_uri_async(&self, uri: &str) -> Result<(), glib::error::BoolError> {
58 unsafe {
59 glib::result_from_gboolean!(
60 ffi::gst_discoverer_discover_uri_async(self.to_glib_none().0, uri.to_glib_none().0),
61 "Failed to add URI to list of discovers"
62 )
63 }
64 }
65
66 #[doc(alias = "gst_discoverer_start")]
67 pub fn start(&self) {
68 unsafe {
69 ffi::gst_discoverer_start(self.to_glib_none().0);
70 }
71 }
72
73 #[doc(alias = "gst_discoverer_stop")]
74 pub fn stop(&self) {
75 unsafe {
76 ffi::gst_discoverer_stop(self.to_glib_none().0);
77 }
78 }
79
80 #[cfg(feature = "v1_16")]
81 #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
82 #[doc(alias = "use-cache")]
83 pub fn uses_cache(&self) -> bool {
84 ObjectExt::property(self, "use-cache")
85 }
86
87 #[cfg(feature = "v1_16")]
88 #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
89 #[doc(alias = "use-cache")]
90 pub fn set_use_cache(&self, use_cache: bool) {
91 ObjectExt::set_property(self, "use-cache", use_cache)
92 }
93
94 #[doc(alias = "discovered")]
95 pub fn connect_discovered<
96 F: Fn(&Self, &DiscovererInfo, Option<&glib::Error>) + Send + Sync + 'static,
97 >(
98 &self,
99 f: F,
100 ) -> SignalHandlerId {
101 unsafe extern "C" fn discovered_trampoline<
102 F: Fn(&Discoverer, &DiscovererInfo, Option<&glib::Error>) + Send + Sync + 'static,
103 >(
104 this: *mut ffi::GstDiscoverer,
105 info: *mut ffi::GstDiscovererInfo,
106 error: *mut glib::ffi::GError,
107 f: glib::ffi::gpointer,
108 ) {
109 unsafe {
110 let f: &F = &*(f as *const F);
111 f(
112 &from_glib_borrow(this),
113 &from_glib_borrow(info),
114 Option::<glib::Error>::from_glib_borrow(error)
115 .as_ref()
116 .as_ref(),
117 )
118 }
119 }
120 unsafe {
121 let f: Box_<F> = Box_::new(f);
122 connect_raw(
123 self.as_ptr() as *mut _,
124 c"discovered".as_ptr(),
125 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
126 discovered_trampoline::<F> as *const (),
127 )),
128 Box_::into_raw(f),
129 )
130 }
131 }
132
133 #[doc(alias = "finished")]
134 pub fn connect_finished<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
135 unsafe extern "C" fn finished_trampoline<F: Fn(&Discoverer) + Send + Sync + 'static>(
136 this: *mut ffi::GstDiscoverer,
137 f: glib::ffi::gpointer,
138 ) {
139 unsafe {
140 let f: &F = &*(f as *const F);
141 f(&from_glib_borrow(this))
142 }
143 }
144 unsafe {
145 let f: Box_<F> = Box_::new(f);
146 connect_raw(
147 self.as_ptr() as *mut _,
148 c"finished".as_ptr(),
149 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
150 finished_trampoline::<F> as *const (),
151 )),
152 Box_::into_raw(f),
153 )
154 }
155 }
156
157 #[cfg(feature = "v1_24")]
158 #[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
159 #[doc(alias = "load-serialized-info")]
160 pub fn connect_load_serialized_info<
161 F: Fn(&Self, &str) -> Option<DiscovererInfo> + Send + Sync + 'static,
162 >(
163 &self,
164 f: F,
165 ) -> SignalHandlerId {
166 unsafe extern "C" fn load_serialized_info_trampoline<
167 F: Fn(&Discoverer, &str) -> Option<DiscovererInfo> + Send + Sync + 'static,
168 >(
169 this: *mut ffi::GstDiscoverer,
170 uri: *mut std::ffi::c_char,
171 f: glib::ffi::gpointer,
172 ) -> *mut ffi::GstDiscovererInfo {
173 unsafe {
174 let f: &F = &*(f as *const F);
175 f(
176 &from_glib_borrow(this),
177 &glib::GString::from_glib_borrow(uri),
178 )
179 .to_glib_full()
180 }
181 }
182 unsafe {
183 let f: Box_<F> = Box_::new(f);
184 connect_raw(
185 self.as_ptr() as *mut _,
186 c"load-serialized-info".as_ptr(),
187 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
188 load_serialized_info_trampoline::<F> as *const (),
189 )),
190 Box_::into_raw(f),
191 )
192 }
193 }
194
195 #[doc(alias = "source-setup")]
196 pub fn connect_source_setup<F: Fn(&Self, &gst::Element) + Send + Sync + 'static>(
197 &self,
198 f: F,
199 ) -> SignalHandlerId {
200 unsafe extern "C" fn source_setup_trampoline<
201 F: Fn(&Discoverer, &gst::Element) + Send + Sync + 'static,
202 >(
203 this: *mut ffi::GstDiscoverer,
204 source: *mut gst::ffi::GstElement,
205 f: glib::ffi::gpointer,
206 ) {
207 unsafe {
208 let f: &F = &*(f as *const F);
209 f(&from_glib_borrow(this), &from_glib_borrow(source))
210 }
211 }
212 unsafe {
213 let f: Box_<F> = Box_::new(f);
214 connect_raw(
215 self.as_ptr() as *mut _,
216 c"source-setup".as_ptr(),
217 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
218 source_setup_trampoline::<F> as *const (),
219 )),
220 Box_::into_raw(f),
221 )
222 }
223 }
224
225 #[doc(alias = "starting")]
226 pub fn connect_starting<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
227 unsafe extern "C" fn starting_trampoline<F: Fn(&Discoverer) + Send + Sync + 'static>(
228 this: *mut ffi::GstDiscoverer,
229 f: glib::ffi::gpointer,
230 ) {
231 unsafe {
232 let f: &F = &*(f as *const F);
233 f(&from_glib_borrow(this))
234 }
235 }
236 unsafe {
237 let f: Box_<F> = Box_::new(f);
238 connect_raw(
239 self.as_ptr() as *mut _,
240 c"starting".as_ptr(),
241 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
242 starting_trampoline::<F> as *const (),
243 )),
244 Box_::into_raw(f),
245 )
246 }
247 }
248
249 #[cfg(feature = "v1_16")]
250 #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
251 #[doc(alias = "use-cache")]
252 pub fn connect_use_cache_notify<F: Fn(&Self) + Send + Sync + 'static>(
253 &self,
254 f: F,
255 ) -> SignalHandlerId {
256 unsafe extern "C" fn notify_use_cache_trampoline<
257 F: Fn(&Discoverer) + Send + Sync + 'static,
258 >(
259 this: *mut ffi::GstDiscoverer,
260 _param_spec: glib::ffi::gpointer,
261 f: glib::ffi::gpointer,
262 ) {
263 unsafe {
264 let f: &F = &*(f as *const F);
265 f(&from_glib_borrow(this))
266 }
267 }
268 unsafe {
269 let f: Box_<F> = Box_::new(f);
270 connect_raw(
271 self.as_ptr() as *mut _,
272 c"notify::use-cache".as_ptr(),
273 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
274 notify_use_cache_trampoline::<F> as *const (),
275 )),
276 Box_::into_raw(f),
277 )
278 }
279 }
280}
281
282unsafe impl Send for Discoverer {}
283unsafe impl Sync for Discoverer {}