gstreamer/auto/
object.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, ClockTime, ControlBinding};
7use glib::{
8    prelude::*,
9    signal::{connect_raw, SignalHandlerId},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    /// [`Object`][crate::Object] provides a root for the object hierarchy tree filed in by the
16    /// GStreamer library. It is currently a thin wrapper on top of
17    /// `GInitiallyUnowned`. It is an abstract class that is not very usable on its own.
18    ///
19    /// [`Object`][crate::Object] gives us basic refcounting, parenting functionality and locking.
20    /// Most of the functions are just extended for special GStreamer needs and can be
21    /// found under the same name in the base class of [`Object`][crate::Object] which is [`glib::Object`][crate::glib::Object]
22    /// (e.g. `g_object_ref()` becomes `gst_object_ref()`).
23    ///
24    /// Since [`Object`][crate::Object] derives from `GInitiallyUnowned`, it also inherits the
25    /// floating reference. Be aware that functions such as [`GstBinExt::add()`][crate::prelude::GstBinExt::add()] and
26    /// [`ElementExt::add_pad()`][crate::prelude::ElementExt::add_pad()] take ownership of the floating reference.
27    ///
28    /// In contrast to [`glib::Object`][crate::glib::Object] instances, [`Object`][crate::Object] adds a name property. The functions
29    /// `gst_object_set_name()` and [`GstObjectExt::name()`][crate::prelude::GstObjectExt::name()] are used to set/get the name
30    /// of the object.
31    ///
32    /// ## controlled properties
33    ///
34    /// Controlled properties offers a lightweight way to adjust gobject properties
35    /// over stream-time. It works by using time-stamped value pairs that are queued
36    /// for element-properties. At run-time the elements continuously pull value
37    /// changes for the current stream-time.
38    ///
39    /// What needs to be changed in a [`Element`][crate::Element]?
40    /// Very little - it is just two steps to make a plugin controllable!
41    ///
42    ///  * mark gobject-properties paramspecs that make sense to be controlled,
43    ///  by GST_PARAM_CONTROLLABLE.
44    ///
45    ///  * when processing data (get, chain, loop function) at the beginning call
46    ///  gst_object_sync_values(element,timestamp).
47    ///  This will make the controller update all GObject properties that are
48    ///  under its control with the current values based on the timestamp.
49    ///
50    /// What needs to be done in applications? Again it's not a lot to change.
51    ///
52    ///  * create a [`ControlSource`][crate::ControlSource].
53    ///  csource = gst_interpolation_control_source_new ();
54    ///  g_object_set (csource, "mode", GST_INTERPOLATION_MODE_LINEAR, NULL);
55    ///
56    ///  * Attach the [`ControlSource`][crate::ControlSource] on the controller to a property.
57    ///  gst_object_add_control_binding (object, gst_direct_control_binding_new (object, "prop1", csource));
58    ///
59    ///  * Set the control values
60    ///  gst_timed_value_control_source_set ((GstTimedValueControlSource *)csource,0 * GST_SECOND, value1);
61    ///  gst_timed_value_control_source_set ((GstTimedValueControlSource *)csource,1 * GST_SECOND, value2);
62    ///
63    ///  * start your pipeline
64    ///
65    /// This is an Abstract Base Class, you cannot instantiate it.
66    ///
67    /// ## Properties
68    ///
69    ///
70    /// #### `name`
71    ///  Readable | Writeable | Construct
72    ///
73    ///
74    /// #### `parent`
75    ///  The parent of the object. Please note, that when changing the 'parent'
76    /// property, we don't emit [`notify`][struct@crate::glib::Object#notify] and [`deep-notify`][struct@crate::Object#deep-notify]
77    /// signals due to locking issues. In some cases one can use
78    /// [`element-added`][struct@crate::Bin#element-added] or [`element-removed`][struct@crate::Bin#element-removed] signals on the parent to
79    /// achieve a similar effect.
80    ///
81    /// Readable | Writeable
82    ///
83    /// ## Signals
84    ///
85    ///
86    /// #### `deep-notify`
87    ///  The deep notify signal is used to be notified of property changes. It is
88    /// typically attached to the toplevel bin to receive notifications from all
89    /// the elements contained in that bin.
90    ///
91    /// Detailed
92    ///
93    /// # Implements
94    ///
95    /// [`GstObjectExt`][trait@crate::prelude::GstObjectExt], [`trait@glib::ObjectExt`]
96    #[doc(alias = "GstObject")]
97    pub struct Object(Object<ffi::GstObject, ffi::GstObjectClass>);
98
99    match fn {
100        type_ => || ffi::gst_object_get_type(),
101    }
102}
103
104impl Object {
105    pub const NONE: Option<&'static Object> = None;
106
107    /// Checks to see if there is any object named `name` in `list`. This function
108    /// does not do any locking of any kind. You might want to protect the
109    /// provided list with the lock of the owner of the list. This function
110    /// will lock each [`Object`][crate::Object] in the list to compare the name, so be
111    /// careful when passing a list with a locked object.
112    /// ## `list`
113    /// a list of [`Object`][crate::Object] to
114    ///  check through
115    /// ## `name`
116    /// the name to search for
117    ///
118    /// # Returns
119    ///
120    /// [`true`] if a [`Object`][crate::Object] named `name` does not appear in `list`,
121    /// [`false`] if it does.
122    ///
123    /// MT safe. Grabs and releases the LOCK of each object in the list.
124    #[doc(alias = "gst_object_check_uniqueness")]
125    pub fn check_uniqueness(list: &[Object], name: &str) -> bool {
126        assert_initialized_main_thread!();
127        unsafe {
128            from_glib(ffi::gst_object_check_uniqueness(
129                list.to_glib_none().0,
130                name.to_glib_none().0,
131            ))
132        }
133    }
134
135    //#[doc(alias = "gst_object_default_deep_notify")]
136    //pub fn default_deep_notify(object: &impl IsA<glib::Object>, orig: &impl IsA<Object>, pspec: /*Ignored*/&glib::ParamSpec, excluded_props: &[&str]) {
137    //    unsafe { TODO: call ffi:gst_object_default_deep_notify() }
138    //}
139
140    //#[doc(alias = "gst_object_replace")]
141    //pub fn replace(oldobj: Option<impl IsA<Object>>, newobj: Option<&impl IsA<Object>>) -> bool {
142    //    unsafe { TODO: call ffi:gst_object_replace() }
143    //}
144}
145
146impl std::fmt::Display for Object {
147    #[inline]
148    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
149        f.write_str(&GstObjectExt::name(self))
150    }
151}
152
153unsafe impl Send for Object {}
154unsafe impl Sync for Object {}
155
156/// Trait containing all [`struct@Object`] methods.
157///
158/// # Implementors
159///
160/// [`Allocator`][struct@crate::Allocator], [`BufferPool`][struct@crate::BufferPool], [`Bus`][struct@crate::Bus], [`Clock`][struct@crate::Clock], [`ControlBinding`][struct@crate::ControlBinding], [`ControlSource`][struct@crate::ControlSource], [`DeviceMonitor`][struct@crate::DeviceMonitor], [`DeviceProvider`][struct@crate::DeviceProvider], [`Device`][struct@crate::Device], [`Element`][struct@crate::Element], [`Object`][struct@crate::Object], [`PadTemplate`][struct@crate::PadTemplate], [`Pad`][struct@crate::Pad], [`PluginFeature`][struct@crate::PluginFeature], [`Plugin`][struct@crate::Plugin], [`Registry`][struct@crate::Registry], [`StreamCollection`][struct@crate::StreamCollection], [`Stream`][struct@crate::Stream], [`TaskPool`][struct@crate::TaskPool], [`Task`][struct@crate::Task], [`Tracer`][struct@crate::Tracer]
161pub trait GstObjectExt: IsA<Object> + 'static {
162    /// Attach the [`ControlBinding`][crate::ControlBinding] to the object. If there already was a
163    /// [`ControlBinding`][crate::ControlBinding] for this property it will be replaced.
164    ///
165    /// The object's reference count will be incremented, and any floating
166    /// reference will be removed (see `gst_object_ref_sink()`)
167    /// ## `binding`
168    /// the [`ControlBinding`][crate::ControlBinding] that should be used
169    ///
170    /// # Returns
171    ///
172    /// [`false`] if the given `binding` has not been setup for this object or
173    /// has been setup for a non suitable property, [`true`] otherwise.
174    #[doc(alias = "gst_object_add_control_binding")]
175    fn add_control_binding(
176        &self,
177        binding: &impl IsA<ControlBinding>,
178    ) -> Result<(), glib::error::BoolError> {
179        unsafe {
180            glib::result_from_gboolean!(
181                ffi::gst_object_add_control_binding(
182                    self.as_ref().to_glib_none().0,
183                    binding.as_ref().to_glib_none().0
184                ),
185                "Failed to add control binding"
186            )
187        }
188    }
189
190    /// A default error function that uses `g_printerr()` to display the error message
191    /// and the optional debug string..
192    ///
193    /// The default handler will simply print the error string using g_print.
194    /// ## `error`
195    /// the GError.
196    /// ## `debug`
197    /// an additional debug information string, or [`None`]
198    #[doc(alias = "gst_object_default_error")]
199    fn default_error(&self, error: &glib::Error, debug: Option<&str>) {
200        unsafe {
201            ffi::gst_object_default_error(
202                self.as_ref().to_glib_none().0,
203                error.to_glib_none().0,
204                debug.to_glib_none().0,
205            );
206        }
207    }
208
209    /// Gets the corresponding [`ControlBinding`][crate::ControlBinding] for the property. This should be
210    /// unreferenced again after use.
211    /// ## `property_name`
212    /// name of the property
213    ///
214    /// # Returns
215    ///
216    /// the [`ControlBinding`][crate::ControlBinding] for
217    /// `property_name` or [`None`] if the property is not controlled.
218    #[doc(alias = "gst_object_get_control_binding")]
219    #[doc(alias = "get_control_binding")]
220    fn control_binding(&self, property_name: &str) -> Option<ControlBinding> {
221        unsafe {
222            from_glib_full(ffi::gst_object_get_control_binding(
223                self.as_ref().to_glib_none().0,
224                property_name.to_glib_none().0,
225            ))
226        }
227    }
228
229    /// Obtain the control-rate for this `self`. Audio processing [`Element`][crate::Element]
230    /// objects will use this rate to sub-divide their processing loop and call
231    /// [`sync_values()`][Self::sync_values()] in between. The length of the processing segment
232    /// should be up to `control`-rate nanoseconds.
233    ///
234    /// If the `self` is not under property control, this will return
235    /// `GST_CLOCK_TIME_NONE`. This allows the element to avoid the sub-dividing.
236    ///
237    /// The control-rate is not expected to change if the element is in
238    /// [`State::Paused`][crate::State::Paused] or [`State::Playing`][crate::State::Playing].
239    ///
240    /// # Returns
241    ///
242    /// the control rate in nanoseconds
243    #[doc(alias = "gst_object_get_control_rate")]
244    #[doc(alias = "get_control_rate")]
245    fn control_rate(&self) -> Option<ClockTime> {
246        unsafe {
247            from_glib(ffi::gst_object_get_control_rate(
248                self.as_ref().to_glib_none().0,
249            ))
250        }
251    }
252
253    /// Returns a copy of the name of `self`.
254    /// Caller should `g_free()` the return value after usage.
255    /// For a nameless object, this returns [`None`], which you can safely `g_free()`
256    /// as well.
257    ///
258    /// Free-function: g_free
259    ///
260    /// # Returns
261    ///
262    /// the name of `self`. `g_free()`
263    /// after usage.
264    ///
265    /// MT safe. This function grabs and releases `self`'s LOCK.
266    #[doc(alias = "gst_object_get_name")]
267    #[doc(alias = "get_name")]
268    fn name(&self) -> glib::GString {
269        unsafe { from_glib_full(ffi::gst_object_get_name(self.as_ref().to_glib_none().0)) }
270    }
271
272    /// Returns the parent of `self`. This function increases the refcount
273    /// of the parent object so you should `gst_object_unref()` it after usage.
274    ///
275    /// # Returns
276    ///
277    /// parent of `self`, this can be
278    ///  [`None`] if `self` has no parent. unref after usage.
279    ///
280    /// MT safe. Grabs and releases `self`'s LOCK.
281    #[doc(alias = "gst_object_get_parent")]
282    #[doc(alias = "get_parent")]
283    #[must_use]
284    fn parent(&self) -> Option<Object> {
285        unsafe { from_glib_full(ffi::gst_object_get_parent(self.as_ref().to_glib_none().0)) }
286    }
287
288    /// Generates a string describing the path of `self` in
289    /// the object hierarchy. Only useful (or used) for debugging.
290    ///
291    /// Free-function: g_free
292    ///
293    /// # Returns
294    ///
295    /// a string describing the path of `self`. You must
296    ///  `g_free()` the string after usage.
297    ///
298    /// MT safe. Grabs and releases the [`Object`][crate::Object]'s LOCK for all objects
299    ///  in the hierarchy.
300    #[doc(alias = "gst_object_get_path_string")]
301    #[doc(alias = "get_path_string")]
302    fn path_string(&self) -> glib::GString {
303        unsafe {
304            from_glib_full(ffi::gst_object_get_path_string(
305                self.as_ref().to_glib_none().0,
306            ))
307        }
308    }
309
310    /// Gets the value for the given controlled property at the requested time.
311    /// ## `property_name`
312    /// the name of the property to get
313    /// ## `timestamp`
314    /// the time the control-change should be read from
315    ///
316    /// # Returns
317    ///
318    /// the GValue of the property at the given time,
319    /// or [`None`] if the property isn't controlled.
320    #[doc(alias = "gst_object_get_value")]
321    #[doc(alias = "get_value")]
322    fn value(
323        &self,
324        property_name: &str,
325        timestamp: impl Into<Option<ClockTime>>,
326    ) -> Option<glib::Value> {
327        unsafe {
328            from_glib_full(ffi::gst_object_get_value(
329                self.as_ref().to_glib_none().0,
330                property_name.to_glib_none().0,
331                timestamp.into().into_glib(),
332            ))
333        }
334    }
335
336    //#[doc(alias = "gst_object_get_value_array")]
337    //#[doc(alias = "get_value_array")]
338    //fn is_value_array(&self, property_name: &str, timestamp: impl Into<Option<ClockTime>>, interval: impl Into<Option<ClockTime>>, values: /*Unimplemented*/&[&Basic: Pointer]) -> bool {
339    //    unsafe { TODO: call ffi:gst_object_get_value_array() }
340    //}
341
342    /// Check if the `self` has active controlled properties.
343    ///
344    /// # Returns
345    ///
346    /// [`true`] if the object has active controlled properties
347    #[doc(alias = "gst_object_has_active_control_bindings")]
348    fn has_active_control_bindings(&self) -> bool {
349        unsafe {
350            from_glib(ffi::gst_object_has_active_control_bindings(
351                self.as_ref().to_glib_none().0,
352            ))
353        }
354    }
355
356    /// Check if `self` has an ancestor `ancestor` somewhere up in
357    /// the hierarchy. One can e.g. check if a [`Element`][crate::Element] is inside a [`Pipeline`][crate::Pipeline].
358    ///
359    /// # Deprecated
360    ///
361    /// Use [`has_as_ancestor()`][Self::has_as_ancestor()] instead.
362    ///
363    /// MT safe. Grabs and releases `self`'s locks.
364    /// ## `ancestor`
365    /// a [`Object`][crate::Object] to check as ancestor
366    ///
367    /// # Returns
368    ///
369    /// [`true`] if `ancestor` is an ancestor of `self`.
370    #[doc(alias = "gst_object_has_ancestor")]
371    fn has_ancestor(&self, ancestor: &impl IsA<Object>) -> bool {
372        unsafe {
373            from_glib(ffi::gst_object_has_ancestor(
374                self.as_ref().to_glib_none().0,
375                ancestor.as_ref().to_glib_none().0,
376            ))
377        }
378    }
379
380    /// Check if `self` has an ancestor `ancestor` somewhere up in
381    /// the hierarchy. One can e.g. check if a [`Element`][crate::Element] is inside a [`Pipeline`][crate::Pipeline].
382    /// ## `ancestor`
383    /// a [`Object`][crate::Object] to check as ancestor
384    ///
385    /// # Returns
386    ///
387    /// [`true`] if `ancestor` is an ancestor of `self`.
388    ///
389    /// MT safe. Grabs and releases `self`'s locks.
390    #[doc(alias = "gst_object_has_as_ancestor")]
391    fn has_as_ancestor(&self, ancestor: &impl IsA<Object>) -> bool {
392        unsafe {
393            from_glib(ffi::gst_object_has_as_ancestor(
394                self.as_ref().to_glib_none().0,
395                ancestor.as_ref().to_glib_none().0,
396            ))
397        }
398    }
399
400    /// Check if `parent` is the parent of `self`.
401    /// E.g. a [`Element`][crate::Element] can check if it owns a given [`Pad`][crate::Pad].
402    /// ## `parent`
403    /// a [`Object`][crate::Object] to check as parent
404    ///
405    /// # Returns
406    ///
407    /// [`false`] if either `self` or `parent` is [`None`]. [`true`] if `parent` is
408    ///  the parent of `self`. Otherwise [`false`].
409    ///
410    /// MT safe. Grabs and releases `self`'s locks.
411    #[doc(alias = "gst_object_has_as_parent")]
412    fn has_as_parent(&self, parent: &impl IsA<Object>) -> bool {
413        unsafe {
414            from_glib(ffi::gst_object_has_as_parent(
415                self.as_ref().to_glib_none().0,
416                parent.as_ref().to_glib_none().0,
417            ))
418        }
419    }
420
421    /// Removes the corresponding [`ControlBinding`][crate::ControlBinding]. If it was the
422    /// last ref of the binding, it will be disposed.
423    /// ## `binding`
424    /// the binding
425    ///
426    /// # Returns
427    ///
428    /// [`true`] if the binding could be removed.
429    #[doc(alias = "gst_object_remove_control_binding")]
430    fn remove_control_binding(&self, binding: &impl IsA<ControlBinding>) -> bool {
431        unsafe {
432            from_glib(ffi::gst_object_remove_control_binding(
433                self.as_ref().to_glib_none().0,
434                binding.as_ref().to_glib_none().0,
435            ))
436        }
437    }
438
439    /// This function is used to disable the control bindings on a property for
440    /// some time, i.e. [`sync_values()`][Self::sync_values()] will do nothing for the
441    /// property.
442    /// ## `property_name`
443    /// property to disable
444    /// ## `disabled`
445    /// boolean that specifies whether to disable the controller
446    /// or not.
447    #[doc(alias = "gst_object_set_control_binding_disabled")]
448    fn set_control_binding_disabled(&self, property_name: &str, disabled: bool) {
449        unsafe {
450            ffi::gst_object_set_control_binding_disabled(
451                self.as_ref().to_glib_none().0,
452                property_name.to_glib_none().0,
453                disabled.into_glib(),
454            );
455        }
456    }
457
458    /// This function is used to disable all controlled properties of the `self` for
459    /// some time, i.e. [`sync_values()`][Self::sync_values()] will do nothing.
460    /// ## `disabled`
461    /// boolean that specifies whether to disable the controller
462    /// or not.
463    #[doc(alias = "gst_object_set_control_bindings_disabled")]
464    fn set_control_bindings_disabled(&self, disabled: bool) {
465        unsafe {
466            ffi::gst_object_set_control_bindings_disabled(
467                self.as_ref().to_glib_none().0,
468                disabled.into_glib(),
469            );
470        }
471    }
472
473    /// Change the control-rate for this `self`. Audio processing [`Element`][crate::Element]
474    /// objects will use this rate to sub-divide their processing loop and call
475    /// [`sync_values()`][Self::sync_values()] in between. The length of the processing segment
476    /// should be up to `control`-rate nanoseconds.
477    ///
478    /// The control-rate should not change if the element is in [`State::Paused`][crate::State::Paused] or
479    /// [`State::Playing`][crate::State::Playing].
480    /// ## `control_rate`
481    /// the new control-rate in nanoseconds.
482    #[doc(alias = "gst_object_set_control_rate")]
483    fn set_control_rate(&self, control_rate: impl Into<Option<ClockTime>>) {
484        unsafe {
485            ffi::gst_object_set_control_rate(
486                self.as_ref().to_glib_none().0,
487                control_rate.into().into_glib(),
488            );
489        }
490    }
491
492    /// Sets the parent of `self` to `parent`. The object's reference count will
493    /// be incremented, and any floating reference will be removed (see `gst_object_ref_sink()`).
494    /// ## `parent`
495    /// new parent of object
496    ///
497    /// # Returns
498    ///
499    /// [`true`] if `parent` could be set or [`false`] when `self`
500    /// already had a parent or `self` and `parent` are the same.
501    ///
502    /// MT safe. Grabs and releases `self`'s LOCK.
503    #[doc(alias = "gst_object_set_parent")]
504    #[doc(alias = "parent")]
505    fn set_parent(&self, parent: &impl IsA<Object>) -> Result<(), glib::error::BoolError> {
506        unsafe {
507            glib::result_from_gboolean!(
508                ffi::gst_object_set_parent(
509                    self.as_ref().to_glib_none().0,
510                    parent.as_ref().to_glib_none().0
511                ),
512                "Failed to set parent object"
513            )
514        }
515    }
516
517    /// Returns a suggestion for timestamps where buffers should be split
518    /// to get best controller results.
519    ///
520    /// # Returns
521    ///
522    /// Returns the suggested timestamp or `GST_CLOCK_TIME_NONE`
523    /// if no control-rate was set.
524    #[doc(alias = "gst_object_suggest_next_sync")]
525    fn suggest_next_sync(&self) -> Option<ClockTime> {
526        unsafe {
527            from_glib(ffi::gst_object_suggest_next_sync(
528                self.as_ref().to_glib_none().0,
529            ))
530        }
531    }
532
533    /// Sets the properties of the object, according to the `GstControlSources` that
534    /// (maybe) handle them and for the given timestamp.
535    ///
536    /// If this function fails, it is most likely the application developers fault.
537    /// Most probably the control sources are not setup correctly.
538    /// ## `timestamp`
539    /// the time that should be processed
540    ///
541    /// # Returns
542    ///
543    /// [`true`] if the controller values could be applied to the object
544    /// properties, [`false`] otherwise
545    #[doc(alias = "gst_object_sync_values")]
546    fn sync_values(&self, timestamp: ClockTime) -> Result<(), glib::error::BoolError> {
547        unsafe {
548            glib::result_from_gboolean!(
549                ffi::gst_object_sync_values(self.as_ref().to_glib_none().0, timestamp.into_glib()),
550                "Failed to sync values"
551            )
552        }
553    }
554
555    /// Clear the parent of `self`, removing the associated reference.
556    /// This function decreases the refcount of `self`.
557    ///
558    /// MT safe. Grabs and releases `self`'s lock.
559    #[doc(alias = "gst_object_unparent")]
560    fn unparent(&self) {
561        unsafe {
562            ffi::gst_object_unparent(self.as_ref().to_glib_none().0);
563        }
564    }
565
566    //#[doc(alias = "deep-notify")]
567    //fn connect_deep_notify<Unsupported or ignored types>(&self, detail: Option<&str>, f: F) -> SignalHandlerId {
568    //    Ignored prop: GObject.ParamSpec
569    //}
570
571    #[doc(alias = "parent")]
572    fn connect_parent_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
573        unsafe extern "C" fn notify_parent_trampoline<
574            P: IsA<Object>,
575            F: Fn(&P) + Send + Sync + 'static,
576        >(
577            this: *mut ffi::GstObject,
578            _param_spec: glib::ffi::gpointer,
579            f: glib::ffi::gpointer,
580        ) {
581            let f: &F = &*(f as *const F);
582            f(Object::from_glib_borrow(this).unsafe_cast_ref())
583        }
584        unsafe {
585            let f: Box_<F> = Box_::new(f);
586            connect_raw(
587                self.as_ptr() as *mut _,
588                c"notify::parent".as_ptr() as *const _,
589                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
590                    notify_parent_trampoline::<Self, F> as *const (),
591                )),
592                Box_::into_raw(f),
593            )
594        }
595    }
596}
597
598impl<O: IsA<Object>> GstObjectExt for O {}