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
// 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::IsA;
use glib::translate::*;
use gst_sys;
use Object;
use Pad;
use ProxyPad;

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), [`ProxyPadExtManual`](prelude/trait.ProxyPadExtManual.html), [`PadExtManual`](prelude/trait.PadExtManual.html)
    pub struct GhostPad(Object<gst_sys::GstGhostPad, gst_sys::GstGhostPadClass, GhostPadClass>) @extends ProxyPad, Pad, Object;

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

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

pub const NONE_GHOST_PAD: Option<&GhostPad> = None;

/// Trait containing all `GhostPad` methods.
///
/// # Implementors
///
/// [`GhostPad`](struct.GhostPad.html)
pub trait GhostPadExt: 'static {
    /// 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<P: IsA<Pad>>(&self, newtarget: Option<&P>) -> Result<(), glib::error::BoolError>;
}

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

    fn set_target<P: IsA<Pad>>(&self, newtarget: Option<&P>) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib_result_from_gboolean!(
                gst_sys::gst_ghost_pad_set_target(
                    self.as_ref().to_glib_none().0,
                    newtarget.map(|p| p.as_ref()).to_glib_none().0
                ),
                "Failed to set target"
            )
        }
    }
}