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
// 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 glib;
use glib::object::Cast;
use glib::object::IsA;
use glib::signal::connect_raw;
use glib::signal::SignalHandlerId;
use glib::translate::*;
use glib::GString;
use glib::StaticType;
use glib::Value;
use glib_sys;
use gobject_sys;
use gst_sys;
use std::boxed::Box as Box_;
use std::mem::transmute;
use Caps;
use Element;
use Event;
use EventType;
use Object;
use PadDirection;
#[cfg(any(feature = "v1_10", feature = "dox"))]
use PadLinkCheck;
use PadMode;
use PadTemplate;
#[cfg(any(feature = "v1_10", feature = "dox"))]
use Stream;
#[cfg(any(feature = "v1_12", feature = "dox"))]
use TaskState;

glib_wrapper! {
    /// A `Element` is linked to other elements via "pads", which are extremely
    /// light-weight generic link points.
    ///
    /// Pads have a `PadDirection`, source pads produce data, sink pads consume
    /// data.
    ///
    /// Pads are typically created from a `PadTemplate` with
    /// `Pad::new_from_template` and are then added to a `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 `Pad::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` 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` that owns the pad.
    ///
    /// After two pads are retrieved from an element by `ElementExt::get_static_pad`,
    /// the pads can be linked with `Pad::link`. (For quick links,
    /// you can also use `ElementExt::link`, which will make the obvious
    /// link for you if it's straightforward.). Pads can be unlinked again with
    /// `PadExt::unlink`. `PadExt::get_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`.
    ///
    /// `Pad::query` and `Pad::peer_query` can be used to query various
    /// properties of the pad and the stream.
    ///
    /// To send a `Event` on a pad, use `Pad::send_event` and
    /// `Pad::push_event`. Some events will be sticky on the pad, meaning that
    /// after they pass on the pad they can be queried later with
    /// `PadExt::get_sticky_event` and `Pad::sticky_events_foreach`.
    /// `PadExt::get_current_caps` and `PadExt::has_current_caps` are convenience
    /// functions to query the current sticky CAPS event on a pad.
    ///
    /// GstElements will use `Pad::push` and `Pad::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 `Pad::add_probe`. `PadExt::is_blocked`
    /// can be used to check if a block probe is installed on the pad.
    /// `PadExt::is_blocking` checks if the blocking probe is currently blocking the
    /// pad. `Pad::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::get_offset`. This
    /// offset will be applied to the running_time of all data passing over the pad.
    /// `PadExt::set_offset` can be used to change the offset.
    ///
    /// Convenience functions exist to start, pause and stop the task on a pad with
    /// `Pad::start_task`, `PadExt::pause_task` and `PadExt::stop_task`
    /// respectively.
    ///
    /// # Implements
    ///
    /// [`PadExt`](trait.PadExt.html), [`GstObjectExt`](trait.GstObjectExt.html), [`glib::object::ObjectExt`](../glib/object/trait.ObjectExt.html), [`PadExtManual`](prelude/trait.PadExtManual.html)
    pub struct Pad(Object<gst_sys::GstPad, gst_sys::GstPadClass, PadClass>) @extends Object;

    match fn {
        get_type => || gst_sys::gst_pad_get_type(),
    }
}

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

pub const NONE_PAD: Option<&Pad> = None;

