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
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
// DO NOT EDIT

use crate::Object;
use crate::Pad;
use crate::ProxyPad;
use glib::object::IsA;
use glib::translate::*;

glib::wrapper! {
    /// GhostPads are useful when organizing pipelines with [`Bin`][crate::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`][crate::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, [`with_target()`][Self::with_target()] is the
    /// function to use to get a ghost-pad. Otherwise one can use [`new()`][Self::new()]
    /// to create the ghost-pad and use [`GhostPadExt::set_target()`][crate::prelude::GhostPadExt::set_target()] to establish the
    /// association later on.
    ///
    /// Note that GhostPads add overhead to the data processing of a pipeline.
    ///
    /// # Implements
    ///
    /// [`GhostPadExt`][trait@crate::prelude::GhostPadExt], [`ProxyPadExt`][trait@crate::prelude::ProxyPadExt], [`PadExt`][trait@crate::prelude::PadExt], [`GstObjectExt`][trait@crate::prelude::GstObjectExt], [`trait@glib::ObjectExt`], [`ProxyPadExtManual`][trait@crate::prelude::ProxyPadExtManual], [`PadExtManual`][trait@crate::prelude::PadExtManual]
    #[doc(alias = "GstGhostPad")]
    pub struct GhostPad(Object<ffi::GstGhostPad, ffi::GstGhostPadClass>) @extends ProxyPad, Pad, Object;

    match fn {
        type_ => || ffi::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 [`struct@GhostPad`] methods.
///
/// # Implementors
///
/// [`GhostPad`][struct@crate::GhostPad]
pub trait GhostPadExt: 'static {
    /// Get the target pad of `self`. Unref target pad after usage.
    ///
    /// # Returns
    ///
    /// the target [`Pad`][crate::Pad], can be
    /// [`None`] if the ghostpad has no target set. Unref target pad after
    /// usage.
    #[doc(alias = "gst_ghost_pad_get_target")]
    #[doc(alias = "get_target")]
    fn 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.
    #[doc(alias = "gst_ghost_pad_set_target")]
    fn set_target<P: IsA<Pad>>(&self, newtarget: Option<&P>) -> Result<(), glib::error::BoolError>;
}

impl<O: IsA<GhostPad>> GhostPadExt for O {
    fn target(&self) -> Option<Pad> {
        unsafe {
            from_glib_full(ffi::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!(
                ffi::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"
            )
        }
    }
}