1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use ChildProxy;
use Element;
#[cfg(any(feature = "v1_10", feature = "dox"))]
use ElementFlags;
use Object;
use Pad;
use PadDirection;
use ffi;
use glib;
use glib::StaticType;
use glib::Value;
use glib::object::Downcast;
use glib::object::IsA;
use glib::signal::SignalHandlerId;
use glib::signal::connect;
use glib::translate::*;
use glib_ffi;
use gobject_ffi;
use std::boxed::Box as Box_;
use std::mem;
use std::mem::transmute;
use std::ptr;

glib_wrapper! {
    /// `Bin` is an element that can contain other `Element`, allowing them to be
    /// managed as a group.
    /// Pads from the child elements can be ghosted to the bin, see `GhostPad`.
    /// This makes the bin look like any other elements and enables creation of
    /// higher-level abstraction elements.
    ///
    /// A new `Bin` is created with `Bin::new`. Use a `Pipeline` instead if you
    /// want to create a toplevel bin because a normal bin doesn't have a bus or
    /// handle clock distribution of its own.
    ///
    /// After the bin has been created you will typically add elements to it with
    /// `BinExt::add`. You can remove elements with `BinExt::remove`.
    ///
    /// An element can be retrieved from a bin with `BinExt::get_by_name`, using the
    /// elements name. `BinExt::get_by_name_recurse_up` is mainly used for internal
    /// purposes and will query the parent bins when the element is not found in the
    /// current bin.
    ///
    /// An iterator of elements in a bin can be retrieved with
    /// `BinExt::iterate_elements`. Various other iterators exist to retrieve the
    /// elements in a bin.
    ///
    /// `GstObjectExt::unref` is used to drop your reference to the bin.
    ///
    /// The `Bin::element-added` signal is fired whenever a new element is added to
    /// the bin. Likewise the `Bin::element-removed` signal is fired whenever an
    /// element is removed from the bin.
    ///
    /// ## Notes
    ///
    /// A `Bin` internally intercepts every `Message` posted by its children and
    /// implements the following default behaviour for each of them:
    ///
    /// * GST_MESSAGE_EOS: This message is only posted by sinks in the PLAYING
    /// state. If all sinks posted the EOS message, this bin will post and EOS
    /// message upwards.
    ///
    /// * GST_MESSAGE_SEGMENT_START: Just collected and never forwarded upwards.
    /// The messages are used to decide when all elements have completed playback
    /// of their segment.
    ///
    /// * GST_MESSAGE_SEGMENT_DONE: Is posted by `Bin` when all elements that posted
    /// a SEGMENT_START have posted a SEGMENT_DONE.
    ///
    /// * GST_MESSAGE_DURATION_CHANGED: Is posted by an element that detected a change
    /// in the stream duration. The default bin behaviour is to clear any
    /// cached duration values so that the next duration query will perform
    /// a full duration recalculation. The duration change is posted to the
    /// application so that it can refetch the new duration with a duration
    /// query. Note that these messages can be posted before the bin is
    /// prerolled, in which case the duration query might fail.
    ///
    /// * GST_MESSAGE_CLOCK_LOST: This message is posted by an element when it
    /// can no longer provide a clock. The default bin behaviour is to
    /// check if the lost clock was the one provided by the bin. If so and
    /// the bin is currently in the PLAYING state, the message is forwarded to
    /// the bin parent.
    /// This message is also generated when a clock provider is removed from
    /// the bin. If this message is received by the application, it should
    /// PAUSE the pipeline and set it back to PLAYING to force a new clock
    /// distribution.
    ///
    /// * GST_MESSAGE_CLOCK_PROVIDE: This message is generated when an element
    /// can provide a clock. This mostly happens when a new clock
    /// provider is added to the bin. The default behaviour of the bin is to
    /// mark the currently selected clock as dirty, which will perform a clock
    /// recalculation the next time the bin is asked to provide a clock.
    /// This message is never sent tot the application but is forwarded to
    /// the parent of the bin.
    ///
    /// * OTHERS: posted upwards.
    ///
    /// A `Bin` implements the following default behaviour for answering to a
    /// `Query`:
    ///
    /// * GST_QUERY_DURATION:If the query has been asked before with the same format
    /// and the bin is a toplevel bin (ie. has no parent),
    /// use the cached previous value. If no previous value was cached, the
    /// query is sent to all sink elements in the bin and the MAXIMUM of all
    /// values is returned. If the bin is a toplevel bin the value is cached.
    /// If no sinks are available in the bin, the query fails.
    ///
    /// * GST_QUERY_POSITION:The query is sent to all sink elements in the bin and the
    /// MAXIMUM of all values is returned. If no sinks are available in the bin,
    /// the query fails.
    ///
    /// * OTHERS:the query is forwarded to all sink elements, the result
    /// of the first sink that answers the query successfully is returned. If no
    /// sink is in the bin, the query fails.
    ///
    /// A `Bin` will by default forward any event sent to it to all sink
    /// (`EventTypeFlags::Downstream`) or source (`EventTypeFlags::Upstream`) elements
    /// depending on the event type.
    /// If all the elements return `true`, the bin will also return `true`, else `false`
    /// is returned. If no elements of the required type are in the bin, the event
    /// handler will return `true`.
    ///
    /// # Implements
    ///
    /// [`BinExt`](trait.BinExt.html), [`ElementExt`](trait.ElementExt.html), [`GstObjectExt`](trait.GstObjectExt.html), [`glib::object::ObjectExt`](../glib/object/trait.ObjectExt.html), [`ChildProxyExt`](trait.ChildProxyExt.html)
    pub struct Bin(Object<ffi::GstBin, ffi::GstBinClass>): Element, Object, ChildProxy;

    match fn {
        get_type => || ffi::gst_bin_get_type(),
    }
}

