gstreamer/auto/
element.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#![allow(deprecated)]
6
7use crate::{
8    ffi, Bus, Caps, Clock, ClockTime, Context, ElementFactory, Message, Object, Pad, PadTemplate,
9    State, StateChange, StateChangeError, StateChangeReturn, StateChangeSuccess, URIType,
10};
11use glib::{
12    object::ObjectType as _,
13    prelude::*,
14    signal::{connect_raw, SignalHandlerId},
15    translate::*,
16};
17use std::boxed::Box as Box_;
18
19glib::wrapper! {
20    /// GstElement is the abstract base class needed to construct an element that
21    /// can be used in a GStreamer pipeline. Please refer to the plugin writers
22    /// guide for more information on creating [`Element`][crate::Element] subclasses.
23    ///
24    /// The name of a [`Element`][crate::Element] can be get with `gst_element_get_name()` and set with
25    /// `gst_element_set_name()`. For speed, GST_ELEMENT_NAME() can be used in the
26    /// core when using the appropriate locking. Do not use this in plug-ins or
27    /// applications in order to retain ABI compatibility.
28    ///
29    /// Elements can have pads (of the type [`Pad`][crate::Pad]). These pads link to pads on
30    /// other elements. [`Buffer`][crate::Buffer] flow between these linked pads.
31    /// A [`Element`][crate::Element] has a `GList` of [`Pad`][crate::Pad] structures for all their input (or sink)
32    /// and output (or source) pads.
33    /// Core and plug-in writers can add and remove pads with [`ElementExt::add_pad()`][crate::prelude::ElementExt::add_pad()]
34    /// and [`ElementExt::remove_pad()`][crate::prelude::ElementExt::remove_pad()].
35    ///
36    /// An existing pad of an element can be retrieved by name with
37    /// [`ElementExt::static_pad()`][crate::prelude::ElementExt::static_pad()]. A new dynamic pad can be created using
38    /// [`ElementExt::request_pad()`][crate::prelude::ElementExt::request_pad()] with a [`PadTemplate`][crate::PadTemplate].
39    /// An iterator of all pads can be retrieved with [`ElementExtManual::iterate_pads()`][crate::prelude::ElementExtManual::iterate_pads()].
40    ///
41    /// Elements can be linked through their pads.
42    /// If the link is straightforward, use the [`ElementExtManual::link()`][crate::prelude::ElementExtManual::link()]
43    /// convenience function to link two elements, or [`ElementExtManual::link_many()`][crate::prelude::ElementExtManual::link_many()]
44    /// for more elements in a row.
45    /// Use [`ElementExtManual::link_filtered()`][crate::prelude::ElementExtManual::link_filtered()] to link two elements constrained by
46    /// a specified set of [`Caps`][crate::Caps].
47    /// For finer control, use [`ElementExtManual::link_pads()`][crate::prelude::ElementExtManual::link_pads()] and
48    /// [`ElementExtManual::link_pads_filtered()`][crate::prelude::ElementExtManual::link_pads_filtered()] to specify the pads to link on
49    /// each element by name.
50    ///
51    /// Each element has a state (see [`State`][crate::State]). You can get and set the state
52    /// of an element with [`ElementExt::state()`][crate::prelude::ElementExt::state()] and [`ElementExt::set_state()`][crate::prelude::ElementExt::set_state()].
53    /// Setting a state triggers a [`StateChange`][crate::StateChange]. To get a string representation
54    /// of a [`State`][crate::State], use `gst_element_state_get_name()`.
55    ///
56    /// You can get and set a [`Clock`][crate::Clock] on an element using [`ElementExt::clock()`][crate::prelude::ElementExt::clock()]
57    /// and [`ElementExt::set_clock()`][crate::prelude::ElementExt::set_clock()].
58    /// Some elements can provide a clock for the pipeline if
59    /// the [`ElementFlags::PROVIDE_CLOCK`][crate::ElementFlags::PROVIDE_CLOCK] flag is set. With the
60    /// [`ElementExt::provide_clock()`][crate::prelude::ElementExt::provide_clock()] method one can retrieve the clock provided by
61    /// such an element.
62    /// Not all elements require a clock to operate correctly. If the
63    /// [`ElementFlags::REQUIRE_CLOCK`][crate::ElementFlags::REQUIRE_CLOCK]() flag is set, a clock should be set on the
64    /// element with [`ElementExt::set_clock()`][crate::prelude::ElementExt::set_clock()].
65    ///
66    /// Note that clock selection and distribution is normally handled by the
67    /// toplevel [`Pipeline`][crate::Pipeline] so the clock functions are only to be used in very
68    /// specific situations.
69    ///
70    /// This is an Abstract Base Class, you cannot instantiate it.
71    ///
72    /// ## Signals
73    ///
74    ///
75    /// #### `no-more-pads`
76    ///  This signals that the element will not generate more dynamic pads.
77    /// Note that this signal will usually be emitted from the context of
78    /// the streaming thread.
79    ///
80    ///
81    ///
82    ///
83    /// #### `pad-added`
84    ///  a new [`Pad`][crate::Pad] has been added to the element. Note that this signal will
85    /// usually be emitted from the context of the streaming thread. Also keep in
86    /// mind that if you add new elements to the pipeline in the signal handler
87    /// you will need to set them to the desired target state with
88    /// [`ElementExt::set_state()`][crate::prelude::ElementExt::set_state()] or [`ElementExt::sync_state_with_parent()`][crate::prelude::ElementExt::sync_state_with_parent()].
89    ///
90    ///
91    ///
92    ///
93    /// #### `pad-removed`
94    ///  a [`Pad`][crate::Pad] has been removed from the element
95    ///
96    ///
97    /// <details><summary><h4>Object</h4></summary>
98    ///
99    ///
100    /// #### `deep-notify`
101    ///  The deep notify signal is used to be notified of property changes. It is
102    /// typically attached to the toplevel bin to receive notifications from all
103    /// the elements contained in that bin.
104    ///
105    /// Detailed
106    /// </details>
107    ///
108    /// # Implements
109    ///
110    /// [`ElementExt`][trait@crate::prelude::ElementExt], [`GstObjectExt`][trait@crate::prelude::GstObjectExt], [`trait@glib::ObjectExt`], [`ElementExtManual`][trait@crate::prelude::ElementExtManual]
111    #[doc(alias = "GstElement")]
112    pub struct Element(Object<ffi::GstElement, ffi::GstElementClass>) @extends Object;
113
114    match fn {
115        type_ => || ffi::gst_element_get_type(),
116    }
117}
118
119impl Element {
120    pub const NONE: Option<&'static Element> = None;
121
122    /// Creates an element for handling the given URI.
123    /// ## `type_`
124    /// Whether to create a source or a sink
125    /// ## `uri`
126    /// URI to create an element for
127    /// ## `elementname`
128    /// Name of created element, can be [`None`].
129    ///
130    /// # Returns
131    ///
132    /// a new element or [`None`] if none
133    /// could be created
134    #[doc(alias = "gst_element_make_from_uri")]
135    pub fn make_from_uri(
136        type_: URIType,
137        uri: &str,
138        elementname: Option<&str>,
139    ) -> Result<Element, glib::Error> {
140        assert_initialized_main_thread!();
141        unsafe {
142            let mut error = std::ptr::null_mut();
143            let ret = ffi::gst_element_make_from_uri(
144                type_.into_glib(),
145                uri.to_glib_none().0,
146                elementname.to_glib_none().0,
147                &mut error,
148            );
149            if error.is_null() {
150                Ok(from_glib_none(ret))
151            } else {
152                Err(from_glib_full(error))
153            }
154        }
155    }
156}
157
158unsafe impl Send for Element {}
159unsafe impl Sync for Element {}
160
161mod sealed {
162    pub trait Sealed {}
163    impl<T: super::IsA<super::Element>> Sealed for T {}
164}
165
166/// Trait containing all [`struct@Element`] methods.
167///
168/// # Implementors
169///
170/// [`Bin`][struct@crate::Bin], [`Element`][struct@crate::Element], [`TagSetter`][struct@crate::TagSetter], [`TocSetter`][struct@crate::TocSetter]
171pub trait ElementExt: IsA<Element> + sealed::Sealed + 'static {
172    /// Abort the state change of the element. This function is used
173    /// by elements that do asynchronous state changes and find out
174    /// something is wrong.
175    ///
176    /// This function should be called with the STATE_LOCK held.
177    ///
178    /// MT safe.
179    #[doc(alias = "gst_element_abort_state")]
180    fn abort_state(&self) {
181        unsafe {
182            ffi::gst_element_abort_state(self.as_ref().to_glib_none().0);
183        }
184    }
185
186    /// Adds a pad (link point) to `self`. `pad`'s parent will be set to `self`;
187    /// see [`GstObjectExt::set_parent()`][crate::prelude::GstObjectExt::set_parent()] for refcounting information.
188    ///
189    /// Pads are automatically activated when added in the PAUSED or PLAYING
190    /// state.
191    ///
192    /// The pad and the element should be unlocked when calling this function.
193    ///
194    /// This function will emit the [`pad-added`][struct@crate::Element#pad-added] signal on the element.
195    /// ## `pad`
196    /// the [`Pad`][crate::Pad] to add to the element.
197    ///
198    /// # Returns
199    ///
200    /// [`true`] if the pad could be added. This function can fail when
201    /// a pad with the same name already existed or the pad already had another
202    /// parent.
203    ///
204    /// MT safe.
205    #[doc(alias = "gst_element_add_pad")]
206    fn add_pad(&self, pad: &impl IsA<Pad>) -> Result<(), glib::error::BoolError> {
207        unsafe {
208            glib::result_from_gboolean!(
209                ffi::gst_element_add_pad(
210                    self.as_ref().to_glib_none().0,
211                    pad.as_ref().to_glib_none().0
212                ),
213                "Failed to add pad"
214            )
215        }
216    }
217
218    /// Perform `transition` on `self`.
219    ///
220    /// This function must be called with STATE_LOCK held and is mainly used
221    /// internally.
222    /// ## `transition`
223    /// the requested transition
224    ///
225    /// # Returns
226    ///
227    /// the [`StateChangeReturn`][crate::StateChangeReturn] of the state transition.
228    #[doc(alias = "gst_element_change_state")]
229    fn change_state(
230        &self,
231        transition: StateChange,
232    ) -> Result<StateChangeSuccess, StateChangeError> {
233        unsafe {
234            try_from_glib(ffi::gst_element_change_state(
235                self.as_ref().to_glib_none().0,
236                transition.into_glib(),
237            ))
238        }
239    }
240
241    /// Commit the state change of the element and proceed to the next
242    /// pending state if any. This function is used
243    /// by elements that do asynchronous state changes.
244    /// The core will normally call this method automatically when an
245    /// element returned [`StateChangeReturn::Success`][crate::StateChangeReturn::Success] from the state change function.
246    ///
247    /// If after calling this method the element still has not reached
248    /// the pending state, the next state change is performed.
249    ///
250    /// This method is used internally and should normally not be called by plugins
251    /// or applications.
252    ///
253    /// This function must be called with STATE_LOCK held.
254    /// ## `ret`
255    /// The previous state return value
256    ///
257    /// # Returns
258    ///
259    /// The result of the commit state change.
260    ///
261    /// MT safe.
262    #[doc(alias = "gst_element_continue_state")]
263    fn continue_state(
264        &self,
265        ret: impl Into<StateChangeReturn>,
266    ) -> Result<StateChangeSuccess, StateChangeError> {
267        unsafe {
268            try_from_glib(ffi::gst_element_continue_state(
269                self.as_ref().to_glib_none().0,
270                ret.into().into_glib(),
271            ))
272        }
273    }
274
275    /// Creates a pad for each pad template that is always available.
276    /// This function is only useful during object initialization of
277    /// subclasses of [`Element`][crate::Element].
278    #[doc(alias = "gst_element_create_all_pads")]
279    fn create_all_pads(&self) {
280        unsafe {
281            ffi::gst_element_create_all_pads(self.as_ref().to_glib_none().0);
282        }
283    }
284
285    /// Creates a stream-id for `self` by combining the upstream information with
286    /// the `stream_id`.
287    ///
288    /// This function generates an unique stream-id by getting the upstream
289    /// stream-start event stream ID and appending `stream_id` to it. If the element
290    /// has no sinkpad it will generate an upstream stream-id by doing an URI query
291    /// on the element and in the worst case just uses a random number. Source
292    /// elements that don't implement the URI handler interface should ideally
293    /// generate a unique, deterministic stream-id manually instead.
294    ///
295    /// Since stream IDs are sorted alphabetically, any numbers in the stream ID
296    /// should be printed with a fixed number of characters, preceded by 0's, such as
297    /// by using the format \`03u` instead of \`u`.
298    /// ## `stream_id`
299    /// The stream-id
300    ///
301    /// # Returns
302    ///
303    /// A stream-id for `self`.
304    #[cfg(feature = "v1_24")]
305    #[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
306    #[doc(alias = "gst_element_decorate_stream_id")]
307    fn decorate_stream_id(&self, stream_id: &str) -> glib::GString {
308        unsafe {
309            from_glib_full(ffi::gst_element_decorate_stream_id(
310                self.as_ref().to_glib_none().0,
311                stream_id.to_glib_none().0,
312            ))
313        }
314    }
315
316    /// Call `func` with `user_data` for each of `self`'s pads. `func` will be called
317    /// exactly once for each pad that exists at the time of this call, unless
318    /// one of the calls to `func` returns [`false`] in which case we will stop
319    /// iterating pads and return early. If new pads are added or pads are removed
320    /// while pads are being iterated, this will not be taken into account until
321    /// next time this function is used.
322    /// ## `func`
323    /// function to call for each pad
324    ///
325    /// # Returns
326    ///
327    /// [`false`] if `self` had no pads or if one of the calls to `func`
328    ///  returned [`false`].
329    #[doc(alias = "gst_element_foreach_pad")]
330    fn foreach_pad<P: FnMut(&Element, &Pad) -> bool>(&self, func: P) -> bool {
331        let mut func_data: P = func;
332        unsafe extern "C" fn func_func<P: FnMut(&Element, &Pad) -> bool>(
333            element: *mut ffi::GstElement,
334            pad: *mut ffi::GstPad,
335            user_data: glib::ffi::gpointer,
336        ) -> glib::ffi::gboolean {
337            let element = from_glib_borrow(element);
338            let pad = from_glib_borrow(pad);
339            let callback = user_data as *mut P;
340            (*callback)(&element, &pad).into_glib()
341        }
342        let func = Some(func_func::<P> as _);
343        let super_callback0: &mut P = &mut func_data;
344        unsafe {
345            from_glib(ffi::gst_element_foreach_pad(
346                self.as_ref().to_glib_none().0,
347                func,
348                super_callback0 as *mut _ as *mut _,
349            ))
350        }
351    }
352
353    /// Call `func` with `user_data` for each of `self`'s sink pads. `func` will be
354    /// called exactly once for each sink pad that exists at the time of this call,
355    /// unless one of the calls to `func` returns [`false`] in which case we will stop
356    /// iterating pads and return early. If new sink pads are added or sink pads
357    /// are removed while the sink pads are being iterated, this will not be taken
358    /// into account until next time this function is used.
359    /// ## `func`
360    /// function to call for each sink pad
361    ///
362    /// # Returns
363    ///
364    /// [`false`] if `self` had no sink pads or if one of the calls to `func`
365    ///  returned [`false`].
366    #[doc(alias = "gst_element_foreach_sink_pad")]
367    fn foreach_sink_pad<P: FnMut(&Element, &Pad) -> bool>(&self, func: P) -> bool {
368        let mut func_data: P = func;
369        unsafe extern "C" fn func_func<P: FnMut(&Element, &Pad) -> bool>(
370            element: *mut ffi::GstElement,
371            pad: *mut ffi::GstPad,
372            user_data: glib::ffi::gpointer,
373        ) -> glib::ffi::gboolean {
374            let element = from_glib_borrow(element);
375            let pad = from_glib_borrow(pad);
376            let callback = user_data as *mut P;
377            (*callback)(&element, &pad).into_glib()
378        }
379        let func = Some(func_func::<P> as _);
380        let super_callback0: &mut P = &mut func_data;
381        unsafe {
382            from_glib(ffi::gst_element_foreach_sink_pad(
383                self.as_ref().to_glib_none().0,
384                func,
385                super_callback0 as *mut _ as *mut _,
386            ))
387        }
388    }
389
390    /// Call `func` with `user_data` for each of `self`'s source pads. `func` will be
391    /// called exactly once for each source pad that exists at the time of this call,
392    /// unless one of the calls to `func` returns [`false`] in which case we will stop
393    /// iterating pads and return early. If new source pads are added or source pads
394    /// are removed while the source pads are being iterated, this will not be taken
395    /// into account until next time this function is used.
396    /// ## `func`
397    /// function to call for each source pad
398    ///
399    /// # Returns
400    ///
401    /// [`false`] if `self` had no source pads or if one of the calls
402    ///  to `func` returned [`false`].
403    #[doc(alias = "gst_element_foreach_src_pad")]
404    fn foreach_src_pad<P: FnMut(&Element, &Pad) -> bool>(&self, func: P) -> bool {
405        let mut func_data: P = func;
406        unsafe extern "C" fn func_func<P: FnMut(&Element, &Pad) -> bool>(
407            element: *mut ffi::GstElement,
408            pad: *mut ffi::GstPad,
409            user_data: glib::ffi::gpointer,
410        ) -> glib::ffi::gboolean {
411            let element = from_glib_borrow(element);
412            let pad = from_glib_borrow(pad);
413            let callback = user_data as *mut P;
414            (*callback)(&element, &pad).into_glib()
415        }
416        let func = Some(func_func::<P> as _);
417        let super_callback0: &mut P = &mut func_data;
418        unsafe {
419            from_glib(ffi::gst_element_foreach_src_pad(
420                self.as_ref().to_glib_none().0,
421                func,
422                super_callback0 as *mut _ as *mut _,
423            ))
424        }
425    }
426
427    /// Returns the base time of the element. The base time is the
428    /// absolute time of the clock when this element was last put to
429    /// PLAYING. Subtracting the base time from the clock time gives
430    /// the running time of the element.
431    ///
432    /// # Returns
433    ///
434    /// the base time of the element.
435    ///
436    /// MT safe.
437    #[doc(alias = "gst_element_get_base_time")]
438    #[doc(alias = "get_base_time")]
439    fn base_time(&self) -> Option<ClockTime> {
440        unsafe {
441            from_glib(ffi::gst_element_get_base_time(
442                self.as_ref().to_glib_none().0,
443            ))
444        }
445    }
446
447    /// Returns the bus of the element. Note that only a [`Pipeline`][crate::Pipeline] will provide a
448    /// bus for the application.
449    ///
450    /// # Returns
451    ///
452    /// the element's [`Bus`][crate::Bus]. unref after
453    /// usage.
454    ///
455    /// MT safe.
456    #[doc(alias = "gst_element_get_bus")]
457    #[doc(alias = "get_bus")]
458    fn bus(&self) -> Option<Bus> {
459        unsafe { from_glib_full(ffi::gst_element_get_bus(self.as_ref().to_glib_none().0)) }
460    }
461
462    /// Gets the currently configured clock of the element. This is the clock as was
463    /// last set with [`set_clock()`][Self::set_clock()].
464    ///
465    /// Elements in a pipeline will only have their clock set when the
466    /// pipeline is in the PLAYING state.
467    ///
468    /// # Returns
469    ///
470    /// the [`Clock`][crate::Clock] of the element. unref after usage.
471    ///
472    /// MT safe.
473    #[doc(alias = "gst_element_get_clock")]
474    #[doc(alias = "get_clock")]
475    fn clock(&self) -> Option<Clock> {
476        unsafe { from_glib_full(ffi::gst_element_get_clock(self.as_ref().to_glib_none().0)) }
477    }
478
479    /// Looks for an unlinked pad to which the given pad can link. It is not
480    /// guaranteed that linking the pads will work, though it should work in most
481    /// cases.
482    ///
483    /// This function will first attempt to find a compatible unlinked ALWAYS pad,
484    /// and if none can be found, it will request a compatible REQUEST pad by looking
485    /// at the templates of `self`.
486    /// ## `pad`
487    /// the [`Pad`][crate::Pad] to find a compatible one for.
488    /// ## `caps`
489    /// the [`Caps`][crate::Caps] to use as a filter.
490    ///
491    /// # Returns
492    ///
493    /// the [`Pad`][crate::Pad] to which a link
494    ///  can be made, or [`None`] if one cannot be found. `gst_object_unref()`
495    ///  after usage.
496    #[doc(alias = "gst_element_get_compatible_pad")]
497    #[doc(alias = "get_compatible_pad")]
498    fn compatible_pad(&self, pad: &impl IsA<Pad>, caps: Option<&Caps>) -> Option<Pad> {
499        unsafe {
500            from_glib_full(ffi::gst_element_get_compatible_pad(
501                self.as_ref().to_glib_none().0,
502                pad.as_ref().to_glib_none().0,
503                caps.to_glib_none().0,
504            ))
505        }
506    }
507
508    /// Retrieves a pad template from `self` that is compatible with `compattempl`.
509    /// Pads from compatible templates can be linked together.
510    /// ## `compattempl`
511    /// the [`PadTemplate`][crate::PadTemplate] to find a compatible
512    ///  template for
513    ///
514    /// # Returns
515    ///
516    /// a compatible [`PadTemplate`][crate::PadTemplate],
517    ///  or [`None`] if none was found. No unreferencing is necessary.
518    #[doc(alias = "gst_element_get_compatible_pad_template")]
519    #[doc(alias = "get_compatible_pad_template")]
520    fn compatible_pad_template(&self, compattempl: &PadTemplate) -> Option<PadTemplate> {
521        unsafe {
522            from_glib_none(ffi::gst_element_get_compatible_pad_template(
523                self.as_ref().to_glib_none().0,
524                compattempl.to_glib_none().0,
525            ))
526        }
527    }
528
529    /// Gets the context with `context_type` set on the element or NULL.
530    ///
531    /// MT safe.
532    /// ## `context_type`
533    /// a name of a context to retrieve
534    ///
535    /// # Returns
536    ///
537    /// A [`Context`][crate::Context] or NULL
538    #[doc(alias = "gst_element_get_context")]
539    #[doc(alias = "get_context")]
540    fn context(&self, context_type: &str) -> Option<Context> {
541        unsafe {
542            from_glib_full(ffi::gst_element_get_context(
543                self.as_ref().to_glib_none().0,
544                context_type.to_glib_none().0,
545            ))
546        }
547    }
548
549    /// Gets the contexts set on the element.
550    ///
551    /// MT safe.
552    ///
553    /// # Returns
554    ///
555    /// List of [`Context`][crate::Context]
556    #[doc(alias = "gst_element_get_contexts")]
557    #[doc(alias = "get_contexts")]
558    fn contexts(&self) -> Vec<Context> {
559        unsafe {
560            FromGlibPtrContainer::from_glib_full(ffi::gst_element_get_contexts(
561                self.as_ref().to_glib_none().0,
562            ))
563        }
564    }
565
566    /// Retrieves the factory that was used to create this element.
567    ///
568    /// # Returns
569    ///
570    /// the [`ElementFactory`][crate::ElementFactory] used for creating this
571    ///  element or [`None`] if element has not been registered (static element). no refcounting is needed.
572    #[doc(alias = "gst_element_get_factory")]
573    #[doc(alias = "get_factory")]
574    fn factory(&self) -> Option<ElementFactory> {
575        unsafe { from_glib_none(ffi::gst_element_get_factory(self.as_ref().to_glib_none().0)) }
576    }
577
578    /// Returns the start time of the element. The start time is the
579    /// running time of the clock when this element was last put to PAUSED.
580    ///
581    /// Usually the start_time is managed by a toplevel element such as
582    /// [`Pipeline`][crate::Pipeline].
583    ///
584    /// MT safe.
585    ///
586    /// # Returns
587    ///
588    /// the start time of the element.
589    #[doc(alias = "gst_element_get_start_time")]
590    #[doc(alias = "get_start_time")]
591    fn start_time(&self) -> Option<ClockTime> {
592        unsafe {
593            from_glib(ffi::gst_element_get_start_time(
594                self.as_ref().to_glib_none().0,
595            ))
596        }
597    }
598
599    /// Gets the state of the element.
600    ///
601    /// For elements that performed an ASYNC state change, as reported by
602    /// [`set_state()`][Self::set_state()], this function will block up to the
603    /// specified timeout value for the state change to complete.
604    /// If the element completes the state change or goes into
605    /// an error, this function returns immediately with a return value of
606    /// [`StateChangeReturn::Success`][crate::StateChangeReturn::Success] or [`StateChangeReturn::Failure`][crate::StateChangeReturn::Failure] respectively.
607    ///
608    /// For elements that did not return [`StateChangeReturn::Async`][crate::StateChangeReturn::Async], this function
609    /// returns the current and pending state immediately.
610    ///
611    /// This function returns [`StateChangeReturn::NoPreroll`][crate::StateChangeReturn::NoPreroll] if the element
612    /// successfully changed its state but is not able to provide data yet.
613    /// This mostly happens for live sources that only produce data in
614    /// [`State::Playing`][crate::State::Playing]. While the state change return is equivalent to
615    /// [`StateChangeReturn::Success`][crate::StateChangeReturn::Success], it is returned to the application to signal that
616    /// some sink elements might not be able to complete their state change because
617    /// an element is not producing data to complete the preroll. When setting the
618    /// element to playing, the preroll will complete and playback will start.
619    /// ## `timeout`
620    /// a `GstClockTime` to specify the timeout for an async
621    ///  state change or `GST_CLOCK_TIME_NONE` for infinite timeout.
622    ///
623    /// # Returns
624    ///
625    /// [`StateChangeReturn::Success`][crate::StateChangeReturn::Success] if the element has no more pending state
626    ///  and the last state change succeeded, [`StateChangeReturn::Async`][crate::StateChangeReturn::Async] if the
627    ///  element is still performing a state change or
628    ///  [`StateChangeReturn::Failure`][crate::StateChangeReturn::Failure] if the last state change failed.
629    ///
630    /// MT safe.
631    ///
632    /// ## `state`
633    /// a pointer to [`State`][crate::State] to hold the state.
634    ///  Can be [`None`].
635    ///
636    /// ## `pending`
637    /// a pointer to [`State`][crate::State] to hold the pending
638    ///  state. Can be [`None`].
639    #[doc(alias = "gst_element_get_state")]
640    #[doc(alias = "get_state")]
641    fn state(
642        &self,
643        timeout: impl Into<Option<ClockTime>>,
644    ) -> (Result<StateChangeSuccess, StateChangeError>, State, State) {
645        unsafe {
646            let mut state = std::mem::MaybeUninit::uninit();
647            let mut pending = std::mem::MaybeUninit::uninit();
648            let ret = try_from_glib(ffi::gst_element_get_state(
649                self.as_ref().to_glib_none().0,
650                state.as_mut_ptr(),
651                pending.as_mut_ptr(),
652                timeout.into().into_glib(),
653            ));
654            (
655                ret,
656                from_glib(state.assume_init()),
657                from_glib(pending.assume_init()),
658            )
659        }
660    }
661
662    /// Retrieves a pad from `self` by name. This version only retrieves
663    /// already-existing (i.e. 'static') pads.
664    /// ## `name`
665    /// the name of the static [`Pad`][crate::Pad] to retrieve.
666    ///
667    /// # Returns
668    ///
669    /// the requested [`Pad`][crate::Pad] if
670    ///  found, otherwise [`None`]. unref after usage.
671    ///
672    /// MT safe.
673    #[doc(alias = "gst_element_get_static_pad")]
674    #[doc(alias = "get_static_pad")]
675    fn static_pad(&self, name: &str) -> Option<Pad> {
676        unsafe {
677            from_glib_full(ffi::gst_element_get_static_pad(
678                self.as_ref().to_glib_none().0,
679                name.to_glib_none().0,
680            ))
681        }
682    }
683
684    /// Checks if the state of an element is locked.
685    /// If the state of an element is locked, state changes of the parent don't
686    /// affect the element.
687    /// This way you can leave currently unused elements inside bins. Just lock their
688    /// state before changing the state from [`State::Null`][crate::State::Null].
689    ///
690    /// MT safe.
691    ///
692    /// # Returns
693    ///
694    /// [`true`], if the element's state is locked.
695    #[doc(alias = "gst_element_is_locked_state")]
696    fn is_locked_state(&self) -> bool {
697        unsafe {
698            from_glib(ffi::gst_element_is_locked_state(
699                self.as_ref().to_glib_none().0,
700            ))
701        }
702    }
703
704    /// Brings the element to the lost state. The current state of the
705    /// element is copied to the pending state so that any call to
706    /// [`state()`][Self::state()] will return [`StateChangeReturn::Async`][crate::StateChangeReturn::Async].
707    ///
708    /// An ASYNC_START message is posted. If the element was PLAYING, it will
709    /// go to PAUSED. The element will be restored to its PLAYING state by
710    /// the parent pipeline when it prerolls again.
711    ///
712    /// This is mostly used for elements that lost their preroll buffer
713    /// in the [`State::Paused`][crate::State::Paused] or [`State::Playing`][crate::State::Playing] state after a flush,
714    /// they will go to their pending state again when a new preroll buffer is
715    /// queued. This function can only be called when the element is currently
716    /// not in error or an async state change.
717    ///
718    /// This function is used internally and should normally not be called from
719    /// plugins or applications.
720    #[doc(alias = "gst_element_lost_state")]
721    fn lost_state(&self) {
722        unsafe {
723            ffi::gst_element_lost_state(self.as_ref().to_glib_none().0);
724        }
725    }
726
727    /// Use this function to signal that the element does not expect any more pads
728    /// to show up in the current pipeline. This function should be called whenever
729    /// pads have been added by the element itself. Elements with [`PadPresence::Sometimes`][crate::PadPresence::Sometimes]
730    /// pad templates use this in combination with autopluggers to figure out that
731    /// the element is done initializing its pads.
732    ///
733    /// This function emits the [`no-more-pads`][struct@crate::Element#no-more-pads] signal.
734    ///
735    /// MT safe.
736    #[doc(alias = "gst_element_no_more_pads")]
737    fn no_more_pads(&self) {
738        unsafe {
739            ffi::gst_element_no_more_pads(self.as_ref().to_glib_none().0);
740        }
741    }
742
743    /// Post a message on the element's [`Bus`][crate::Bus]. This function takes ownership of the
744    /// message; if you want to access the message after this call, you should add an
745    /// additional reference before calling.
746    /// ## `message`
747    /// a [`Message`][crate::Message] to post
748    ///
749    /// # Returns
750    ///
751    /// [`true`] if the message was successfully posted. The function returns
752    /// [`false`] if the element did not have a bus.
753    ///
754    /// MT safe.
755    #[doc(alias = "gst_element_post_message")]
756    fn post_message(&self, message: Message) -> Result<(), glib::error::BoolError> {
757        unsafe {
758            glib::result_from_gboolean!(
759                ffi::gst_element_post_message(
760                    self.as_ref().to_glib_none().0,
761                    message.into_glib_ptr()
762                ),
763                "Failed to post message"
764            )
765        }
766    }
767
768    /// Get the clock provided by the given element.
769    /// > An element is only required to provide a clock in the PAUSED
770    /// > state. Some elements can provide a clock in other states.
771    ///
772    /// # Returns
773    ///
774    /// the GstClock provided by the
775    /// element or [`None`] if no clock could be provided. Unref after usage.
776    ///
777    /// MT safe.
778    #[doc(alias = "gst_element_provide_clock")]
779    fn provide_clock(&self) -> Option<Clock> {
780        unsafe {
781            from_glib_full(ffi::gst_element_provide_clock(
782                self.as_ref().to_glib_none().0,
783            ))
784        }
785    }
786
787    /// Makes the element free the previously requested pad as obtained
788    /// with [`request_pad()`][Self::request_pad()].
789    ///
790    /// This does not unref the pad. If the pad was created by using
791    /// [`request_pad()`][Self::request_pad()], [`release_request_pad()`][Self::release_request_pad()] needs to be
792    /// followed by `gst_object_unref()` to free the `pad`.
793    ///
794    /// MT safe.
795    /// ## `pad`
796    /// the [`Pad`][crate::Pad] to release.
797    #[doc(alias = "gst_element_release_request_pad")]
798    fn release_request_pad(&self, pad: &impl IsA<Pad>) {
799        unsafe {
800            ffi::gst_element_release_request_pad(
801                self.as_ref().to_glib_none().0,
802                pad.as_ref().to_glib_none().0,
803            );
804        }
805    }
806
807    /// Removes `pad` from `self`. `pad` will be destroyed if it has not been
808    /// referenced elsewhere using [`GstObjectExt::unparent()`][crate::prelude::GstObjectExt::unparent()].
809    ///
810    /// This function is used by plugin developers and should not be used
811    /// by applications. Pads that were dynamically requested from elements
812    /// with [`request_pad()`][Self::request_pad()] should be released with the
813    /// [`release_request_pad()`][Self::release_request_pad()] function instead.
814    ///
815    /// Pads are not automatically deactivated so elements should perform the needed
816    /// steps to deactivate the pad in case this pad is removed in the PAUSED or
817    /// PLAYING state. See [`PadExt::set_active()`][crate::prelude::PadExt::set_active()] for more information about
818    /// deactivating pads.
819    ///
820    /// The pad and the element should be unlocked when calling this function.
821    ///
822    /// This function will emit the [`pad-removed`][struct@crate::Element#pad-removed] signal on the element.
823    /// ## `pad`
824    /// the [`Pad`][crate::Pad] to remove from the element.
825    ///
826    /// # Returns
827    ///
828    /// [`true`] if the pad could be removed. Can return [`false`] if the
829    /// pad does not belong to the provided element.
830    ///
831    /// MT safe.
832    #[doc(alias = "gst_element_remove_pad")]
833    fn remove_pad(&self, pad: &impl IsA<Pad>) -> Result<(), glib::error::BoolError> {
834        unsafe {
835            glib::result_from_gboolean!(
836                ffi::gst_element_remove_pad(
837                    self.as_ref().to_glib_none().0,
838                    pad.as_ref().to_glib_none().0
839                ),
840                "Failed to remove pad"
841            )
842        }
843    }
844
845    /// Retrieves a request pad from the element according to the provided template.
846    /// Pad templates can be looked up using
847    /// [`ElementFactory::static_pad_templates()`][crate::ElementFactory::static_pad_templates()].
848    ///
849    /// The pad should be released with [`release_request_pad()`][Self::release_request_pad()].
850    /// ## `templ`
851    /// a [`PadTemplate`][crate::PadTemplate] of which we want a pad of.
852    /// ## `name`
853    /// the name of the request [`Pad`][crate::Pad]
854    /// to retrieve. Can be [`None`].
855    /// ## `caps`
856    /// the caps of the pad we want to
857    /// request. Can be [`None`].
858    ///
859    /// # Returns
860    ///
861    /// requested [`Pad`][crate::Pad] if found,
862    ///  otherwise [`None`]. Release after usage.
863    #[doc(alias = "gst_element_request_pad")]
864    fn request_pad(
865        &self,
866        templ: &PadTemplate,
867        name: Option<&str>,
868        caps: Option<&Caps>,
869    ) -> Option<Pad> {
870        unsafe {
871            from_glib_full(ffi::gst_element_request_pad(
872                self.as_ref().to_glib_none().0,
873                templ.to_glib_none().0,
874                name.to_glib_none().0,
875                caps.to_glib_none().0,
876            ))
877        }
878    }
879
880    /// Set the base time of an element. See [`base_time()`][Self::base_time()].
881    ///
882    /// MT safe.
883    /// ## `time`
884    /// the base time to set.
885    #[doc(alias = "gst_element_set_base_time")]
886    fn set_base_time(&self, time: ClockTime) {
887        unsafe {
888            ffi::gst_element_set_base_time(self.as_ref().to_glib_none().0, time.into_glib());
889        }
890    }
891
892    /// Sets the bus of the element. Increases the refcount on the bus.
893    /// For internal use only, unless you're testing elements.
894    ///
895    /// MT safe.
896    /// ## `bus`
897    /// the [`Bus`][crate::Bus] to set.
898    #[doc(alias = "gst_element_set_bus")]
899    fn set_bus(&self, bus: Option<&Bus>) {
900        unsafe {
901            ffi::gst_element_set_bus(self.as_ref().to_glib_none().0, bus.to_glib_none().0);
902        }
903    }
904
905    /// Sets the clock for the element. This function increases the
906    /// refcount on the clock. Any previously set clock on the object
907    /// is unreffed.
908    /// ## `clock`
909    /// the [`Clock`][crate::Clock] to set for the element.
910    ///
911    /// # Returns
912    ///
913    /// [`true`] if the element accepted the clock. An element can refuse a
914    /// clock when it, for example, is not able to slave its internal clock to the
915    /// `clock` or when it requires a specific clock to operate.
916    ///
917    /// MT safe.
918    #[doc(alias = "gst_element_set_clock")]
919    fn set_clock(&self, clock: Option<&impl IsA<Clock>>) -> Result<(), glib::error::BoolError> {
920        unsafe {
921            glib::result_from_gboolean!(
922                ffi::gst_element_set_clock(
923                    self.as_ref().to_glib_none().0,
924                    clock.map(|p| p.as_ref()).to_glib_none().0
925                ),
926                "Failed to set clock"
927            )
928        }
929    }
930
931    /// Sets the context of the element. Increases the refcount of the context.
932    ///
933    /// MT safe.
934    /// ## `context`
935    /// the [`Context`][crate::Context] to set.
936    #[doc(alias = "gst_element_set_context")]
937    fn set_context(&self, context: &Context) {
938        unsafe {
939            ffi::gst_element_set_context(self.as_ref().to_glib_none().0, context.to_glib_none().0);
940        }
941    }
942
943    /// Locks the state of an element, so state changes of the parent don't affect
944    /// this element anymore.
945    ///
946    /// Note that this is racy if the state lock of the parent bin is not taken.
947    /// The parent bin might've just checked the flag in another thread and as the
948    /// next step proceed to change the child element's state.
949    ///
950    /// MT safe.
951    /// ## `locked_state`
952    /// [`true`] to lock the element's state
953    ///
954    /// # Returns
955    ///
956    /// [`true`] if the state was changed, [`false`] if bad parameters were given
957    /// or the elements state-locking needed no change.
958    #[doc(alias = "gst_element_set_locked_state")]
959    fn set_locked_state(&self, locked_state: bool) -> bool {
960        unsafe {
961            from_glib(ffi::gst_element_set_locked_state(
962                self.as_ref().to_glib_none().0,
963                locked_state.into_glib(),
964            ))
965        }
966    }
967
968    /// Set the start time of an element. The start time of the element is the
969    /// running time of the element when it last went to the PAUSED state. In READY
970    /// or after a flushing seek, it is set to 0.
971    ///
972    /// Toplevel elements like [`Pipeline`][crate::Pipeline] will manage the start_time and
973    /// base_time on its children. Setting the start_time to `GST_CLOCK_TIME_NONE`
974    /// on such a toplevel element will disable the distribution of the base_time to
975    /// the children and can be useful if the application manages the base_time
976    /// itself, for example if you want to synchronize capture from multiple
977    /// pipelines, and you can also ensure that the pipelines have the same clock.
978    ///
979    /// MT safe.
980    /// ## `time`
981    /// the base time to set.
982    #[doc(alias = "gst_element_set_start_time")]
983    fn set_start_time(&self, time: impl Into<Option<ClockTime>>) {
984        unsafe {
985            ffi::gst_element_set_start_time(
986                self.as_ref().to_glib_none().0,
987                time.into().into_glib(),
988            );
989        }
990    }
991
992    /// Sets the state of the element. This function will try to set the
993    /// requested state by going through all the intermediary states and calling
994    /// the class's state change function for each.
995    ///
996    /// This function can return [`StateChangeReturn::Async`][crate::StateChangeReturn::Async], in which case the
997    /// element will perform the remainder of the state change asynchronously in
998    /// another thread.
999    /// An application can use [`state()`][Self::state()] to wait for the completion
1000    /// of the state change or it can wait for a `GST_MESSAGE_ASYNC_DONE` or
1001    /// `GST_MESSAGE_STATE_CHANGED` on the bus.
1002    ///
1003    /// State changes to [`State::Ready`][crate::State::Ready] or [`State::Null`][crate::State::Null] never return
1004    /// [`StateChangeReturn::Async`][crate::StateChangeReturn::Async].
1005    /// ## `state`
1006    /// the element's new [`State`][crate::State].
1007    ///
1008    /// # Returns
1009    ///
1010    /// Result of the state change using [`StateChangeReturn`][crate::StateChangeReturn].
1011    ///
1012    /// MT safe.
1013    #[doc(alias = "gst_element_set_state")]
1014    fn set_state(&self, state: State) -> Result<StateChangeSuccess, StateChangeError> {
1015        unsafe {
1016            try_from_glib(ffi::gst_element_set_state(
1017                self.as_ref().to_glib_none().0,
1018                state.into_glib(),
1019            ))
1020        }
1021    }
1022
1023    /// Tries to change the state of the element to the same as its parent.
1024    /// If this function returns [`false`], the state of element is undefined.
1025    ///
1026    /// # Returns
1027    ///
1028    /// [`true`], if the element's state could be synced to the parent's state.
1029    ///
1030    /// MT safe.
1031    #[doc(alias = "gst_element_sync_state_with_parent")]
1032    fn sync_state_with_parent(&self) -> Result<(), glib::error::BoolError> {
1033        unsafe {
1034            glib::result_from_gboolean!(
1035                ffi::gst_element_sync_state_with_parent(self.as_ref().to_glib_none().0),
1036                "Failed to sync state with parent"
1037            )
1038        }
1039    }
1040
1041    /// Unlinks all source pads of the source element with all sink pads
1042    /// of the sink element to which they are linked.
1043    ///
1044    /// If the link has been made using [`ElementExtManual::link()`][crate::prelude::ElementExtManual::link()], it could have created an
1045    /// requestpad, which has to be released using [`release_request_pad()`][Self::release_request_pad()].
1046    /// ## `dest`
1047    /// the sink [`Element`][crate::Element] to unlink.
1048    #[doc(alias = "gst_element_unlink")]
1049    fn unlink(&self, dest: &impl IsA<Element>) {
1050        unsafe {
1051            ffi::gst_element_unlink(
1052                self.as_ref().to_glib_none().0,
1053                dest.as_ref().to_glib_none().0,
1054            );
1055        }
1056    }
1057
1058    /// Unlinks the two named pads of the source and destination elements.
1059    ///
1060    /// This is a convenience function for [`PadExt::unlink()`][crate::prelude::PadExt::unlink()].
1061    /// ## `srcpadname`
1062    /// the name of the [`Pad`][crate::Pad] in source element.
1063    /// ## `dest`
1064    /// a [`Element`][crate::Element] containing the destination pad.
1065    /// ## `destpadname`
1066    /// the name of the [`Pad`][crate::Pad] in destination element.
1067    #[doc(alias = "gst_element_unlink_pads")]
1068    fn unlink_pads(&self, srcpadname: &str, dest: &impl IsA<Element>, destpadname: &str) {
1069        unsafe {
1070            ffi::gst_element_unlink_pads(
1071                self.as_ref().to_glib_none().0,
1072                srcpadname.to_glib_none().0,
1073                dest.as_ref().to_glib_none().0,
1074                destpadname.to_glib_none().0,
1075            );
1076        }
1077    }
1078
1079    /// This signals that the element will not generate more dynamic pads.
1080    /// Note that this signal will usually be emitted from the context of
1081    /// the streaming thread.
1082    #[doc(alias = "no-more-pads")]
1083    fn connect_no_more_pads<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
1084        unsafe extern "C" fn no_more_pads_trampoline<
1085            P: IsA<Element>,
1086            F: Fn(&P) + Send + Sync + 'static,
1087        >(
1088            this: *mut ffi::GstElement,
1089            f: glib::ffi::gpointer,
1090        ) {
1091            let f: &F = &*(f as *const F);
1092            f(Element::from_glib_borrow(this).unsafe_cast_ref())
1093        }
1094        unsafe {
1095            let f: Box_<F> = Box_::new(f);
1096            connect_raw(
1097                self.as_ptr() as *mut _,
1098                b"no-more-pads\0".as_ptr() as *const _,
1099                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1100                    no_more_pads_trampoline::<Self, F> as *const (),
1101                )),
1102                Box_::into_raw(f),
1103            )
1104        }
1105    }
1106
1107    /// a new [`Pad`][crate::Pad] has been added to the element. Note that this signal will
1108    /// usually be emitted from the context of the streaming thread. Also keep in
1109    /// mind that if you add new elements to the pipeline in the signal handler
1110    /// you will need to set them to the desired target state with
1111    /// [`set_state()`][Self::set_state()] or [`sync_state_with_parent()`][Self::sync_state_with_parent()].
1112    /// ## `new_pad`
1113    /// the pad that has been added
1114    #[doc(alias = "pad-added")]
1115    fn connect_pad_added<F: Fn(&Self, &Pad) + Send + Sync + 'static>(
1116        &self,
1117        f: F,
1118    ) -> SignalHandlerId {
1119        unsafe extern "C" fn pad_added_trampoline<
1120            P: IsA<Element>,
1121            F: Fn(&P, &Pad) + Send + Sync + 'static,
1122        >(
1123            this: *mut ffi::GstElement,
1124            new_pad: *mut ffi::GstPad,
1125            f: glib::ffi::gpointer,
1126        ) {
1127            let f: &F = &*(f as *const F);
1128            f(
1129                Element::from_glib_borrow(this).unsafe_cast_ref(),
1130                &from_glib_borrow(new_pad),
1131            )
1132        }
1133        unsafe {
1134            let f: Box_<F> = Box_::new(f);
1135            connect_raw(
1136                self.as_ptr() as *mut _,
1137                b"pad-added\0".as_ptr() as *const _,
1138                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1139                    pad_added_trampoline::<Self, F> as *const (),
1140                )),
1141                Box_::into_raw(f),
1142            )
1143        }
1144    }
1145
1146    /// a [`Pad`][crate::Pad] has been removed from the element
1147    /// ## `old_pad`
1148    /// the pad that has been removed
1149    #[doc(alias = "pad-removed")]
1150    fn connect_pad_removed<F: Fn(&Self, &Pad) + Send + Sync + 'static>(
1151        &self,
1152        f: F,
1153    ) -> SignalHandlerId {
1154        unsafe extern "C" fn pad_removed_trampoline<
1155            P: IsA<Element>,
1156            F: Fn(&P, &Pad) + Send + Sync + 'static,
1157        >(
1158            this: *mut ffi::GstElement,
1159            old_pad: *mut ffi::GstPad,
1160            f: glib::ffi::gpointer,
1161        ) {
1162            let f: &F = &*(f as *const F);
1163            f(
1164                Element::from_glib_borrow(this).unsafe_cast_ref(),
1165                &from_glib_borrow(old_pad),
1166            )
1167        }
1168        unsafe {
1169            let f: Box_<F> = Box_::new(f);
1170            connect_raw(
1171                self.as_ptr() as *mut _,
1172                b"pad-removed\0".as_ptr() as *const _,
1173                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1174                    pad_removed_trampoline::<Self, F> as *const (),
1175                )),
1176                Box_::into_raw(f),
1177            )
1178        }
1179    }
1180}
1181
1182impl<O: IsA<Element>> ElementExt for O {}