Skip to main content

gstreamer_pbutils/auto/
discoverer.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::{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    /// The [`Discoverer`][crate::Discoverer] is a utility object which allows to get as much
17    /// information as possible from one or many URIs.
18    ///
19    /// It provides two APIs, allowing usage in blocking or non-blocking mode.
20    ///
21    /// The blocking mode just requires calling [`discover_uri()`][Self::discover_uri()]
22    /// with the URI one wishes to discover.
23    ///
24    /// The non-blocking mode requires a running [`glib::MainLoop`][crate::glib::MainLoop] iterating a
25    /// [`glib::MainContext`][crate::glib::MainContext], where one connects to the various signals, appends the
26    /// URIs to be processed (through [`discover_uri_async()`][Self::discover_uri_async()]) and then
27    /// asks for the discovery to begin (through [`start()`][Self::start()]).
28    /// By default this will use the GLib default main context unless you have
29    /// set a custom context using [`glib::MainContext::push_thread_default()`][crate::glib::MainContext::push_thread_default()].
30    ///
31    /// All the information is returned in a [`DiscovererInfo`][crate::DiscovererInfo] structure.
32    ///
33    /// ## Properties
34    ///
35    ///
36    /// #### `timeout`
37    ///  The duration (in nanoseconds) after which the discovery of an individual
38    /// URI will timeout.
39    ///
40    /// If the discovery of a URI times out, the [`DiscovererResult::Timeout`][crate::DiscovererResult::Timeout] will be
41    /// set on the result flags.
42    ///
43    /// Readable | Writeable | Construct
44    ///
45    ///
46    /// #### `use-cache`
47    ///  Readable | Writeable | Construct
48    ///
49    /// ## Signals
50    ///
51    ///
52    /// #### `discovered`
53    ///  Will be emitted in async mode when all information on a URI could be
54    /// discovered, or an error occurred.
55    ///
56    /// When an error occurs, `info` might still contain some partial information,
57    /// depending on the circumstances of the error.
58    ///
59    ///
60    ///
61    ///
62    /// #### `finished`
63    ///  Will be emitted in async mode when all pending URIs have been processed.
64    ///
65    ///
66    ///
67    ///
68    /// #### `load-serialized-info`
69    ///  Retrieves information about a URI from and external source of information,
70    /// like a cache file. This is used by the discoverer to speed up the
71    /// discovery.
72    ///
73    ///
74    ///
75    ///
76    /// #### `source-setup`
77    ///  This signal is emitted after the source element has been created for, so
78    /// the URI being discovered, so it can be configured by setting additional
79    /// properties (e.g. set a proxy server for an http source, or set the device
80    /// and read speed for an audio cd source).
81    ///
82    /// This signal is usually emitted from the context of a GStreamer streaming
83    /// thread.
84    ///
85    ///
86    ///
87    ///
88    /// #### `starting`
89    ///  Will be emitted when the discover starts analyzing the pending URIs
90    ///
91    ///
92    ///
93    /// # Implements
94    ///
95    /// [`trait@glib::ObjectExt`]
96    #[doc(alias = "GstDiscoverer")]
97    pub struct Discoverer(Object<ffi::GstDiscoverer, ffi::GstDiscovererClass>);
98
99    match fn {
100        type_ => || ffi::gst_discoverer_get_type(),
101    }
102}
103
104impl Discoverer {
105    /// Creates a new [`Discoverer`][crate::Discoverer] with the provided timeout.
106    /// ## `timeout`
107    /// timeout per file, in nanoseconds. Allowed are values between
108    ///  one second (`GST_SECOND`) and one hour (3600 * `GST_SECOND`)
109    ///
110    /// # Returns
111    ///
112    /// The new [`Discoverer`][crate::Discoverer].
113    /// If an error occurred when creating the discoverer, `err` will be set
114    /// accordingly and [`None`] will be returned. If `err` is set, the caller must
115    /// free it when no longer needed using `g_error_free()`.
116    #[doc(alias = "gst_discoverer_new")]
117    pub fn new(timeout: gst::ClockTime) -> Result<Discoverer, glib::Error> {
118        assert_initialized_main_thread!();
119        unsafe {
120            let mut error = std::ptr::null_mut();
121            let ret = ffi::gst_discoverer_new(timeout.into_glib(), &mut error);
122            if error.is_null() {
123                Ok(from_glib_full(ret))
124            } else {
125                Err(from_glib_full(error))
126            }
127        }
128    }
129
130    /// Synchronously discovers the given `uri`.
131    ///
132    /// A copy of `uri` will be made internally, so the caller can safely `g_free()`
133    /// afterwards.
134    /// ## `uri`
135    /// The URI to run on.
136    ///
137    /// # Returns
138    ///
139    /// the result of the scanning. Can be [`None`] if an
140    /// error occurred.
141    #[doc(alias = "gst_discoverer_discover_uri")]
142    pub fn discover_uri(&self, uri: &str) -> Result<DiscovererInfo, glib::Error> {
143        unsafe {
144            let mut error = std::ptr::null_mut();
145            let ret = ffi::gst_discoverer_discover_uri(
146                self.to_glib_none().0,
147                uri.to_glib_none().0,
148                &mut error,
149            );
150            if error.is_null() {
151                Ok(from_glib_full(ret))
152            } else {
153                Err(from_glib_full(error))
154            }
155        }
156    }
157
158    /// Appends the given `uri` to the list of URIs to discoverer. The actual
159    /// discovery of the `uri` will only take place if [`start()`][Self::start()] has
160    /// been called.
161    ///
162    /// A copy of `uri` will be made internally, so the caller can safely `g_free()`
163    /// afterwards.
164    /// ## `uri`
165    /// the URI to add.
166    ///
167    /// # Returns
168    ///
169    /// [`true`] if the `uri` was successfully appended to the list of pending
170    /// uris, else [`false`]
171    #[doc(alias = "gst_discoverer_discover_uri_async")]
172    pub fn discover_uri_async(&self, uri: &str) -> Result<(), glib::error::BoolError> {
173        unsafe {
174            glib::result_from_gboolean!(
175                ffi::gst_discoverer_discover_uri_async(self.to_glib_none().0, uri.to_glib_none().0),
176                "Failed to add URI to list of discovers"
177            )
178        }
179    }
180
181    /// Allow asynchronous discovering of URIs to take place.
182    /// A [`glib::MainLoop`][crate::glib::MainLoop] must be available for [`Discoverer`][crate::Discoverer] to properly work in
183    /// asynchronous mode.
184    #[doc(alias = "gst_discoverer_start")]
185    pub fn start(&self) {
186        unsafe {
187            ffi::gst_discoverer_start(self.to_glib_none().0);
188        }
189    }
190
191    /// Stop the discovery of any pending URIs and clears the list of
192    /// pending URIS (if any).
193    #[doc(alias = "gst_discoverer_stop")]
194    pub fn stop(&self) {
195        unsafe {
196            ffi::gst_discoverer_stop(self.to_glib_none().0);
197        }
198    }
199
200    #[cfg(feature = "v1_16")]
201    #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
202    #[doc(alias = "use-cache")]
203    pub fn uses_cache(&self) -> bool {
204        ObjectExt::property(self, "use-cache")
205    }
206
207    #[cfg(feature = "v1_16")]
208    #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
209    #[doc(alias = "use-cache")]
210    pub fn set_use_cache(&self, use_cache: bool) {
211        ObjectExt::set_property(self, "use-cache", use_cache)
212    }
213
214    /// Will be emitted in async mode when all information on a URI could be
215    /// discovered, or an error occurred.
216    ///
217    /// When an error occurs, `info` might still contain some partial information,
218    /// depending on the circumstances of the error.
219    /// ## `info`
220    /// the results [`DiscovererInfo`][crate::DiscovererInfo]
221    /// ## `error`
222    /// [`glib::Error`][crate::glib::Error], which will be non-NULL
223    ///  if an error occurred during
224    ///  discovery. You must not free
225    ///  this [`glib::Error`][crate::glib::Error], it will be freed by
226    ///  the discoverer.
227    #[doc(alias = "discovered")]
228    pub fn connect_discovered<
229        F: Fn(&Self, &DiscovererInfo, Option<&glib::Error>) + Send + Sync + 'static,
230    >(
231        &self,
232        f: F,
233    ) -> SignalHandlerId {
234        unsafe extern "C" fn discovered_trampoline<
235            F: Fn(&Discoverer, &DiscovererInfo, Option<&glib::Error>) + Send + Sync + 'static,
236        >(
237            this: *mut ffi::GstDiscoverer,
238            info: *mut ffi::GstDiscovererInfo,
239            error: *mut glib::ffi::GError,
240            f: glib::ffi::gpointer,
241        ) {
242            unsafe {
243                let f: &F = &*(f as *const F);
244                f(
245                    &from_glib_borrow(this),
246                    &from_glib_borrow(info),
247                    Option::<glib::Error>::from_glib_borrow(error)
248                        .as_ref()
249                        .as_ref(),
250                )
251            }
252        }
253        unsafe {
254            let f: Box_<F> = Box_::new(f);
255            connect_raw(
256                self.as_ptr() as *mut _,
257                c"discovered".as_ptr(),
258                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
259                    discovered_trampoline::<F> as *const (),
260                )),
261                Box_::into_raw(f),
262            )
263        }
264    }
265
266    /// Will be emitted in async mode when all pending URIs have been processed.
267    #[doc(alias = "finished")]
268    pub fn connect_finished<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
269        unsafe extern "C" fn finished_trampoline<F: Fn(&Discoverer) + Send + Sync + 'static>(
270            this: *mut ffi::GstDiscoverer,
271            f: glib::ffi::gpointer,
272        ) {
273            unsafe {
274                let f: &F = &*(f as *const F);
275                f(&from_glib_borrow(this))
276            }
277        }
278        unsafe {
279            let f: Box_<F> = Box_::new(f);
280            connect_raw(
281                self.as_ptr() as *mut _,
282                c"finished".as_ptr(),
283                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
284                    finished_trampoline::<F> as *const (),
285                )),
286                Box_::into_raw(f),
287            )
288        }
289    }
290
291    /// Retrieves information about a URI from and external source of information,
292    /// like a cache file. This is used by the discoverer to speed up the
293    /// discovery.
294    /// ## `uri`
295    /// THe URI to load the serialized info for
296    ///
297    /// # Returns
298    ///
299    /// The [`DiscovererInfo`][crate::DiscovererInfo] representing
300    /// `uri`, or [`None`] if no information
301    #[cfg(feature = "v1_24")]
302    #[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
303    #[doc(alias = "load-serialized-info")]
304    pub fn connect_load_serialized_info<
305        F: Fn(&Self, &str) -> Option<DiscovererInfo> + Send + Sync + 'static,
306    >(
307        &self,
308        f: F,
309    ) -> SignalHandlerId {
310        unsafe extern "C" fn load_serialized_info_trampoline<
311            F: Fn(&Discoverer, &str) -> Option<DiscovererInfo> + Send + Sync + 'static,
312        >(
313            this: *mut ffi::GstDiscoverer,
314            uri: *mut std::ffi::c_char,
315            f: glib::ffi::gpointer,
316        ) -> *mut ffi::GstDiscovererInfo {
317            unsafe {
318                let f: &F = &*(f as *const F);
319                f(
320                    &from_glib_borrow(this),
321                    &glib::GString::from_glib_borrow(uri),
322                )
323                .to_glib_full()
324            }
325        }
326        unsafe {
327            let f: Box_<F> = Box_::new(f);
328            connect_raw(
329                self.as_ptr() as *mut _,
330                c"load-serialized-info".as_ptr(),
331                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
332                    load_serialized_info_trampoline::<F> as *const (),
333                )),
334                Box_::into_raw(f),
335            )
336        }
337    }
338
339    /// This signal is emitted after the source element has been created for, so
340    /// the URI being discovered, so it can be configured by setting additional
341    /// properties (e.g. set a proxy server for an http source, or set the device
342    /// and read speed for an audio cd source).
343    ///
344    /// This signal is usually emitted from the context of a GStreamer streaming
345    /// thread.
346    /// ## `source`
347    /// source element
348    #[doc(alias = "source-setup")]
349    pub fn connect_source_setup<F: Fn(&Self, &gst::Element) + Send + Sync + 'static>(
350        &self,
351        f: F,
352    ) -> SignalHandlerId {
353        unsafe extern "C" fn source_setup_trampoline<
354            F: Fn(&Discoverer, &gst::Element) + Send + Sync + 'static,
355        >(
356            this: *mut ffi::GstDiscoverer,
357            source: *mut gst::ffi::GstElement,
358            f: glib::ffi::gpointer,
359        ) {
360            unsafe {
361                let f: &F = &*(f as *const F);
362                f(&from_glib_borrow(this), &from_glib_borrow(source))
363            }
364        }
365        unsafe {
366            let f: Box_<F> = Box_::new(f);
367            connect_raw(
368                self.as_ptr() as *mut _,
369                c"source-setup".as_ptr(),
370                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
371                    source_setup_trampoline::<F> as *const (),
372                )),
373                Box_::into_raw(f),
374            )
375        }
376    }
377
378    /// Will be emitted when the discover starts analyzing the pending URIs
379    #[doc(alias = "starting")]
380    pub fn connect_starting<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
381        unsafe extern "C" fn starting_trampoline<F: Fn(&Discoverer) + Send + Sync + 'static>(
382            this: *mut ffi::GstDiscoverer,
383            f: glib::ffi::gpointer,
384        ) {
385            unsafe {
386                let f: &F = &*(f as *const F);
387                f(&from_glib_borrow(this))
388            }
389        }
390        unsafe {
391            let f: Box_<F> = Box_::new(f);
392            connect_raw(
393                self.as_ptr() as *mut _,
394                c"starting".as_ptr(),
395                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
396                    starting_trampoline::<F> as *const (),
397                )),
398                Box_::into_raw(f),
399            )
400        }
401    }
402
403    #[cfg(feature = "v1_16")]
404    #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
405    #[doc(alias = "use-cache")]
406    pub fn connect_use_cache_notify<F: Fn(&Self) + Send + Sync + 'static>(
407        &self,
408        f: F,
409    ) -> SignalHandlerId {
410        unsafe extern "C" fn notify_use_cache_trampoline<
411            F: Fn(&Discoverer) + Send + Sync + 'static,
412        >(
413            this: *mut ffi::GstDiscoverer,
414            _param_spec: glib::ffi::gpointer,
415            f: glib::ffi::gpointer,
416        ) {
417            unsafe {
418                let f: &F = &*(f as *const F);
419                f(&from_glib_borrow(this))
420            }
421        }
422        unsafe {
423            let f: Box_<F> = Box_::new(f);
424            connect_raw(
425                self.as_ptr() as *mut _,
426                c"notify::use-cache".as_ptr(),
427                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
428                    notify_use_cache_trampoline::<F> as *const (),
429                )),
430                Box_::into_raw(f),
431            )
432        }
433    }
434}
435
436unsafe impl Send for Discoverer {}
437unsafe impl Sync for Discoverer {}