impl Bin {
    /// Creates a new bin with the given name.
    /// ## `name`
    /// the name of the new bin
    ///
    /// # Returns
    ///
    /// a new `Bin`
    pub fn new<'a, P: Into<Option<&'a str>>>(name: P) -> Bin {
        assert_initialized_main_thread!();
        let name = name.into();
        let name = name.to_glib_none();
        unsafe {
            Element::from_glib_none(ffi::gst_bin_new(name.0)).downcast_unchecked()
        }
    }
}

unsafe impl Send for Bin {}
unsafe impl Sync for Bin {}

/// Trait containing all `Bin` methods.
///
/// # Implementors
///
/// [`Bin`](struct.Bin.html), [`Pipeline`](struct.Pipeline.html)
pub trait BinExt {
    /// Adds the given element to the bin. Sets the element's parent, and thus
    /// takes ownership of the element. An element can only be added to one bin.
    ///
    /// If the element's pads are linked to other pads, the pads will be unlinked
    /// before the element is added to the bin.
    ///
    /// > When you add an element to an already-running pipeline, you will have to
    /// > take care to set the state of the newly-added element to the desired
    /// > state (usually PLAYING or PAUSED, same you set the pipeline to originally)
    /// > with `ElementExt::set_state`, or use `ElementExt::sync_state_with_parent`.
    /// > The bin or pipeline will not take care of this for you.
    ///
    /// MT safe.
    /// ## `element`
    /// the `Element` to add
    ///
    /// # Returns
    ///
    /// `true` if the element could be added, `false` if
    /// the bin does not want to accept the element.
    fn add<P: IsA<Element>>(&self, element: &P) -> Result<(), glib::error::BoolError>;

    //fn add_many<P: IsA<Element>>(&self, element_1: &P, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs);

    /// Recursively looks for elements with an unlinked pad of the given
    /// direction within the specified bin and returns an unlinked pad
    /// if one is found, or `None` otherwise. If a pad is found, the caller
    /// owns a reference to it and should use `GstObjectExt::unref` on the
    /// pad when it is not needed any longer.
    /// ## `direction`
    /// whether to look for an unlinked source or sink pad
    ///
    /// # Returns
    ///
    /// unlinked pad of the given
    /// direction, `None`.
    fn find_unlinked_pad(&self, direction: PadDirection) -> Option<Pad>;