/// Trait containing all `Pad` methods.
///
/// # Implementors
///
/// [`Pad`](struct.Pad.html), [`ProxyPad`](struct.ProxyPad.html)
pub trait PadExt: '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.
    fn activate_mode(&self, mode: PadMode, active: bool) -> Result<(), glib::error::BoolError>;

    /// Checks if the source pad and the sink pad are compatible so they can be
    /// linked.
    /// ## `sinkpad`
    /// the sink `Pad`.
    ///
    /// # Returns
    ///
    /// `true` if the pads can be linked.
    fn can_link<P: IsA<Pad>>(&self, sinkpad: &P) -> bool;

    /// Check and clear the `PadFlags::NeedReconfigure` 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`.
    fn check_reconfigure(&self) -> bool;

    /// Creates a stream-id for the source `Pad` `self` by combining the
    /// upstream information with the optional `stream_id` of the stream
    /// of `self`. `self` must have a parent `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` of `self`
    /// ## `stream_id`
    /// The stream-id
    ///
    /// # Returns
    ///
    /// A stream-id for `self`. `g_free` after usage.
    fn create_stream_id<P: IsA<Element>>(
        &self,
        parent: &P,
        stream_id: Option<&str>,
    ) -> Option<GString>;

    //fn create_stream_id_printf<P: IsA<Element>>(&self, parent: &P, stream_id: Option<&str>, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> Option<GString>;

    //fn create_stream_id_printf_valist<P: IsA<Element>>(&self, parent: &P, stream_id: Option<&str>, var_args: /*Unknown conversion*//*Unimplemented*/Unsupported) -> Option<GString>;

    /// 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`
    /// ## `user_data`
    /// user data passed to `forward`
    ///
    /// # Returns
    ///
    /// `true` if one of the dispatcher functions returned `true`.
    fn forward<P: FnMut(&Pad) -> bool>(&self, forward: P) -> bool;

    /// 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 `PadExt::query_caps` on `self` and its peer. The caller owns a reference
    /// on the resulting caps.
    ///
    /// # Returns
    ///
    /// the allowed `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.
    fn get_allowed_caps(&self) -> Option<Caps>;

    /// Gets the capabilities currently configured on `self` with the last
    /// `EventType::Caps` event.
    ///
    /// # Returns
    ///
    /// the current caps of the pad with
    /// incremented ref-count or `None` when pad has no caps. Unref after usage.
    fn get_current_caps(&self) -> Option<Caps>;

    /// 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` of the pad.
    ///
    /// MT safe.
    fn get_direction(&self) -> PadDirection;

    //fn get_element_private(&self) -> /*Unimplemented*/Option<Fundamental: Pointer>;

    /// Get the offset applied to the running time of `self`. `self` has to be a source
    /// pad.
    ///
    /// # Returns
    ///
    /// the offset.
    fn get_offset(&self) -> i64;

    /// Gets the template for `self`.
    ///
    /// # Returns
    ///
    /// the `PadTemplate` from which
    ///  this pad was instantiated, or `None` if this pad has no
    ///  template. Unref after usage.
    fn get_pad_template(&self) -> Option<PadTemplate>;

    /// Gets the capabilities for `self`'s template.
    ///
    /// # Returns
    ///
    /// the `Caps` of this pad template.
    /// Unref after usage.
    fn get_pad_template_caps(&self) -> Option<Caps>;

    /// Gets the parent of `self`, cast to a `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.
    fn get_parent_element(&self) -> Option<Element>;

    /// Gets the peer of `self`. This function refs the peer pad so
    /// you need to unref it after use.
    ///
    /// # Returns
    ///
    /// the peer `Pad`. Unref after usage.
    ///
    /// MT safe.
    fn get_peer(&self) -> Option<Pad>;

    /// If there is a single internal link of the given pad, this function will
    /// return it. Otherwise, it will return NULL.
    ///
    /// Feature: `v1_18`
    ///
    ///
    /// # Returns
    ///
    /// a `Pad`, or `None` if `self` has none
    /// or more than one internal links. Unref returned pad with
    /// `GstObjectExt::unref`.
    #[cfg(any(feature = "v1_18", feature = "dox"))]
    fn get_single_internal_link(&self) -> Option<Pad>;

    /// Returns a new reference of the sticky event of type `event_type`
    /// from the event.
    /// ## `event_type`
    /// the `EventType` that should be retrieved.
    /// ## `idx`
    /// the index of the event
    ///
    /// # Returns
    ///
    /// a `Event` of type
    /// `event_type` or `None` when no event of `event_type` was on
    /// `self`. Unref after usage.
    fn get_sticky_event(&self, event_type: EventType, idx: u32) -> Option<Event>;

    /// Returns the current `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 `PadExt::get_sticky_event` and
    /// `Event::parse_stream`.
    ///
    /// Feature: `v1_10`
    ///
    ///
    /// # Returns
    ///
    /// the current `Stream` for `self`, or `None`.
    ///  unref the returned stream when no longer needed.
    #[cfg(any(feature = "v1_10", feature = "dox"))]
    fn get_stream(&self) -> Option<Stream>;

    /// 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 `PadExt::get_sticky_event` and
    /// `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.
    fn get_stream_id(&self) -> Option<GString>;

    /// Get `self` task state. If no task is currently
    /// set, `TaskState::Stopped` is returned.
    ///
    /// Feature: `v1_12`
    ///
    ///
    /// # Returns
    ///
    /// The current state of `self`'s task.
    #[cfg(any(feature = "v1_12", feature = "dox"))]
    fn get_task_state(&self) -> TaskState;

    /// Check if `self` has caps set on it with a `EventType::Caps` event.
    ///
    /// # Returns
    ///
    /// `true` when `self` has caps associated with it.
    fn has_current_caps(&self) -> bool;

    /// Query if a pad is active
    ///
    /// # Returns
    ///
    /// `true` if the pad is active.
    ///
    /// MT safe.
    fn is_active(&self) -> bool;

    /// 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 `PadExt::is_blocking`).
    ///
    /// # Returns
    ///
    /// `true` if the pad is blocked.
    ///
    /// MT safe.
    fn is_blocked(&self) -> bool;

    /// Checks if the pad is blocking or not. This is a guaranteed state
    /// of whether the pad is actually blocking on a `Buffer` or a `Event`.
    ///
    /// # Returns
    ///
    /// `true` if the pad is blocking.
    ///
    /// MT safe.
    fn is_blocking(&self) -> bool;

    /// Checks if a `self` is linked to another pad or not.
    ///
    /// # Returns
    ///
    /// `true` if the pad is linked, `false` otherwise.
    ///
    /// MT safe.
    fn is_linked(&self) -> bool;

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

    //fn iterate_internal_links_default<P: IsA<Object>>(&self, parent: Option<&P>) -> /*Ignored*/Option<Iterator>;

    /// Links `self` to `sink`, creating any `GhostPad`'s in between as necessary.
    ///
    /// This is a convenience function to save having to create and add intermediate
    /// `GhostPad`'s as required for linking across `Bin` boundaries.
    ///
    /// If `self` or `sink` pads don't have parent elements or do not share a common
    /// ancestor, the link will fail.
    ///
    /// Feature: `v1_10`
    ///
    /// ## `sink`
    /// a `Pad`
    ///
    /// # Returns
    ///
    /// whether the link succeeded.
    #[cfg(any(feature = "v1_10", feature = "dox"))]
    fn link_maybe_ghosting<P: IsA<Pad>>(&self, sink: &P) -> Result<(), glib::error::BoolError>;

    /// Links `self` to `sink`, creating any `GhostPad`'s in between as necessary.
    ///
    /// This is a convenience function to save having to create and add intermediate
    /// `GhostPad`'s as required for linking across `Bin` boundaries.
    ///
    /// If `self` or `sink` pads don't have parent elements or do not share a common
    /// ancestor, the link will fail.
    ///
    /// Calling `PadExt::link_maybe_ghosting_full` with
    /// `flags` == `PadLinkCheck::Default` is the recommended way of linking
    /// pads with safety checks applied.
    ///
    /// Feature: `v1_10`
    ///
    /// ## `sink`
    /// a `Pad`
    /// ## `flags`
    /// some `PadLinkCheck` flags
    ///
    /// # Returns
    ///
    /// whether the link succeeded.
    #[cfg(any(feature = "v1_10", feature = "dox"))]
    fn link_maybe_ghosting_full<P: IsA<Pad>>(
        &self,
        sink: &P,
        flags: PadLinkCheck,
    ) -> Result<(), glib::error::BoolError>;

    /// Mark a pad for needing reconfiguration. The next call to
    /// `PadExt::check_reconfigure` will return `true` after this call.
    fn mark_reconfigure(&self);

    /// Check the `PadFlags::NeedReconfigure` 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`.
    fn needs_reconfigure(&self) -> bool;

    /// 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.
    fn pause_task(&self) -> Result<(), glib::error::BoolError>;

    /// Check if the peer of `self` accepts `caps`. If `self` has no peer, this function
    /// returns `true`.
    /// ## `caps`
    /// a `Caps` to check on the pad
    ///
    /// # Returns
    ///
    /// `true` if the peer of `self` can accept the caps or `self` has no peer.
    fn peer_query_accept_caps(&self, caps: &Caps) -> bool;

    /// Gets the capabilities of the peer connected to this pad. Similar to
    /// `PadExt::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` 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.
    fn peer_query_caps(&self, filter: Option<&Caps>) -> Option<Caps>;

    /// Check if the given pad accepts the caps.
    /// ## `caps`
    /// a `Caps` to check on the pad
    ///
    /// # Returns
    ///
    /// `true` if the pad can accept the caps.
    fn query_accept_caps(&self, caps: &Caps) -> bool;

    /// Gets the capabilities this pad can produce or consume.
    /// Note that this method doesn't necessarily return the caps set by sending a
    /// `Event::new_caps` - use `PadExt::get_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`, use
    /// `gst_caps_make_writable` before modifying the caps.
    /// ## `filter`
    /// suggested `Caps`, or `None`
    ///
    /// # Returns
    ///
    /// the caps of the pad with incremented ref-count.
    fn query_caps(&self, filter: Option<&Caps>) -> Option<Caps>;

    /// 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 `PadExt::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.
    fn set_active(&self, active: bool) -> Result<(), glib::error::BoolError>;

    //fn set_element_private(&self, priv_: /*Unimplemented*/Option<Fundamental: Pointer>);

    /// Set the offset that will be applied to the running time of `self`.
    /// ## `offset`
    /// the offset
    fn set_offset(&self, offset: i64);

    /// 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 `Task::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.
    fn stop_task(&self) -> Result<(), glib::error::BoolError>;

    /// Unlinks the source pad from the sink pad. Will emit the `Pad::unlinked`
    /// signal on both pads.
    /// ## `sinkpad`
    /// the sink `Pad` to unlink.
    ///
    /// # Returns
    ///
    /// `true` if the pads were unlinked. This function returns `false` if
    /// the pads were not linked together.
    ///
    /// MT safe.
    fn unlink<P: IsA<Pad>>(&self, sinkpad: &P) -> Result<(), glib::error::BoolError>;

    /// 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.
    fn use_fixed_caps(&self);

    fn get_property_caps(&self) -> Option<Caps>;

    /// Signals that a pad has been linked to the peer pad.
    /// ## `peer`
    /// the peer pad that has been connected
    fn connect_linked<F: Fn(&Self, &Pad) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId;

    /// Signals that a pad has been unlinked from the peer pad.
    /// ## `peer`
    /// the peer pad that has been disconnected
    fn connect_unlinked<F: Fn(&Self, &Pad) + Send + Sync + 'static>(&self, f: F)
        -> SignalHandlerId;

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

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

