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
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
// DO NOT EDIT

use crate::{
    Buffer, BufferList, Caps, Element, Event, FlowError, FlowSuccess, Object, PadDirection,
    PadLinkCheck, PadLinkError, PadLinkSuccess, PadMode, PadTemplate, Stream, TaskState,
};
use glib::{
    prelude::*,
    signal::{connect_raw, SignalHandlerId},
    translate::*,
};
use std::boxed::Box as Box_;

glib::wrapper! {
    /// A [`Element`][crate::Element] is linked to other elements via "pads", which are extremely
    /// light-weight generic link points.
    ///
    /// Pads have a [`PadDirection`][crate::PadDirection], source pads produce data, sink pads consume
    /// data.
    ///
    /// Pads are typically created from a [`PadTemplate`][crate::PadTemplate] with
    /// [`from_template()`][Self::from_template()] and are then added to a [`Element`][crate::Element]. This usually
    /// happens when the element is created but it can also happen dynamically based
    /// on the data that the element is processing or based on the pads that the
    /// application requests.
    ///
    /// Pads without pad templates can be created with [`new()`][Self::new()],
    /// which takes a direction and a name as an argument. If the name is [`None`],
    /// then a guaranteed unique name will be assigned to it.
    ///
    /// A [`Element`][crate::Element] creating a pad will typically use the various
    /// gst_pad_set_*_function\() calls to register callbacks for events, queries or
    /// dataflow on the pads.
    ///
    /// `gst_pad_get_parent()` will retrieve the [`Element`][crate::Element] that owns the pad.
    ///
    /// After two pads are retrieved from an element by [`ElementExt::static_pad()`][crate::prelude::ElementExt::static_pad()],
    /// the pads can be linked with [`PadExt::link()`][crate::prelude::PadExt::link()]. (For quick links,
    /// you can also use [`ElementExtManual::link()`][crate::prelude::ElementExtManual::link()], which will make the obvious
    /// link for you if it's straightforward.). Pads can be unlinked again with
    /// [`PadExt::unlink()`][crate::prelude::PadExt::unlink()]. [`PadExt::peer()`][crate::prelude::PadExt::peer()] can be used to check what the pad is
    /// linked to.
    ///
    /// Before dataflow is possible on the pads, they need to be activated with
    /// [`PadExt::set_active()`][crate::prelude::PadExt::set_active()].
    ///
    /// [`PadExtManual::query()`][crate::prelude::PadExtManual::query()] and [`PadExtManual::peer_query()`][crate::prelude::PadExtManual::peer_query()] can be used to query various
    /// properties of the pad and the stream.
    ///
    /// To send a [`Event`][crate::Event] on a pad, use [`PadExtManual::send_event()`][crate::prelude::PadExtManual::send_event()] and
    /// [`PadExtManual::push_event()`][crate::prelude::PadExtManual::push_event()]. Some events will be sticky on the pad, meaning that
    /// after they pass on the pad they can be queried later with
    /// [`PadExtManual::sticky_event()`][crate::prelude::PadExtManual::sticky_event()] and [`PadExtManual::sticky_events_foreach()`][crate::prelude::PadExtManual::sticky_events_foreach()].
    /// [`PadExt::current_caps()`][crate::prelude::PadExt::current_caps()] and [`PadExt::has_current_caps()`][crate::prelude::PadExt::has_current_caps()] are convenience
    /// functions to query the current sticky CAPS event on a pad.
    ///
    /// GstElements will use [`PadExt::push()`][crate::prelude::PadExt::push()] and [`PadExtManual::pull_range()`][crate::prelude::PadExtManual::pull_range()] to push out
    /// or pull in a buffer.
    ///
    /// The dataflow, events and queries that happen on a pad can be monitored with
    /// probes that can be installed with [`PadExtManual::add_probe()`][crate::prelude::PadExtManual::add_probe()]. [`PadExt::is_blocked()`][crate::prelude::PadExt::is_blocked()]
    /// can be used to check if a block probe is installed on the pad.
    /// [`PadExt::is_blocking()`][crate::prelude::PadExt::is_blocking()] checks if the blocking probe is currently blocking the
    /// pad. [`PadExtManual::remove_probe()`][crate::prelude::PadExtManual::remove_probe()] is used to remove a previously installed probe
    /// and unblock blocking probes if any.
    ///
    /// Pad have an offset that can be retrieved with [`PadExt::offset()`][crate::prelude::PadExt::offset()]. This
    /// offset will be applied to the running_time of all data passing over the pad.
    /// [`PadExt::set_offset()`][crate::prelude::PadExt::set_offset()] can be used to change the offset.
    ///
    /// Convenience functions exist to start, pause and stop the task on a pad with
    /// [`PadExtManual::start_task()`][crate::prelude::PadExtManual::start_task()], [`PadExt::pause_task()`][crate::prelude::PadExt::pause_task()] and [`PadExt::stop_task()`][crate::prelude::PadExt::stop_task()]
    /// respectively.
    ///
    /// ## Properties
    ///
    ///
    /// #### `caps`
    ///  Readable
    ///
    ///
    /// #### `direction`
    ///  Readable | Writeable | Construct Only
    ///
    ///
    /// #### `offset`
    ///  The offset that will be applied to the running time of the pad.
    ///
    /// Readable | Writeable
    ///
    ///
    /// #### `template`
    ///  Readable | Writeable
    /// <details><summary><h4>Object</h4></summary>
    ///
    ///
    /// #### `name`
    ///  Readable | Writeable | Construct
    ///
    ///
    /// #### `parent`
    ///  The parent of the object. Please note, that when changing the 'parent'
    /// property, we don't emit [`notify`][struct@crate::glib::Object#notify] and [`deep-notify`][struct@crate::Object#deep-notify]
    /// signals due to locking issues. In some cases one can use
    /// [`element-added`][struct@crate::Bin#element-added] or [`element-removed`][struct@crate::Bin#element-removed] signals on the parent to
    /// achieve a similar effect.
    ///
    /// Readable | Writeable
    /// </details>
    ///
    /// ## Signals
    ///
    ///
    /// #### `linked`
    ///  Signals that a pad has been linked to the peer pad.
    ///
    ///
    ///
    ///
    /// #### `unlinked`
    ///  Signals that a pad has been unlinked from the peer pad.
    ///
    ///
    /// <details><summary><h4>Object</h4></summary>
    ///
    ///
    /// #### `deep-notify`
    ///  The deep notify signal is used to be notified of property changes. It is
    /// typically attached to the toplevel bin to receive notifications from all
    /// the elements contained in that bin.
    ///
    /// Detailed
    /// </details>
    ///
    /// # Implements
    ///
    /// [`PadExt`][trait@crate::prelude::PadExt], [`GstObjectExt`][trait@crate::prelude::GstObjectExt], [`trait@glib::ObjectExt`], [`PadExtManual`][trait@crate::prelude::PadExtManual]
    #[doc(alias = "GstPad")]
    pub struct Pad(Object<ffi::GstPad, ffi::GstPadClass>) @extends Object;

    match fn {
        type_ => || ffi::gst_pad_get_type(),
    }
}

