1use crate::{ChildProxy, Element, ElementFlags, Object, Pad, PadDirection, ffi};
7use glib::{
8 object::ObjectType as _,
9 prelude::*,
10 signal::{SignalHandlerId, connect_raw},
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 unsafe {
173 let f: &F = &*(f as *const F);
174 f(
175 Bin::from_glib_borrow(this).unsafe_cast_ref(),
176 &from_glib_borrow(sub_bin),
177 &from_glib_borrow(element),
178 )
179 }
180 }
181 unsafe {
182 let f: Box_<F> = Box_::new(f);
183 connect_raw(
184 self.as_ptr() as *mut _,
185 c"deep-element-added".as_ptr(),
186 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
187 deep_element_added_trampoline::<Self, F> as *const (),
188 )),
189 Box_::into_raw(f),
190 )
191 }
192 }
193
194 #[doc(alias = "deep-element-removed")]
195 fn connect_deep_element_removed<F: Fn(&Self, &Bin, &Element) + Send + Sync + 'static>(
196 &self,
197 f: F,
198 ) -> SignalHandlerId {
199 unsafe extern "C" fn deep_element_removed_trampoline<
200 P: IsA<Bin>,
201 F: Fn(&P, &Bin, &Element) + Send + Sync + 'static,
202 >(
203 this: *mut ffi::GstBin,
204 sub_bin: *mut ffi::GstBin,
205 element: *mut ffi::GstElement,
206 f: glib::ffi::gpointer,
207 ) {
208 unsafe {
209 let f: &F = &*(f as *const F);
210 f(
211 Bin::from_glib_borrow(this).unsafe_cast_ref(),
212 &from_glib_borrow(sub_bin),
213 &from_glib_borrow(element),
214 )
215 }
216 }
217 unsafe {
218 let f: Box_<F> = Box_::new(f);
219 connect_raw(
220 self.as_ptr() as *mut _,
221 c"deep-element-removed".as_ptr(),
222 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
223 deep_element_removed_trampoline::<Self, F> as *const (),
224 )),
225 Box_::into_raw(f),
226 )
227 }
228 }
229
230 #[doc(alias = "element-added")]
231 fn connect_element_added<F: Fn(&Self, &Element) + Send + Sync + 'static>(
232 &self,
233 f: F,
234 ) -> SignalHandlerId {
235 unsafe extern "C" fn element_added_trampoline<
236 P: IsA<Bin>,
237 F: Fn(&P, &Element) + Send + Sync + 'static,
238 >(
239 this: *mut ffi::GstBin,
240 element: *mut ffi::GstElement,
241 f: glib::ffi::gpointer,
242 ) {
243 unsafe {
244 let f: &F = &*(f as *const F);
245 f(
246 Bin::from_glib_borrow(this).unsafe_cast_ref(),
247 &from_glib_borrow(element),
248 )
249 }
250 }
251 unsafe {
252 let f: Box_<F> = Box_::new(f);
253 connect_raw(
254 self.as_ptr() as *mut _,
255 c"element-added".as_ptr(),
256 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
257 element_added_trampoline::<Self, F> as *const (),
258 )),
259 Box_::into_raw(f),
260 )
261 }
262 }
263
264 #[doc(alias = "element-removed")]
265 fn connect_element_removed<F: Fn(&Self, &Element) + Send + Sync + 'static>(
266 &self,
267 f: F,
268 ) -> SignalHandlerId {
269 unsafe extern "C" fn element_removed_trampoline<
270 P: IsA<Bin>,
271 F: Fn(&P, &Element) + Send + Sync + 'static,
272 >(
273 this: *mut ffi::GstBin,
274 element: *mut ffi::GstElement,
275 f: glib::ffi::gpointer,
276 ) {
277 unsafe {
278 let f: &F = &*(f as *const F);
279 f(
280 Bin::from_glib_borrow(this).unsafe_cast_ref(),
281 &from_glib_borrow(element),
282 )
283 }
284 }
285 unsafe {
286 let f: Box_<F> = Box_::new(f);
287 connect_raw(
288 self.as_ptr() as *mut _,
289 c"element-removed".as_ptr(),
290 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
291 element_removed_trampoline::<Self, F> as *const (),
292 )),
293 Box_::into_raw(f),
294 )
295 }
296 }
297
298 #[doc(alias = "async-handling")]
299 fn connect_async_handling_notify<F: Fn(&Self) + Send + Sync + 'static>(
300 &self,
301 f: F,
302 ) -> SignalHandlerId {
303 unsafe extern "C" fn notify_async_handling_trampoline<
304 P: IsA<Bin>,
305 F: Fn(&P) + Send + Sync + 'static,
306 >(
307 this: *mut ffi::GstBin,
308 _param_spec: glib::ffi::gpointer,
309 f: glib::ffi::gpointer,
310 ) {
311 unsafe {
312 let f: &F = &*(f as *const F);
313 f(Bin::from_glib_borrow(this).unsafe_cast_ref())
314 }
315 }
316 unsafe {
317 let f: Box_<F> = Box_::new(f);
318 connect_raw(
319 self.as_ptr() as *mut _,
320 c"notify::async-handling".as_ptr(),
321 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
322 notify_async_handling_trampoline::<Self, F> as *const (),
323 )),
324 Box_::into_raw(f),
325 )
326 }
327 }
328
329 #[doc(alias = "message-forward")]
330 fn connect_message_forward_notify<F: Fn(&Self) + Send + Sync + 'static>(
331 &self,
332 f: F,
333 ) -> SignalHandlerId {
334 unsafe extern "C" fn notify_message_forward_trampoline<
335 P: IsA<Bin>,
336 F: Fn(&P) + Send + Sync + 'static,
337 >(
338 this: *mut ffi::GstBin,
339 _param_spec: glib::ffi::gpointer,
340 f: glib::ffi::gpointer,
341 ) {
342 unsafe {
343 let f: &F = &*(f as *const F);
344 f(Bin::from_glib_borrow(this).unsafe_cast_ref())
345 }
346 }
347 unsafe {
348 let f: Box_<F> = Box_::new(f);
349 connect_raw(
350 self.as_ptr() as *mut _,
351 c"notify::message-forward".as_ptr(),
352 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
353 notify_message_forward_trampoline::<Self, F> as *const (),
354 )),
355 Box_::into_raw(f),
356 )
357 }
358 }
359}
360
361impl<O: IsA<Bin>> GstBinExt for O {}