1use crate::{ffi, DiscovererInfo};
7use glib::{
8 object::ObjectType as _,
9 prelude::*,
10 signal::{connect_raw, SignalHandlerId},
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 let f: &F = &*(f as *const F);
110 f(
111 &from_glib_borrow(this),
112 &from_glib_borrow(info),
113 Option::<glib::Error>::from_glib_borrow(error)
114 .as_ref()
115 .as_ref(),
116 )
117 }
118 unsafe {
119 let f: Box_<F> = Box_::new(f);
120 connect_raw(
121 self.as_ptr() as *mut _,
122 c"discovered".as_ptr() as *const _,
123 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
124 discovered_trampoline::<F> as *const (),
125 )),
126 Box_::into_raw(f),
127 )
128 }
129 }
130
131 #[doc(alias = "finished")]
132 pub fn connect_finished<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
133 unsafe extern "C" fn finished_trampoline<F: Fn(&Discoverer) + Send + Sync + 'static>(
134 this: *mut ffi::GstDiscoverer,
135 f: glib::ffi::gpointer,
136 ) {
137 let f: &F = &*(f as *const F);
138 f(&from_glib_borrow(this))
139 }
140 unsafe {
141 let f: Box_<F> = Box_::new(f);
142 connect_raw(
143 self.as_ptr() as *mut _,
144 c"finished".as_ptr() as *const _,
145 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
146 finished_trampoline::<F> as *const (),
147 )),
148 Box_::into_raw(f),
149 )
150 }
151 }
152
153 #[cfg(feature = "v1_24")]
154 #[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
155 #[doc(alias = "load-serialized-info")]
156 pub fn connect_load_serialized_info<
157 F: Fn(&Self, &str) -> Option<DiscovererInfo> + Send + Sync + 'static,
158 >(
159 &self,
160 f: F,
161 ) -> SignalHandlerId {
162 unsafe extern "C" fn load_serialized_info_trampoline<
163 F: Fn(&Discoverer, &str) -> Option<DiscovererInfo> + Send + Sync + 'static,
164 >(
165 this: *mut ffi::GstDiscoverer,
166 uri: *mut std::ffi::c_char,
167 f: glib::ffi::gpointer,
168 ) -> *mut ffi::GstDiscovererInfo {
169 let f: &F = &*(f as *const F);
170 f(
171 &from_glib_borrow(this),
172 &glib::GString::from_glib_borrow(uri),
173 )
174 .to_glib_full()
175 }
176 unsafe {
177 let f: Box_<F> = Box_::new(f);
178 connect_raw(
179 self.as_ptr() as *mut _,
180 c"load-serialized-info".as_ptr() as *const _,
181 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
182 load_serialized_info_trampoline::<F> as *const (),
183 )),
184 Box_::into_raw(f),
185 )
186 }
187 }
188
189 #[doc(alias = "source-setup")]
190 pub fn connect_source_setup<F: Fn(&Self, &gst::Element) + Send + Sync + 'static>(
191 &self,
192 f: F,
193 ) -> SignalHandlerId {
194 unsafe extern "C" fn source_setup_trampoline<
195 F: Fn(&Discoverer, &gst::Element) + Send + Sync + 'static,
196 >(
197 this: *mut ffi::GstDiscoverer,
198 source: *mut gst::ffi::GstElement,
199 f: glib::ffi::gpointer,
200 ) {
201 let f: &F = &*(f as *const F);
202 f(&from_glib_borrow(this), &from_glib_borrow(source))
203 }
204 unsafe {
205 let f: Box_<F> = Box_::new(f);
206 connect_raw(
207 self.as_ptr() as *mut _,
208 c"source-setup".as_ptr() as *const _,
209 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
210 source_setup_trampoline::<F> as *const (),
211 )),
212 Box_::into_raw(f),
213 )
214 }
215 }
216
217 #[doc(alias = "starting")]
218 pub fn connect_starting<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
219 unsafe extern "C" fn starting_trampoline<F: Fn(&Discoverer) + Send + Sync + 'static>(
220 this: *mut ffi::GstDiscoverer,
221 f: glib::ffi::gpointer,
222 ) {
223 let f: &F = &*(f as *const F);
224 f(&from_glib_borrow(this))
225 }
226 unsafe {
227 let f: Box_<F> = Box_::new(f);
228 connect_raw(
229 self.as_ptr() as *mut _,
230 c"starting".as_ptr() as *const _,
231 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
232 starting_trampoline::<F> as *const (),
233 )),
234 Box_::into_raw(f),
235 )
236 }
237 }
238
239 #[cfg(feature = "v1_16")]
240 #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
241 #[doc(alias = "use-cache")]
242 pub fn connect_use_cache_notify<F: Fn(&Self) + Send + Sync + 'static>(
243 &self,
244 f: F,
245 ) -> SignalHandlerId {
246 unsafe extern "C" fn notify_use_cache_trampoline<
247 F: Fn(&Discoverer) + Send + Sync + 'static,
248 >(
249 this: *mut ffi::GstDiscoverer,
250 _param_spec: glib::ffi::gpointer,
251 f: glib::ffi::gpointer,
252 ) {
253 let f: &F = &*(f as *const F);
254 f(&from_glib_borrow(this))
255 }
256 unsafe {
257 let f: Box_<F> = Box_::new(f);
258 connect_raw(
259 self.as_ptr() as *mut _,
260 c"notify::use-cache".as_ptr() as *const _,
261 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
262 notify_use_cache_trampoline::<F> as *const (),
263 )),
264 Box_::into_raw(f),
265 )
266 }
267 }
268}
269
270unsafe impl Send for Discoverer {}
271unsafe impl Sync for Discoverer {}