impl Pad {
    pub const NONE: Option<&'static Pad> = None;
}

unsafe impl Send for Pad {}
unsafe impl Sync for Pad {}

mod sealed {
    pub trait Sealed {}
    impl<T: super::IsA<super::Pad>> Sealed for T {}
}

/// Trait containing all [`struct@Pad`] methods.
///
/// # Implementors
///
/// [`Pad`][struct@crate::Pad], [`ProxyPad`][struct@crate::ProxyPad]
pub trait PadExt: IsA<Pad> + sealed::Sealed + 'static {
    /// Activates or deactivates the given pad in `mode` via dispatching to the
    /// pad's activatemodefunc. For use from within pad activation functions only.
    ///
    /// If you don't know what this is, you probably don't want to call it.
    /// ## `mode`
    /// the requested activation mode
    /// ## `active`
    /// whether or not the pad should be active.
    ///
    /// # Returns
    ///
    /// [`true`] if the operation was successful.
    ///
    /// MT safe.
    #[doc(alias = "gst_pad_activate_mode")]
    fn activate_mode(&self, mode: PadMode, active: bool) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib::result_from_gboolean!(
                ffi::gst_pad_activate_mode(
                    self.as_ref().to_glib_none().0,
                    mode.into_glib(),
                    active.into_glib()
                ),
                "Failed to activate mode pad"
            )
        }
    }

    /// Checks if the source pad and the sink pad are compatible so they can be
    /// linked.
    /// ## `sinkpad`
    /// the sink [`Pad`][crate::Pad].
    ///
    /// # Returns
    ///
    /// [`true`] if the pads can be linked.
    #[doc(alias = "gst_pad_can_link")]
    fn can_link(&self, sinkpad: &impl IsA<Pad>) -> bool {
        unsafe {
            from_glib(ffi::gst_pad_can_link(
                self.as_ref().to_glib_none().0,
                sinkpad.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Chain a buffer to `self`.
    ///
    /// The function returns [`FlowReturn::Flushing`][crate::FlowReturn::Flushing] if the pad was flushing.
    ///
    /// If the buffer type is not acceptable for `self` (as negotiated with a
    /// preceding GST_EVENT_CAPS event), this function returns
    /// [`FlowReturn::NotNegotiated`][crate::FlowReturn::NotNegotiated].
    ///
    /// The function proceeds calling the chain function installed on `self` (see
    /// `gst_pad_set_chain_function()`) and the return value of that function is
    /// returned to the caller. [`FlowReturn::NotSupported`][crate::FlowReturn::NotSupported] is returned if `self` has no
    /// chain function.
    ///
    /// In all cases, success or failure, the caller loses its reference to `buffer`
    /// after calling this function.
    /// ## `buffer`
    /// the [`Buffer`][crate::Buffer] to send, return GST_FLOW_ERROR
    ///  if not.
    ///
    /// # Returns
    ///
    /// a [`FlowReturn`][crate::FlowReturn] from the pad.
    ///
    /// MT safe.
    #[doc(alias = "gst_pad_chain")]
    fn chain(&self, buffer: Buffer) -> Result<FlowSuccess, FlowError> {
        unsafe {
            try_from_glib(ffi::gst_pad_chain(
                self.as_ref().to_glib_none().0,
                buffer.into_glib_ptr(),
            ))
        }
    }

    /// Chain a bufferlist to `self`.
    ///
    /// The function returns [`FlowReturn::Flushing`][crate::FlowReturn::Flushing] if the pad was flushing.
    ///
    /// If `self` was not negotiated properly with a CAPS event, this function
    /// returns [`FlowReturn::NotNegotiated`][crate::FlowReturn::NotNegotiated].
    ///
    /// The function proceeds calling the chainlist function installed on `self` (see
    /// `gst_pad_set_chain_list_function()`) and the return value of that function is
    /// returned to the caller. [`FlowReturn::NotSupported`][crate::FlowReturn::NotSupported] is returned if `self` has no
    /// chainlist function.
    ///
    /// In all cases, success or failure, the caller loses its reference to `list`
    /// after calling this function.
    ///
    /// MT safe.
    /// ## `list`
    /// the [`BufferList`][crate::BufferList] to send, return GST_FLOW_ERROR
    ///  if not.
    ///
    /// # Returns
    ///
    /// a [`FlowReturn`][crate::FlowReturn] from the pad.
    #[doc(alias = "gst_pad_chain_list")]
    fn chain_list(&self, list: BufferList) -> Result<FlowSuccess, FlowError> {
        unsafe {
            try_from_glib(ffi::gst_pad_chain_list(
                self.as_ref().to_glib_none().0,
                list.into_glib_ptr(),
            ))
        }
    }

    /// Check and clear the [`PadFlags::NEED_RECONFIGURE`][crate::PadFlags::NEED_RECONFIGURE] flag on `self` and return [`true`]
    /// if the flag was set.
    ///
    /// # Returns
    ///
    /// [`true`] is the GST_PAD_FLAG_NEED_RECONFIGURE flag was set on `self`.
    #[doc(alias = "gst_pad_check_reconfigure")]
    fn check_reconfigure(&self) -> bool {
        unsafe {
            from_glib(ffi::gst_pad_check_reconfigure(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Creates a stream-id for the source [`Pad`][crate::Pad] `self` by combining the
    /// upstream information with the optional `stream_id` of the stream
    /// of `self`. `self` must have a parent [`Element`][crate::Element] and which must have zero
    /// or one sinkpad. `stream_id` can only be [`None`] if the parent element
    /// of `self` has only a single source pad.
    ///
    /// This function generates an unique stream-id by getting the upstream
    /// stream-start event stream ID and appending `stream_id` to it. If the
    /// element has no sinkpad it will generate an upstream stream-id by
    /// doing an URI query on the element and in the worst case just uses
    /// a random number. Source elements that don't implement the URI
    /// handler interface should ideally generate a unique, deterministic
    /// stream-id manually instead.
    ///
    /// Since stream IDs are sorted alphabetically, any numbers in the
    /// stream ID should be printed with a fixed number of characters,
    /// preceded by 0's, such as by using the format \`03u` instead of \`u`.
    /// ## `parent`
    /// Parent [`Element`][crate::Element] of `self`
    /// ## `stream_id`
    /// The stream-id
    ///
    /// # Returns
    ///
    /// A stream-id for `self`. `g_free()` after usage.
    #[doc(alias = "gst_pad_create_stream_id")]
    fn create_stream_id(
        &self,
        parent: &impl IsA<Element>,
        stream_id: Option<&str>,
    ) -> glib::GString {
        unsafe {
            from_glib_full(ffi::gst_pad_create_stream_id(
                self.as_ref().to_glib_none().0,
                parent.as_ref().to_glib_none().0,
                stream_id.to_glib_none().0,
            ))
        }
    }

    //#[doc(alias = "gst_pad_create_stream_id_printf")]
    //fn create_stream_id_printf(&self, parent: &impl IsA<Element>, stream_id: Option<&str>, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) -> glib::GString {
    //    unsafe { TODO: call ffi:gst_pad_create_stream_id_printf() }
    //}

    //#[doc(alias = "gst_pad_create_stream_id_printf_valist")]
    //fn create_stream_id_printf_valist(&self, parent: &impl IsA<Element>, stream_id: Option<&str>, var_args: /*Unknown conversion*//*Unimplemented*/Unsupported) -> glib::GString {
    //    unsafe { TODO: call ffi:gst_pad_create_stream_id_printf_valist() }
    //}

    /// Calls `forward` for all internally linked pads of `self`. This function deals with
    /// dynamically changing internal pads and will make sure that the `forward`
    /// function is only called once for each pad.
    ///
    /// When `forward` returns [`true`], no further pads will be processed.
    /// ## `forward`
    /// a `GstPadForwardFunction`
    ///
    /// # Returns
    ///
    /// [`true`] if one of the dispatcher functions returned [`true`].
    #[doc(alias = "gst_pad_forward")]
    fn forward<P: FnMut(&Pad) -> bool>(&self, forward: P) -> bool {
        let forward_data: P = forward;
        unsafe extern "C" fn forward_func<P: FnMut(&Pad) -> bool>(
            pad: *mut ffi::GstPad,
            user_data: glib::ffi::gpointer,
        ) -> glib::ffi::gboolean {
            let pad = from_glib_borrow(pad);
            let callback = user_data as *mut P;
            (*callback)(&pad).into_glib()
        }
        let forward = Some(forward_func::<P> as _);
        let super_callback0: &P = &forward_data;
        unsafe {
            from_glib(ffi::gst_pad_forward(
                self.as_ref().to_glib_none().0,
                forward,
                super_callback0 as *const _ as *mut _,
            ))
        }
    }

    /// Gets the capabilities of the allowed media types that can flow through
    /// `self` and its peer.
    ///
    /// The allowed capabilities is calculated as the intersection of the results of
    /// calling [`query_caps()`][Self::query_caps()] on `self` and its peer. The caller owns a reference
    /// on the resulting caps.
    ///
    /// # Returns
    ///
    /// the allowed [`Caps`][crate::Caps] of the
    ///  pad link. Unref the caps when you no longer need it. This
    ///  function returns [`None`] when `self` has no peer.
    ///
    /// MT safe.
    #[doc(alias = "gst_pad_get_allowed_caps")]
    #[doc(alias = "get_allowed_caps")]
    fn allowed_caps(&self) -> Option<Caps> {
        unsafe {
            from_glib_full(ffi::gst_pad_get_allowed_caps(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Gets the capabilities currently configured on `self` with the last
    /// [`EventType::Caps`][crate::EventType::Caps] event.
    ///
    /// # Returns
    ///
    /// the current caps of the pad with
    /// incremented ref-count or [`None`] when pad has no caps. Unref after usage.
    #[doc(alias = "gst_pad_get_current_caps")]
    #[doc(alias = "get_current_caps")]
    fn current_caps(&self) -> Option<Caps> {
        unsafe {
            from_glib_full(ffi::gst_pad_get_current_caps(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Gets the direction of the pad. The direction of the pad is
    /// decided at construction time so this function does not take
    /// the LOCK.
    ///
    /// # Returns
    ///
    /// the [`PadDirection`][crate::PadDirection] of the pad.
    ///
    /// MT safe.
    #[doc(alias = "gst_pad_get_direction")]
    #[doc(alias = "get_direction")]
    fn direction(&self) -> PadDirection {
        unsafe { from_glib(ffi::gst_pad_get_direction(self.as_ref().to_glib_none().0)) }
    }

    //#[doc(alias = "gst_pad_get_element_private")]
    //#[doc(alias = "get_element_private")]
    //fn element_private(&self) -> /*Unimplemented*/Option<Basic: Pointer> {
    //    unsafe { TODO: call ffi:gst_pad_get_element_private() }
    //}

    /// Gets the [`FlowReturn`][crate::FlowReturn] return from the last data passed by this pad.
    #[doc(alias = "gst_pad_get_last_flow_return")]
    #[doc(alias = "get_last_flow_return")]
    fn last_flow_result(&self) -> Result<FlowSuccess, FlowError> {
        unsafe {
            try_from_glib(ffi::gst_pad_get_last_flow_return(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Get the offset applied to the running time of `self`. `self` has to be a source
    /// pad.
    ///
    /// # Returns
    ///
    /// the offset.
    #[doc(alias = "gst_pad_get_offset")]
    #[doc(alias = "get_offset")]
    fn offset(&self) -> i64 {
        unsafe { ffi::gst_pad_get_offset(self.as_ref().to_glib_none().0) }
    }

    /// Gets the template for `self`.
    ///
    /// # Returns
    ///
    /// the [`PadTemplate`][crate::PadTemplate] from which
    ///  this pad was instantiated, or [`None`] if this pad has no
    ///  template. Unref after usage.
    #[doc(alias = "gst_pad_get_pad_template")]
    #[doc(alias = "get_pad_template")]
    fn pad_template(&self) -> Option<PadTemplate> {
        unsafe {
            from_glib_full(ffi::gst_pad_get_pad_template(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Gets the capabilities for `self`'s template.
    ///
    /// # Returns
    ///
    /// the [`Caps`][crate::Caps] of this pad template.
    /// Unref after usage.
    #[doc(alias = "gst_pad_get_pad_template_caps")]
    #[doc(alias = "get_pad_template_caps")]
    fn pad_template_caps(&self) -> Caps {
        unsafe {
            from_glib_full(ffi::gst_pad_get_pad_template_caps(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Gets the parent of `self`, cast to a [`Element`][crate::Element]. If a `self` has no parent or
    /// its parent is not an element, return [`None`].
    ///
    /// # Returns
    ///
    /// the parent of the pad. The
    /// caller has a reference on the parent, so unref when you're finished
    /// with it.
    ///
    /// MT safe.
    #[doc(alias = "gst_pad_get_parent_element")]
    #[doc(alias = "get_parent_element")]
    fn parent_element(&self) -> Option<Element> {
        unsafe {
            from_glib_full(ffi::gst_pad_get_parent_element(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Gets the peer of `self`. This function refs the peer pad so
    /// you need to unref it after use.
    ///
    /// # Returns
    ///
    /// the peer [`Pad`][crate::Pad]. Unref after usage.
    ///
    /// MT safe.
    #[doc(alias = "gst_pad_get_peer")]
    #[doc(alias = "get_peer")]
    #[must_use]
    fn peer(&self) -> Option<Pad> {
        unsafe { from_glib_full(ffi::gst_pad_get_peer(self.as_ref().to_glib_none().0)) }
    }

    /// If there is a single internal link of the given pad, this function will
    /// return it. Otherwise, it will return NULL.
    ///
    /// # Returns
    ///
    /// a [`Pad`][crate::Pad], or [`None`] if `self` has none
    /// or more than one internal links. Unref returned pad with
    /// `gst_object_unref()`.
    #[cfg(feature = "v1_18")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
    #[doc(alias = "gst_pad_get_single_internal_link")]
    #[doc(alias = "get_single_internal_link")]
    #[must_use]
    fn single_internal_link(&self) -> Option<Pad> {
        unsafe {
            from_glib_full(ffi::gst_pad_get_single_internal_link(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Returns the current [`Stream`][crate::Stream] for the `self`, or [`None`] if none has been
    /// set yet, i.e. the pad has not received a stream-start event yet.
    ///
    /// This is a convenience wrapper around [`PadExtManual::sticky_event()`][crate::prelude::PadExtManual::sticky_event()] and
    /// `gst_event_parse_stream()`.
    ///
    /// # Returns
    ///
    /// the current [`Stream`][crate::Stream] for `self`, or [`None`].
    ///  unref the returned stream when no longer needed.
    #[doc(alias = "gst_pad_get_stream")]
    #[doc(alias = "get_stream")]
    fn stream(&self) -> Option<Stream> {
        unsafe { from_glib_full(ffi::gst_pad_get_stream(self.as_ref().to_glib_none().0)) }
    }

    /// Returns the current stream-id for the `self`, or [`None`] if none has been
    /// set yet, i.e. the pad has not received a stream-start event yet.
    ///
    /// This is a convenience wrapper around [`PadExtManual::sticky_event()`][crate::prelude::PadExtManual::sticky_event()] and
    /// `gst_event_parse_stream_start()`.
    ///
    /// The returned stream-id string should be treated as an opaque string, its
    /// contents should not be interpreted.
    ///
    /// # Returns
    ///
    /// a newly-allocated copy of the stream-id for
    ///  `self`, or [`None`]. `g_free()` the returned string when no longer
    ///  needed.
    #[doc(alias = "gst_pad_get_stream_id")]
    #[doc(alias = "get_stream_id")]
    fn stream_id(&self) -> Option<glib::GString> {
        unsafe { from_glib_full(ffi::gst_pad_get_stream_id(self.as_ref().to_glib_none().0)) }
    }

    /// Get `self` task state. If no task is currently
    /// set, [`TaskState::Stopped`][crate::TaskState::Stopped] is returned.
    ///
    /// # Returns
    ///
    /// The current state of `self`'s task.
    #[doc(alias = "gst_pad_get_task_state")]
    #[doc(alias = "get_task_state")]
    fn task_state(&self) -> TaskState {
        unsafe { from_glib(ffi::gst_pad_get_task_state(self.as_ref().to_glib_none().0)) }
    }

    /// Check if `self` has caps set on it with a [`EventType::Caps`][crate::EventType::Caps] event.
    ///
    /// # Returns
    ///
    /// [`true`] when `self` has caps associated with it.
    #[doc(alias = "gst_pad_has_current_caps")]
    fn has_current_caps(&self) -> bool {
        unsafe {
            from_glib(ffi::gst_pad_has_current_caps(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Query if a pad is active
    ///
    /// # Returns
    ///
    /// [`true`] if the pad is active.
    ///
    /// MT safe.
    #[doc(alias = "gst_pad_is_active")]
    fn is_active(&self) -> bool {
        unsafe { from_glib(ffi::gst_pad_is_active(self.as_ref().to_glib_none().0)) }
    }

    /// Checks if the pad is blocked or not. This function returns the
    /// last requested state of the pad. It is not certain that the pad
    /// is actually blocking at this point (see [`is_blocking()`][Self::is_blocking()]).
    ///
    /// # Returns
    ///
    /// [`true`] if the pad is blocked.
    ///
    /// MT safe.
    #[doc(alias = "gst_pad_is_blocked")]
    fn is_blocked(&self) -> bool {
        unsafe { from_glib(ffi::gst_pad_is_blocked(self.as_ref().to_glib_none().0)) }
    }

    /// Checks if the pad is blocking or not. This is a guaranteed state
    /// of whether the pad is actually blocking on a [`Buffer`][crate::Buffer] or a [`Event`][crate::Event].
    ///
    /// # Returns
    ///
    /// [`true`] if the pad is blocking.
    ///
    /// MT safe.
    #[doc(alias = "gst_pad_is_blocking")]
    fn is_blocking(&self) -> bool {
        unsafe { from_glib(ffi::gst_pad_is_blocking(self.as_ref().to_glib_none().0)) }
    }

    /// Checks if a `self` is linked to another pad or not.
    ///
    /// # Returns
    ///
    /// [`true`] if the pad is linked, [`false`] otherwise.
    ///
    /// MT safe.
    #[doc(alias = "gst_pad_is_linked")]
    fn is_linked(&self) -> bool {
        unsafe { from_glib(ffi::gst_pad_is_linked(self.as_ref().to_glib_none().0)) }
    }

    //#[doc(alias = "gst_pad_iterate_internal_links")]
    //fn iterate_internal_links(&self) -> /*Ignored*/Option<Iterator> {
    //    unsafe { TODO: call ffi:gst_pad_iterate_internal_links() }
    //}

    //#[doc(alias = "gst_pad_iterate_internal_links_default")]
    //fn iterate_internal_links_default(&self, parent: Option<&impl IsA<Object>>) -> /*Ignored*/Option<Iterator> {
    //    unsafe { TODO: call ffi:gst_pad_iterate_internal_links_default() }
    //}

    /// Links the source pad and the sink pad.
    /// ## `sinkpad`
    /// the sink [`Pad`][crate::Pad] to link.
    ///
    /// # Returns
    ///
    /// A result code indicating if the connection worked or
    ///  what went wrong.
    ///
    /// MT Safe.
    #[doc(alias = "gst_pad_link")]
    fn link(&self, sinkpad: &impl IsA<Pad>) -> Result<PadLinkSuccess, PadLinkError> {
        unsafe {
            try_from_glib(ffi::gst_pad_link(
                self.as_ref().to_glib_none().0,
                sinkpad.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Links the source pad and the sink pad.
    ///
    /// This variant of `gst_pad_link` provides a more granular control on the
    /// checks being done when linking. While providing some considerable speedups
    /// the caller of this method must be aware that wrong usage of those flags
    /// can cause severe issues. Refer to the documentation of [`PadLinkCheck`][crate::PadLinkCheck]
    /// for more information.
    ///
    /// MT Safe.
    /// ## `sinkpad`
    /// the sink [`Pad`][crate::Pad] to link.
    /// ## `flags`
    /// the checks to validate when linking
    ///
    /// # Returns
    ///
    /// A result code indicating if the connection worked or
    ///  what went wrong.
    #[doc(alias = "gst_pad_link_full")]
    fn link_full(
        &self,
        sinkpad: &impl IsA<Pad>,
        flags: PadLinkCheck,
    ) -> Result<PadLinkSuccess, PadLinkError> {
        unsafe {
            try_from_glib(ffi::gst_pad_link_full(
                self.as_ref().to_glib_none().0,
                sinkpad.as_ref().to_glib_none().0,
                flags.into_glib(),
            ))
        }
    }

    /// Links `self` to `sink`, creating any [`GhostPad`][crate::GhostPad]'s in between as necessary.
    ///
    /// This is a convenience function to save having to create and add intermediate
    /// [`GhostPad`][crate::GhostPad]'s as required for linking across [`Bin`][crate::Bin] boundaries.
    ///
    /// If `self` or `sink` pads don't have parent elements or do not share a common
    /// ancestor, the link will fail.
    /// ## `sink`
    /// a [`Pad`][crate::Pad]
    ///
    /// # Returns
    ///
    /// whether the link succeeded.
    #[doc(alias = "gst_pad_link_maybe_ghosting")]
    fn link_maybe_ghosting(&self, sink: &impl IsA<Pad>) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib::result_from_gboolean!(
                ffi::gst_pad_link_maybe_ghosting(
                    self.as_ref().to_glib_none().0,
                    sink.as_ref().to_glib_none().0
                ),
                "Failed to link pads, possibly ghosting"
            )
        }
    }

    /// Links `self` to `sink`, creating any [`GhostPad`][crate::GhostPad]'s in between as necessary.
    ///
    /// This is a convenience function to save having to create and add intermediate
    /// [`GhostPad`][crate::GhostPad]'s as required for linking across [`Bin`][crate::Bin] boundaries.
    ///
    /// If `self` or `sink` pads don't have parent elements or do not share a common
    /// ancestor, the link will fail.
    ///
    /// Calling [`link_maybe_ghosting_full()`][Self::link_maybe_ghosting_full()] with
    /// `flags` == [`PadLinkCheck::DEFAULT`][crate::PadLinkCheck::DEFAULT] is the recommended way of linking
    /// pads with safety checks applied.
    /// ## `sink`
    /// a [`Pad`][crate::Pad]
    /// ## `flags`
    /// some [`PadLinkCheck`][crate::PadLinkCheck] flags
    ///
    /// # Returns
    ///
    /// whether the link succeeded.
    #[doc(alias = "gst_pad_link_maybe_ghosting_full")]
    fn link_maybe_ghosting_full(
        &self,
        sink: &impl IsA<Pad>,
        flags: PadLinkCheck,
    ) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib::result_from_gboolean!(
                ffi::gst_pad_link_maybe_ghosting_full(
                    self.as_ref().to_glib_none().0,
                    sink.as_ref().to_glib_none().0,
                    flags.into_glib()
                ),
                "Failed to link pads, possibly ghosting"
            )
        }
    }

    /// Mark a pad for needing reconfiguration. The next call to
    /// [`check_reconfigure()`][Self::check_reconfigure()] will return [`true`] after this call.
    #[doc(alias = "gst_pad_mark_reconfigure")]
    fn mark_reconfigure(&self) {
        unsafe {
            ffi::gst_pad_mark_reconfigure(self.as_ref().to_glib_none().0);
        }
    }

    /// Check the [`PadFlags::NEED_RECONFIGURE`][crate::PadFlags::NEED_RECONFIGURE] flag on `self` and return [`true`]
    /// if the flag was set.
    ///
    /// # Returns
    ///
    /// [`true`] is the GST_PAD_FLAG_NEED_RECONFIGURE flag is set on `self`.
    #[doc(alias = "gst_pad_needs_reconfigure")]
    fn needs_reconfigure(&self) -> bool {
        unsafe {
            from_glib(ffi::gst_pad_needs_reconfigure(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Pause the task of `self`. This function will also wait until the
    /// function executed by the task is finished if this function is not
    /// called from the task function.
    ///
    /// # Returns
    ///
    /// a [`true`] if the task could be paused or [`false`] when the pad
    /// has no task.
    #[doc(alias = "gst_pad_pause_task")]
    fn pause_task(&self) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib::result_from_gboolean!(
                ffi::gst_pad_pause_task(self.as_ref().to_glib_none().0),
                "Failed to pause pad task"
            )
        }
    }

    /// Check if the peer of `self` accepts `caps`. If `self` has no peer, this function
    /// returns [`true`].
    /// ## `caps`
    /// a [`Caps`][crate::Caps] to check on the pad
    ///
    /// # Returns
    ///
    /// [`true`] if the peer of `self` can accept the caps or `self` has no peer.
    #[doc(alias = "gst_pad_peer_query_accept_caps")]
    fn peer_query_accept_caps(&self, caps: &Caps) -> bool {
        unsafe {
            from_glib(ffi::gst_pad_peer_query_accept_caps(
                self.as_ref().to_glib_none().0,
                caps.to_glib_none().0,
            ))
        }
    }

    /// Gets the capabilities of the peer connected to this pad. Similar to
    /// [`query_caps()`][Self::query_caps()].
    ///
    /// When called on srcpads `filter` contains the caps that
    /// upstream could produce in the order preferred by upstream. When
    /// called on sinkpads `filter` contains the caps accepted by
    /// downstream in the preferred order. `filter` might be [`None`] but
    /// if it is not [`None`] the returned caps will be a subset of `filter`.
    /// ## `filter`
    /// a [`Caps`][crate::Caps] filter, or [`None`].
    ///
    /// # Returns
    ///
    /// the caps of the peer pad with incremented
    /// ref-count. When there is no peer pad, this function returns `filter` or,
    /// when `filter` is [`None`], ANY caps.
    #[doc(alias = "gst_pad_peer_query_caps")]
    fn peer_query_caps(&self, filter: Option<&Caps>) -> Caps {
        unsafe {
            from_glib_full(ffi::gst_pad_peer_query_caps(
                self.as_ref().to_glib_none().0,
                filter.to_glib_none().0,
            ))
        }
    }

    /// Pushes a buffer to the peer of `self`.
    ///
    /// This function will call installed block probes before triggering any
    /// installed data probes.
    ///
    /// The function proceeds calling [`chain()`][Self::chain()] on the peer pad and returns
    /// the value from that function. If `self` has no peer, [`FlowReturn::NotLinked`][crate::FlowReturn::NotLinked] will
    /// be returned.
    ///
    /// In all cases, success or failure, the caller loses its reference to `buffer`
    /// after calling this function.
    /// ## `buffer`
    /// the [`Buffer`][crate::Buffer] to push returns GST_FLOW_ERROR
    ///  if not.
    ///
    /// # Returns
    ///
    /// a [`FlowReturn`][crate::FlowReturn] from the peer pad.
    ///
    /// MT safe.
    #[doc(alias = "gst_pad_push")]
    fn push(&self, buffer: Buffer) -> Result<FlowSuccess, FlowError> {
        unsafe {
            try_from_glib(ffi::gst_pad_push(
                self.as_ref().to_glib_none().0,
                buffer.into_glib_ptr(),
            ))
        }
    }

    /// Pushes a buffer list to the peer of `self`.
    ///
    /// This function will call installed block probes before triggering any
    /// installed data probes.
    ///
    /// The function proceeds calling the chain function on the peer pad and returns
    /// the value from that function. If `self` has no peer, [`FlowReturn::NotLinked`][crate::FlowReturn::NotLinked] will
    /// be returned. If the peer pad does not have any installed chainlist function
    /// every group buffer of the list will be merged into a normal [`Buffer`][crate::Buffer] and
    /// chained via [`chain()`][Self::chain()].
    ///
    /// In all cases, success or failure, the caller loses its reference to `list`
    /// after calling this function.
    /// ## `list`
    /// the [`BufferList`][crate::BufferList] to push returns GST_FLOW_ERROR
    ///  if not.
    ///
    /// # Returns
    ///
    /// a [`FlowReturn`][crate::FlowReturn] from the peer pad.
    ///
    /// MT safe.
    #[doc(alias = "gst_pad_push_list")]
    fn push_list(&self, list: BufferList) -> Result<FlowSuccess, FlowError> {
        unsafe {
            try_from_glib(ffi::gst_pad_push_list(
                self.as_ref().to_glib_none().0,
                list.into_glib_ptr(),
            ))
        }
    }

    /// Check if the given pad accepts the caps.
    /// ## `caps`
    /// a [`Caps`][crate::Caps] to check on the pad
    ///
    /// # Returns
    ///
    /// [`true`] if the pad can accept the caps.
    #[doc(alias = "gst_pad_query_accept_caps")]
    fn query_accept_caps(&self, caps: &Caps) -> bool {
        unsafe {
            from_glib(ffi::gst_pad_query_accept_caps(
                self.as_ref().to_glib_none().0,
                caps.to_glib_none().0,
            ))
        }
    }

    /// Gets the capabilities this pad can produce or consume.
    /// Note that this method doesn't necessarily return the caps set by sending a
    /// `gst_event_new_caps()` - use [`current_caps()`][Self::current_caps()] for that instead.
    /// gst_pad_query_caps returns all possible caps a pad can operate with, using
    /// the pad's CAPS query function, If the query fails, this function will return
    /// `filter`, if not [`None`], otherwise ANY.
    ///
    /// When called on sinkpads `filter` contains the caps that
    /// upstream could produce in the order preferred by upstream. When
    /// called on srcpads `filter` contains the caps accepted by
    /// downstream in the preferred order. `filter` might be [`None`] but
    /// if it is not [`None`] the returned caps will be a subset of `filter`.
    ///
    /// Note that this function does not return writable [`Caps`][crate::Caps], use
    /// `gst_caps_make_writable()` before modifying the caps.
    /// ## `filter`
    /// suggested [`Caps`][crate::Caps], or [`None`]
    ///
    /// # Returns
    ///
    /// the caps of the pad with incremented ref-count.
    #[doc(alias = "gst_pad_query_caps")]
    fn query_caps(&self, filter: Option<&Caps>) -> Caps {
        unsafe {
            from_glib_full(ffi::gst_pad_query_caps(
                self.as_ref().to_glib_none().0,
                filter.to_glib_none().0,
            ))
        }
    }

    /// Activates or deactivates the given pad.
    /// Normally called from within core state change functions.
    ///
    /// If `active`, makes sure the pad is active. If it is already active, either in
    /// push or pull mode, just return. Otherwise dispatches to the pad's activate
    /// function to perform the actual activation.
    ///
    /// If not `active`, calls [`activate_mode()`][Self::activate_mode()] with the pad's current mode
    /// and a [`false`] argument.
    /// ## `active`
    /// whether or not the pad should be active.
    ///
    /// # Returns
    ///
    /// [`true`] if the operation was successful.
    ///
    /// MT safe.
    #[doc(alias = "gst_pad_set_active")]
    fn set_active(&self, active: bool) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib::result_from_gboolean!(
                ffi::gst_pad_set_active(self.as_ref().to_glib_none().0, active.into_glib()),
                "Failed to activate pad"
            )
        }
    }

    //#[doc(alias = "gst_pad_set_element_private")]
    //fn set_element_private(&self, priv_: /*Unimplemented*/Option<Basic: Pointer>) {
    //    unsafe { TODO: call ffi:gst_pad_set_element_private() }
    //}

    /// Set the offset that will be applied to the running time of `self`.
    /// ## `offset`
    /// the offset
    #[doc(alias = "gst_pad_set_offset")]
    fn set_offset(&self, offset: i64) {
        unsafe {
            ffi::gst_pad_set_offset(self.as_ref().to_glib_none().0, offset);
        }
    }

    /// Stop the task of `self`. This function will also make sure that the
    /// function executed by the task will effectively stop if not called
    /// from the GstTaskFunction.
    ///
    /// This function will deadlock if called from the GstTaskFunction of
    /// the task. Use [`TaskExt::pause()`][crate::prelude::TaskExt::pause()] instead.
    ///
    /// Regardless of whether the pad has a task, the stream lock is acquired and
    /// released so as to ensure that streaming through this pad has finished.
    ///
    /// # Returns
    ///
    /// a [`true`] if the task could be stopped or [`false`] on error.
    #[doc(alias = "gst_pad_stop_task")]
    fn stop_task(&self) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib::result_from_gboolean!(
                ffi::gst_pad_stop_task(self.as_ref().to_glib_none().0),
                "Failed to stop pad task"
            )
        }
    }

    /// Store the sticky `event` on `self`
    /// ## `event`
    /// a [`Event`][crate::Event]
    ///
    /// # Returns
    ///
    /// [`FlowReturn::Ok`][crate::FlowReturn::Ok] on success, [`FlowReturn::Flushing`][crate::FlowReturn::Flushing] when the pad
    /// was flushing or [`FlowReturn::Eos`][crate::FlowReturn::Eos] when the pad was EOS.
    #[doc(alias = "gst_pad_store_sticky_event")]
    fn store_sticky_event(&self, event: &Event) -> Result<FlowSuccess, FlowError> {
        unsafe {
            try_from_glib(ffi::gst_pad_store_sticky_event(
                self.as_ref().to_glib_none().0,
                event.to_glib_none().0,
            ))
        }
    }

    /// Unlinks the source pad from the sink pad. Will emit the [`unlinked`][struct@crate::Pad#unlinked]
    /// signal on both pads.
    /// ## `sinkpad`
    /// the sink [`Pad`][crate::Pad] to unlink.
    ///
    /// # Returns
    ///
    /// [`true`] if the pads were unlinked. This function returns [`false`] if
    /// the pads were not linked together.
    ///
    /// MT safe.
    #[doc(alias = "gst_pad_unlink")]
    fn unlink(&self, sinkpad: &impl IsA<Pad>) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib::result_from_gboolean!(
                ffi::gst_pad_unlink(
                    self.as_ref().to_glib_none().0,
                    sinkpad.as_ref().to_glib_none().0
                ),
                "Failed to unlink pad"
            )
        }
    }

    /// A helper function you can use that sets the FIXED_CAPS flag
    /// This way the default CAPS query will always return the negotiated caps
    /// or in case the pad is not negotiated, the padtemplate caps.
    ///
    /// The negotiated caps are the caps of the last CAPS event that passed on the
    /// pad. Use this function on a pad that, once it negotiated to a CAPS, cannot
    /// be renegotiated to something else.
    #[doc(alias = "gst_pad_use_fixed_caps")]
    fn use_fixed_caps(&self) {
        unsafe {
            ffi::gst_pad_use_fixed_caps(self.as_ref().to_glib_none().0);
        }
    }

    /// Signals that a pad has been linked to the peer pad.
    /// ## `peer`
    /// the peer pad that has been connected
    #[doc(alias = "linked")]
    fn connect_linked<F: Fn(&Self, &Pad) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn linked_trampoline<
            P: IsA<Pad>,
            F: Fn(&P, &Pad) + Send + Sync + 'static,
        >(
            this: *mut ffi::GstPad,
            peer: *mut ffi::GstPad,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(
                Pad::from_glib_borrow(this).unsafe_cast_ref(),
                &from_glib_borrow(peer),
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"linked\0".as_ptr() as *const _,
                Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
                    linked_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    /// Signals that a pad has been unlinked from the peer pad.
    /// ## `peer`
    /// the peer pad that has been disconnected
    #[doc(alias = "unlinked")]
    fn connect_unlinked<F: Fn(&Self, &Pad) + Send + Sync + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn unlinked_trampoline<
            P: IsA<Pad>,
            F: Fn(&P, &Pad) + Send + Sync + 'static,
        >(
            this: *mut ffi::GstPad,
            peer: *mut ffi::GstPad,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(
                Pad::from_glib_borrow(this).unsafe_cast_ref(),
                &from_glib_borrow(peer),
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"unlinked\0".as_ptr() as *const _,
                Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
                    unlinked_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "caps")]
    fn connect_caps_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_caps_trampoline<
            P: IsA<Pad>,
            F: Fn(&P) + Send + Sync + 'static,
        >(
            this: *mut ffi::GstPad,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Pad::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::caps\0".as_ptr() as *const _,
                Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
                    notify_caps_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "offset")]
    fn connect_offset_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_offset_trampoline<
            P: IsA<Pad>,
            F: Fn(&P) + Send + Sync + 'static,
        >(
            this: *mut ffi::GstPad,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Pad::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::offset\0".as_ptr() as *const _,
                Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
                    notify_offset_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl<O: IsA<Pad>> PadExt for O {}