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
161/// Trait containing all [`struct@Element`] methods.
162///
163/// # Implementors
164///
165/// [`Bin`][struct@crate::Bin], [`Element`][struct@crate::Element], [`TagSetter`][struct@crate::TagSetter], [`TocSetter`][struct@crate::TocSetter]
166pub trait ElementExt: IsA<Element> + 'static {
167    /// Abort the state change of the element. This function is used
168    /// by elements that do asynchronous state changes and find out
169    /// something is wrong.
170    ///
171    /// This function should be called with the STATE_LOCK held.
172    ///
173    /// MT safe.
174    #[doc(alias = "gst_element_abort_state")]
175    fn abort_state(&self) {
176        unsafe {
177            ffi::gst_element_abort_state(self.as_ref().to_glib_none().0);
178        }
179    }
180
181    /// Adds a pad (link point) to `self`. `pad`'s parent will be set to `self`;
182    /// see [`GstObjectExt::set_parent()`][crate::prelude::GstObjectExt::set_parent()] for refcounting information.
183    ///
184    /// Pads are automatically activated when added in the PAUSED or PLAYING
185    /// state.
186    ///
187    /// The pad and the element should be unlocked when calling this function.
188    ///
189    /// This function will emit the [`pad-added`][struct@crate::Element#pad-added] signal on the element.
190    /// ## `pad`
191    /// the [`Pad`][crate::Pad] to add to the element.
192    ///
193    /// # Returns
194    ///
195    /// [`true`] if the pad could be added. This function can fail when
196    /// a pad with the same name already existed or the pad already had another
197    /// parent.
198    ///
199    /// MT safe.
200    #[doc(alias = "gst_element_add_pad")]
201    fn add_pad(&self, pad: &impl IsA<Pad>) -> Result<(), glib::error::BoolError> {
202        unsafe {
203            glib::result_from_gboolean!(
204                ffi::gst_element_add_pad(
205                    self.as_ref().to_glib_none().0,
206                    pad.as_ref().to_glib_none().0
207                ),
208                "Failed to add pad"
209            )
210        }
211    }
212
213    /// Perform `transition` on `self`.
214    ///
215    /// This function must be called with STATE_LOCK held and is mainly used
216    /// internally.
217    /// ## `transition`
218    /// the requested transition
219    ///
220    /// # Returns
221    ///
222    /// the [`StateChangeReturn`][crate::StateChangeReturn] of the state transition.
223    #[doc(alias = "gst_element_change_state")]
224    fn change_state(
225        &self,
226        transition: StateChange,
227    ) -> Result<StateChangeSuccess, StateChangeError> {
228        unsafe {
229            try_from_glib(ffi::gst_element_change_state(
230                self.as_ref().to_glib_none().0,
231                transition.into_glib(),
232            ))
233        }
234    }
235
236    /// Commit the state change of the element and proceed to the next
237    /// pending state if any. This function is used
238    /// by elements that do asynchronous state changes.
239    /// The core will normally call this method automatically when an
240    /// element returned [`StateChangeReturn::Success`][crate::StateChangeReturn::Success] from the state change function.
241    ///
242    /// If after calling this method the element still has not reached
243    /// the pending state, the next state change is performed.
244    ///
245    /// This method is used internally and should normally not be called by plugins
246    /// or applications.
247    ///
248    /// This function must be called with STATE_LOCK held.
249    /// ## `ret`
250    /// The previous state return value
251    ///
252    /// # Returns
253    ///
254    /// The result of the commit state change.
255    ///
256    /// MT safe.
257    #[doc(alias = "gst_element_continue_state")]
258    fn continue_state(
259        &self,
260        ret: impl Into<StateChangeReturn>,
261    ) -> Result<StateChangeSuccess, StateChangeError> {
262        unsafe {
263            try_from_glib(ffi::gst_element_continue_state(
264                self.as_ref().to_glib_none().0,
265                ret.into().into_glib(),
266            ))
267        }
268    }
269
270    /// Creates a pad for each pad template that is always available.
271    /// This function is only useful during object initialization of
272    /// subclasses of [`Element`][crate::Element].
273    #[doc(alias = "gst_element_create_all_pads")]
274    fn create_all_pads(&self) {
275        unsafe {
276            ffi::gst_element_create_all_pads(self.as_ref().to_glib_none().0);
277        }
278    }
279
280    /// Creates a stream-id for `self` by combining the upstream information with
281    /// the `stream_id`.
282    ///
283    /// This function generates an unique stream-id by getting the upstream
284    /// stream-start event stream ID and appending `stream_id` to it. If the element
285    /// has no sinkpad it will generate an upstream stream-id by doing an URI query
286    /// on the element and in the worst case just uses a random number. Source
287    /// elements that don't implement the URI handler interface should ideally
288    /// generate a unique, deterministic stream-id manually instead.
289    ///
290    /// Since stream IDs are sorted alphabetically, any numbers in the stream ID
291    /// should be printed with a fixed number of characters, preceded by 0's, such as
292    /// by using the format \`03u` instead of \`u`.
293    /// ## `stream_id`
294    /// The stream-id
295    ///
296    /// # Returns
297    ///
298    /// A stream-id for `self`.
299    #[cfg(feature = "v1_24")]
300    #[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
301    #[doc(alias = "gst_element_decorate_stream_id")]
302    fn decorate_stream_id(&self, stream_id: &str) -> glib::GString {
303        unsafe {
304            from_glib_full(ffi::gst_element_decorate_stream_id(
305                self.as_ref().to_glib_none().0,
306                stream_id.to_glib_none().0,
307            ))
308        }
309    }
310
311    /// Returns the base time of the element. The base time is the
312    /// absolute time of the clock when this element was last put to
313    /// PLAYING. Subtracting the base time from the clock time gives
314    /// the running time of the element.
315    ///
316    /// # Returns
317    ///
318    /// the base time of the element.
319    ///
320    /// MT safe.
321    #[doc(alias = "gst_element_get_base_time")]
322    #[doc(alias = "get_base_time")]
323    fn base_time(&self) -> Option<ClockTime> {
324        unsafe {
325            from_glib(ffi::gst_element_get_base_time(
326                self.as_ref().to_glib_none().0,
327            ))
328        }
329    }
330
331    /// Returns the bus of the element. Note that only a [`Pipeline`][crate::Pipeline] will provide a
332    /// bus for the application.
333    ///
334    /// # Returns
335    ///
336    /// the element's [`Bus`][crate::Bus]. unref after
337    /// usage.
338    ///
339    /// MT safe.
340    #[doc(alias = "gst_element_get_bus")]
341    #[doc(alias = "get_bus")]
342    fn bus(&self) -> Option<Bus> {
343        unsafe { from_glib_full(ffi::gst_element_get_bus(self.as_ref().to_glib_none().0)) }
344    }
345
346    /// Gets the currently configured clock of the element. This is the clock as was
347    /// last set with [`set_clock()`][Self::set_clock()].
348    ///
349    /// Elements in a pipeline will only have their clock set when the
350    /// pipeline is in the PLAYING state.
351    ///
352    /// # Returns
353    ///
354    /// the [`Clock`][crate::Clock] of the element. unref after usage.
355    ///
356    /// MT safe.
357    #[doc(alias = "gst_element_get_clock")]
358    #[doc(alias = "get_clock")]
359    fn clock(&self) -> Option<Clock> {
360        unsafe { from_glib_full(ffi::gst_element_get_clock(self.as_ref().to_glib_none().0)) }
361    }
362
363    /// Looks for an unlinked pad to which the given pad can link. It is not
364    /// guaranteed that linking the pads will work, though it should work in most
365    /// cases.
366    ///
367    /// This function will first attempt to find a compatible unlinked ALWAYS pad,
368    /// and if none can be found, it will request a compatible REQUEST pad by looking
369    /// at the templates of `self`.
370    /// ## `pad`
371    /// the [`Pad`][crate::Pad] to find a compatible one for.
372    /// ## `caps`
373    /// the [`Caps`][crate::Caps] to use as a filter.
374    ///
375    /// # Returns
376    ///
377    /// the [`Pad`][crate::Pad] to which a link
378    ///  can be made, or [`None`] if one cannot be found. `gst_object_unref()`
379    ///  after usage.
380    #[doc(alias = "gst_element_get_compatible_pad")]
381    #[doc(alias = "get_compatible_pad")]
382    fn compatible_pad(&self, pad: &impl IsA<Pad>, caps: Option<&Caps>) -> Option<Pad> {
383        unsafe {
384            from_glib_full(ffi::gst_element_get_compatible_pad(
385                self.as_ref().to_glib_none().0,
386                pad.as_ref().to_glib_none().0,
387                caps.to_glib_none().0,
388            ))
389        }
390    }
391
392    /// Retrieves a pad template from `self` that is compatible with `compattempl`.
393    /// Pads from compatible templates can be linked together.
394    /// ## `compattempl`
395    /// the [`PadTemplate`][crate::PadTemplate] to find a compatible
396    ///  template for
397    ///
398    /// # Returns
399    ///
400    /// a compatible [`PadTemplate`][crate::PadTemplate],
401    ///  or [`None`] if none was found. No unreferencing is necessary.
402    #[doc(alias = "gst_element_get_compatible_pad_template")]
403    #[doc(alias = "get_compatible_pad_template")]
404    fn compatible_pad_template(&self, compattempl: &PadTemplate) -> Option<PadTemplate> {
405        unsafe {
406            from_glib_none(ffi::gst_element_get_compatible_pad_template(
407                self.as_ref().to_glib_none().0,
408                compattempl.to_glib_none().0,
409            ))
410        }
411    }
412
413    /// Gets the context with `context_type` set on the element or NULL.
414    ///
415    /// MT safe.
416    /// ## `context_type`
417    /// a name of a context to retrieve
418    ///
419    /// # Returns
420    ///
421    /// A [`Context`][crate::Context] or NULL
422    #[doc(alias = "gst_element_get_context")]
423    #[doc(alias = "get_context")]
424    fn context(&self, context_type: &str) -> Option<Context> {
425        unsafe {
426            from_glib_full(ffi::gst_element_get_context(
427                self.as_ref().to_glib_none().0,
428                context_type.to_glib_none().0,
429            ))
430        }
431    }
432
433    /// Gets the contexts set on the element.
434    ///
435    /// MT safe.
436    ///
437    /// # Returns
438    ///
439    /// List of [`Context`][crate::Context]
440    #[doc(alias = "gst_element_get_contexts")]
441    #[doc(alias = "get_contexts")]
442    fn contexts(&self) -> Vec<Context> {
443        unsafe {
444            FromGlibPtrContainer::from_glib_full(ffi::gst_element_get_contexts(
445                self.as_ref().to_glib_none().0,
446            ))
447        }
448    }
449
450    /// Retrieves the factory that was used to create this element.
451    ///
452    /// # Returns
453    ///
454    /// the [`ElementFactory`][crate::ElementFactory] used for creating this
455    ///  element or [`None`] if element has not been registered (static element). no refcounting is needed.
456    #[doc(alias = "gst_element_get_factory")]
457    #[doc(alias = "get_factory")]
458    fn factory(&self) -> Option<ElementFactory> {
459        unsafe { from_glib_none(ffi::gst_element_get_factory(self.as_ref().to_glib_none().0)) }
460    }
461
462    /// Returns the start time of the element. The start time is the
463    /// running time of the clock when this element was last put to PAUSED.
464    ///
465    /// Usually the start_time is managed by a toplevel element such as
466    /// [`Pipeline`][crate::Pipeline].
467    ///
468    /// MT safe.
469    ///
470    /// # Returns
471    ///
472    /// the start time of the element.
473    #[doc(alias = "gst_element_get_start_time")]
474    #[doc(alias = "get_start_time")]
475    fn start_time(&self) -> Option<ClockTime> {
476        unsafe {
477            from_glib(ffi::gst_element_get_start_time(
478                self.as_ref().to_glib_none().0,
479            ))
480        }
481    }
482
483    /// Gets the state of the element.
484    ///
485    /// For elements that performed an ASYNC state change, as reported by
486    /// [`set_state()`][Self::set_state()], this function will block up to the
487    /// specified timeout value for the state change to complete.
488    /// If the element completes the state change or goes into
489    /// an error, this function returns immediately with a return value of
490    /// [`StateChangeReturn::Success`][crate::StateChangeReturn::Success] or [`StateChangeReturn::Failure`][crate::StateChangeReturn::Failure] respectively.
491    ///
492    /// For elements that did not return [`StateChangeReturn::Async`][crate::StateChangeReturn::Async], this function
493    /// returns the current and pending state immediately.
494    ///
495    /// This function returns [`StateChangeReturn::NoPreroll`][crate::StateChangeReturn::NoPreroll] if the element
496    /// successfully changed its state but is not able to provide data yet.
497    /// This mostly happens for live sources that only produce data in
498    /// [`State::Playing`][crate::State::Playing]. While the state change return is equivalent to
499    /// [`StateChangeReturn::Success`][crate::StateChangeReturn::Success], it is returned to the application to signal that
500    /// some sink elements might not be able to complete their state change because
501    /// an element is not producing data to complete the preroll. When setting the
502    /// element to playing, the preroll will complete and playback will start.
503    /// ## `timeout`
504    /// a `GstClockTime` to specify the timeout for an async
505    ///  state change or `GST_CLOCK_TIME_NONE` for infinite timeout.
506    ///
507    /// # Returns
508    ///
509    /// [`StateChangeReturn::Success`][crate::StateChangeReturn::Success] if the element has no more pending state
510    ///  and the last state change succeeded, [`StateChangeReturn::Async`][crate::StateChangeReturn::Async] if the
511    ///  element is still performing a state change or
512    ///  [`StateChangeReturn::Failure`][crate::StateChangeReturn::Failure] if the last state change failed.
513    ///
514    /// MT safe.
515    ///
516    /// ## `state`
517    /// a pointer to [`State`][crate::State] to hold the state.
518    ///  Can be [`None`].
519    ///
520    /// ## `pending`
521    /// a pointer to [`State`][crate::State] to hold the pending
522    ///  state. Can be [`None`].
523    #[doc(alias = "gst_element_get_state")]
524    #[doc(alias = "get_state")]
525    fn state(
526        &self,
527        timeout: impl Into<Option<ClockTime>>,
528    ) -> (Result<StateChangeSuccess, StateChangeError>, State, State) {
529        unsafe {
530            let mut state = std::mem::MaybeUninit::uninit();
531            let mut pending = std::mem::MaybeUninit::uninit();
532            let ret = try_from_glib(ffi::gst_element_get_state(
533                self.as_ref().to_glib_none().0,
534                state.as_mut_ptr(),
535                pending.as_mut_ptr(),
536                timeout.into().into_glib(),
537            ));
538            (
539                ret,
540                from_glib(state.assume_init()),
541                from_glib(pending.assume_init()),
542            )
543        }
544    }
545
546    /// Retrieves a pad from `self` by name. This version only retrieves
547    /// already-existing (i.e. 'static') pads.
548    /// ## `name`
549    /// the name of the static [`Pad`][crate::Pad] to retrieve.
550    ///
551    /// # Returns
552    ///
553    /// the requested [`Pad`][crate::Pad] if
554    ///  found, otherwise [`None`]. unref after usage.
555    ///
556    /// MT safe.
557    #[doc(alias = "gst_element_get_static_pad")]
558    #[doc(alias = "get_static_pad")]
559    fn static_pad(&self, name: &str) -> Option<Pad> {
560        unsafe {
561            from_glib_full(ffi::gst_element_get_static_pad(
562                self.as_ref().to_glib_none().0,
563                name.to_glib_none().0,
564            ))
565        }
566    }
567
568    /// Checks if the state of an element is locked.
569    /// If the state of an element is locked, state changes of the parent don't
570    /// affect the element.
571    /// This way you can leave currently unused elements inside bins. Just lock their
572    /// state before changing the state from [`State::Null`][crate::State::Null].
573    ///
574    /// MT safe.
575    ///
576    /// # Returns
577    ///
578    /// [`true`], if the element's state is locked.
579    #[doc(alias = "gst_element_is_locked_state")]
580    fn is_locked_state(&self) -> bool {
581        unsafe {
582            from_glib(ffi::gst_element_is_locked_state(
583                self.as_ref().to_glib_none().0,
584            ))
585        }
586    }
587
588    /// Brings the element to the lost state. The current state of the
589    /// element is copied to the pending state so that any call to
590    /// [`state()`][Self::state()] will return [`StateChangeReturn::Async`][crate::StateChangeReturn::Async].
591    ///
592    /// An ASYNC_START message is posted. If the element was PLAYING, it will
593    /// go to PAUSED. The element will be restored to its PLAYING state by
594    /// the parent pipeline when it prerolls again.
595    ///
596    /// This is mostly used for elements that lost their preroll buffer
597    /// in the [`State::Paused`][crate::State::Paused] or [`State::Playing`][crate::State::Playing] state after a flush,
598    /// they will go to their pending state again when a new preroll buffer is
599    /// queued. This function can only be called when the element is currently
600    /// not in error or an async state change.
601    ///
602    /// This function is used internally and should normally not be called from
603    /// plugins or applications.
604    #[doc(alias = "gst_element_lost_state")]
605    fn lost_state(&self) {
606        unsafe {
607            ffi::gst_element_lost_state(self.as_ref().to_glib_none().0);
608        }
609    }
610
611    /// Use this function to signal that the element does not expect any more pads
612    /// to show up in the current pipeline. This function should be called whenever
613    /// pads have been added by the element itself. Elements with [`PadPresence::Sometimes`][crate::PadPresence::Sometimes]
614    /// pad templates use this in combination with autopluggers to figure out that
615    /// the element is done initializing its pads.
616    ///
617    /// This function emits the [`no-more-pads`][struct@crate::Element#no-more-pads] signal.
618    ///
619    /// MT safe.
620    #[doc(alias = "gst_element_no_more_pads")]
621    fn no_more_pads(&self) {
622        unsafe {
623            ffi::gst_element_no_more_pads(self.as_ref().to_glib_none().0);
624        }
625    }
626
627    /// Post a message on the element's [`Bus`][crate::Bus]. This function takes ownership of the
628    /// message; if you want to access the message after this call, you should add an
629    /// additional reference before calling.
630    /// ## `message`
631    /// a [`Message`][crate::Message] to post
632    ///
633    /// # Returns
634    ///
635    /// [`true`] if the message was successfully posted. The function returns
636    /// [`false`] if the element did not have a bus.
637    ///
638    /// MT safe.
639    #[doc(alias = "gst_element_post_message")]
640    fn post_message(&self, message: Message) -> Result<(), glib::error::BoolError> {
641        unsafe {
642            glib::result_from_gboolean!(
643                ffi::gst_element_post_message(
644                    self.as_ref().to_glib_none().0,
645                    message.into_glib_ptr()
646                ),
647                "Failed to post message"
648            )
649        }
650    }
651
652    /// Get the clock provided by the given element.
653    /// > An element is only required to provide a clock in the PAUSED
654    /// > state. Some elements can provide a clock in other states.
655    ///
656    /// # Returns
657    ///
658    /// the GstClock provided by the
659    /// element or [`None`] if no clock could be provided. Unref after usage.
660    ///
661    /// MT safe.
662    #[doc(alias = "gst_element_provide_clock")]
663    fn provide_clock(&self) -> Option<Clock> {
664        unsafe {
665            from_glib_full(ffi::gst_element_provide_clock(
666                self.as_ref().to_glib_none().0,
667            ))
668        }
669    }
670
671    /// Makes the element free the previously requested pad as obtained
672    /// with [`request_pad()`][Self::request_pad()].
673    ///
674    /// This does not unref the pad. If the pad was created by using
675    /// [`request_pad()`][Self::request_pad()], [`release_request_pad()`][Self::release_request_pad()] needs to be
676    /// followed by `gst_object_unref()` to free the `pad`.
677    ///
678    /// MT safe.
679    /// ## `pad`
680    /// the [`Pad`][crate::Pad] to release.
681    #[doc(alias = "gst_element_release_request_pad")]
682    fn release_request_pad(&self, pad: &impl IsA<Pad>) {
683        unsafe {
684            ffi::gst_element_release_request_pad(
685                self.as_ref().to_glib_none().0,
686                pad.as_ref().to_glib_none().0,
687            );
688        }
689    }
690
691    /// Removes `pad` from `self`. `pad` will be destroyed if it has not been
692    /// referenced elsewhere using [`GstObjectExt::unparent()`][crate::prelude::GstObjectExt::unparent()].
693    ///
694    /// This function is used by plugin developers and should not be used
695    /// by applications. Pads that were dynamically requested from elements
696    /// with [`request_pad()`][Self::request_pad()] should be released with the
697    /// [`release_request_pad()`][Self::release_request_pad()] function instead.
698    ///
699    /// Pads are not automatically deactivated so elements should perform the needed
700    /// steps to deactivate the pad in case this pad is removed in the PAUSED or
701    /// PLAYING state. See [`PadExt::set_active()`][crate::prelude::PadExt::set_active()] for more information about
702    /// deactivating pads.
703    ///
704    /// The pad and the element should be unlocked when calling this function.
705    ///
706    /// This function will emit the [`pad-removed`][struct@crate::Element#pad-removed] signal on the element.
707    /// ## `pad`
708    /// the [`Pad`][crate::Pad] to remove from the element.
709    ///
710    /// # Returns
711    ///
712    /// [`true`] if the pad could be removed. Can return [`false`] if the
713    /// pad does not belong to the provided element.
714    ///
715    /// MT safe.
716    #[doc(alias = "gst_element_remove_pad")]
717    fn remove_pad(&self, pad: &impl IsA<Pad>) -> Result<(), glib::error::BoolError> {
718        unsafe {
719            glib::result_from_gboolean!(
720                ffi::gst_element_remove_pad(
721                    self.as_ref().to_glib_none().0,
722                    pad.as_ref().to_glib_none().0
723                ),
724                "Failed to remove pad"
725            )
726        }
727    }
728
729    /// Retrieves a request pad from the element according to the provided template.
730    /// Pad templates can be looked up using
731    /// [`ElementFactory::static_pad_templates()`][crate::ElementFactory::static_pad_templates()].
732    ///
733    /// The pad should be released with [`release_request_pad()`][Self::release_request_pad()].
734    /// ## `templ`
735    /// a [`PadTemplate`][crate::PadTemplate] of which we want a pad of.
736    /// ## `name`
737    /// the name of the request [`Pad`][crate::Pad]
738    /// to retrieve. Can be [`None`].
739    /// ## `caps`
740    /// the caps of the pad we want to
741    /// request. Can be [`None`].
742    ///
743    /// # Returns
744    ///
745    /// requested [`Pad`][crate::Pad] if found,
746    ///  otherwise [`None`]. Release after usage.
747    #[doc(alias = "gst_element_request_pad")]
748    fn request_pad(
749        &self,
750        templ: &PadTemplate,
751        name: Option<&str>,
752        caps: Option<&Caps>,
753    ) -> Option<Pad> {
754        unsafe {
755            from_glib_full(ffi::gst_element_request_pad(
756                self.as_ref().to_glib_none().0,
757                templ.to_glib_none().0,
758                name.to_glib_none().0,
759                caps.to_glib_none().0,
760            ))
761        }
762    }
763
764    /// Set the base time of an element. See [`base_time()`][Self::base_time()].
765    ///
766    /// MT safe.
767    /// ## `time`
768    /// the base time to set.
769    #[doc(alias = "gst_element_set_base_time")]
770    fn set_base_time(&self, time: ClockTime) {
771        unsafe {
772            ffi::gst_element_set_base_time(self.as_ref().to_glib_none().0, time.into_glib());
773        }
774    }
775
776    /// Sets the bus of the element. Increases the refcount on the bus.
777    /// For internal use only, unless you're testing elements.
778    ///
779    /// MT safe.
780    /// ## `bus`
781    /// the [`Bus`][crate::Bus] to set.
782    #[doc(alias = "gst_element_set_bus")]
783    fn set_bus(&self, bus: Option<&Bus>) {
784        unsafe {
785            ffi::gst_element_set_bus(self.as_ref().to_glib_none().0, bus.to_glib_none().0);
786        }
787    }
788
789    /// Sets the clock for the element. This function increases the
790    /// refcount on the clock. Any previously set clock on the object
791    /// is unreffed.
792    /// ## `clock`
793    /// the [`Clock`][crate::Clock] to set for the element.
794    ///
795    /// # Returns
796    ///
797    /// [`true`] if the element accepted the clock. An element can refuse a
798    /// clock when it, for example, is not able to slave its internal clock to the
799    /// `clock` or when it requires a specific clock to operate.
800    ///
801    /// MT safe.
802    #[doc(alias = "gst_element_set_clock")]
803    fn set_clock(&self, clock: Option<&impl IsA<Clock>>) -> Result<(), glib::error::BoolError> {
804        unsafe {
805            glib::result_from_gboolean!(
806                ffi::gst_element_set_clock(
807                    self.as_ref().to_glib_none().0,
808                    clock.map(|p| p.as_ref()).to_glib_none().0
809                ),
810                "Failed to set clock"
811            )
812        }
813    }
814
815    /// Sets the context of the element. Increases the refcount of the context.
816    ///
817    /// MT safe.
818    /// ## `context`
819    /// the [`Context`][crate::Context] to set.
820    #[doc(alias = "gst_element_set_context")]
821    fn set_context(&self, context: &Context) {
822        unsafe {
823            ffi::gst_element_set_context(self.as_ref().to_glib_none().0, context.to_glib_none().0);
824        }
825    }
826
827    /// Locks the state of an element, so state changes of the parent don't affect
828    /// this element anymore.
829    ///
830    /// Note that this is racy if the state lock of the parent bin is not taken.
831    /// The parent bin might've just checked the flag in another thread and as the
832    /// next step proceed to change the child element's state.
833    ///
834    /// MT safe.
835    /// ## `locked_state`
836    /// [`true`] to lock the element's state
837    ///
838    /// # Returns
839    ///
840    /// [`true`] if the state was changed, [`false`] if bad parameters were given
841    /// or the elements state-locking needed no change.
842    #[doc(alias = "gst_element_set_locked_state")]
843    fn set_locked_state(&self, locked_state: bool) -> bool {
844        unsafe {
845            from_glib(ffi::gst_element_set_locked_state(
846                self.as_ref().to_glib_none().0,
847                locked_state.into_glib(),
848            ))
849        }
850    }
851
852    /// Set the start time of an element. The start time of the element is the
853    /// running time of the element when it last went to the PAUSED state. In READY
854    /// or after a flushing seek, it is set to 0.
855    ///
856    /// Toplevel elements like [`Pipeline`][crate::Pipeline] will manage the start_time and
857    /// base_time on its children. Setting the start_time to `GST_CLOCK_TIME_NONE`
858    /// on such a toplevel element will disable the distribution of the base_time to
859    /// the children and can be useful if the application manages the base_time
860    /// itself, for example if you want to synchronize capture from multiple
861    /// pipelines, and you can also ensure that the pipelines have the same clock.
862    ///
863    /// MT safe.
864    /// ## `time`
865    /// the base time to set.
866    #[doc(alias = "gst_element_set_start_time")]
867    fn set_start_time(&self, time: impl Into<Option<ClockTime>>) {
868        unsafe {
869            ffi::gst_element_set_start_time(
870                self.as_ref().to_glib_none().0,
871                time.into().into_glib(),
872            );
873        }
874    }
875
876    /// Sets the state of the element. This function will try to set the
877    /// requested state by going through all the intermediary states and calling
878    /// the class's state change function for each.
879    ///
880    /// This function can return [`StateChangeReturn::Async`][crate::StateChangeReturn::Async], in which case the
881    /// element will perform the remainder of the state change asynchronously in
882    /// another thread.
883    /// An application can use [`state()`][Self::state()] to wait for the completion
884    /// of the state change or it can wait for a `GST_MESSAGE_ASYNC_DONE` or
885    /// `GST_MESSAGE_STATE_CHANGED` on the bus.
886    ///
887    /// State changes to [`State::Ready`][crate::State::Ready] or [`State::Null`][crate::State::Null] never return
888    /// [`StateChangeReturn::Async`][crate::StateChangeReturn::Async].
889    /// ## `state`
890    /// the element's new [`State`][crate::State].
891    ///
892    /// # Returns
893    ///
894    /// Result of the state change using [`StateChangeReturn`][crate::StateChangeReturn].
895    ///
896    /// MT safe.
897    #[doc(alias = "gst_element_set_state")]
898    fn set_state(&self, state: State) -> Result<StateChangeSuccess, StateChangeError> {
899        unsafe {
900            try_from_glib(ffi::gst_element_set_state(
901                self.as_ref().to_glib_none().0,
902                state.into_glib(),
903            ))
904        }
905    }
906
907    /// Tries to change the state of the element to the same as its parent.
908    /// If this function returns [`false`], the state of element is undefined.
909    ///
910    /// # Returns
911    ///
912    /// [`true`], if the element's state could be synced to the parent's state.
913    ///
914    /// MT safe.
915    #[doc(alias = "gst_element_sync_state_with_parent")]
916    fn sync_state_with_parent(&self) -> Result<(), glib::error::BoolError> {
917        unsafe {
918            glib::result_from_gboolean!(
919                ffi::gst_element_sync_state_with_parent(self.as_ref().to_glib_none().0),
920                "Failed to sync state with parent"
921            )
922        }
923    }
924
925    /// Unlinks all source pads of the source element with all sink pads
926    /// of the sink element to which they are linked.
927    ///
928    /// If the link has been made using [`ElementExtManual::link()`][crate::prelude::ElementExtManual::link()], it could have created an
929    /// requestpad, which has to be released using [`release_request_pad()`][Self::release_request_pad()].
930    /// ## `dest`
931    /// the sink [`Element`][crate::Element] to unlink.
932    #[doc(alias = "gst_element_unlink")]
933    fn unlink(&self, dest: &impl IsA<Element>) {
934        unsafe {
935            ffi::gst_element_unlink(
936                self.as_ref().to_glib_none().0,
937                dest.as_ref().to_glib_none().0,
938            );
939        }
940    }
941
942    /// Unlinks the two named pads of the source and destination elements.
943    ///
944    /// This is a convenience function for [`PadExt::unlink()`][crate::prelude::PadExt::unlink()].
945    /// ## `srcpadname`
946    /// the name of the [`Pad`][crate::Pad] in source element.
947    /// ## `dest`
948    /// a [`Element`][crate::Element] containing the destination pad.
949    /// ## `destpadname`
950    /// the name of the [`Pad`][crate::Pad] in destination element.
951    #[doc(alias = "gst_element_unlink_pads")]
952    fn unlink_pads(&self, srcpadname: &str, dest: &impl IsA<Element>, destpadname: &str) {
953        unsafe {
954            ffi::gst_element_unlink_pads(
955                self.as_ref().to_glib_none().0,
956                srcpadname.to_glib_none().0,
957                dest.as_ref().to_glib_none().0,
958                destpadname.to_glib_none().0,
959            );
960        }
961    }
962
963    /// This signals that the element will not generate more dynamic pads.
964    /// Note that this signal will usually be emitted from the context of
965    /// the streaming thread.
966    #[doc(alias = "no-more-pads")]
967    fn connect_no_more_pads<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
968        unsafe extern "C" fn no_more_pads_trampoline<
969            P: IsA<Element>,
970            F: Fn(&P) + Send + Sync + 'static,
971        >(
972            this: *mut ffi::GstElement,
973            f: glib::ffi::gpointer,
974        ) {
975            let f: &F = &*(f as *const F);
976            f(Element::from_glib_borrow(this).unsafe_cast_ref())
977        }
978        unsafe {
979            let f: Box_<F> = Box_::new(f);
980            connect_raw(
981                self.as_ptr() as *mut _,
982                c"no-more-pads".as_ptr() as *const _,
983                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
984                    no_more_pads_trampoline::<Self, F> as *const (),
985                )),
986                Box_::into_raw(f),
987            )
988        }
989    }
990
991    /// a new [`Pad`][crate::Pad] has been added to the element. Note that this signal will
992    /// usually be emitted from the context of the streaming thread. Also keep in
993    /// mind that if you add new elements to the pipeline in the signal handler
994    /// you will need to set them to the desired target state with
995    /// [`set_state()`][Self::set_state()] or [`sync_state_with_parent()`][Self::sync_state_with_parent()].
996    /// ## `new_pad`
997    /// the pad that has been added
998    #[doc(alias = "pad-added")]
999    fn connect_pad_added<F: Fn(&Self, &Pad) + Send + Sync + 'static>(
1000        &self,
1001        f: F,
1002    ) -> SignalHandlerId {
1003        unsafe extern "C" fn pad_added_trampoline<
1004            P: IsA<Element>,
1005            F: Fn(&P, &Pad) + Send + Sync + 'static,
1006        >(
1007            this: *mut ffi::GstElement,
1008            new_pad: *mut ffi::GstPad,
1009            f: glib::ffi::gpointer,
1010        ) {
1011            let f: &F = &*(f as *const F);
1012            f(
1013                Element::from_glib_borrow(this).unsafe_cast_ref(),
1014                &from_glib_borrow(new_pad),
1015            )
1016        }
1017        unsafe {
1018            let f: Box_<F> = Box_::new(f);
1019            connect_raw(
1020                self.as_ptr() as *mut _,
1021                c"pad-added".as_ptr() as *const _,
1022                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1023                    pad_added_trampoline::<Self, F> as *const (),
1024                )),
1025                Box_::into_raw(f),
1026            )
1027        }
1028    }
1029
1030    /// a [`Pad`][crate::Pad] has been removed from the element
1031    /// ## `old_pad`
1032    /// the pad that has been removed
1033    #[doc(alias = "pad-removed")]
1034    fn connect_pad_removed<F: Fn(&Self, &Pad) + Send + Sync + 'static>(
1035        &self,
1036        f: F,
1037    ) -> SignalHandlerId {
1038        unsafe extern "C" fn pad_removed_trampoline<
1039            P: IsA<Element>,
1040            F: Fn(&P, &Pad) + Send + Sync + 'static,
1041        >(
1042            this: *mut ffi::GstElement,
1043            old_pad: *mut ffi::GstPad,
1044            f: glib::ffi::gpointer,
1045        ) {
1046            let f: &F = &*(f as *const F);
1047            f(
1048                Element::from_glib_borrow(this).unsafe_cast_ref(),
1049                &from_glib_borrow(old_pad),
1050            )
1051        }
1052        unsafe {
1053            let f: Box_<F> = Box_::new(f);
1054            connect_raw(
1055                self.as_ptr() as *mut _,
1056                c"pad-removed".as_ptr() as *const _,
1057                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1058                    pad_removed_trampoline::<Self, F> as *const (),
1059                )),
1060                Box_::into_raw(f),
1061            )
1062        }
1063    }
1064}
1065
1066impl<O: IsA<Element>> ElementExt for O {}