gstreamer/auto/
pipeline.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
4// DO NOT EDIT
5
6use crate::{ffi, Bin, ChildProxy, Clock, ClockTime, Element, Object};
7use glib::{
8    prelude::*,
9    signal::{connect_raw, SignalHandlerId},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    /// A [`Pipeline`][crate::Pipeline] is a special [`Bin`][crate::Bin] used as the toplevel container for
16    /// the filter graph. The [`Pipeline`][crate::Pipeline] will manage the selection and
17    /// distribution of a global [`Clock`][crate::Clock] as well as provide a [`Bus`][crate::Bus] to the
18    /// application.
19    ///
20    /// [`new()`][Self::new()] is used to create a pipeline. when you are done with
21    /// the pipeline, use `gst_object_unref()` to free its resources including all
22    /// added [`Element`][crate::Element] objects (if not otherwise referenced).
23    ///
24    /// Elements are added and removed from the pipeline using the [`Bin`][crate::Bin]
25    /// methods like [`GstBinExt::add()`][crate::prelude::GstBinExt::add()] and [`GstBinExt::remove()`][crate::prelude::GstBinExt::remove()] (see [`Bin`][crate::Bin]).
26    ///
27    /// Before changing the state of the [`Pipeline`][crate::Pipeline] (see [`Element`][crate::Element]) a [`Bus`][crate::Bus]
28    /// should be retrieved with `gst_pipeline_get_bus()`. This [`Bus`][crate::Bus] should then
29    /// be used to receive [`Message`][crate::Message] from the elements in the pipeline. Listening
30    /// to the [`Bus`][crate::Bus] is necessary for retrieving error messages from the
31    /// [`Pipeline`][crate::Pipeline] and otherwise the [`Pipeline`][crate::Pipeline] might stop without any
32    /// indication, why. Furthermore, the [`Pipeline`][crate::Pipeline] posts messages even if
33    /// nobody listens on the [`Bus`][crate::Bus], which will pile up and use up memory.
34    ///
35    /// By default, a [`Pipeline`][crate::Pipeline] will automatically flush the pending [`Bus`][crate::Bus]
36    /// messages when going to the NULL state to ensure that no circular
37    /// references exist when no messages are read from the [`Bus`][crate::Bus]. This
38    /// behaviour can be changed with [`PipelineExt::set_auto_flush_bus()`][crate::prelude::PipelineExt::set_auto_flush_bus()].
39    ///
40    /// When the [`Pipeline`][crate::Pipeline] performs the PAUSED to PLAYING state change it will
41    /// select a clock for the elements. The clock selection algorithm will by
42    /// default select a clock provided by an element that is most upstream
43    /// (closest to the source). For live pipelines (ones that return
44    /// [`StateChangeReturn::NoPreroll`][crate::StateChangeReturn::NoPreroll] from the [`ElementExt::set_state()`][crate::prelude::ElementExt::set_state()] call) this
45    /// will select the clock provided by the live source. For normal pipelines
46    /// this will select a clock provided by the sinks (most likely the audio
47    /// sink). If no element provides a clock, a default [`SystemClock`][crate::SystemClock] is used.
48    ///
49    /// The clock selection can be controlled with the [`PipelineExt::use_clock()`][crate::prelude::PipelineExt::use_clock()]
50    /// method, which will enforce a given clock on the pipeline. With
51    /// [`PipelineExt::auto_clock()`][crate::prelude::PipelineExt::auto_clock()] the default clock selection algorithm can be
52    /// restored.
53    ///
54    /// A [`Pipeline`][crate::Pipeline] maintains a running time for the elements. The running
55    /// time is defined as the difference between the current clock time and
56    /// the base time. When the pipeline goes to READY or a flushing seek is
57    /// performed on it, the running time is reset to 0. When the pipeline is
58    /// set from PLAYING to PAUSED, the current clock time is sampled and used to
59    /// configure the base time for the elements when the pipeline is set
60    /// to PLAYING again. The effect is that the running time (as the difference
61    /// between the clock time and the base time) will count how much time was spent
62    /// in the PLAYING state. This default behaviour can be changed with the
63    /// [`ElementExt::set_start_time()`][crate::prelude::ElementExt::set_start_time()] method.
64    ///
65    /// ## Properties
66    ///
67    ///
68    /// #### `auto-flush-bus`
69    ///  Whether or not to automatically flush all messages on the
70    /// pipeline's bus when going from READY to NULL state. Please see
71    /// [`PipelineExt::set_auto_flush_bus()`][crate::prelude::PipelineExt::set_auto_flush_bus()] for more information on this option.
72    ///
73    /// Readable | Writeable
74    ///
75    ///
76    /// #### `delay`
77    ///  The expected delay needed for elements to spin up to the
78    /// PLAYING state expressed in nanoseconds.
79    /// see [`PipelineExt::set_delay()`][crate::prelude::PipelineExt::set_delay()] for more information on this option.
80    ///
81    /// Readable | Writeable
82    ///
83    ///
84    /// #### `latency`
85    ///  Latency to configure on the pipeline. See [`PipelineExt::set_latency()`][crate::prelude::PipelineExt::set_latency()].
86    ///
87    /// Readable | Writeable
88    /// <details><summary><h4>Bin</h4></summary>
89    ///
90    ///
91    /// #### `async-handling`
92    ///  If set to [`true`], the bin will handle asynchronous state changes.
93    /// This should be used only if the bin subclass is modifying the state
94    /// of its children on its own.
95    ///
96    /// Readable | Writeable
97    ///
98    ///
99    /// #### `message-forward`
100    ///  Forward all children messages, even those that would normally be filtered by
101    /// the bin. This can be interesting when one wants to be notified of the EOS
102    /// state of individual elements, for example.
103    ///
104    /// The messages are converted to an ELEMENT message with the bin as the
105    /// source. The structure of the message is named `GstBinForwarded` and contains
106    /// a field named `message` that contains the original forwarded [`Message`][crate::Message].
107    ///
108    /// Readable | Writeable
109    /// </details>
110    /// <details><summary><h4>Object</h4></summary>
111    ///
112    ///
113    /// #### `name`
114    ///  Readable | Writeable | Construct
115    ///
116    ///
117    /// #### `parent`
118    ///  The parent of the object. Please note, that when changing the 'parent'
119    /// property, we don't emit [`notify`][struct@crate::glib::Object#notify] and [`deep-notify`][struct@crate::Object#deep-notify]
120    /// signals due to locking issues. In some cases one can use
121    /// [`element-added`][struct@crate::Bin#element-added] or [`element-removed`][struct@crate::Bin#element-removed] signals on the parent to
122    /// achieve a similar effect.
123    ///
124    /// Readable | Writeable
125    /// </details>
126    ///
127    /// # Implements
128    ///
129    /// [`PipelineExt`][trait@crate::prelude::PipelineExt], [`GstBinExt`][trait@crate::prelude::GstBinExt], [`ElementExt`][trait@crate::prelude::ElementExt], [`GstObjectExt`][trait@crate::prelude::GstObjectExt], [`trait@glib::ObjectExt`], [`ChildProxyExt`][trait@crate::prelude::ChildProxyExt], [`ElementExtManual`][trait@crate::prelude::ElementExtManual], [`ChildProxyExtManual`][trait@crate::prelude::ChildProxyExtManual]
130    #[doc(alias = "GstPipeline")]
131    pub struct Pipeline(Object<ffi::GstPipeline, ffi::GstPipelineClass>) @extends Bin, Element, Object, @implements ChildProxy;
132
133    match fn {
134        type_ => || ffi::gst_pipeline_get_type(),
135    }
136}
137
138impl Pipeline {
139    pub const NONE: Option<&'static Pipeline> = None;
140}
141
142unsafe impl Send for Pipeline {}
143unsafe impl Sync for Pipeline {}
144
145/// Trait containing all [`struct@Pipeline`] methods.
146///
147/// # Implementors
148///
149/// [`Pipeline`][struct@crate::Pipeline]
150pub trait PipelineExt: IsA<Pipeline> + 'static {
151    /// Let `self` select a clock automatically. This is the default
152    /// behaviour.
153    ///
154    /// Use this function if you previous forced a fixed clock with
155    /// [`use_clock()`][Self::use_clock()] and want to restore the default
156    /// pipeline clock selection algorithm.
157    ///
158    /// MT safe.
159    #[doc(alias = "gst_pipeline_auto_clock")]
160    fn auto_clock(&self) {
161        unsafe {
162            ffi::gst_pipeline_auto_clock(self.as_ref().to_glib_none().0);
163        }
164    }
165
166    /// Check if `self` will automatically flush messages when going to
167    /// the NULL state.
168    ///
169    /// # Returns
170    ///
171    /// whether the pipeline will automatically flush its bus when
172    /// going from READY to NULL state or not.
173    ///
174    /// MT safe.
175    #[doc(alias = "gst_pipeline_get_auto_flush_bus")]
176    #[doc(alias = "get_auto_flush_bus")]
177    #[doc(alias = "auto-flush-bus")]
178    fn is_auto_flush_bus(&self) -> bool {
179        unsafe {
180            from_glib(ffi::gst_pipeline_get_auto_flush_bus(
181                self.as_ref().to_glib_none().0,
182            ))
183        }
184    }
185
186    /// Return the configured latency on `self`.
187    ///
188    /// # Returns
189    ///
190    /// `self` configured latency, or `GST_CLOCK_TIME_NONE` if none has been configured
191    /// because `self` did not reach the PLAYING state yet.
192    ///
193    /// MT safe.
194    #[cfg(feature = "v1_24")]
195    #[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
196    #[doc(alias = "gst_pipeline_get_configured_latency")]
197    #[doc(alias = "get_configured_latency")]
198    fn configured_latency(&self) -> Option<ClockTime> {
199        unsafe {
200            from_glib(ffi::gst_pipeline_get_configured_latency(
201                self.as_ref().to_glib_none().0,
202            ))
203        }
204    }
205
206    /// Get the configured delay (see [`set_delay()`][Self::set_delay()]).
207    ///
208    /// # Returns
209    ///
210    /// The configured delay.
211    ///
212    /// MT safe.
213    #[doc(alias = "gst_pipeline_get_delay")]
214    #[doc(alias = "get_delay")]
215    fn delay(&self) -> ClockTime {
216        unsafe {
217            try_from_glib(ffi::gst_pipeline_get_delay(self.as_ref().to_glib_none().0))
218                .expect("mandatory glib value is None")
219        }
220    }
221
222    /// Gets the latency that should be configured on the pipeline. See
223    /// [`set_latency()`][Self::set_latency()].
224    ///
225    /// # Returns
226    ///
227    /// Latency to configure on the pipeline or GST_CLOCK_TIME_NONE
228    #[doc(alias = "gst_pipeline_get_latency")]
229    #[doc(alias = "get_latency")]
230    fn latency(&self) -> Option<ClockTime> {
231        unsafe {
232            from_glib(ffi::gst_pipeline_get_latency(
233                self.as_ref().to_glib_none().0,
234            ))
235        }
236    }
237
238    /// Gets the current clock used by `self`.
239    ///
240    /// Unlike [`ElementExt::clock()`][crate::prelude::ElementExt::clock()], this function will always return a
241    /// clock, even if the pipeline is not in the PLAYING state.
242    ///
243    /// # Returns
244    ///
245    /// a [`Clock`][crate::Clock], unref after usage.
246    #[doc(alias = "gst_pipeline_get_pipeline_clock")]
247    #[doc(alias = "get_pipeline_clock")]
248    fn pipeline_clock(&self) -> Clock {
249        unsafe {
250            from_glib_full(ffi::gst_pipeline_get_pipeline_clock(
251                self.as_ref().to_glib_none().0,
252            ))
253        }
254    }
255
256    /// Check if `self` is live.
257    ///
258    /// # Returns
259    ///
260    /// [`true`] if `self` is live, [`false`] if not or if it did not reach the PAUSED state yet.
261    ///
262    /// MT safe.
263    #[cfg(feature = "v1_24")]
264    #[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
265    #[doc(alias = "gst_pipeline_is_live")]
266    fn is_live(&self) -> bool {
267        unsafe { from_glib(ffi::gst_pipeline_is_live(self.as_ref().to_glib_none().0)) }
268    }
269
270    /// Usually, when a pipeline goes from READY to NULL state, it automatically
271    /// flushes all pending messages on the bus, which is done for refcounting
272    /// purposes, to break circular references.
273    ///
274    /// This means that applications that update state using (async) bus messages
275    /// (e.g. do certain things when a pipeline goes from PAUSED to READY) might
276    /// not get to see messages when the pipeline is shut down, because they might
277    /// be flushed before they can be dispatched in the main thread. This behaviour
278    /// can be disabled using this function.
279    ///
280    /// It is important that all messages on the bus are handled when the
281    /// automatic flushing is disabled else memory leaks will be introduced.
282    ///
283    /// MT safe.
284    /// ## `auto_flush`
285    /// whether or not to automatically flush the bus when
286    /// the pipeline goes from READY to NULL state
287    #[doc(alias = "gst_pipeline_set_auto_flush_bus")]
288    #[doc(alias = "auto-flush-bus")]
289    fn set_auto_flush_bus(&self, auto_flush: bool) {
290        unsafe {
291            ffi::gst_pipeline_set_auto_flush_bus(
292                self.as_ref().to_glib_none().0,
293                auto_flush.into_glib(),
294            );
295        }
296    }
297
298    /// Set the expected delay needed for all elements to perform the
299    /// PAUSED to PLAYING state change. `delay` will be added to the
300    /// base time of the elements so that they wait an additional `delay`
301    /// amount of time before starting to process buffers and cannot be
302    /// `GST_CLOCK_TIME_NONE`.
303    ///
304    /// This option is used for tuning purposes and should normally not be
305    /// used.
306    ///
307    /// MT safe.
308    /// ## `delay`
309    /// the delay
310    #[doc(alias = "gst_pipeline_set_delay")]
311    #[doc(alias = "delay")]
312    fn set_delay(&self, delay: ClockTime) {
313        unsafe {
314            ffi::gst_pipeline_set_delay(self.as_ref().to_glib_none().0, delay.into_glib());
315        }
316    }
317
318    /// Sets the latency that should be configured on the pipeline. Setting
319    /// GST_CLOCK_TIME_NONE will restore the default behaviour of using the minimum
320    /// latency from the LATENCY query. Setting this is usually not required and
321    /// the pipeline will figure out an appropriate latency automatically.
322    ///
323    /// Setting a too low latency, especially lower than the minimum latency from
324    /// the LATENCY query, will most likely cause the pipeline to fail.
325    /// ## `latency`
326    /// latency to configure
327    #[doc(alias = "gst_pipeline_set_latency")]
328    #[doc(alias = "latency")]
329    fn set_latency(&self, latency: impl Into<Option<ClockTime>>) {
330        unsafe {
331            ffi::gst_pipeline_set_latency(
332                self.as_ref().to_glib_none().0,
333                latency.into().into_glib(),
334            );
335        }
336    }
337
338    /// Force `self` to use the given `clock`. The pipeline will
339    /// always use the given clock even if new clock providers are added
340    /// to this pipeline.
341    ///
342    /// If `clock` is [`None`] all clocking will be disabled which will make
343    /// the pipeline run as fast as possible.
344    ///
345    /// MT safe.
346    /// ## `clock`
347    /// the clock to use
348    #[doc(alias = "gst_pipeline_use_clock")]
349    fn use_clock(&self, clock: Option<&impl IsA<Clock>>) {
350        unsafe {
351            ffi::gst_pipeline_use_clock(
352                self.as_ref().to_glib_none().0,
353                clock.map(|p| p.as_ref()).to_glib_none().0,
354            );
355        }
356    }
357
358    #[doc(alias = "auto-flush-bus")]
359    fn connect_auto_flush_bus_notify<F: Fn(&Self) + Send + Sync + 'static>(
360        &self,
361        f: F,
362    ) -> SignalHandlerId {
363        unsafe extern "C" fn notify_auto_flush_bus_trampoline<
364            P: IsA<Pipeline>,
365            F: Fn(&P) + Send + Sync + 'static,
366        >(
367            this: *mut ffi::GstPipeline,
368            _param_spec: glib::ffi::gpointer,
369            f: glib::ffi::gpointer,
370        ) {
371            let f: &F = &*(f as *const F);
372            f(Pipeline::from_glib_borrow(this).unsafe_cast_ref())
373        }
374        unsafe {
375            let f: Box_<F> = Box_::new(f);
376            connect_raw(
377                self.as_ptr() as *mut _,
378                c"notify::auto-flush-bus".as_ptr() as *const _,
379                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
380                    notify_auto_flush_bus_trampoline::<Self, F> as *const (),
381                )),
382                Box_::into_raw(f),
383            )
384        }
385    }
386
387    #[doc(alias = "delay")]
388    fn connect_delay_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
389        unsafe extern "C" fn notify_delay_trampoline<
390            P: IsA<Pipeline>,
391            F: Fn(&P) + Send + Sync + 'static,
392        >(
393            this: *mut ffi::GstPipeline,
394            _param_spec: glib::ffi::gpointer,
395            f: glib::ffi::gpointer,
396        ) {
397            let f: &F = &*(f as *const F);
398            f(Pipeline::from_glib_borrow(this).unsafe_cast_ref())
399        }
400        unsafe {
401            let f: Box_<F> = Box_::new(f);
402            connect_raw(
403                self.as_ptr() as *mut _,
404                c"notify::delay".as_ptr() as *const _,
405                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
406                    notify_delay_trampoline::<Self, F> as *const (),
407                )),
408                Box_::into_raw(f),
409            )
410        }
411    }
412
413    #[doc(alias = "latency")]
414    fn connect_latency_notify<F: Fn(&Self) + Send + Sync + 'static>(
415        &self,
416        f: F,
417    ) -> SignalHandlerId {
418        unsafe extern "C" fn notify_latency_trampoline<
419            P: IsA<Pipeline>,
420            F: Fn(&P) + Send + Sync + 'static,
421        >(
422            this: *mut ffi::GstPipeline,
423            _param_spec: glib::ffi::gpointer,
424            f: glib::ffi::gpointer,
425        ) {
426            let f: &F = &*(f as *const F);
427            f(Pipeline::from_glib_borrow(this).unsafe_cast_ref())
428        }
429        unsafe {
430            let f: Box_<F> = Box_::new(f);
431            connect_raw(
432                self.as_ptr() as *mut _,
433                c"notify::latency".as_ptr() as *const _,
434                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
435                    notify_latency_trampoline::<Self, F> as *const (),
436                )),
437                Box_::into_raw(f),
438            )
439        }
440    }
441}
442
443impl<O: IsA<Pipeline>> PipelineExt for O {}