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
// 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 Object;
use Pad;
use PadDirection;
use PadTemplate;
use ProxyPad;
use ffi;
use glib;
use glib::object::Downcast;
use glib::object::IsA;
use glib::translate::*;
use glib_ffi;
use gobject_ffi;
use std::mem;
use std::ptr;

glib_wrapper! {
    /// GhostPads are useful when organizing pipelines with `Bin` like elements.
    /// The idea here is to create hierarchical element graphs. The bin element
    /// contains a sub-graph. Now one would like to treat the bin-element like any
    /// other `Element`. This is where GhostPads come into play. A GhostPad acts as
    /// a proxy for another pad. Thus the bin can have sink and source ghost-pads
    /// that are associated with sink and source pads of the child elements.
    ///
    /// If the target pad is known at creation time, `GhostPad::new` is the
    /// function to use to get a ghost-pad. Otherwise one can use `GhostPad::new_no_target`
    /// to create the ghost-pad and use `GhostPadExt::set_target` to establish the
    /// association later on.
    ///
    /// Note that GhostPads add overhead to the data processing of a pipeline.
    ///
    /// # Implements
    ///
    /// [`GhostPadExt`](trait.GhostPadExt.html), [`ProxyPadExt`](trait.ProxyPadExt.html), [`PadExt`](trait.PadExt.html), [`GstObjectExt`](trait.GstObjectExt.html), [`glib::object::ObjectExt`](../glib/object/trait.ObjectExt.html)
    pub struct GhostPad(Object<ffi::GstGhostPad, ffi::GstGhostPadClass>): ProxyPad, Pad, Object;

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

impl GhostPad {
    /// Create a new ghostpad without a target with the given direction.
    /// A target can be set on the ghostpad later with the
    /// `GhostPadExt::set_target` function.
    ///
    /// The created ghostpad will not have a padtemplate.
    /// ## `name`
    /// the name of the new pad, or `None` to assign a default name.
    /// ## `dir`
    /// the direction of the ghostpad
    ///
    /// # Returns
    ///
    /// a new `Pad`, or `None` in
    /// case of an error.
    pub fn new_no_target<'a, P: Into<Option<&'a str>>>(name: P, dir: PadDirection) -> GhostPad {
        assert_initialized_main_thread!();
        let name = name.into();
        let name = name.to_glib_none();
        unsafe {
            Pad::from_glib_none(ffi::gst_ghost_pad_new_no_target(name.0, dir.to_glib())).downcast_unchecked()
        }
    }

    /// Create a new ghostpad based on `templ`, without setting a target. The
    /// direction will be taken from the `templ`.
    /// ## `name`
    /// the name of the new pad, or `None` to assign a default name
    /// ## `templ`
    /// the `PadTemplate` to create the ghostpad from.
    ///
    /// # Returns
    ///
    /// a new `Pad`, or `None` in
    /// case of an error.
    pub fn new_no_target_from_template<'a, P: Into<Option<&'a str>>>(name: P, templ: &PadTemplate) -> GhostPad {
        skip_assert_initialized!();
        let name = name.into();
        let name = name.to_glib_none();
        unsafe {
            Pad::from_glib_none(ffi::gst_ghost_pad_new_no_target_from_template(name.0, templ.to_glib_none().0)).downcast_unchecked()
        }
    }
}

unsafe impl Send for GhostPad {}
unsafe impl Sync for GhostPad {}

/// Trait containing all `GhostPad` methods.
///
/// # Implementors
///
/// [`GhostPad`](struct.GhostPad.html)
pub trait GhostPadExt {
    /// Get the target pad of `self`. Unref target pad after usage.
    ///
    /// # Returns
    ///
    /// the target `Pad`, can be
    /// `None` if the ghostpad has no target set. Unref target pad after
    /// usage.
    fn get_target(&self) -> Option<Pad>;

    /// Set the new target of the ghostpad `self`. Any existing target
    /// is unlinked and links to the new target are established. if `newtarget` is
    /// `None` the target will be cleared.
    /// ## `newtarget`
    /// the new pad target
    ///
    /// # Returns
    ///
    /// `true` if the new target could be set. This function
    ///  can return `false` when the internal pads could not be linked.
    fn set_target<'a, P: IsA<Pad> + 'a, Q: Into<Option<&'a P>>>(&self, newtarget: Q) -> Result<(), glib::error::BoolError>;
}

impl<O: IsA<GhostPad>> GhostPadExt for O {
    fn get_target(&self) -> Option<Pad> {
        unsafe {
            from_glib_full(ffi::gst_ghost_pad_get_target(self.to_glib_none().0))
        }
    }

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