Skip to main content

gstreamer/auto/
pad_template.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
4// DO NOT EDIT
5
6use crate::{Caps, Object, Pad, PadDirection, PadPresence, ffi};
7use glib::{
8    object::ObjectType as _,
9    prelude::*,
10    signal::{SignalHandlerId, connect_raw},
11    translate::*,
12};
13use std::boxed::Box as Box_;
14
15glib::wrapper! {
16    /// my_template);
17    ///  }
18    /// ]|
19    ///
20    /// ## Properties
21    ///
22    ///
23    /// #### `caps`
24    ///  The capabilities of the pad described by the pad template.
25    ///
26    /// Readable | Writable | Construct Only
27    ///
28    ///
29    /// #### `direction`
30    ///  The direction of the pad described by the pad template.
31    ///
32    /// Readable | Writable | Construct Only
33    ///
34    ///
35    /// #### `gtype`
36    ///  The type of the pad described by the pad template.
37    ///
38    /// Readable | Writable | Construct Only
39    ///
40    ///
41    /// #### `name-template`
42    ///  The name template of the pad template.
43    ///
44    /// Readable | Writable | Construct Only
45    ///
46    ///
47    /// #### `presence`
48    ///  When the pad described by the pad template will become available.
49    ///
50    /// Readable | Writable | Construct Only
51    /// <details><summary><h4>Object</h4></summary>
52    ///
53    ///
54    /// #### `name`
55    ///  Readable | Writable | Construct
56    ///
57    ///
58    /// #### `parent`
59    ///  The parent of the object. Please note, that when changing the 'parent'
60    /// property, we don't emit [`notify`][struct@crate::glib::Object#notify] and [`deep-notify`][struct@crate::Object#deep-notify]
61    /// signals due to locking issues. In some cases one can use
62    /// [`element-added`][struct@crate::Bin#element-added] or [`element-removed`][struct@crate::Bin#element-removed] signals on the parent to
63    /// achieve a similar effect.
64    ///
65    /// Readable | Writable
66    /// </details>
67    ///
68    /// ## Signals
69    ///
70    ///
71    /// #### `pad-created`
72    ///  This signal is fired when an element creates a pad from this template.
73    ///
74    ///
75    /// <details><summary><h4>Object</h4></summary>
76    ///
77    ///
78    /// #### `deep-notify`
79    ///  The deep notify signal is used to be notified of property changes. It is
80    /// typically attached to the toplevel bin to receive notifications from all
81    /// the elements contained in that bin.
82    ///
83    /// Detailed
84    /// </details>
85    ///
86    /// # Implements
87    ///
88    /// [`GstObjectExt`][trait@crate::prelude::GstObjectExt], [`trait@glib::ObjectExt`], [`GstObjectExtManual`][trait@crate::prelude::GstObjectExtManual]
89    #[doc(alias = "GstPadTemplate")]
90    pub struct PadTemplate(Object<ffi::GstPadTemplate, ffi::GstPadTemplateClass>) @extends Object;
91
92    match fn {
93        type_ => || ffi::gst_pad_template_get_type(),
94    }
95}
96
97impl PadTemplate {
98    /// Creates a new pad template with a name according to the given template
99    /// and with the given arguments.
100    /// ## `name_template`
101    /// the name template.
102    /// ## `direction`
103    /// the [`PadDirection`][crate::PadDirection] of the template.
104    /// ## `presence`
105    /// the [`PadPresence`][crate::PadPresence] of the pad.
106    /// ## `caps`
107    /// a [`Caps`][crate::Caps] set for the template.
108    ///
109    /// # Returns
110    ///
111    /// a new [`PadTemplate`][crate::PadTemplate].
112    #[doc(alias = "gst_pad_template_new")]
113    pub fn new(
114        name_template: &str,
115        direction: PadDirection,
116        presence: PadPresence,
117        caps: &Caps,
118    ) -> Result<PadTemplate, glib::BoolError> {
119        assert_initialized_main_thread!();
120        unsafe {
121            Option::<_>::from_glib_none(ffi::gst_pad_template_new(
122                name_template.to_glib_none().0,
123                direction.into_glib(),
124                presence.into_glib(),
125                caps.to_glib_none().0,
126            ))
127            .ok_or_else(|| glib::bool_error!("Failed to create pad template"))
128        }
129    }
130
131    /// Creates a new pad template with a name according to the given template
132    /// and with the given arguments.
133    /// ## `name_template`
134    /// the name template.
135    /// ## `direction`
136    /// the [`PadDirection`][crate::PadDirection] of the template.
137    /// ## `presence`
138    /// the [`PadPresence`][crate::PadPresence] of the pad.
139    /// ## `caps`
140    /// a [`Caps`][crate::Caps] set for the template.
141    /// ## `pad_type`
142    /// The `GType` of the pad to create
143    ///
144    /// # Returns
145    ///
146    /// a new [`PadTemplate`][crate::PadTemplate].
147    #[doc(alias = "gst_pad_template_new_with_gtype")]
148    #[doc(alias = "new_with_gtype")]
149    pub fn with_gtype(
150        name_template: &str,
151        direction: PadDirection,
152        presence: PadPresence,
153        caps: &Caps,
154        pad_type: glib::types::Type,
155    ) -> Result<PadTemplate, glib::BoolError> {
156        assert_initialized_main_thread!();
157        unsafe {
158            Option::<_>::from_glib_none(ffi::gst_pad_template_new_with_gtype(
159                name_template.to_glib_none().0,
160                direction.into_glib(),
161                presence.into_glib(),
162                caps.to_glib_none().0,
163                pad_type.into_glib(),
164            ))
165            .ok_or_else(|| glib::bool_error!("Failed to create pad template"))
166        }
167    }
168
169    /// Emit the pad-created signal for this template when created by this pad.
170    /// ## `pad`
171    /// the [`Pad`][crate::Pad] that created it
172    #[doc(alias = "gst_pad_template_pad_created")]
173    pub fn pad_created(&self, pad: &impl IsA<Pad>) {
174        unsafe {
175            ffi::gst_pad_template_pad_created(self.to_glib_none().0, pad.as_ref().to_glib_none().0);
176        }
177    }
178
179    /// This signal is fired when an element creates a pad from this template.
180    /// ## `pad`
181    /// the pad that was created.
182    #[doc(alias = "pad-created")]
183    pub fn connect_pad_created<F: Fn(&Self, &Pad) + Send + Sync + 'static>(
184        &self,
185        f: F,
186    ) -> SignalHandlerId {
187        unsafe extern "C" fn pad_created_trampoline<
188            F: Fn(&PadTemplate, &Pad) + Send + Sync + 'static,
189        >(
190            this: *mut ffi::GstPadTemplate,
191            pad: *mut ffi::GstPad,
192            f: glib::ffi::gpointer,
193        ) {
194            unsafe {
195                let f: &F = &*(f as *const F);
196                f(&from_glib_borrow(this), &from_glib_borrow(pad))
197            }
198        }
199        unsafe {
200            let f: Box_<F> = Box_::new(f);
201            connect_raw(
202                self.as_ptr() as *mut _,
203                c"pad-created".as_ptr(),
204                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
205                    pad_created_trampoline::<F> as *const (),
206                )),
207                Box_::into_raw(f),
208            )
209        }
210    }
211}
212
213unsafe impl Send for PadTemplate {}
214unsafe impl Sync for PadTemplate {}