impl<O: IsA<Pad>> PadExt for O {
    fn activate_mode(&self, mode: PadMode, active: bool) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib_result_from_gboolean!(
                gst_sys::gst_pad_activate_mode(
                    self.as_ref().to_glib_none().0,
                    mode.to_glib(),
                    active.to_glib()
                ),
                "Failed to activate mode pad"
            )
        }
    }

    fn can_link<P: IsA<Pad>>(&self, sinkpad: &P) -> bool {
        unsafe {
            from_glib(gst_sys::gst_pad_can_link(
                self.as_ref().to_glib_none().0,
                sinkpad.as_ref().to_glib_none().0,
            ))
        }
    }

    fn check_reconfigure(&self) -> bool {
        unsafe {
            from_glib(gst_sys::gst_pad_check_reconfigure(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn create_stream_id<P: IsA<Element>>(
        &self,
        parent: &P,
        stream_id: Option<&str>,
    ) -> Option<GString> {
        unsafe {
            from_glib_full(gst_sys::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,
            ))
        }
    }

    //fn create_stream_id_printf<P: IsA<Element>>(&self, parent: &P, stream_id: Option<&str>, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> Option<GString> {
    //    unsafe { TODO: call gst_sys:gst_pad_create_stream_id_printf() }
    //}

    //fn create_stream_id_printf_valist<P: IsA<Element>>(&self, parent: &P, stream_id: Option<&str>, var_args: /*Unknown conversion*//*Unimplemented*/Unsupported) -> Option<GString> {
    //    unsafe { TODO: call gst_sys:gst_pad_create_stream_id_printf_valist() }
    //}

    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 gst_sys::GstPad,
            user_data: glib_sys::gpointer,
        ) -> glib_sys::gboolean {
            let pad = from_glib_borrow(pad);
            let callback: *mut P = user_data as *const _ as usize as *mut P;
            let res = (*callback)(&pad);
            res.to_glib()
        }
        let forward = Some(forward_func::<P> as _);
        let super_callback0: &P = &forward_data;
        unsafe {
            from_glib(gst_sys::gst_pad_forward(
                self.as_ref().to_glib_none().0,
                forward,
                super_callback0 as *const _ as usize as *mut _,
            ))
        }
    }

    fn get_allowed_caps(&self) -> Option<Caps> {
        unsafe {
            from_glib_full(gst_sys::gst_pad_get_allowed_caps(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn get_current_caps(&self) -> Option<Caps> {
        unsafe {
            from_glib_full(gst_sys::gst_pad_get_current_caps(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn get_direction(&self) -> PadDirection {
        unsafe {
            from_glib(gst_sys::gst_pad_get_direction(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    //fn get_element_private(&self) -> /*Unimplemented*/Option<Fundamental: Pointer> {
    //    unsafe { TODO: call gst_sys:gst_pad_get_element_private() }
    //}

    fn get_offset(&self) -> i64 {
        unsafe { gst_sys::gst_pad_get_offset(self.as_ref().to_glib_none().0) }
    }

    fn get_pad_template(&self) -> Option<PadTemplate> {
        unsafe {
            from_glib_full(gst_sys::gst_pad_get_pad_template(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn get_pad_template_caps(&self) -> Option<Caps> {
        unsafe {
            from_glib_full(gst_sys::gst_pad_get_pad_template_caps(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn get_parent_element(&self) -> Option<Element> {
        unsafe {
            from_glib_full(gst_sys::gst_pad_get_parent_element(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn get_peer(&self) -> Option<Pad> {
        unsafe { from_glib_full(gst_sys::gst_pad_get_peer(self.as_ref().to_glib_none().0)) }
    }

    #[cfg(any(feature = "v1_18", feature = "dox"))]
    fn get_single_internal_link(&self) -> Option<Pad> {
        unsafe {
            from_glib_full(gst_sys::gst_pad_get_single_internal_link(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn get_sticky_event(&self, event_type: EventType, idx: u32) -> Option<Event> {
        unsafe {
            from_glib_full(gst_sys::gst_pad_get_sticky_event(
                self.as_ref().to_glib_none().0,
                event_type.to_glib(),
                idx,
            ))
        }
    }

    #[cfg(any(feature = "v1_10", feature = "dox"))]
    fn get_stream(&self) -> Option<Stream> {
        unsafe { from_glib_full(gst_sys::gst_pad_get_stream(self.as_ref().to_glib_none().0)) }
    }

    fn get_stream_id(&self) -> Option<GString> {
        unsafe {
            from_glib_full(gst_sys::gst_pad_get_stream_id(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[cfg(any(feature = "v1_12", feature = "dox"))]
    fn get_task_state(&self) -> TaskState {
        unsafe {
            from_glib(gst_sys::gst_pad_get_task_state(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn has_current_caps(&self) -> bool {
        unsafe {
            from_glib(gst_sys::gst_pad_has_current_caps(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn is_active(&self) -> bool {
        unsafe { from_glib(gst_sys::gst_pad_is_active(self.as_ref().to_glib_none().0)) }
    }

    fn is_blocked(&self) -> bool {
        unsafe { from_glib(gst_sys::gst_pad_is_blocked(self.as_ref().to_glib_none().0)) }
    }

    fn is_blocking(&self) -> bool {
        unsafe { from_glib(gst_sys::gst_pad_is_blocking(self.as_ref().to_glib_none().0)) }
    }

    fn is_linked(&self) -> bool {
        unsafe { from_glib(gst_sys::gst_pad_is_linked(self.as_ref().to_glib_none().0)) }
    }

    //fn iterate_internal_links(&self) -> /*Ignored*/Option<Iterator> {
    //    unsafe { TODO: call gst_sys:gst_pad_iterate_internal_links() }
    //}

    //fn iterate_internal_links_default<P: IsA<Object>>(&self, parent: Option<&P>) -> /*Ignored*/Option<Iterator> {
    //    unsafe { TODO: call gst_sys:gst_pad_iterate_internal_links_default() }
    //}

    #[cfg(any(feature = "v1_10", feature = "dox"))]
    fn link_maybe_ghosting<P: IsA<Pad>>(&self, sink: &P) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib_result_from_gboolean!(
                gst_sys::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"
            )
        }
    }

    #[cfg(any(feature = "v1_10", feature = "dox"))]
    fn link_maybe_ghosting_full<P: IsA<Pad>>(
        &self,
        sink: &P,
        flags: PadLinkCheck,
    ) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib_result_from_gboolean!(
                gst_sys::gst_pad_link_maybe_ghosting_full(
                    self.as_ref().to_glib_none().0,
                    sink.as_ref().to_glib_none().0,
                    flags.to_glib()
                ),
                "Failed to link pads, possibly ghosting"
            )
        }
    }

    fn mark_reconfigure(&self) {
        unsafe {
            gst_sys::gst_pad_mark_reconfigure(self.as_ref().to_glib_none().0);
        }
    }

    fn needs_reconfigure(&self) -> bool {
        unsafe {
            from_glib(gst_sys::gst_pad_needs_reconfigure(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn pause_task(&self) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib_result_from_gboolean!(
                gst_sys::gst_pad_pause_task(self.as_ref().to_glib_none().0),
                "Failed to pause pad task"
            )
        }
    }

    fn peer_query_accept_caps(&self, caps: &Caps) -> bool {
        unsafe {
            from_glib(gst_sys::gst_pad_peer_query_accept_caps(
                self.as_ref().to_glib_none().0,
                caps.to_glib_none().0,
            ))
        }
    }

    fn peer_query_caps(&self, filter: Option<&Caps>) -> Option<Caps> {
        unsafe {
            from_glib_full(gst_sys::gst_pad_peer_query_caps(
                self.as_ref().to_glib_none().0,
                filter.to_glib_none().0,
            ))
        }
    }

    fn query_accept_caps(&self, caps: &Caps) -> bool {
        unsafe {
            from_glib(gst_sys::gst_pad_query_accept_caps(
                self.as_ref().to_glib_none().0,
                caps.to_glib_none().0,
            ))
        }
    }

    fn query_caps(&self, filter: Option<&Caps>) -> Option<Caps> {
        unsafe {
            from_glib_full(gst_sys::gst_pad_query_caps(
                self.as_ref().to_glib_none().0,
                filter.to_glib_none().0,
            ))
        }
    }

    fn set_active(&self, active: bool) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib_result_from_gboolean!(
                gst_sys::gst_pad_set_active(self.as_ref().to_glib_none().0, active.to_glib()),
                "Failed to activate pad"
            )
        }
    }

    //fn set_element_private(&self, priv_: /*Unimplemented*/Option<Fundamental: Pointer>) {
    //    unsafe { TODO: call gst_sys:gst_pad_set_element_private() }
    //}

    fn set_offset(&self, offset: i64) {
        unsafe {
            gst_sys::gst_pad_set_offset(self.as_ref().to_glib_none().0, offset);
        }
    }

    fn stop_task(&self) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib_result_from_gboolean!(
                gst_sys::gst_pad_stop_task(self.as_ref().to_glib_none().0),
                "Failed to stop pad task"
            )
        }
    }

    fn unlink<P: IsA<Pad>>(&self, sinkpad: &P) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib_result_from_gboolean!(
                gst_sys::gst_pad_unlink(
                    self.as_ref().to_glib_none().0,
                    sinkpad.as_ref().to_glib_none().0
                ),
                "Failed to unlink pad"
            )
        }
    }

    fn use_fixed_caps(&self) {
        unsafe {
            gst_sys::gst_pad_use_fixed_caps(self.as_ref().to_glib_none().0);
        }
    }

    fn get_property_caps(&self) -> Option<Caps> {
        unsafe {
            let mut value = Value::from_type(<Caps as StaticType>::static_type());
            gobject_sys::g_object_get_property(
                self.to_glib_none().0 as *mut gobject_sys::GObject,
                b"caps\0".as_ptr() as *const _,
                value.to_glib_none_mut().0,
            );
            value
                .get()
                .expect("Return Value for property `caps` getter")
        }
    }

    fn connect_linked<F: Fn(&Self, &Pad) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn linked_trampoline<P, F: Fn(&P, &Pad) + Send + Sync + 'static>(
            this: *mut gst_sys::GstPad,
            peer: *mut gst_sys::GstPad,
            f: glib_sys::gpointer,
        ) where
            P: IsA<Pad>,
        {
            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(transmute::<_, unsafe extern "C" fn()>(
                    linked_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_unlinked<F: Fn(&Self, &Pad) + Send + Sync + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn unlinked_trampoline<P, F: Fn(&P, &Pad) + Send + Sync + 'static>(
            this: *mut gst_sys::GstPad,
            peer: *mut gst_sys::GstPad,
            f: glib_sys::gpointer,
        ) where
            P: IsA<Pad>,
        {
            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(transmute::<_, unsafe extern "C" fn()>(
                    unlinked_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_property_caps_notify<F: Fn(&Self) + Send + Sync + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_caps_trampoline<P, F: Fn(&P) + Send + Sync + 'static>(
            this: *mut gst_sys::GstPad,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) where
            P: IsA<Pad>,
        {
            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(transmute::<_, unsafe extern "C" fn()>(
                    notify_caps_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_property_offset_notify<F: Fn(&Self) + Send + Sync + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_offset_trampoline<P, F: Fn(&P) + Send + Sync + 'static>(
            this: *mut gst_sys::GstPad,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) where
            P: IsA<Pad>,
        {
            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(transmute::<_, unsafe extern "C" fn()>(
                    notify_offset_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}