    /// Looks for an element inside the bin that implements the given
    /// interface. If such an element is found, it returns the element.
    /// You can cast this element to the given interface afterwards. If you want
    /// all elements that implement the interface, use
    /// `BinExt::iterate_all_by_interface`. This function recurses into child bins.
    ///
    /// MT safe. Caller owns returned reference.
    /// ## `iface`
    /// the `glib::Type` of an interface
    ///
    /// # Returns
    ///
    /// A `Element` inside the bin
    /// implementing the interface
    fn get_by_interface(&self, iface: glib::types::Type) -> Option<Element>;

    /// Gets the element with the given name from a bin. This
    /// function recurses into child bins.
    ///
    /// Returns `None` if no element with the given name is found in the bin.
    ///
    /// MT safe. Caller owns returned reference.
    /// ## `name`
    /// the element name to search for
    ///
    /// # Returns
    ///
    /// the `Element` with the given
    /// name, or `None`
    fn get_by_name(&self, name: &str) -> Option<Element>;

    /// Gets the element with the given name from this bin. If the
    /// element is not found, a recursion is performed on the parent bin.
    ///
    /// Returns `None` if:
    /// - no element with the given name is found in the bin
    ///
    /// MT safe. Caller owns returned reference.
    /// ## `name`
    /// the element name to search for
    ///
    /// # Returns
    ///
    /// the `Element` with the given
    /// name, or `None`
    fn get_by_name_recurse_up(&self, name: &str) -> Option<Element>;

    /// Return the suppressed flags of the bin.
    ///
    /// MT safe.
    ///
    /// Feature: `v1_10`
    ///
    ///
    /// # Returns
    ///
    /// the bin's suppressed `ElementFlags`.
    #[cfg(any(feature = "v1_10", feature = "dox"))]
    fn get_suppressed_flags(&self) -> ElementFlags;

    //fn iterate_all_by_interface(&self, iface: glib::types::Type) -> /*Ignored*/Option<Iterator>;

    //fn iterate_elements(&self) -> /*Ignored*/Option<Iterator>;

    //fn iterate_recurse(&self) -> /*Ignored*/Option<Iterator>;

    //fn iterate_sinks(&self) -> /*Ignored*/Option<Iterator>;

    //fn iterate_sorted(&self) -> /*Ignored*/Option<Iterator>;

    //fn iterate_sources(&self) -> /*Ignored*/Option<Iterator>;

    /// Query `self` for the current latency using and reconfigures this latency to all the
    /// elements with a LATENCY event.
    ///
    /// This method is typically called on the pipeline when a `MessageType::Latency`
    /// is posted on the bus.
    ///
    /// This function simply emits the 'do-latency' signal so any custom latency
    /// calculations will be performed.
    ///
    /// # Returns
    ///
    /// `true` if the latency could be queried and reconfigured.
    fn recalculate_latency(&self) -> Result<(), glib::error::BoolError>;

    /// Removes the element from the bin, unparenting it as well.
    /// Unparenting the element means that the element will be dereferenced,
    /// so if the bin holds the only reference to the element, the element
    /// will be freed in the process of removing it from the bin. If you
    /// want the element to still exist after removing, you need to call
    /// `GstObjectExt::ref` before removing it from the bin.
    ///
    /// If the element's pads are linked to other pads, the pads will be unlinked
    /// before the element is removed from the bin.
    ///
    /// MT safe.
    /// ## `element`
    /// the `Element` to remove
    ///
    /// # Returns
    ///
    /// `true` if the element could be removed, `false` if
    /// the bin does not want to remove the element.
    fn remove<P: IsA<Element>>(&self, element: &P) -> Result<(), glib::error::BoolError>;

    //fn remove_many<P: IsA<Element>>(&self, element_1: &P, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs);

    /// Suppress the given flags on the bin. `ElementFlags` of a
    /// child element are propagated when it is added to the bin.
    /// When suppressed flags are set, those specified flags will
    /// not be propagated to the bin.
    ///
    /// MT safe.
    ///
    /// Feature: `v1_10`
    ///
    /// ## `flags`
    /// the `ElementFlags` to suppress
    #[cfg(any(feature = "v1_10", feature = "dox"))]
    fn set_suppressed_flags(&self, flags: ElementFlags);

