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::{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    /// 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            let f: &F = &*(f as *const F);
243            f(
244                &from_glib_borrow(this),
245                &from_glib_borrow(info),
246                Option::<glib::Error>::from_glib_borrow(error)
247                    .as_ref()
248                    .as_ref(),
249            )
250        }
251        unsafe {
252            let f: Box_<F> = Box_::new(f);
253            connect_raw(
254                self.as_ptr() as *mut _,
255                c"discovered".as_ptr() as *const _,
256                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
257                    discovered_trampoline::<F> as *const (),
258                )),
259                Box_::into_raw(f),
260            )
261        }
262    }
263
264    /// Will be emitted in async mode when all pending URIs have been processed.
265    #[doc(alias = "finished")]
266    pub fn connect_finished<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
267        unsafe extern "C" fn finished_trampoline<F: Fn(&Discoverer) + Send + Sync + 'static>(
268            this: *mut ffi::GstDiscoverer,
269            f: glib::ffi::gpointer,
270        ) {
271            let f: &F = &*(f as *const F);
272            f(&from_glib_borrow(this))
273        }
274        unsafe {
275            let f: Box_<F> = Box_::new(f);
276            connect_raw(
277                self.as_ptr() as *mut _,
278                c"finished".as_ptr() as *const _,
279                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
280                    finished_trampoline::<F> as *const (),
281                )),
282                Box_::into_raw(f),
283            )
284        }
285    }
286
287    /// Retrieves information about a URI from and external source of information,
288    /// like a cache file. This is used by the discoverer to speed up the
289    /// discovery.
290    /// ## `uri`
291    /// THe URI to load the serialized info for
292    ///
293    /// # Returns
294    ///
295    /// The [`DiscovererInfo`][crate::DiscovererInfo] representing
296    /// `uri`, or [`None`] if no information
297    #[cfg(feature = "v1_24")]
298    #[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
299    #[doc(alias = "load-serialized-info")]
300    pub fn connect_load_serialized_info<
301        F: Fn(&Self, &str) -> Option<DiscovererInfo> + Send + Sync + 'static,
302    >(
303        &self,
304        f: F,
305    ) -> SignalHandlerId {
306        unsafe extern "C" fn load_serialized_info_trampoline<
307            F: Fn(&Discoverer, &str) -> Option<DiscovererInfo> + Send + Sync + 'static,
308        >(
309            this: *mut ffi::GstDiscoverer,
310            uri: *mut std::ffi::c_char,
311            f: glib::ffi::gpointer,
312        ) -> *mut ffi::GstDiscovererInfo {
313            let f: &F = &*(f as *const F);
314            f(
315                &from_glib_borrow(this),
316                &glib::GString::from_glib_borrow(uri),
317            )
318            .to_glib_full()
319        }
320        unsafe {
321            let f: Box_<F> = Box_::new(f);
322            connect_raw(
323                self.as_ptr() as *mut _,
324                c"load-serialized-info".as_ptr() as *const _,
325                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
326                    load_serialized_info_trampoline::<F> as *const (),
327                )),
328                Box_::into_raw(f),
329            )
330        }
331    }
332
333    /// This signal is emitted after the source element has been created for, so
334    /// the URI being discovered, so it can be configured by setting additional
335    /// properties (e.g. set a proxy server for an http source, or set the device
336    /// and read speed for an audio cd source).
337    ///
338    /// This signal is usually emitted from the context of a GStreamer streaming
339    /// thread.
340    /// ## `source`
341    /// source element
342    #[doc(alias = "source-setup")]
343    pub fn connect_source_setup<F: Fn(&Self, &gst::Element) + Send + Sync + 'static>(
344        &self,
345        f: F,
346    ) -> SignalHandlerId {
347        unsafe extern "C" fn source_setup_trampoline<
348            F: Fn(&Discoverer, &gst::Element) + Send + Sync + 'static,
349        >(
350            this: *mut ffi::GstDiscoverer,
351            source: *mut gst::ffi::GstElement,
352            f: glib::ffi::gpointer,
353        ) {
354            let f: &F = &*(f as *const F);
355            f(&from_glib_borrow(this), &from_glib_borrow(source))
356        }
357        unsafe {
358            let f: Box_<F> = Box_::new(f);
359            connect_raw(
360                self.as_ptr() as *mut _,
361                c"source-setup".as_ptr() as *const _,
362                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
363                    source_setup_trampoline::<F> as *const (),
364                )),
365                Box_::into_raw(f),
366            )
367        }
368    }
369
370    /// Will be emitted when the discover starts analyzing the pending URIs
371    #[doc(alias = "starting")]
372    pub fn connect_starting<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
373        unsafe extern "C" fn starting_trampoline<F: Fn(&Discoverer) + Send + Sync + 'static>(
374            this: *mut ffi::GstDiscoverer,
375            f: glib::ffi::gpointer,
376        ) {
377            let f: &F = &*(f as *const F);
378            f(&from_glib_borrow(this))
379        }
380        unsafe {
381            let f: Box_<F> = Box_::new(f);
382            connect_raw(
383                self.as_ptr() as *mut _,
384                c"starting".as_ptr() as *const _,
385                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
386                    starting_trampoline::<F> as *const (),
387                )),
388                Box_::into_raw(f),
389            )
390        }
391    }
392
393    #[cfg(feature = "v1_16")]
394    #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
395    #[doc(alias = "use-cache")]
396    pub fn connect_use_cache_notify<F: Fn(&Self) + Send + Sync + 'static>(
397        &self,
398        f: F,
399    ) -> SignalHandlerId {
400        unsafe extern "C" fn notify_use_cache_trampoline<
401            F: Fn(&Discoverer) + Send + Sync + 'static,
402        >(
403            this: *mut ffi::GstDiscoverer,
404            _param_spec: glib::ffi::gpointer,
405            f: glib::ffi::gpointer,
406        ) {
407            let f: &F = &*(f as *const F);
408            f(&from_glib_borrow(this))
409        }
410        unsafe {
411            let f: Box_<F> = Box_::new(f);
412            connect_raw(
413                self.as_ptr() as *mut _,
414                c"notify::use-cache".as_ptr() as *const _,
415                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
416                    notify_use_cache_trampoline::<F> as *const (),
417                )),
418                Box_::into_raw(f),
419            )
420        }
421    }
422}
423
424unsafe impl Send for Discoverer {}
425unsafe impl Sync for Discoverer {}