gstreamer/
parse.rs
1use std::ptr;
4
5use glib::{prelude::*, translate::*};
6
7use crate::{ffi, Bin, Element, Object, ParseContext, ParseFlags};
8
9pub use crate::auto::functions::parse_bin_from_description as bin_from_description;
10pub use crate::auto::functions::parse_launch as launch;
11pub use crate::auto::functions::parse_launchv as launchv;
12
13#[doc(alias = "gst_parse_bin_from_description_full")]
14pub fn bin_from_description_with_name(
15 bin_description: &str,
16 ghost_unlinked_pads: bool,
17 bin_name: &str,
18) -> Result<Bin, glib::Error> {
19 skip_assert_initialized!();
20 let bin = bin_from_description(bin_description, ghost_unlinked_pads)?;
21 if !bin_name.is_empty() {
22 let obj = bin.clone().upcast::<Object>();
23 unsafe {
24 ffi::gst_object_set_name(obj.to_glib_none().0, bin_name.to_glib_none().0);
25 }
26 }
27 Ok(bin)
28}
29
30#[doc(alias = "gst_parse_bin_from_description_full")]
31pub fn bin_from_description_full(
32 bin_description: &str,
33 ghost_unlinked_pads: bool,
34 mut context: Option<&mut ParseContext>,
35 flags: ParseFlags,
36) -> Result<Element, glib::Error> {
37 skip_assert_initialized!();
38 unsafe {
39 let mut error = ptr::null_mut();
40 let ret = ffi::gst_parse_bin_from_description_full(
41 bin_description.to_glib_none().0,
42 ghost_unlinked_pads.into_glib(),
43 context.to_glib_none_mut().0,
44 flags.into_glib(),
45 &mut error,
46 );
47 if error.is_null() {
48 Ok(from_glib_none(ret))
49 } else {
50 Err(from_glib_full(error))
51 }
52 }
53}
54
55#[doc(alias = "gst_parse_bin_from_description_full")]
56pub fn bin_from_description_with_name_full(
57 bin_description: &str,
58 ghost_unlinked_pads: bool,
59 bin_name: &str,
60 context: Option<&mut ParseContext>,
61 flags: ParseFlags,
62) -> Result<Element, glib::Error> {
63 skip_assert_initialized!();
64 let bin = bin_from_description_full(bin_description, ghost_unlinked_pads, context, flags)?;
65 if !bin_name.is_empty() {
66 let obj = bin.clone().upcast::<Object>();
67 unsafe {
68 ffi::gst_object_set_name(obj.to_glib_none().0, bin_name.to_glib_none().0);
69 }
70 }
71 Ok(bin)
72}
73
74#[doc(alias = "gst_parse_launch_full")]
75pub fn launch_full(
76 pipeline_description: &str,
77 mut context: Option<&mut ParseContext>,
78 flags: ParseFlags,
79) -> Result<Element, glib::Error> {
80 assert_initialized_main_thread!();
81 unsafe {
82 let mut error = ptr::null_mut();
83 let ret = ffi::gst_parse_launch_full(
84 pipeline_description.to_glib_none().0,
85 context.to_glib_none_mut().0,
86 flags.into_glib(),
87 &mut error,
88 );
89 if error.is_null() {
90 Ok(from_glib_none(ret))
91 } else {
92 Err(from_glib_full(error))
93 }
94 }
95}
96
97#[doc(alias = "gst_parse_launchv_full")]
98pub fn launchv_full(
99 argv: &[&str],
100 mut context: Option<&mut ParseContext>,
101 flags: ParseFlags,
102) -> Result<Element, glib::Error> {
103 assert_initialized_main_thread!();
104 unsafe {
105 let mut error = ptr::null_mut();
106 let ret = ffi::gst_parse_launchv_full(
107 argv.to_glib_none().0,
108 context.to_glib_none_mut().0,
109 flags.into_glib(),
110 &mut error,
111 );
112 if error.is_null() {
113 Ok(from_glib_none(ret))
114 } else {
115 Err(from_glib_full(error))
116 }
117 }
118}
119
120#[cfg(test)]
121mod tests {
122 use super::*;
123 use crate::prelude::*;
124
125 #[test]
126 fn test_parse_bin_from_description_with_name() {
127 crate::init().unwrap();
128
129 let bin = bin_from_description_with_name("fakesrc ! fakesink", false, "all_fake").unwrap();
130 let name = bin.name();
131 assert_eq!(name, "all_fake");
132
133 let bin = bin_from_description_with_name("fakesrc ! fakesink", false, "").unwrap();
134 let name = bin.name();
135 assert_ne!(name, "");
136 }
137}