    /// Synchronizes the state of every child of `self` with the state
    /// of `self`. See also `ElementExt::sync_state_with_parent`.
    ///
    /// # Returns
    ///
    /// `true` if syncing the state was successful for all children,
    ///  otherwise `false`.
    fn sync_children_states(&self) -> Result<(), glib::error::BoolError>;

    fn get_property_async_handling(&self) -> bool;

    fn set_property_async_handling(&self, async_handling: bool);

    fn get_property_message_forward(&self) -> bool;

    fn set_property_message_forward(&self, message_forward: bool);

    /// Will be emitted after the element was added to sub_bin.
    ///
    /// Feature: `v1_10`
    ///
    /// ## `sub_bin`
    /// the `Bin` the element was added to
    /// ## `element`
    /// the `Element` that was added to `sub_bin`
    #[cfg(any(feature = "v1_10", feature = "dox"))]
    fn connect_deep_element_added<F: Fn(&Self, &Bin, &Element) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId;

    /// Will be emitted after the element was removed from sub_bin.
    ///
    /// Feature: `v1_10`
    ///
    /// ## `sub_bin`
    /// the `Bin` the element was removed from
    /// ## `element`
    /// the `Element` that was removed from `sub_bin`
    #[cfg(any(feature = "v1_10", feature = "dox"))]
    fn connect_deep_element_removed<F: Fn(&Self, &Bin, &Element) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId;

    /// Will be emitted when the bin needs to perform latency calculations. This
    /// signal is only emitted for toplevel bins or when async-handling is
    /// enabled.
    ///
    /// Only one signal handler is invoked. If no signals are connected, the
    /// default handler is invoked, which will query and distribute the lowest
    /// possible latency to all sinks.
    ///
    /// Connect to this signal if the default latency calculations are not
    /// sufficient, like when you need different latencies for different sinks in
    /// the same pipeline.
    fn connect_do_latency<F: Fn(&Self) -> bool + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId;

    /// Will be emitted after the element was added to the bin.
    /// ## `element`
    /// the `Element` that was added to the bin
    fn connect_element_added<F: Fn(&Self, &Element) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId;

    /// Will be emitted after the element was removed from the bin.
    /// ## `element`
    /// the `Element` that was removed from the bin
    fn connect_element_removed<F: Fn(&Self, &Element) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId;

    fn connect_property_async_handling_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId;

    fn connect_property_message_forward_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId;
}

