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
// 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 Bus;
use Caps;
use Clock;
use ClockTime;
use Context;
use ElementFactory;
use Error;
use Message;
use Object;
use Pad;
use PadLinkCheck;
use PadTemplate;
use Plugin;
use State;
use StateChange;
use StateChangeReturn;
use URIType;
use ffi;
use glib;
use glib::object::Downcast;
use glib::object::IsA;
use glib::signal::SignalHandlerId;
use glib::signal::connect;
use glib::translate::*;
use glib_ffi;
use gobject_ffi;
use std::boxed::Box as Box_;
use std::mem;
use std::mem::transmute;
use std::ptr;

glib_wrapper! {
    /// GstElement is the abstract base class needed to construct an element that
    /// can be used in a GStreamer pipeline. Please refer to the plugin writers
    /// guide for more information on creating `Element` subclasses.
    ///
    /// The name of a `Element` can be get with `gst_element_get_name` and set with
    /// `gst_element_set_name`. For speed, GST_ELEMENT_NAME() can be used in the
    /// core when using the appropriate locking. Do not use this in plug-ins or
    /// applications in order to retain ABI compatibility.
    ///
    /// Elements can have pads (of the type `Pad`). These pads link to pads on
    /// other elements. `Buffer` flow between these linked pads.
    /// A `Element` has a `glib::List` of `Pad` structures for all their input (or sink)
    /// and output (or source) pads.
    /// Core and plug-in writers can add and remove pads with `ElementExt::add_pad`
    /// and `ElementExt::remove_pad`.
    ///
    /// An existing pad of an element can be retrieved by name with
    /// `ElementExt::get_static_pad`. A new dynamic pad can be created using
    /// `ElementExt::request_pad` with a `PadTemplate`.
    /// An iterator of all pads can be retrieved with `ElementExt::iterate_pads`.
    ///
    /// Elements can be linked through their pads.
    /// If the link is straightforward, use the `ElementExt::link`
    /// convenience function to link two elements, or `ElementExt::link_many`
    /// for more elements in a row.
    /// Use `ElementExt::link_filtered` to link two elements constrained by
    /// a specified set of `Caps`.
    /// For finer control, use `ElementExt::link_pads` and
    /// `ElementExt::link_pads_filtered` to specify the pads to link on
    /// each element by name.
    ///
    /// Each element has a state (see `State`). You can get and set the state
    /// of an element with `ElementExt::get_state` and `ElementExt::set_state`.
    /// Setting a state triggers a `StateChange`. To get a string representation
    /// of a `State`, use `Element::state_get_name`.
    ///
    /// You can get and set a `Clock` on an element using `ElementExt::get_clock`
    /// and `ElementExt::set_clock`.
    /// Some elements can provide a clock for the pipeline if
    /// the `ElementFlags::ProvideClock` flag is set. With the
    /// `ElementExt::provide_clock` method one can retrieve the clock provided by
    /// such an element.
    /// Not all elements require a clock to operate correctly. If the
    /// `ElementFlags::RequireClock`() flag is set, a clock should be set on the
    /// element with `ElementExt::set_clock`.
    ///
    /// Note that clock selection and distribution is normally handled by the
    /// toplevel `Pipeline` so the clock functions are only to be used in very
    /// specific situations.
    ///
    /// # Implements
    ///
    /// [`ElementExt`](trait.ElementExt.html), [`GstObjectExt`](trait.GstObjectExt.html), [`glib::object::ObjectExt`](../glib/object/trait.ObjectExt.html)
    pub struct Element(Object<ffi::GstElement, ffi::GstElementClass>): Object;

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

impl Element {
    /// Creates an element for handling the given URI.
    /// ## `type_`
    /// Whether to create a source or a sink
    /// ## `uri`
    /// URI to create an element for
    /// ## `elementname`
    /// Name of created element, can be `None`.
    ///
    /// # Returns
    ///
    /// a new element or `None` if none
    /// could be created
    pub fn make_from_uri<'a, P: Into<Option<&'a str>>>(type_: URIType, uri: &str, elementname: P) -> Result<Element, Error> {
        assert_initialized_main_thread!();
        let elementname = elementname.into();
        let elementname = elementname.to_glib_none();
        unsafe {
            let mut error = ptr::null_mut();
            let ret = ffi::gst_element_make_from_uri(type_.to_glib(), uri.to_glib_none().0, elementname.0, &mut error);
            if error.is_null() { Ok(from_glib_none(ret)) } else { Err(from_glib_full(error)) }
        }
    }

    pub fn register<'a, P: Into<Option<&'a Plugin>>>(plugin: P, name: &str, rank: u32, type_: glib::types::Type) -> bool {
        assert_initialized_main_thread!();
        let plugin = plugin.into();
        let plugin = plugin.to_glib_none();
        unsafe {
            from_glib(ffi::gst_element_register(plugin.0, name.to_glib_none().0, rank, type_.to_glib()))
        }
    }
}

unsafe impl Send for Element {}
unsafe impl Sync for Element {}

/// Trait containing all `Element` methods.
///
/// # Implementors
///
/// [`Bin`](struct.Bin.html), [`Element`](struct.Element.html), [`TagSetter`](struct.TagSetter.html), [`TocSetter`](struct.TocSetter.html)
pub trait ElementExt {
    /// Abort the state change of the element. This function is used
    /// by elements that do asynchronous state changes and find out
    /// something is wrong.
    ///
    /// This function should be called with the STATE_LOCK held.
    ///
    /// MT safe.
    fn abort_state(&self);

    /// Adds a pad (link point) to `self`. `pad`'s parent will be set to `self`;
    /// see `GstObjectExt::set_parent` for refcounting information.
    ///
    /// Pads are not automatically activated so elements should perform the needed
    /// steps to activate the pad in case this pad is added in the PAUSED or PLAYING
    /// state. See `PadExt::set_active` for more information about activating pads.
    ///
    /// The pad and the element should be unlocked when calling this function.
    ///
    /// This function will emit the `Element::pad-added` signal on the element.
    /// ## `pad`
    /// the `Pad` to add to the element.
    ///
    /// # Returns
    ///
    /// `true` if the pad could be added. This function can fail when
    /// a pad with the same name already existed or the pad already had another
    /// parent.
    ///
    /// MT safe.
    fn add_pad<P: IsA<Pad>>(&self, pad: &P) -> Result<(), glib::error::BoolError>;

    //#[cfg(any(feature = "v1_10", feature = "dox"))]
    //fn call_async(&self, func: /*Unknown conversion*//*Unimplemented*/ElementCallAsyncFunc, destroy_notify: /*Unknown conversion*//*Unimplemented*/DestroyNotify);

    /// Perform `transition` on `self`.
    ///
    /// This function must be called with STATE_LOCK held and is mainly used
    /// internally.
    /// ## `transition`
    /// the requested transition
    ///
    /// # Returns
    ///
    /// the `StateChangeReturn` of the state transition.
    fn change_state(&self, transition: StateChange) -> StateChangeReturn;

    /// Commit the state change of the element and proceed to the next
    /// pending state if any. This function is used
    /// by elements that do asynchronous state changes.
    /// The core will normally call this method automatically when an
    /// element returned `StateChangeReturn::Success` from the state change function.
    ///
    /// If after calling this method the element still has not reached
    /// the pending state, the next state change is performed.
    ///
    /// This method is used internally and should normally not be called by plugins
    /// or applications.
    ///
    /// This function must be called with STATE_LOCK held.
    /// ## `ret`
    /// The previous state return value
    ///
    /// # Returns
    ///
    /// The result of the commit state change.
    ///
    /// MT safe.
    fn continue_state(&self, ret: StateChangeReturn) -> StateChangeReturn;

    /// Creates a pad for each pad template that is always available.
    /// This function is only useful during object initialization of
    /// subclasses of `Element`.
    fn create_all_pads(&self);

    //#[cfg(any(feature = "v1_14", feature = "dox"))]
    //fn foreach_pad<P: Into<Option</*Unimplemented*/Fundamental: Pointer>>>(&self, func: /*Unknown conversion*//*Unimplemented*/ElementForeachPadFunc, user_data: P) -> bool;

    //#[cfg(any(feature = "v1_14", feature = "dox"))]
    //fn foreach_sink_pad<P: Into<Option</*Unimplemented*/Fundamental: Pointer>>>(&self, func: /*Unknown conversion*//*Unimplemented*/ElementForeachPadFunc, user_data: P) -> bool;

    //#[cfg(any(feature = "v1_14", feature = "dox"))]
    //fn foreach_src_pad<P: Into<Option</*Unimplemented*/Fundamental: Pointer>>>(&self, func: /*Unknown conversion*//*Unimplemented*/ElementForeachPadFunc, user_data: P) -> bool;

    /// Returns the base time of the element. The base time is the
    /// absolute time of the clock when this element was last put to
    /// PLAYING. Subtracting the base time from the clock time gives
    /// the running time of the element.
    ///
    /// # Returns
    ///
    /// the base time of the element.
    ///
    /// MT safe.
    fn get_base_time(&self) -> ClockTime;

    /// Returns the bus of the element. Note that only a `Pipeline` will provide a
    /// bus for the application.
    ///
    /// # Returns
    ///
    /// the element's `Bus`. unref after
    /// usage.
    ///
    /// MT safe.
    fn get_bus(&self) -> Option<Bus>;

    /// Gets the currently configured clock of the element. This is the clock as was
    /// last set with `ElementExt::set_clock`.
    ///
    /// Elements in a pipeline will only have their clock set when the
    /// pipeline is in the PLAYING state.
    ///
    /// # Returns
    ///
    /// the `Clock` of the element. unref after usage.
    ///
    /// MT safe.
    fn get_clock(&self) -> Option<Clock>;

    /// Looks for an unlinked pad to which the given pad can link. It is not
    /// guaranteed that linking the pads will work, though it should work in most
    /// cases.
    ///
    /// This function will first attempt to find a compatible unlinked ALWAYS pad,
    /// and if none can be found, it will request a compatible REQUEST pad by looking
    /// at the templates of `self`.
    /// ## `pad`
    /// the `Pad` to find a compatible one for.
    /// ## `caps`
    /// the `Caps` to use as a filter.
    ///
    /// # Returns
    ///
    /// the `Pad` to which a link
    ///  can be made, or `None` if one cannot be found. `GstObjectExt::unref`
    ///  after usage.
    fn get_compatible_pad<'a, P: IsA<Pad>, Q: Into<Option<&'a Caps>>>(&self, pad: &P, caps: Q) -> Option<Pad>;

    /// Retrieves a pad template from `self` that is compatible with `compattempl`.
    /// Pads from compatible templates can be linked together.
    /// ## `compattempl`
    /// the `PadTemplate` to find a compatible
    ///  template for
    ///
    /// # Returns
    ///
    /// a compatible `PadTemplate`,
    ///  or `None` if none was found. No unreferencing is necessary.
    fn get_compatible_pad_template(&self, compattempl: &PadTemplate) -> Option<PadTemplate>;

    /// Gets the context with `context_type` set on the element or NULL.
    ///
    /// MT safe.
    /// ## `context_type`
    /// a name of a context to retrieve
    ///
    /// # Returns
    ///
    /// A `Context` or NULL
    fn get_context(&self, context_type: &str) -> Option<Context>;

    /// Gets the contexts set on the element.
    ///
    /// MT safe.
    ///
    /// # Returns
    ///
    /// List of `Context`
    fn get_contexts(&self) -> Vec<Context>;

    /// Retrieves the factory that was used to create this element.
    ///
    /// # Returns
    ///
    /// the `ElementFactory` used for creating this
    ///  element. no refcounting is needed.
    fn get_factory(&self) -> Option<ElementFactory>;

    /// Retrieves a pad from the element by name (e.g. "src_\%d"). This version only
    /// retrieves request pads. The pad should be released with
    /// `ElementExt::release_request_pad`.
    ///
    /// This method is slower than manually getting the pad template and calling
    /// `ElementExt::request_pad` if the pads should have a specific name (e.g.
    /// `name` is "src_1" instead of "src_\%u").
    /// ## `name`
    /// the name of the request `Pad` to retrieve.
    ///
    /// # Returns
    ///
    /// requested `Pad` if found,
    ///  otherwise `None`. Release after usage.
    fn get_request_pad(&self, name: &str) -> Option<Pad>;

    /// Returns the start time of the element. The start time is the
    /// running time of the clock when this element was last put to PAUSED.
    ///
    /// Usually the start_time is managed by a toplevel element such as
    /// `Pipeline`.
    ///
    /// MT safe.
    ///
    /// # Returns
    ///
    /// the start time of the element.
    fn get_start_time(&self) -> ClockTime;

    /// Gets the state of the element.
    ///
    /// For elements that performed an ASYNC state change, as reported by
    /// `ElementExt::set_state`, this function will block up to the
    /// specified timeout value for the state change to complete.
    /// If the element completes the state change or goes into
    /// an error, this function returns immediately with a return value of
    /// `StateChangeReturn::Success` or `StateChangeReturn::Failure` respectively.
    ///
    /// For elements that did not return `StateChangeReturn::Async`, this function
    /// returns the current and pending state immediately.
    ///
    /// This function returns `StateChangeReturn::NoPreroll` if the element
    /// successfully changed its state but is not able to provide data yet.
    /// This mostly happens for live sources that only produce data in
    /// `State::Playing`. While the state change return is equivalent to
    /// `StateChangeReturn::Success`, it is returned to the application to signal that
    /// some sink elements might not be able to complete their state change because
    /// an element is not producing data to complete the preroll. When setting the
    /// element to playing, the preroll will complete and playback will start.
    /// ## `state`
    /// a pointer to `State` to hold the state.
    ///  Can be `None`.
    /// ## `pending`
    /// a pointer to `State` to hold the pending
    ///  state. Can be `None`.
    /// ## `timeout`
    /// a `ClockTime` to specify the timeout for an async
    ///  state change or `GST_CLOCK_TIME_NONE` for infinite timeout.
    ///
    /// # Returns
    ///
    /// `StateChangeReturn::Success` if the element has no more pending state
    ///  and the last state change succeeded, `StateChangeReturn::Async` if the
    ///  element is still performing a state change or
    ///  `StateChangeReturn::Failure` if the last state change failed.
    ///
    /// MT safe.
    fn get_state(&self, timeout: ClockTime) -> (StateChangeReturn, State, State);

    /// Retrieves a pad from `self` by name. This version only retrieves
    /// already-existing (i.e. 'static') pads.
    /// ## `name`
    /// the name of the static `Pad` to retrieve.
    ///
    /// # Returns
    ///
    /// the requested `Pad` if
    ///  found, otherwise `None`. unref after usage.
    ///
    /// MT safe.
    fn get_static_pad(&self, name: &str) -> Option<Pad>;

    /// Checks if the state of an element is locked.
    /// If the state of an element is locked, state changes of the parent don't
    /// affect the element.
    /// This way you can leave currently unused elements inside bins. Just lock their
    /// state before changing the state from `State::Null`.
    ///
    /// MT safe.
    ///
    /// # Returns
    ///
    /// `true`, if the element's state is locked.
    fn is_locked_state(&self) -> bool;

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

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

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

    /// Links `self` to `dest`. The link must be from source to
    /// destination; the other direction will not be tried. The function looks for
    /// existing pads that aren't linked yet. It will request new pads if necessary.
    /// Such pads need to be released manually when unlinking.
    /// If multiple links are possible, only one is established.
    ///
    /// Make sure you have added your elements to a bin or pipeline with
    /// `BinExt::add` before trying to link them.
    /// ## `dest`
    /// the `Element` containing the destination pad.
    ///
    /// # Returns
    ///
    /// `true` if the elements could be linked, `false` otherwise.
    fn link<P: IsA<Element>>(&self, dest: &P) -> Result<(), glib::error::BoolError>;

    /// Links `self` to `dest` using the given caps as filtercaps.
    /// The link must be from source to
    /// destination; the other direction will not be tried. The function looks for
    /// existing pads that aren't linked yet. It will request new pads if necessary.
    /// If multiple links are possible, only one is established.
    ///
    /// Make sure you have added your elements to a bin or pipeline with
    /// `BinExt::add` before trying to link them.
    /// ## `dest`
    /// the `Element` containing the destination pad.
    /// ## `filter`
    /// the `Caps` to filter the link,
    ///  or `None` for no filter.
    ///
    /// # Returns
    ///
    /// `true` if the pads could be linked, `false` otherwise.
    fn link_filtered<'a, P: IsA<Element>, Q: Into<Option<&'a Caps>>>(&self, dest: &P, filter: Q) -> Result<(), glib::error::BoolError>;

    //fn link_many<P: IsA<Element>>(&self, element_2: &P, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> bool;

    /// Links the two named pads of the source and destination elements.
    /// Side effect is that if one of the pads has no parent, it becomes a
    /// child of the parent of the other element. If they have different
    /// parents, the link fails.
    /// ## `srcpadname`
    /// the name of the `Pad` in source element
    ///  or `None` for any pad.
    /// ## `dest`
    /// the `Element` containing the destination pad.
    /// ## `destpadname`
    /// the name of the `Pad` in destination element,
    /// or `None` for any pad.
    ///
    /// # Returns
    ///
    /// `true` if the pads could be linked, `false` otherwise.
    fn link_pads<'a, 'b, P: Into<Option<&'a str>>, Q: IsA<Element>, R: Into<Option<&'b str>>>(&self, srcpadname: P, dest: &Q, destpadname: R) -> Result<(), glib::error::BoolError>;

    /// Links the two named pads of the source and destination elements. Side effect
    /// is that if one of the pads has no parent, it becomes a child of the parent of
    /// the other element. If they have different parents, the link fails. If `caps`
    /// is not `None`, makes sure that the caps of the link is a subset of `caps`.
    /// ## `srcpadname`
    /// the name of the `Pad` in source element
    ///  or `None` for any pad.
    /// ## `dest`
    /// the `Element` containing the destination pad.
    /// ## `destpadname`
    /// the name of the `Pad` in destination element
    ///  or `None` for any pad.
    /// ## `filter`
    /// the `Caps` to filter the link,
    ///  or `None` for no filter.
    ///
    /// # Returns
    ///
    /// `true` if the pads could be linked, `false` otherwise.
    fn link_pads_filtered<'a, 'b, 'c, P: Into<Option<&'a str>>, Q: IsA<Element>, R: Into<Option<&'b str>>, S: Into<Option<&'c Caps>>>(&self, srcpadname: P, dest: &Q, destpadname: R, filter: S) -> Result<(), glib::error::BoolError>;

    /// Links the two named pads of the source and destination elements.
    /// Side effect is that if one of the pads has no parent, it becomes a
    /// child of the parent of the other element. If they have different
    /// parents, the link fails.
    ///
    /// Calling `ElementExt::link_pads_full` with `flags` == `PadLinkCheck::Default`
    /// is the same as calling `ElementExt::link_pads` and the recommended way of
    /// linking pads with safety checks applied.
    ///
    /// This is a convenience function for `PadExt::link_full`.
    /// ## `srcpadname`
    /// the name of the `Pad` in source element
    ///  or `None` for any pad.
    /// ## `dest`
    /// the `Element` containing the destination pad.
    /// ## `destpadname`
    /// the name of the `Pad` in destination element,
    /// or `None` for any pad.
    /// ## `flags`
    /// the `PadLinkCheck` to be performed when linking pads.
    ///
    /// # Returns
    ///
    /// `true` if the pads could be linked, `false` otherwise.
    fn link_pads_full<'a, 'b, P: Into<Option<&'a str>>, Q: IsA<Element>, R: Into<Option<&'b str>>>(&self, srcpadname: P, dest: &Q, destpadname: R, flags: PadLinkCheck) -> Result<(), glib::error::BoolError>;

    /// Brings the element to the lost state. The current state of the
    /// element is copied to the pending state so that any call to
    /// `ElementExt::get_state` will return `StateChangeReturn::Async`.
    ///
    /// An ASYNC_START message is posted. If the element was PLAYING, it will
    /// go to PAUSED. The element will be restored to its PLAYING state by
    /// the parent pipeline when it prerolls again.
    ///
    /// This is mostly used for elements that lost their preroll buffer
    /// in the `State::Paused` or `State::Playing` state after a flush,
    /// they will go to their pending state again when a new preroll buffer is
    /// queued. This function can only be called when the element is currently
    /// not in error or an async state change.
    ///
    /// This function is used internally and should normally not be called from
    /// plugins or applications.
    fn lost_state(&self);

    //fn message_full<'a, 'b, P: Into<Option<&'a str>>, Q: Into<Option<&'b str>>>(&self, type_: /*Ignored*/MessageType, domain: /*Ignored*/glib::Quark, code: i32, text: P, debug: Q, file: &str, function: &str, line: i32);

    //#[cfg(any(feature = "v1_10", feature = "dox"))]
    //fn message_full_with_details<'a, 'b, P: Into<Option<&'a str>>, Q: Into<Option<&'b str>>>(&self, type_: /*Ignored*/MessageType, domain: /*Ignored*/glib::Quark, code: i32, text: P, debug: Q, file: &str, function: &str, line: i32, structure: &mut Structure);

    /// Use this function to signal that the element does not expect any more pads
    /// to show up in the current pipeline. This function should be called whenever
    /// pads have been added by the element itself. Elements with `PadPresence::Sometimes`
    /// pad templates use this in combination with autopluggers to figure out that
    /// the element is done initializing its pads.
    ///
    /// This function emits the `Element::no-more-pads` signal.
    ///
    /// MT safe.
    fn no_more_pads(&self);

    /// Post a message on the element's `Bus`. This function takes ownership of the
    /// message; if you want to access the message after this call, you should add an
    /// additional reference before calling.
    /// ## `message`
    /// a `Message` to post
    ///
    /// # Returns
    ///
    /// `true` if the message was successfully posted. The function returns
    /// `false` if the element did not have a bus.
    ///
    /// MT safe.
    fn post_message(&self, message: &Message) -> Result<(), glib::error::BoolError>;

    /// Get the clock provided by the given element.
    /// > An element is only required to provide a clock in the PAUSED
    /// > state. Some elements can provide a clock in other states.
    ///
    /// # Returns
    ///
    /// the GstClock provided by the
    /// element or `None` if no clock could be provided. Unref after usage.
    ///
    /// MT safe.
    fn provide_clock(&self) -> Option<Clock>;

    /// Makes the element free the previously requested pad as obtained
    /// with `ElementExt::request_pad`.
    ///
    /// This does not unref the pad. If the pad was created by using
    /// `ElementExt::request_pad`, `ElementExt::release_request_pad` needs to be
    /// followed by `GstObjectExt::unref` to free the `pad`.
    ///
    /// MT safe.
    /// ## `pad`
    /// the `Pad` to release.
    fn release_request_pad<P: IsA<Pad>>(&self, pad: &P);

    /// Removes `pad` from `self`. `pad` will be destroyed if it has not been
    /// referenced elsewhere using `GstObjectExt::unparent`.
    ///
    /// This function is used by plugin developers and should not be used
    /// by applications. Pads that were dynamically requested from elements
    /// with `ElementExt::request_pad` should be released with the
    /// `ElementExt::release_request_pad` function instead.
    ///
    /// Pads are not automatically deactivated so elements should perform the needed
    /// steps to deactivate the pad in case this pad is removed in the PAUSED or
    /// PLAYING state. See `PadExt::set_active` for more information about
    /// deactivating pads.
    ///
    /// The pad and the element should be unlocked when calling this function.
    ///
    /// This function will emit the `Element::pad-removed` signal on the element.
    /// ## `pad`
    /// the `Pad` to remove from the element.
    ///
    /// # Returns
    ///
    /// `true` if the pad could be removed. Can return `false` if the
    /// pad does not belong to the provided element.
    ///
    /// MT safe.
    fn remove_pad<P: IsA<Pad>>(&self, pad: &P) -> Result<(), glib::error::BoolError>;

    /// Retrieves a request pad from the element according to the provided template.
    /// Pad templates can be looked up using
    /// `ElementFactory::get_static_pad_templates`.
    ///
    /// The pad should be released with `ElementExt::release_request_pad`.
    /// ## `templ`
    /// a `PadTemplate` of which we want a pad of.
    /// ## `name`
    /// the name of the request `Pad`
    /// to retrieve. Can be `None`.
    /// ## `caps`
    /// the caps of the pad we want to
    /// request. Can be `None`.
    ///
    /// # Returns
    ///
    /// requested `Pad` if found,
    ///  otherwise `None`. Release after usage.
    fn request_pad<'a, 'b, P: Into<Option<&'a str>>, Q: Into<Option<&'b Caps>>>(&self, templ: &PadTemplate, name: P, caps: Q) -> Option<Pad>;

    /// Set the base time of an element. See `ElementExt::get_base_time`.
    ///
    /// MT safe.
    /// ## `time`
    /// the base time to set.
    fn set_base_time(&self, time: ClockTime);

    /// Sets the bus of the element. Increases the refcount on the bus.
    /// For internal use only, unless you're testing elements.
    ///
    /// MT safe.
    /// ## `bus`
    /// the `Bus` to set.
    fn set_bus<'a, P: Into<Option<&'a Bus>>>(&self, bus: P);

    /// Sets the clock for the element. This function increases the
    /// refcount on the clock. Any previously set clock on the object
    /// is unreffed.
    /// ## `clock`
    /// the `Clock` to set for the element.
    ///
    /// # Returns
    ///
    /// `true` if the element accepted the clock. An element can refuse a
    /// clock when it, for example, is not able to slave its internal clock to the
    /// `clock` or when it requires a specific clock to operate.
    ///
    /// MT safe.
    fn set_clock<'a, P: IsA<Clock> + 'a, Q: Into<Option<&'a P>>>(&self, clock: Q) -> Result<(), glib::error::BoolError>;

    /// Sets the context of the element. Increases the refcount of the context.
    ///
    /// MT safe.
    /// ## `context`
    /// the `Context` to set.
    fn set_context(&self, context: &Context);

    /// Locks the state of an element, so state changes of the parent don't affect
    /// this element anymore.
    ///
    /// MT safe.
    /// ## `locked_state`
    /// `true` to lock the element's state
    ///
    /// # Returns
    ///
    /// `true` if the state was changed, `false` if bad parameters were given
    /// or the elements state-locking needed no change.
    fn set_locked_state(&self, locked_state: bool) -> bool;

    /// Set the start time of an element. The start time of the element is the
    /// running time of the element when it last went to the PAUSED state. In READY
    /// or after a flushing seek, it is set to 0.
    ///
    /// Toplevel elements like `Pipeline` will manage the start_time and
    /// base_time on its children. Setting the start_time to `GST_CLOCK_TIME_NONE`
    /// on such a toplevel element will disable the distribution of the base_time to
    /// the children and can be useful if the application manages the base_time
    /// itself, for example if you want to synchronize capture from multiple
    /// pipelines, and you can also ensure that the pipelines have the same clock.
    ///
    /// MT safe.
    /// ## `time`
    /// the base time to set.
    fn set_start_time(&self, time: ClockTime);

    /// Sets the state of the element. This function will try to set the
    /// requested state by going through all the intermediary states and calling
    /// the class's state change function for each.
    ///
    /// This function can return `StateChangeReturn::Async`, in which case the
    /// element will perform the remainder of the state change asynchronously in
    /// another thread.
    /// An application can use `ElementExt::get_state` to wait for the completion
    /// of the state change or it can wait for a `MessageType::AsyncDone` or
    /// `MessageType::StateChanged` on the bus.
    ///
    /// State changes to `State::Ready` or `State::Null` never return
    /// `StateChangeReturn::Async`.
    /// ## `state`
    /// the element's new `State`.
    ///
    /// # Returns
    ///
    /// Result of the state change using `StateChangeReturn`.
    ///
    /// MT safe.
    fn set_state(&self, state: State) -> StateChangeReturn;

    /// Tries to change the state of the element to the same as its parent.
    /// If this function returns `false`, the state of element is undefined.
    ///
    /// # Returns
    ///
    /// `true`, if the element's state could be synced to the parent's state.
    ///
    /// MT safe.
    fn sync_state_with_parent(&self) -> Result<(), glib::error::BoolError>;

    /// Unlinks all source pads of the source element with all sink pads
    /// of the sink element to which they are linked.
    ///
    /// If the link has been made using `ElementExt::link`, it could have created an
    /// requestpad, which has to be released using `ElementExt::release_request_pad`.
    /// ## `dest`
    /// the sink `Element` to unlink.
    fn unlink<P: IsA<Element>>(&self, dest: &P);

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

    /// Unlinks the two named pads of the source and destination elements.
    ///
    /// This is a convenience function for `PadExt::unlink`.
    /// ## `srcpadname`
    /// the name of the `Pad` in source element.
    /// ## `dest`
    /// a `Element` containing the destination pad.
    /// ## `destpadname`
    /// the name of the `Pad` in destination element.
    fn unlink_pads<P: IsA<Element>>(&self, srcpadname: &str, dest: &P, destpadname: &str);

    /// This signals that the element will not generate more dynamic pads.
    /// Note that this signal will usually be emitted from the context of
    /// the streaming thread.
    fn connect_no_more_pads<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId;

    /// a new `Pad` has been added to the element. Note that this signal will
    /// usually be emitted from the context of the streaming thread. Also keep in
    /// mind that if you add new elements to the pipeline in the signal handler
    /// you will need to set them to the desired target state with
    /// `ElementExt::set_state` or `ElementExt::sync_state_with_parent`.
    /// ## `new_pad`
    /// the pad that has been added
    fn connect_pad_added<F: Fn(&Self, &Pad) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId;

    /// a `Pad` has been removed from the element
    /// ## `old_pad`
    /// the pad that has been removed
    fn connect_pad_removed<F: Fn(&Self, &Pad) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId;
}

impl<O: IsA<Element> + IsA<glib::object::Object>> ElementExt for O {
    fn abort_state(&self) {
        unsafe {
            ffi::gst_element_abort_state(self.to_glib_none().0);
        }
    }

    fn add_pad<P: IsA<Pad>>(&self, pad: &P) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib::error::BoolError::from_glib(ffi::gst_element_add_pad(self.to_glib_none().0, pad.to_glib_none().0), "Failed to add pad")
        }
    }

    //#[cfg(any(feature = "v1_10", feature = "dox"))]
    //fn call_async(&self, func: /*Unknown conversion*//*Unimplemented*/ElementCallAsyncFunc, destroy_notify: /*Unknown conversion*//*Unimplemented*/DestroyNotify) {
    //    unsafe { TODO: call ffi::gst_element_call_async() }
    //}

    fn change_state(&self, transition: StateChange) -> StateChangeReturn {
        unsafe {
            from_glib(ffi::gst_element_change_state(self.to_glib_none().0, transition.to_glib()))
        }
    }

    fn continue_state(&self, ret: StateChangeReturn) -> StateChangeReturn {
        unsafe {
            from_glib(ffi::gst_element_continue_state(self.to_glib_none().0, ret.to_glib()))
        }
    }

    fn create_all_pads(&self) {
        unsafe {
            ffi::gst_element_create_all_pads(self.to_glib_none().0);
        }
    }

    //#[cfg(any(feature = "v1_14", feature = "dox"))]
    //fn foreach_pad<P: Into<Option</*Unimplemented*/Fundamental: Pointer>>>(&self, func: /*Unknown conversion*//*Unimplemented*/ElementForeachPadFunc, user_data: P) -> bool {
    //    unsafe { TODO: call ffi::gst_element_foreach_pad() }
    //}

    //#[cfg(any(feature = "v1_14", feature = "dox"))]
    //fn foreach_sink_pad<P: Into<Option</*Unimplemented*/Fundamental: Pointer>>>(&self, func: /*Unknown conversion*//*Unimplemented*/ElementForeachPadFunc, user_data: P) -> bool {
    //    unsafe { TODO: call ffi::gst_element_foreach_sink_pad() }
    //}

    //#[cfg(any(feature = "v1_14", feature = "dox"))]
    //fn foreach_src_pad<P: Into<Option</*Unimplemented*/Fundamental: Pointer>>>(&self, func: /*Unknown conversion*//*Unimplemented*/ElementForeachPadFunc, user_data: P) -> bool {
    //    unsafe { TODO: call ffi::gst_element_foreach_src_pad() }
    //}

    fn get_base_time(&self) -> ClockTime {
        unsafe {
            from_glib(ffi::gst_element_get_base_time(self.to_glib_none().0))
        }
    }

    fn get_bus(&self) -> Option<Bus> {
        unsafe {
            from_glib_full(ffi::gst_element_get_bus(self.to_glib_none().0))
        }
    }

    fn get_clock(&self) -> Option<Clock> {
        unsafe {
            from_glib_full(ffi::gst_element_get_clock(self.to_glib_none().0))
        }
    }

    fn get_compatible_pad<'a, P: IsA<Pad>, Q: Into<Option<&'a Caps>>>(&self, pad: &P, caps: Q) -> Option<Pad> {
        let caps = caps.into();
        let caps = caps.to_glib_none();
        unsafe {
            from_glib_full(ffi::gst_element_get_compatible_pad(self.to_glib_none().0, pad.to_glib_none().0, caps.0))
        }
    }

    fn get_compatible_pad_template(&self, compattempl: &PadTemplate) -> Option<PadTemplate> {
        unsafe {
            from_glib_none(ffi::gst_element_get_compatible_pad_template(self.to_glib_none().0, compattempl.to_glib_none().0))
        }
    }

    fn get_context(&self, context_type: &str) -> Option<Context> {
        unsafe {
            from_glib_full(ffi::gst_element_get_context(self.to_glib_none().0, context_type.to_glib_none().0))
        }
    }

    fn get_contexts(&self) -> Vec<Context> {
        unsafe {
            FromGlibPtrContainer::from_glib_full(ffi::gst_element_get_contexts(self.to_glib_none().0))
        }
    }

    fn get_factory(&self) -> Option<ElementFactory> {
        unsafe {
            from_glib_none(ffi::gst_element_get_factory(self.to_glib_none().0))
        }
    }

    fn get_request_pad(&self, name: &str) -> Option<Pad> {
        unsafe {
            from_glib_full(ffi::gst_element_get_request_pad(self.to_glib_none().0, name.to_glib_none().0))
        }
    }

    fn get_start_time(&self) -> ClockTime {
        unsafe {
            from_glib(ffi::gst_element_get_start_time(self.to_glib_none().0))
        }
    }

    fn get_state(&self, timeout: ClockTime) -> (StateChangeReturn, State, State) {
        unsafe {
            let mut state = mem::uninitialized();
            let mut pending = mem::uninitialized();
            let ret = from_glib(ffi::gst_element_get_state(self.to_glib_none().0, &mut state, &mut pending, timeout.to_glib()));
            (ret, from_glib(state), from_glib(pending))
        }
    }

    fn get_static_pad(&self, name: &str) -> Option<Pad> {
        unsafe {
            from_glib_full(ffi::gst_element_get_static_pad(self.to_glib_none().0, name.to_glib_none().0))
        }
    }

    fn is_locked_state(&self) -> bool {
        unsafe {
            from_glib(ffi::gst_element_is_locked_state(self.to_glib_none().0))
        }
    }

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

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

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

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

    fn link_filtered<'a, P: IsA<Element>, Q: Into<Option<&'a Caps>>>(&self, dest: &P, filter: Q) -> Result<(), glib::error::BoolError> {
        let filter = filter.into();
        let filter = filter.to_glib_none();
        unsafe {
            glib::error::BoolError::from_glib(ffi::gst_element_link_filtered(self.to_glib_none().0, dest.to_glib_none().0, filter.0), "Failed to link elements")
        }
    }

    //fn link_many<P: IsA<Element>>(&self, element_2: &P, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> bool {
    //    unsafe { TODO: call ffi::gst_element_link_many() }
    //}

    fn link_pads<'a, 'b, P: Into<Option<&'a str>>, Q: IsA<Element>, R: Into<Option<&'b str>>>(&self, srcpadname: P, dest: &Q, destpadname: R) -> Result<(), glib::error::BoolError> {
        let srcpadname = srcpadname.into();
        let srcpadname = srcpadname.to_glib_none();
        let destpadname = destpadname.into();
        let destpadname = destpadname.to_glib_none();
        unsafe {
            glib::error::BoolError::from_glib(ffi::gst_element_link_pads(self.to_glib_none().0, srcpadname.0, dest.to_glib_none().0, destpadname.0), "Failed to link pads")
        }
    }

    fn link_pads_filtered<'a, 'b, 'c, P: Into<Option<&'a str>>, Q: IsA<Element>, R: Into<Option<&'b str>>, S: Into<Option<&'c Caps>>>(&self, srcpadname: P, dest: &Q, destpadname: R, filter: S) -> Result<(), glib::error::BoolError> {
        let srcpadname = srcpadname.into();
        let srcpadname = srcpadname.to_glib_none();
        let destpadname = destpadname.into();
        let destpadname = destpadname.to_glib_none();
        let filter = filter.into();
        let filter = filter.to_glib_none();
        unsafe {
            glib::error::BoolError::from_glib(ffi::gst_element_link_pads_filtered(self.to_glib_none().0, srcpadname.0, dest.to_glib_none().0, destpadname.0, filter.0), "Failed to link pads")
        }
    }

    fn link_pads_full<'a, 'b, P: Into<Option<&'a str>>, Q: IsA<Element>, R: Into<Option<&'b str>>>(&self, srcpadname: P, dest: &Q, destpadname: R, flags: PadLinkCheck) -> Result<(), glib::error::BoolError> {
        let srcpadname = srcpadname.into();
        let srcpadname = srcpadname.to_glib_none();
        let destpadname = destpadname.into();
        let destpadname = destpadname.to_glib_none();
        unsafe {
            glib::error::BoolError::from_glib(ffi::gst_element_link_pads_full(self.to_glib_none().0, srcpadname.0, dest.to_glib_none().0, destpadname.0, flags.to_glib()), "Failed to link pads")
        }
    }

    fn lost_state(&self) {
        unsafe {
            ffi::gst_element_lost_state(self.to_glib_none().0);
        }
    }

    //fn message_full<'a, 'b, P: Into<Option<&'a str>>, Q: Into<Option<&'b str>>>(&self, type_: /*Ignored*/MessageType, domain: /*Ignored*/glib::Quark, code: i32, text: P, debug: Q, file: &str, function: &str, line: i32) {
    //    unsafe { TODO: call ffi::gst_element_message_full() }
    //}

    //#[cfg(any(feature = "v1_10", feature = "dox"))]
    //fn message_full_with_details<'a, 'b, P: Into<Option<&'a str>>, Q: Into<Option<&'b str>>>(&self, type_: /*Ignored*/MessageType, domain: /*Ignored*/glib::Quark, code: i32, text: P, debug: Q, file: &str, function: &str, line: i32, structure: &mut Structure) {
    //    unsafe { TODO: call ffi::gst_element_message_full_with_details() }
    //}

    fn no_more_pads(&self) {
        unsafe {
            ffi::gst_element_no_more_pads(self.to_glib_none().0);
        }
    }

    fn post_message(&self, message: &Message) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib::error::BoolError::from_glib(ffi::gst_element_post_message(self.to_glib_none().0, message.to_glib_full()), "Failed to post message")
        }
    }

    fn provide_clock(&self) -> Option<Clock> {
        unsafe {
            from_glib_full(ffi::gst_element_provide_clock(self.to_glib_none().0))
        }
    }

    fn release_request_pad<P: IsA<Pad>>(&self, pad: &P) {
        unsafe {
            ffi::gst_element_release_request_pad(self.to_glib_none().0, pad.to_glib_none().0);
        }
    }

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

    fn request_pad<'a, 'b, P: Into<Option<&'a str>>, Q: Into<Option<&'b Caps>>>(&self, templ: &PadTemplate, name: P, caps: Q) -> Option<Pad> {
        let name = name.into();
        let name = name.to_glib_none();
        let caps = caps.into();
        let caps = caps.to_glib_none();
        unsafe {
            from_glib_full(ffi::gst_element_request_pad(self.to_glib_none().0, templ.to_glib_none().0, name.0, caps.0))
        }
    }

    fn set_base_time(&self, time: ClockTime) {
        unsafe {
            ffi::gst_element_set_base_time(self.to_glib_none().0, time.to_glib());
        }
    }

    fn set_bus<'a, P: Into<Option<&'a Bus>>>(&self, bus: P) {
        let bus = bus.into();
        let bus = bus.to_glib_none();
        unsafe {
            ffi::gst_element_set_bus(self.to_glib_none().0, bus.0);
        }
    }

    fn set_clock<'a, P: IsA<Clock> + 'a, Q: Into<Option<&'a P>>>(&self, clock: Q) -> Result<(), glib::error::BoolError> {
        let clock = clock.into();
        let clock = clock.to_glib_none();
        unsafe {
            glib::error::BoolError::from_glib(ffi::gst_element_set_clock(self.to_glib_none().0, clock.0), "Failed to set clock")
        }
    }

    fn set_context(&self, context: &Context) {
        unsafe {
            ffi::gst_element_set_context(self.to_glib_none().0, context.to_glib_none().0);
        }
    }

    fn set_locked_state(&self, locked_state: bool) -> bool {
        unsafe {
            from_glib(ffi::gst_element_set_locked_state(self.to_glib_none().0, locked_state.to_glib()))
        }
    }

    fn set_start_time(&self, time: ClockTime) {
        unsafe {
            ffi::gst_element_set_start_time(self.to_glib_none().0, time.to_glib());
        }
    }

    fn set_state(&self, state: State) -> StateChangeReturn {
        unsafe {
            from_glib(ffi::gst_element_set_state(self.to_glib_none().0, state.to_glib()))
        }
    }

    fn sync_state_with_parent(&self) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib::error::BoolError::from_glib(ffi::gst_element_sync_state_with_parent(self.to_glib_none().0), "Failed to sync state with parent")
        }
    }

    fn unlink<P: IsA<Element>>(&self, dest: &P) {
        unsafe {
            ffi::gst_element_unlink(self.to_glib_none().0, dest.to_glib_none().0);
        }
    }

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

    fn unlink_pads<P: IsA<Element>>(&self, srcpadname: &str, dest: &P, destpadname: &str) {
        unsafe {
            ffi::gst_element_unlink_pads(self.to_glib_none().0, srcpadname.to_glib_none().0, dest.to_glib_none().0, destpadname.to_glib_none().0);
        }
    }

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

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

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

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

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

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