1use crate::{ffi, ChildProxy, Element, ElementFlags, Object, Pad, PadDirection};
7use glib::{
8 object::ObjectType as _,
9 prelude::*,
10 signal::{connect_raw, SignalHandlerId},
11 translate::*,
12};
13use std::boxed::Box as Box_;
14
15glib::wrapper! {
16 #[doc(alias = "GstBin")]
17 pub struct Bin(Object<ffi::GstBin, ffi::GstBinClass>) @extends Element, Object, @implements ChildProxy;
18
19 match fn {
20 type_ => || ffi::gst_bin_get_type(),
21 }
22}
23
24impl Bin {
25 pub const NONE: Option<&'static Bin> = None;
26}
27
28unsafe impl Send for Bin {}
29unsafe impl Sync for Bin {}
30
31pub trait GstBinExt: IsA<Bin> + 'static {
32 #[doc(alias = "gst_bin_add")]
33 fn add(&self, element: &impl IsA<Element>) -> Result<(), glib::error::BoolError> {
34 unsafe {
35 glib::result_from_gboolean!(
36 ffi::gst_bin_add(
37 self.as_ref().to_glib_none().0,
38 element.as_ref().to_glib_none().0
39 ),
40 "Failed to add element"
41 )
42 }
43 }
44
45 #[doc(alias = "gst_bin_find_unlinked_pad")]
46 fn find_unlinked_pad(&self, direction: PadDirection) -> Option<Pad> {
47 unsafe {
48 from_glib_full(ffi::gst_bin_find_unlinked_pad(
49 self.as_ref().to_glib_none().0,
50 direction.into_glib(),
51 ))
52 }
53 }
54
55 #[doc(alias = "gst_bin_get_by_interface")]
56 #[doc(alias = "get_by_interface")]
57 fn by_interface(&self, iface: glib::types::Type) -> Option<Element> {
58 unsafe {
59 from_glib_full(ffi::gst_bin_get_by_interface(
60 self.as_ref().to_glib_none().0,
61 iface.into_glib(),
62 ))
63 }
64 }
65
66 #[doc(alias = "gst_bin_get_by_name")]
67 #[doc(alias = "get_by_name")]
68 fn by_name(&self, name: &str) -> Option<Element> {
69 unsafe {
70 from_glib_full(ffi::gst_bin_get_by_name(
71 self.as_ref().to_glib_none().0,
72 name.to_glib_none().0,
73 ))
74 }
75 }
76
77 #[doc(alias = "gst_bin_get_by_name_recurse_up")]
78 #[doc(alias = "get_by_name_recurse_up")]
79 fn by_name_recurse_up(&self, name: &str) -> Option<Element> {
80 unsafe {
81 from_glib_full(ffi::gst_bin_get_by_name_recurse_up(
82 self.as_ref().to_glib_none().0,
83 name.to_glib_none().0,
84 ))
85 }
86 }
87
88 #[doc(alias = "gst_bin_get_suppressed_flags")]
89 #[doc(alias = "get_suppressed_flags")]
90 fn suppressed_flags(&self) -> ElementFlags {
91 unsafe {
92 from_glib(ffi::gst_bin_get_suppressed_flags(
93 self.as_ref().to_glib_none().0,
94 ))
95 }
96 }
97
98 #[doc(alias = "gst_bin_recalculate_latency")]
99 fn recalculate_latency(&self) -> Result<(), glib::error::BoolError> {
100 unsafe {
101 glib::result_from_gboolean!(
102 ffi::gst_bin_recalculate_latency(self.as_ref().to_glib_none().0),
103 "Failed to recalculate latency"
104 )
105 }
106 }
107
108 #[doc(alias = "gst_bin_remove")]
109 fn remove(&self, element: &impl IsA<Element>) -> Result<(), glib::error::BoolError> {
110 unsafe {
111 glib::result_from_gboolean!(
112 ffi::gst_bin_remove(
113 self.as_ref().to_glib_none().0,
114 element.as_ref().to_glib_none().0
115 ),
116 "Failed to remove element"
117 )
118 }
119 }
120
121 #[doc(alias = "gst_bin_set_suppressed_flags")]
122 fn set_suppressed_flags(&self, flags: ElementFlags) {
123 unsafe {
124 ffi::gst_bin_set_suppressed_flags(self.as_ref().to_glib_none().0, flags.into_glib());
125 }
126 }
127
128 #[doc(alias = "gst_bin_sync_children_states")]
129 fn sync_children_states(&self) -> Result<(), glib::error::BoolError> {
130 unsafe {
131 glib::result_from_gboolean!(
132 ffi::gst_bin_sync_children_states(self.as_ref().to_glib_none().0),
133 "Failed to sync children states"
134 )
135 }
136 }
137
138 #[doc(alias = "async-handling")]
139 fn is_async_handling(&self) -> bool {
140 ObjectExt::property(self.as_ref(), "async-handling")
141 }
142
143 #[doc(alias = "async-handling")]
144 fn set_async_handling(&self, async_handling: bool) {
145 ObjectExt::set_property(self.as_ref(), "async-handling", async_handling)
146 }
147
148 #[doc(alias = "message-forward")]
149 fn is_message_forward(&self) -> bool {
150 ObjectExt::property(self.as_ref(), "message-forward")
151 }
152
153 #[doc(alias = "message-forward")]
154 fn set_message_forward(&self, message_forward: bool) {
155 ObjectExt::set_property(self.as_ref(), "message-forward", message_forward)
156 }
157
158 #[doc(alias = "deep-element-added")]
159 fn connect_deep_element_added<F: Fn(&Self, &Bin, &Element) + Send + Sync + 'static>(
160 &self,
161 f: F,
162 ) -> SignalHandlerId {
163 unsafe extern "C" fn deep_element_added_trampoline<
164 P: IsA<Bin>,
165 F: Fn(&P, &Bin, &Element) + Send + Sync + 'static,
166 >(
167 this: *mut ffi::GstBin,
168 sub_bin: *mut ffi::GstBin,
169 element: *mut ffi::GstElement,
170 f: glib::ffi::gpointer,
171 ) {
172 let f: &F = &*(f as *const F);
173 f(
174 Bin::from_glib_borrow(this).unsafe_cast_ref(),
175 &from_glib_borrow(sub_bin),
176 &from_glib_borrow(element),
177 )
178 }
179 unsafe {
180 let f: Box_<F> = Box_::new(f);
181 connect_raw(
182 self.as_ptr() as *mut _,
183 c"deep-element-added".as_ptr() as *const _,
184 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
185 deep_element_added_trampoline::<Self, F> as *const (),
186 )),
187 Box_::into_raw(f),
188 )
189 }
190 }
191
192 #[doc(alias = "deep-element-removed")]
193 fn connect_deep_element_removed<F: Fn(&Self, &Bin, &Element) + Send + Sync + 'static>(
194 &self,
195 f: F,
196 ) -> SignalHandlerId {
197 unsafe extern "C" fn deep_element_removed_trampoline<
198 P: IsA<Bin>,
199 F: Fn(&P, &Bin, &Element) + Send + Sync + 'static,
200 >(
201 this: *mut ffi::GstBin,
202 sub_bin: *mut ffi::GstBin,
203 element: *mut ffi::GstElement,
204 f: glib::ffi::gpointer,
205 ) {
206 let f: &F = &*(f as *const F);
207 f(
208 Bin::from_glib_borrow(this).unsafe_cast_ref(),
209 &from_glib_borrow(sub_bin),
210 &from_glib_borrow(element),
211 )
212 }
213 unsafe {
214 let f: Box_<F> = Box_::new(f);
215 connect_raw(
216 self.as_ptr() as *mut _,
217 c"deep-element-removed".as_ptr() as *const _,
218 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
219 deep_element_removed_trampoline::<Self, F> as *const (),
220 )),
221 Box_::into_raw(f),
222 )
223 }
224 }
225
226 #[doc(alias = "element-added")]
227 fn connect_element_added<F: Fn(&Self, &Element) + Send + Sync + 'static>(
228 &self,
229 f: F,
230 ) -> SignalHandlerId {
231 unsafe extern "C" fn element_added_trampoline<
232 P: IsA<Bin>,
233 F: Fn(&P, &Element) + Send + Sync + 'static,
234 >(
235 this: *mut ffi::GstBin,
236 element: *mut ffi::GstElement,
237 f: glib::ffi::gpointer,
238 ) {
239 let f: &F = &*(f as *const F);
240 f(
241 Bin::from_glib_borrow(this).unsafe_cast_ref(),
242 &from_glib_borrow(element),
243 )
244 }
245 unsafe {
246 let f: Box_<F> = Box_::new(f);
247 connect_raw(
248 self.as_ptr() as *mut _,
249 c"element-added".as_ptr() as *const _,
250 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
251 element_added_trampoline::<Self, F> as *const (),
252 )),
253 Box_::into_raw(f),
254 )
255 }
256 }
257
258 #[doc(alias = "element-removed")]
259 fn connect_element_removed<F: Fn(&Self, &Element) + Send + Sync + 'static>(
260 &self,
261 f: F,
262 ) -> SignalHandlerId {
263 unsafe extern "C" fn element_removed_trampoline<
264 P: IsA<Bin>,
265 F: Fn(&P, &Element) + Send + Sync + 'static,
266 >(
267 this: *mut ffi::GstBin,
268 element: *mut ffi::GstElement,
269 f: glib::ffi::gpointer,
270 ) {
271 let f: &F = &*(f as *const F);
272 f(
273 Bin::from_glib_borrow(this).unsafe_cast_ref(),
274 &from_glib_borrow(element),
275 )
276 }
277 unsafe {
278 let f: Box_<F> = Box_::new(f);
279 connect_raw(
280 self.as_ptr() as *mut _,
281 c"element-removed".as_ptr() as *const _,
282 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
283 element_removed_trampoline::<Self, F> as *const (),
284 )),
285 Box_::into_raw(f),
286 )
287 }
288 }
289
290 #[doc(alias = "async-handling")]
291 fn connect_async_handling_notify<F: Fn(&Self) + Send + Sync + 'static>(
292 &self,
293 f: F,
294 ) -> SignalHandlerId {
295 unsafe extern "C" fn notify_async_handling_trampoline<
296 P: IsA<Bin>,
297 F: Fn(&P) + Send + Sync + 'static,
298 >(
299 this: *mut ffi::GstBin,
300 _param_spec: glib::ffi::gpointer,
301 f: glib::ffi::gpointer,
302 ) {
303 let f: &F = &*(f as *const F);
304 f(Bin::from_glib_borrow(this).unsafe_cast_ref())
305 }
306 unsafe {
307 let f: Box_<F> = Box_::new(f);
308 connect_raw(
309 self.as_ptr() as *mut _,
310 c"notify::async-handling".as_ptr() as *const _,
311 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
312 notify_async_handling_trampoline::<Self, F> as *const (),
313 )),
314 Box_::into_raw(f),
315 )
316 }
317 }
318
319 #[doc(alias = "message-forward")]
320 fn connect_message_forward_notify<F: Fn(&Self) + Send + Sync + 'static>(
321 &self,
322 f: F,
323 ) -> SignalHandlerId {
324 unsafe extern "C" fn notify_message_forward_trampoline<
325 P: IsA<Bin>,
326 F: Fn(&P) + Send + Sync + 'static,
327 >(
328 this: *mut ffi::GstBin,
329 _param_spec: glib::ffi::gpointer,
330 f: glib::ffi::gpointer,
331 ) {
332 let f: &F = &*(f as *const F);
333 f(Bin::from_glib_borrow(this).unsafe_cast_ref())
334 }
335 unsafe {
336 let f: Box_<F> = Box_::new(f);
337 connect_raw(
338 self.as_ptr() as *mut _,
339 c"notify::message-forward".as_ptr() as *const _,
340 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
341 notify_message_forward_trampoline::<Self, F> as *const (),
342 )),
343 Box_::into_raw(f),
344 )
345 }
346 }
347}
348
349impl<O: IsA<Bin>> GstBinExt for O {}