impl<O: IsA<Bin> + IsA<glib::object::Object>> BinExt for O {
    fn add<P: IsA<Element>>(&self, element: &P) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib::error::BoolError::from_glib(ffi::gst_bin_add(self.to_glib_none().0, element.to_glib_none().0), "Failed to add element")
        }
    }

    //fn add_many<P: IsA<Element>>(&self, element_1: &P, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) {
    //    unsafe { TODO: call ffi::gst_bin_add_many() }
    //}

    fn find_unlinked_pad(&self, direction: PadDirection) -> Option<Pad> {
        unsafe {
            from_glib_full(ffi::gst_bin_find_unlinked_pad(self.to_glib_none().0, direction.to_glib()))
        }
    }

    fn get_by_interface(&self, iface: glib::types::Type) -> Option<Element> {
        unsafe {
            from_glib_full(ffi::gst_bin_get_by_interface(self.to_glib_none().0, iface.to_glib()))
        }
    }

    fn get_by_name(&self, name: &str) -> Option<Element> {
        unsafe {
            from_glib_full(ffi::gst_bin_get_by_name(self.to_glib_none().0, name.to_glib_none().0))
        }
    }

    fn get_by_name_recurse_up(&self, name: &str) -> Option<Element> {
        unsafe {
            from_glib_full(ffi::gst_bin_get_by_name_recurse_up(self.to_glib_none().0, name.to_glib_none().0))
        }
    }

    #[cfg(any(feature = "v1_10", feature = "dox"))]
    fn get_suppressed_flags(&self) -> ElementFlags {
        unsafe {
            from_glib(ffi::gst_bin_get_suppressed_flags(self.to_glib_none().0))
        }
    }

    //fn iterate_all_by_interface(&self, iface: glib::types::Type) -> /*Ignored*/Option<Iterator> {
    //    unsafe { TODO: call ffi::gst_bin_iterate_all_by_interface() }
    //}

    //fn iterate_elements(&self) -> /*Ignored*/Option<Iterator> {
    //    unsafe { TODO: call ffi::gst_bin_iterate_elements() }
    //}

    //fn iterate_recurse(&self) -> /*Ignored*/Option<Iterator> {
    //    unsafe { TODO: call ffi::gst_bin_iterate_recurse() }
    //}

    //fn iterate_sinks(&self) -> /*Ignored*/Option<Iterator> {
    //    unsafe { TODO: call ffi::gst_bin_iterate_sinks() }
    //}

    //fn iterate_sorted(&self) -> /*Ignored*/Option<Iterator> {
    //    unsafe { TODO: call ffi::gst_bin_iterate_sorted() }
    //}

    //fn iterate_sources(&self) -> /*Ignored*/Option<Iterator> {
    //    unsafe { TODO: call ffi::gst_bin_iterate_sources() }
    //}

    fn recalculate_latency(&self) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib::error::BoolError::from_glib(ffi::gst_bin_recalculate_latency(self.to_glib_none().0), "Failed to recalculate latency")
        }
    }

    fn remove<P: IsA<Element>>(&self, element: &P) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib::error::BoolError::from_glib(ffi::gst_bin_remove(self.to_glib_none().0, element.to_glib_none().0), "Failed to remove element")
        }
    }

    //fn remove_many<P: IsA<Element>>(&self, element_1: &P, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) {
    //    unsafe { TODO: call ffi::gst_bin_remove_many() }
    //}

    #[cfg(any(feature = "v1_10", feature = "dox"))]
    fn set_suppressed_flags(&self, flags: ElementFlags) {
        unsafe {
            ffi::gst_bin_set_suppressed_flags(self.to_glib_none().0, flags.to_glib());
        }
    }

    fn sync_children_states(&self) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib::error::BoolError::from_glib(ffi::gst_bin_sync_children_states(self.to_glib_none().0), "Failed to sync children states")
        }
    }

    fn get_property_async_handling(&self) -> bool {
        unsafe {
            let mut value = Value::from_type(<bool as StaticType>::static_type());
            gobject_ffi::g_object_get_property(self.to_glib_none().0, "async-handling".to_glib_none().0, value.to_glib_none_mut().0);
            value.get().unwrap()
        }
    }

    fn set_property_async_handling(&self, async_handling: bool) {
        unsafe {
            gobject_ffi::g_object_set_property(self.to_glib_none().0, "async-handling".to_glib_none().0, Value::from(&async_handling).to_glib_none().0);
        }
    }

    fn get_property_message_forward(&self) -> bool {
        unsafe {
            let mut value = Value::from_type(<bool as StaticType>::static_type());
            gobject_ffi::g_object_get_property(self.to_glib_none().0, "message-forward".to_glib_none().0, value.to_glib_none_mut().0);
            value.get().unwrap()
        }
    }

    fn set_property_message_forward(&self, message_forward: bool) {
        unsafe {
            gobject_ffi::g_object_set_property(self.to_glib_none().0, "message-forward".to_glib_none().0, Value::from(&message_forward).to_glib_none().0);
        }
    }

    #[cfg(any(feature = "v1_10", feature = "dox"))]
    fn connect_deep_element_added<F: Fn(&Self, &Bin, &Element) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe {
            let f: Box_<Box_<Fn(&Self, &Bin, &Element) + Send + Sync + 'static>> = Box_::new(Box_::new(f));
            connect(self.to_glib_none().0, "deep-element-added",
                transmute(deep_element_added_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
        }
    }

    #[cfg(any(feature = "v1_10", feature = "dox"))]
    fn connect_deep_element_removed<F: Fn(&Self, &Bin, &Element) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe {
            let f: Box_<Box_<Fn(&Self, &Bin, &Element) + Send + Sync + 'static>> = Box_::new(Box_::new(f));
            connect(self.to_glib_none().0, "deep-element-removed",
                transmute(deep_element_removed_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
        }
    }

    fn connect_do_latency<F: Fn(&Self) -> bool + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe {
            let f: Box_<Box_<Fn(&Self) -> bool + Send + Sync + 'static>> = Box_::new(Box_::new(f));
            connect(self.to_glib_none().0, "do-latency",
                transmute(do_latency_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
        }
    }

    fn connect_element_added<F: Fn(&Self, &Element) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe {
            let f: Box_<Box_<Fn(&Self, &Element) + Send + Sync + 'static>> = Box_::new(Box_::new(f));
            connect(self.to_glib_none().0, "element-added",
                transmute(element_added_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
        }
    }

    fn connect_element_removed<F: Fn(&Self, &Element) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe {
            let f: Box_<Box_<Fn(&Self, &Element) + Send + Sync + 'static>> = Box_::new(Box_::new(f));
            connect(self.to_glib_none().0, "element-removed",
                transmute(element_removed_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
        }
    }

    fn connect_property_async_handling_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe {
            let f: Box_<Box_<Fn(&Self) + Send + Sync + 'static>> = Box_::new(Box_::new(f));
            connect(self.to_glib_none().0, "notify::async-handling",
                transmute(notify_async_handling_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
        }
    }

    fn connect_property_message_forward_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe {
            let f: Box_<Box_<Fn(&Self) + Send + Sync + 'static>> = Box_::new(Box_::new(f));
            connect(self.to_glib_none().0, "notify::message-forward",
                transmute(notify_message_forward_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
        }
    }
}

#[cfg(any(feature = "v1_10", feature = "dox"))]
unsafe extern "C" fn deep_element_added_trampoline<P>(this: *mut ffi::GstBin, sub_bin: *mut ffi::GstBin, element: *mut ffi::GstElement, f: glib_ffi::gpointer)
where P: IsA<Bin> {
    let f: &&(Fn(&P, &Bin, &Element) + Send + Sync + 'static) = transmute(f);
    f(&Bin::from_glib_borrow(this).downcast_unchecked(), &from_glib_borrow(sub_bin), &from_glib_borrow(element))
}

#[cfg(any(feature = "v1_10", feature = "dox"))]
unsafe extern "C" fn deep_element_removed_trampoline<P>(this: *mut ffi::GstBin, sub_bin: *mut ffi::GstBin, element: *mut ffi::GstElement, f: glib_ffi::gpointer)
where P: IsA<Bin> {
    let f: &&(Fn(&P, &Bin, &Element) + Send + Sync + 'static) = transmute(f);
    f(&Bin::from_glib_borrow(this).downcast_unchecked(), &from_glib_borrow(sub_bin), &from_glib_borrow(element))
}

unsafe extern "C" fn do_latency_trampoline<P>(this: *mut ffi::GstBin, f: glib_ffi::gpointer) -> glib_ffi::gboolean
where P: IsA<Bin> {
    let f: &&(Fn(&P) -> bool + Send + Sync + 'static) = transmute(f);
    f(&Bin::from_glib_borrow(this).downcast_unchecked()).to_glib()
}

unsafe extern "C" fn element_added_trampoline<P>(this: *mut ffi::GstBin, element: *mut ffi::GstElement, f: glib_ffi::gpointer)
where P: IsA<Bin> {
    let f: &&(Fn(&P, &Element) + Send + Sync + 'static) = transmute(f);
    f(&Bin::from_glib_borrow(this).downcast_unchecked(), &from_glib_borrow(element))
}

unsafe extern "C" fn element_removed_trampoline<P>(this: *mut ffi::GstBin, element: *mut ffi::GstElement, f: glib_ffi::gpointer)
where P: IsA<Bin> {
    let f: &&(Fn(&P, &Element) + Send + Sync + 'static) = transmute(f);
    f(&Bin::from_glib_borrow(this).downcast_unchecked(), &from_glib_borrow(element))
}

unsafe extern "C" fn notify_async_handling_trampoline<P>(this: *mut ffi::GstBin, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<Bin> {
    let f: &&(Fn(&P) + Send + Sync + 'static) = transmute(f);
    f(&Bin::from_glib_borrow(this).downcast_unchecked())
}

unsafe extern "C" fn notify_message_forward_trampoline<P>(this: *mut ffi::GstBin, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<Bin> {
    let f: &&(Fn(&P) + Send + Sync + 'static) = transmute(f);
    f(&Bin::from_glib_borrow(this).downcast_unchecked())
}