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::{ClockTime, ControlBinding, ffi};
7use glib::{
8 prelude::*,
9 signal::{SignalHandlerId, connect_raw},
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 /// Returns the toplevel parent of `self`. This function increases the refcount
311 /// of the toplevel object so you should `gst_object_unref()` it after usage.
312 ///
313 /// # Returns
314 ///
315 /// toplevel of `self`, or `self` itself if it has no
316 /// parent. unref after usage.
317 ///
318 /// MT safe. Grabs and releases `self`'s LOCK.
319 #[cfg(feature = "v1_28")]
320 #[cfg_attr(docsrs, doc(cfg(feature = "v1_28")))]
321 #[doc(alias = "gst_object_get_toplevel")]
322 #[doc(alias = "get_toplevel")]
323 #[must_use]
324 fn toplevel(&self) -> Object {
325 unsafe { from_glib_full(ffi::gst_object_get_toplevel(self.as_ref().to_glib_none().0)) }
326 }
327
328 /// Gets the value for the given controlled property at the requested time.
329 /// ## `property_name`
330 /// the name of the property to get
331 /// ## `timestamp`
332 /// the time the control-change should be read from
333 ///
334 /// # Returns
335 ///
336 /// the GValue of the property at the given time,
337 /// or [`None`] if the property isn't controlled.
338 #[doc(alias = "gst_object_get_value")]
339 #[doc(alias = "get_value")]
340 fn value(
341 &self,
342 property_name: &str,
343 timestamp: impl Into<Option<ClockTime>>,
344 ) -> Option<glib::Value> {
345 unsafe {
346 from_glib_full(ffi::gst_object_get_value(
347 self.as_ref().to_glib_none().0,
348 property_name.to_glib_none().0,
349 timestamp.into().into_glib(),
350 ))
351 }
352 }
353
354 //#[doc(alias = "gst_object_get_value_array")]
355 //#[doc(alias = "get_value_array")]
356 //fn is_value_array(&self, property_name: &str, timestamp: impl Into<Option<ClockTime>>, interval: impl Into<Option<ClockTime>>, values: /*Unimplemented*/&[&Basic: Pointer]) -> bool {
357 // unsafe { TODO: call ffi:gst_object_get_value_array() }
358 //}
359
360 /// Check if the `self` has active controlled properties.
361 ///
362 /// # Returns
363 ///
364 /// [`true`] if the object has active controlled properties
365 #[doc(alias = "gst_object_has_active_control_bindings")]
366 fn has_active_control_bindings(&self) -> bool {
367 unsafe {
368 from_glib(ffi::gst_object_has_active_control_bindings(
369 self.as_ref().to_glib_none().0,
370 ))
371 }
372 }
373
374 /// Check if `self` has an ancestor `ancestor` somewhere up in
375 /// the hierarchy. One can e.g. check if a [`Element`][crate::Element] is inside a [`Pipeline`][crate::Pipeline].
376 ///
377 /// # Deprecated
378 ///
379 /// Use [`has_as_ancestor()`][Self::has_as_ancestor()] instead.
380 ///
381 /// MT safe. Grabs and releases `self`'s locks.
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 #[doc(alias = "gst_object_has_ancestor")]
389 fn has_ancestor(&self, ancestor: &impl IsA<Object>) -> bool {
390 unsafe {
391 from_glib(ffi::gst_object_has_ancestor(
392 self.as_ref().to_glib_none().0,
393 ancestor.as_ref().to_glib_none().0,
394 ))
395 }
396 }
397
398 /// Check if `self` has an ancestor `ancestor` somewhere up in
399 /// the hierarchy. One can e.g. check if a [`Element`][crate::Element] is inside a [`Pipeline`][crate::Pipeline].
400 /// ## `ancestor`
401 /// a [`Object`][crate::Object] to check as ancestor
402 ///
403 /// # Returns
404 ///
405 /// [`true`] if `ancestor` is an ancestor of `self`.
406 ///
407 /// MT safe. Grabs and releases `self`'s locks.
408 #[doc(alias = "gst_object_has_as_ancestor")]
409 fn has_as_ancestor(&self, ancestor: &impl IsA<Object>) -> bool {
410 unsafe {
411 from_glib(ffi::gst_object_has_as_ancestor(
412 self.as_ref().to_glib_none().0,
413 ancestor.as_ref().to_glib_none().0,
414 ))
415 }
416 }
417
418 /// Check if `parent` is the parent of `self`.
419 /// E.g. a [`Element`][crate::Element] can check if it owns a given [`Pad`][crate::Pad].
420 /// ## `parent`
421 /// a [`Object`][crate::Object] to check as parent
422 ///
423 /// # Returns
424 ///
425 /// [`false`] if either `self` or `parent` is [`None`]. [`true`] if `parent` is
426 /// the parent of `self`. Otherwise [`false`].
427 ///
428 /// MT safe. Grabs and releases `self`'s locks.
429 #[doc(alias = "gst_object_has_as_parent")]
430 fn has_as_parent(&self, parent: &impl IsA<Object>) -> bool {
431 unsafe {
432 from_glib(ffi::gst_object_has_as_parent(
433 self.as_ref().to_glib_none().0,
434 parent.as_ref().to_glib_none().0,
435 ))
436 }
437 }
438
439 /// Removes the corresponding [`ControlBinding`][crate::ControlBinding]. If it was the
440 /// last ref of the binding, it will be disposed.
441 /// ## `binding`
442 /// the binding
443 ///
444 /// # Returns
445 ///
446 /// [`true`] if the binding could be removed.
447 #[doc(alias = "gst_object_remove_control_binding")]
448 fn remove_control_binding(&self, binding: &impl IsA<ControlBinding>) -> bool {
449 unsafe {
450 from_glib(ffi::gst_object_remove_control_binding(
451 self.as_ref().to_glib_none().0,
452 binding.as_ref().to_glib_none().0,
453 ))
454 }
455 }
456
457 /// This function is used to disable the control bindings on a property for
458 /// some time, i.e. [`sync_values()`][Self::sync_values()] will do nothing for the
459 /// property.
460 /// ## `property_name`
461 /// property to disable
462 /// ## `disabled`
463 /// boolean that specifies whether to disable the controller
464 /// or not.
465 #[doc(alias = "gst_object_set_control_binding_disabled")]
466 fn set_control_binding_disabled(&self, property_name: &str, disabled: bool) {
467 unsafe {
468 ffi::gst_object_set_control_binding_disabled(
469 self.as_ref().to_glib_none().0,
470 property_name.to_glib_none().0,
471 disabled.into_glib(),
472 );
473 }
474 }
475
476 /// This function is used to disable all controlled properties of the `self` for
477 /// some time, i.e. [`sync_values()`][Self::sync_values()] will do nothing.
478 /// ## `disabled`
479 /// boolean that specifies whether to disable the controller
480 /// or not.
481 #[doc(alias = "gst_object_set_control_bindings_disabled")]
482 fn set_control_bindings_disabled(&self, disabled: bool) {
483 unsafe {
484 ffi::gst_object_set_control_bindings_disabled(
485 self.as_ref().to_glib_none().0,
486 disabled.into_glib(),
487 );
488 }
489 }
490
491 /// Change the control-rate for this `self`. Audio processing [`Element`][crate::Element]
492 /// objects will use this rate to sub-divide their processing loop and call
493 /// [`sync_values()`][Self::sync_values()] in between. The length of the processing segment
494 /// should be up to `control`-rate nanoseconds.
495 ///
496 /// The control-rate should not change if the element is in [`State::Paused`][crate::State::Paused] or
497 /// [`State::Playing`][crate::State::Playing].
498 /// ## `control_rate`
499 /// the new control-rate in nanoseconds.
500 #[doc(alias = "gst_object_set_control_rate")]
501 fn set_control_rate(&self, control_rate: impl Into<Option<ClockTime>>) {
502 unsafe {
503 ffi::gst_object_set_control_rate(
504 self.as_ref().to_glib_none().0,
505 control_rate.into().into_glib(),
506 );
507 }
508 }
509
510 /// Returns a suggestion for timestamps where buffers should be split
511 /// to get best controller results.
512 ///
513 /// # Returns
514 ///
515 /// Returns the suggested timestamp or `GST_CLOCK_TIME_NONE`
516 /// if no control-rate was set.
517 #[doc(alias = "gst_object_suggest_next_sync")]
518 fn suggest_next_sync(&self) -> Option<ClockTime> {
519 unsafe {
520 from_glib(ffi::gst_object_suggest_next_sync(
521 self.as_ref().to_glib_none().0,
522 ))
523 }
524 }
525
526 /// Sets the properties of the object, according to the `GstControlSources` that
527 /// (maybe) handle them and for the given timestamp.
528 ///
529 /// If this function fails, it is most likely the application developers fault.
530 /// Most probably the control sources are not setup correctly.
531 /// ## `timestamp`
532 /// the time that should be processed
533 ///
534 /// # Returns
535 ///
536 /// [`true`] if the controller values could be applied to the object
537 /// properties, [`false`] otherwise
538 #[doc(alias = "gst_object_sync_values")]
539 fn sync_values(&self, timestamp: ClockTime) -> Result<(), glib::error::BoolError> {
540 unsafe {
541 glib::result_from_gboolean!(
542 ffi::gst_object_sync_values(self.as_ref().to_glib_none().0, timestamp.into_glib()),
543 "Failed to sync values"
544 )
545 }
546 }
547
548 /// Clear the parent of `self`, removing the associated reference.
549 /// This function decreases the refcount of `self`.
550 ///
551 /// MT safe. Grabs and releases `self`'s lock.
552 #[doc(alias = "gst_object_unparent")]
553 fn unparent(&self) {
554 unsafe {
555 ffi::gst_object_unparent(self.as_ref().to_glib_none().0);
556 }
557 }
558
559 //#[doc(alias = "deep-notify")]
560 //fn connect_deep_notify<Unsupported or ignored types>(&self, detail: Option<&str>, f: F) -> SignalHandlerId {
561 // Ignored prop: GObject.ParamSpec
562 //}
563
564 #[doc(alias = "parent")]
565 fn connect_parent_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
566 unsafe extern "C" fn notify_parent_trampoline<
567 P: IsA<Object>,
568 F: Fn(&P) + Send + Sync + 'static,
569 >(
570 this: *mut ffi::GstObject,
571 _param_spec: glib::ffi::gpointer,
572 f: glib::ffi::gpointer,
573 ) {
574 unsafe {
575 let f: &F = &*(f as *const F);
576 f(Object::from_glib_borrow(this).unsafe_cast_ref())
577 }
578 }
579 unsafe {
580 let f: Box_<F> = Box_::new(f);
581 connect_raw(
582 self.as_ptr() as *mut _,
583 c"notify::parent".as_ptr(),
584 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
585 notify_parent_trampoline::<Self, F> as *const (),
586 )),
587 Box_::into_raw(f),
588 )
589 }
590 }
591}
592
593impl<O: IsA<Object>> GstObjectExt for O {}