gstreamer/auto/
functions.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, ClockTime, DebugGraphDetails, DebugLevel, Element, StackTraceFlags};
7use glib::{prelude::*, translate::*};
8
9/// Adds a memory ringbuffer based debug logger that stores up to
10/// `max_size_per_thread` bytes of logs per thread and times out threads after
11/// `thread_timeout` seconds of inactivity.
12///
13/// Logs can be fetched with [`debug_ring_buffer_logger_get_logs()`][crate::debug_ring_buffer_logger_get_logs()] and the
14/// logger can be removed again with [`debug_remove_ring_buffer_logger()`][crate::debug_remove_ring_buffer_logger()].
15/// Only one logger at a time is possible.
16/// ## `max_size_per_thread`
17/// Maximum size of log per thread in bytes
18/// ## `thread_timeout`
19/// Timeout for threads in seconds
20#[doc(alias = "gst_debug_add_ring_buffer_logger")]
21pub fn debug_add_ring_buffer_logger(max_size_per_thread: u32, thread_timeout: u32) {
22    skip_assert_initialized!();
23    unsafe {
24        ffi::gst_debug_add_ring_buffer_logger(max_size_per_thread, thread_timeout);
25    }
26}
27
28/// To aid debugging applications one can use this method to obtain the whole
29/// network of gstreamer elements that form the pipeline into a dot file.
30/// This data can be processed with graphviz to get an image.
31/// ## `bin`
32/// the top-level pipeline that should be analyzed
33/// ## `details`
34/// type of [`DebugGraphDetails`][crate::DebugGraphDetails] to use
35///
36/// # Returns
37///
38/// a string containing the pipeline in graphviz
39/// dot format.
40#[doc(alias = "gst_debug_bin_to_dot_data")]
41pub fn debug_bin_to_dot_data(bin: &impl IsA<Bin>, details: DebugGraphDetails) -> glib::GString {
42    skip_assert_initialized!();
43    unsafe {
44        from_glib_full(ffi::gst_debug_bin_to_dot_data(
45            bin.as_ref().to_glib_none().0,
46            details.into_glib(),
47        ))
48    }
49}
50
51/// To aid debugging applications one can use this method to write out the whole
52/// network of gstreamer elements that form the pipeline into a dot file.
53/// This file can be processed with graphviz to get an image.
54///
55/// **⚠️ The following code is in  shell ⚠️**
56///
57/// ``` shell
58///  dot -Tpng -oimage.png graph_lowlevel.dot
59/// ```
60/// ## `bin`
61/// the top-level pipeline that should be analyzed
62/// ## `details`
63/// type of [`DebugGraphDetails`][crate::DebugGraphDetails] to use
64/// ## `file_name`
65/// output base filename (e.g. "myplayer")
66#[doc(alias = "gst_debug_bin_to_dot_file")]
67pub fn debug_bin_to_dot_file(
68    bin: &impl IsA<Bin>,
69    details: DebugGraphDetails,
70    file_name: impl AsRef<std::path::Path>,
71) {
72    skip_assert_initialized!();
73    unsafe {
74        ffi::gst_debug_bin_to_dot_file(
75            bin.as_ref().to_glib_none().0,
76            details.into_glib(),
77            file_name.as_ref().to_glib_none().0,
78        );
79    }
80}
81
82/// This works like [`debug_bin_to_dot_file()`][crate::debug_bin_to_dot_file()], but adds the current timestamp
83/// to the filename, so that it can be used to take multiple snapshots.
84/// ## `bin`
85/// the top-level pipeline that should be analyzed
86/// ## `details`
87/// type of [`DebugGraphDetails`][crate::DebugGraphDetails] to use
88/// ## `file_name`
89/// output base filename (e.g. "myplayer")
90#[doc(alias = "gst_debug_bin_to_dot_file_with_ts")]
91pub fn debug_bin_to_dot_file_with_ts(
92    bin: &impl IsA<Bin>,
93    details: DebugGraphDetails,
94    file_name: impl AsRef<std::path::Path>,
95) {
96    skip_assert_initialized!();
97    unsafe {
98        ffi::gst_debug_bin_to_dot_file_with_ts(
99            bin.as_ref().to_glib_none().0,
100            details.into_glib(),
101            file_name.as_ref().to_glib_none().0,
102        );
103    }
104}
105
106/// Returns the default threshold that is used for new categories.
107///
108/// # Returns
109///
110/// the default threshold level
111#[doc(alias = "gst_debug_get_default_threshold")]
112pub fn debug_get_default_threshold() -> DebugLevel {
113    skip_assert_initialized!();
114    unsafe { from_glib(ffi::gst_debug_get_default_threshold()) }
115}
116
117/// ## `flags`
118/// A set of [`StackTraceFlags`][crate::StackTraceFlags] to determine how the stack trace should
119/// look like. Pass `GST_STACK_TRACE_SHOW_NONE` to retrieve a minimal backtrace.
120///
121/// # Returns
122///
123/// a stack trace, if libunwind or glibc backtrace are
124/// present, else [`None`].
125#[doc(alias = "gst_debug_get_stack_trace")]
126pub fn debug_get_stack_trace(flags: StackTraceFlags) -> Result<glib::GString, glib::BoolError> {
127    skip_assert_initialized!();
128    unsafe {
129        Option::<_>::from_glib_full(ffi::gst_debug_get_stack_trace(flags.into_glib()))
130            .ok_or_else(|| glib::bool_error!("Failed to get stack trace"))
131    }
132}
133
134/// Checks if debugging output is activated.
135///
136/// # Returns
137///
138/// [`true`], if debugging is activated
139#[doc(alias = "gst_debug_is_active")]
140pub fn debug_is_active() -> bool {
141    skip_assert_initialized!();
142    unsafe { from_glib(ffi::gst_debug_is_active()) }
143}
144
145/// Checks if the debugging output should be colored.
146///
147/// # Returns
148///
149/// [`true`], if the debug output should be colored.
150#[doc(alias = "gst_debug_is_colored")]
151pub fn debug_is_colored() -> bool {
152    skip_assert_initialized!();
153    unsafe { from_glib(ffi::gst_debug_is_colored()) }
154}
155
156/// If libunwind, glibc backtrace or DbgHelp are present
157/// a stack trace is printed.
158#[doc(alias = "gst_debug_print_stack_trace")]
159pub fn debug_print_stack_trace() {
160    skip_assert_initialized!();
161    unsafe {
162        ffi::gst_debug_print_stack_trace();
163    }
164}
165
166/// Removes any previously added ring buffer logger with
167/// [`debug_add_ring_buffer_logger()`][crate::debug_add_ring_buffer_logger()].
168#[doc(alias = "gst_debug_remove_ring_buffer_logger")]
169pub fn debug_remove_ring_buffer_logger() {
170    skip_assert_initialized!();
171    unsafe {
172        ffi::gst_debug_remove_ring_buffer_logger();
173    }
174}
175
176/// Fetches the current logs per thread from the ring buffer logger. See
177/// [`debug_add_ring_buffer_logger()`][crate::debug_add_ring_buffer_logger()] for details.
178///
179/// # Returns
180///
181/// NULL-terminated array of
182/// strings with the debug output per thread
183#[doc(alias = "gst_debug_ring_buffer_logger_get_logs")]
184pub fn debug_ring_buffer_logger_get_logs() -> Vec<glib::GString> {
185    skip_assert_initialized!();
186    unsafe { FromGlibPtrContainer::from_glib_full(ffi::gst_debug_ring_buffer_logger_get_logs()) }
187}
188
189/// If activated, debugging messages are sent to the debugging
190/// handlers.
191/// It makes sense to deactivate it for speed issues.
192/// > This function is not threadsafe. It makes sense to only call it
193/// during initialization.
194/// ## `active`
195/// Whether to use debugging output or not
196#[doc(alias = "gst_debug_set_active")]
197pub fn debug_set_active(active: bool) {
198    skip_assert_initialized!();
199    unsafe {
200        ffi::gst_debug_set_active(active.into_glib());
201    }
202}
203
204/// Sets or unsets the use of coloured debugging output.
205/// Same as gst_debug_set_color_mode () with the argument being
206/// being GST_DEBUG_COLOR_MODE_ON or GST_DEBUG_COLOR_MODE_OFF.
207///
208/// This function may be called before `gst_init()`.
209/// ## `colored`
210/// Whether to use colored output or not
211#[doc(alias = "gst_debug_set_colored")]
212pub fn debug_set_colored(colored: bool) {
213    skip_assert_initialized!();
214    unsafe {
215        ffi::gst_debug_set_colored(colored.into_glib());
216    }
217}
218
219/// Sets the default threshold to the given level and updates all categories to
220/// use this threshold.
221///
222/// This function may be called before `gst_init()`.
223/// ## `level`
224/// level to set
225#[doc(alias = "gst_debug_set_default_threshold")]
226pub fn debug_set_default_threshold(level: DebugLevel) {
227    skip_assert_initialized!();
228    unsafe {
229        ffi::gst_debug_set_default_threshold(level.into_glib());
230    }
231}
232
233/// Sets all categories which match the given glob style pattern to the given
234/// level.
235/// ## `name`
236/// name of the categories to set
237/// ## `level`
238/// level to set them to
239#[doc(alias = "gst_debug_set_threshold_for_name")]
240pub fn debug_set_threshold_for_name(name: &str, level: DebugLevel) {
241    skip_assert_initialized!();
242    unsafe {
243        ffi::gst_debug_set_threshold_for_name(name.to_glib_none().0, level.into_glib());
244    }
245}
246
247/// Sets the debug logging wanted in the same form as with the GST_DEBUG
248/// environment variable. You can use wildcards such as `*`, but note that
249/// the order matters when you use wild cards, e.g. `foosrc:6,*src:3,*:2` sets
250/// everything to log level 2.
251/// ## `list`
252/// comma-separated list of "category:level" pairs to be used
253///  as debug logging levels
254/// ## `reset`
255/// [`true`] to clear all previously-set debug levels before setting
256///  new thresholds
257/// [`false`] if adding the threshold described by `list` to the one already set.
258#[doc(alias = "gst_debug_set_threshold_from_string")]
259pub fn debug_set_threshold_from_string(list: &str, reset: bool) {
260    skip_assert_initialized!();
261    unsafe {
262        ffi::gst_debug_set_threshold_from_string(list.to_glib_none().0, reset.into_glib());
263    }
264}
265
266/// Resets all categories with the given name back to the default level.
267/// ## `name`
268/// name of the categories to set
269#[doc(alias = "gst_debug_unset_threshold_for_name")]
270pub fn debug_unset_threshold_for_name(name: &str) {
271    skip_assert_initialized!();
272    unsafe {
273        ffi::gst_debug_unset_threshold_for_name(name.to_glib_none().0);
274    }
275}
276
277/// This helper is mostly helpful for plugins that need to
278/// inspect the folder of the main executable to determine
279/// their set of features.
280///
281/// When a plugin is initialized from the gst-plugin-scanner
282/// external process, the returned path will be the same as from the
283/// parent process.
284///
285/// # Returns
286///
287/// The path of the executable that
288///  initialized GStreamer, or [`None`] if it could not be determined.
289#[doc(alias = "gst_get_main_executable_path")]
290#[doc(alias = "get_main_executable_path")]
291pub fn main_executable_path() -> Result<glib::GString, glib::BoolError> {
292    assert_initialized_main_thread!();
293    unsafe {
294        Option::<_>::from_glib_none(ffi::gst_get_main_executable_path())
295            .ok_or_else(|| glib::bool_error!("Failed to get main executable path"))
296    }
297}
298
299/// This is a convenience wrapper around [`parse_launch()`][crate::parse_launch()] to create a
300/// [`Bin`][crate::Bin] from a gst-launch-style pipeline description. See
301/// [`parse_launch()`][crate::parse_launch()] and the gst-launch man page for details about the
302/// syntax. Ghost pads on the bin for unlinked source or sink pads
303/// within the bin can automatically be created (but only a maximum of
304/// one ghost pad for each direction will be created; if you expect
305/// multiple unlinked source pads or multiple unlinked sink pads
306/// and want them all ghosted, you will have to create the ghost pads
307/// yourself).
308/// ## `bin_description`
309/// command line describing the bin
310/// ## `ghost_unlinked_pads`
311/// whether to automatically create ghost pads
312///  for unlinked source or sink pads within the bin
313///
314/// # Returns
315///
316/// a
317///  newly-created bin, or [`None`] if an error occurred.
318#[doc(alias = "gst_parse_bin_from_description")]
319pub fn parse_bin_from_description(
320    bin_description: &str,
321    ghost_unlinked_pads: bool,
322) -> Result<Bin, glib::Error> {
323    assert_initialized_main_thread!();
324    unsafe {
325        let mut error = std::ptr::null_mut();
326        let ret = ffi::gst_parse_bin_from_description(
327            bin_description.to_glib_none().0,
328            ghost_unlinked_pads.into_glib(),
329            &mut error,
330        );
331        if error.is_null() {
332            Ok(from_glib_none(ret))
333        } else {
334            Err(from_glib_full(error))
335        }
336    }
337}
338
339/// Create a new pipeline based on command line syntax.
340/// Please note that you might get a return value that is not [`None`] even though
341/// the `error` is set. In this case there was a recoverable parsing error and you
342/// can try to play the pipeline.
343///
344/// To create a sub-pipeline (bin) for embedding into an existing pipeline
345/// use [`parse_bin_from_description()`][crate::parse_bin_from_description()].
346/// ## `pipeline_description`
347/// the command line describing the pipeline
348///
349/// # Returns
350///
351/// a new element on success, [`None`] on
352///  failure. If more than one toplevel element is specified by the
353///  `pipeline_description`, all elements are put into a [`Pipeline`][crate::Pipeline], which
354///  than is returned.
355#[doc(alias = "gst_parse_launch")]
356pub fn parse_launch(pipeline_description: &str) -> Result<Element, glib::Error> {
357    assert_initialized_main_thread!();
358    unsafe {
359        let mut error = std::ptr::null_mut();
360        let ret = ffi::gst_parse_launch(pipeline_description.to_glib_none().0, &mut error);
361        if error.is_null() {
362            Ok(from_glib_none(ret))
363        } else {
364            Err(from_glib_full(error))
365        }
366    }
367}
368
369/// Create a new element based on command line syntax.
370/// `error` will contain an error message if an erroneous pipeline is specified.
371/// An error does not mean that the pipeline could not be constructed.
372/// ## `argv`
373/// null-terminated array of arguments
374///
375/// # Returns
376///
377/// a new element on success and [`None`]
378/// on failure.
379#[doc(alias = "gst_parse_launchv")]
380pub fn parse_launchv(argv: &[&str]) -> Result<Element, glib::Error> {
381    assert_initialized_main_thread!();
382    unsafe {
383        let mut error = std::ptr::null_mut();
384        let ret = ffi::gst_parse_launchv(argv.to_glib_none().0, &mut error);
385        if error.is_null() {
386            Ok(from_glib_none(ret))
387        } else {
388            Err(from_glib_full(error))
389        }
390    }
391}
392
393/// Forces GStreamer to re-scan its plugin paths and update the default
394/// plugin registry.
395///
396/// Applications will almost never need to call this function, it is only
397/// useful if the application knows new plugins have been installed (or old
398/// ones removed) since the start of the application (or, to be precise, the
399/// first call to `gst_init()`) and the application wants to make use of any
400/// newly-installed plugins without restarting the application.
401///
402/// Applications should assume that the registry update is neither atomic nor
403/// thread-safe and should therefore not have any dynamic pipelines running
404/// (including the playbin and decodebin elements) and should also not create
405/// any elements or access the GStreamer registry while the update is in
406/// progress.
407///
408/// Note that this function may block for a significant amount of time.
409///
410/// # Returns
411///
412/// [`true`] if the registry has been updated successfully (does not
413///  imply that there were changes), otherwise [`false`].
414#[doc(alias = "gst_update_registry")]
415pub fn update_registry() -> Result<(), glib::error::BoolError> {
416    assert_initialized_main_thread!();
417    unsafe {
418        glib::result_from_gboolean!(ffi::gst_update_registry(), "Failed to update the registry")
419    }
420}
421
422/// Get a timestamp as GstClockTime to be used for interval measurements.
423/// The timestamp should not be interpreted in any other way.
424///
425/// # Returns
426///
427/// the timestamp
428#[doc(alias = "gst_util_get_timestamp")]
429pub fn util_get_timestamp() -> ClockTime {
430    skip_assert_initialized!();
431    unsafe { try_from_glib(ffi::gst_util_get_timestamp()).expect("mandatory glib value is None") }
432}
433
434/// Gets the version number of the GStreamer library.
435///
436/// # Returns
437///
438///
439/// ## `major`
440/// pointer to a guint to store the major version number
441///
442/// ## `minor`
443/// pointer to a guint to store the minor version number
444///
445/// ## `micro`
446/// pointer to a guint to store the micro version number
447///
448/// ## `nano`
449/// pointer to a guint to store the nano version number
450#[doc(alias = "gst_version")]
451pub fn version() -> (u32, u32, u32, u32) {
452    skip_assert_initialized!();
453    unsafe {
454        let mut major = std::mem::MaybeUninit::uninit();
455        let mut minor = std::mem::MaybeUninit::uninit();
456        let mut micro = std::mem::MaybeUninit::uninit();
457        let mut nano = std::mem::MaybeUninit::uninit();
458        ffi::gst_version(
459            major.as_mut_ptr(),
460            minor.as_mut_ptr(),
461            micro.as_mut_ptr(),
462            nano.as_mut_ptr(),
463        );
464        (
465            major.assume_init(),
466            minor.assume_init(),
467            micro.assume_init(),
468            nano.assume_init(),
469        )
470    }
471}
472
473/// This function returns a string that is useful for describing this version
474/// of GStreamer to the outside world: user agent strings, logging, ...
475///
476/// # Returns
477///
478/// a newly allocated string describing this version
479///  of GStreamer.
480#[doc(alias = "gst_version_string")]
481pub fn version_string() -> glib::GString {
482    skip_assert_initialized!();
483    unsafe { from_glib_full(ffi::gst_version_string()) }
484}