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::{ffi, Caps, Object, Pad, PadDirection, PadPresence};
7use glib::{
8 object::ObjectType as _,
9 prelude::*,
10 signal::{connect_raw, SignalHandlerId},
11 translate::*,
12};
13use std::boxed::Box as Box_;
14
15glib::wrapper! {
16 /// Padtemplates describe the possible media types a pad or an elementfactory can
17 /// handle. This allows for both inspection of handled types before loading the
18 /// element plugin as well as identifying pads on elements that are not yet
19 /// created (request or sometimes pads).
20 ///
21 /// Pad and PadTemplates have [`Caps`][crate::Caps] attached to it to describe the media type
22 /// they are capable of dealing with. [`caps()`][Self::caps()] or
23 /// GST_PAD_TEMPLATE_CAPS() are used to get the caps of a padtemplate. It's not
24 /// possible to modify the caps of a padtemplate after creation.
25 ///
26 /// PadTemplates have a [`PadPresence`][crate::PadPresence] property which identifies the lifetime
27 /// of the pad and that can be retrieved with GST_PAD_TEMPLATE_PRESENCE(). Also
28 /// the direction of the pad can be retrieved from the [`PadTemplate`][crate::PadTemplate] with
29 /// GST_PAD_TEMPLATE_DIRECTION().
30 ///
31 /// The GST_PAD_TEMPLATE_NAME_TEMPLATE () is important for GST_PAD_REQUEST pads
32 /// because it has to be used as the name in the [`ElementExtManual::request_pad_simple()`][crate::prelude::ElementExtManual::request_pad_simple()]
33 /// call to instantiate a pad from this template.
34 ///
35 /// Padtemplates can be created with [`new()`][Self::new()] or with
36 /// gst_static_pad_template_get (), which creates a [`PadTemplate`][crate::PadTemplate] from a
37 /// [`StaticPadTemplate`][crate::StaticPadTemplate] that can be filled with the
38 /// convenient GST_STATIC_PAD_TEMPLATE() macro.
39 ///
40 /// A padtemplate can be used to create a pad (see [`Pad::from_template()`][crate::Pad::from_template()]
41 /// or gst_pad_new_from_static_template ()) or to add to an element class
42 /// (see gst_element_class_add_static_pad_template ()).
43 ///
44 /// The following code example shows the code to create a pad from a padtemplate.
45 ///
46 ///
47 /// **⚠️ The following code is in C ⚠️**
48 ///
49 /// ```C
50 /// GstStaticPadTemplate my_template =
51 /// GST_STATIC_PAD_TEMPLATE (
52 /// "sink", // the name of the pad
53 /// GST_PAD_SINK, // the direction of the pad
54 /// GST_PAD_ALWAYS, // when this pad will be present
55 /// GST_STATIC_CAPS ( // the capabilities of the padtemplate
56 /// "audio/x-raw, "
57 /// "channels = (int) [ 1, 6 ]"
58 /// )
59 /// );
60 /// void
61 /// my_method (void)
62 /// {
63 /// GstPad *pad;
64 /// pad = gst_pad_new_from_static_template (&my_template, "sink");
65 /// ...
66 /// }
67 /// ```
68 ///
69 /// The following example shows you how to add the padtemplate to an
70 /// element class, this is usually done in the class_init of the class:
71 ///
72 ///
73 /// **⚠️ The following code is in C ⚠️**
74 ///
75 /// ```C
76 /// static void
77 /// my_element_class_init (GstMyElementClass *klass)
78 /// {
79 /// GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
80 ///
81 /// gst_element_class_add_static_pad_template (gstelement_class, &my_template);
82 /// }
83 /// ```
84 ///
85 /// ## Properties
86 ///
87 ///
88 /// #### `caps`
89 /// The capabilities of the pad described by the pad template.
90 ///
91 /// Readable | Writeable | Construct Only
92 ///
93 ///
94 /// #### `direction`
95 /// The direction of the pad described by the pad template.
96 ///
97 /// Readable | Writeable | Construct Only
98 ///
99 ///
100 /// #### `gtype`
101 /// The type of the pad described by the pad template.
102 ///
103 /// Readable | Writeable | Construct Only
104 ///
105 ///
106 /// #### `name-template`
107 /// The name template of the pad template.
108 ///
109 /// Readable | Writeable | Construct Only
110 ///
111 ///
112 /// #### `presence`
113 /// When the pad described by the pad template will become available.
114 ///
115 /// Readable | Writeable | Construct Only
116 /// <details><summary><h4>Object</h4></summary>
117 ///
118 ///
119 /// #### `name`
120 /// Readable | Writeable | Construct
121 ///
122 ///
123 /// #### `parent`
124 /// The parent of the object. Please note, that when changing the 'parent'
125 /// property, we don't emit [`notify`][struct@crate::glib::Object#notify] and [`deep-notify`][struct@crate::Object#deep-notify]
126 /// signals due to locking issues. In some cases one can use
127 /// [`element-added`][struct@crate::Bin#element-added] or [`element-removed`][struct@crate::Bin#element-removed] signals on the parent to
128 /// achieve a similar effect.
129 ///
130 /// Readable | Writeable
131 /// </details>
132 ///
133 /// ## Signals
134 ///
135 ///
136 /// #### `pad-created`
137 /// This signal is fired when an element creates a pad from this template.
138 ///
139 ///
140 /// <details><summary><h4>Object</h4></summary>
141 ///
142 ///
143 /// #### `deep-notify`
144 /// The deep notify signal is used to be notified of property changes. It is
145 /// typically attached to the toplevel bin to receive notifications from all
146 /// the elements contained in that bin.
147 ///
148 /// Detailed
149 /// </details>
150 ///
151 /// # Implements
152 ///
153 /// [`GstObjectExt`][trait@crate::prelude::GstObjectExt], [`trait@glib::ObjectExt`]
154 #[doc(alias = "GstPadTemplate")]
155 pub struct PadTemplate(Object<ffi::GstPadTemplate, ffi::GstPadTemplateClass>) @extends Object;
156
157 match fn {
158 type_ => || ffi::gst_pad_template_get_type(),
159 }
160}
161
162impl PadTemplate {
163 /// Creates a new pad template with a name according to the given template
164 /// and with the given arguments.
165 /// ## `name_template`
166 /// the name template.
167 /// ## `direction`
168 /// the [`PadDirection`][crate::PadDirection] of the template.
169 /// ## `presence`
170 /// the [`PadPresence`][crate::PadPresence] of the pad.
171 /// ## `caps`
172 /// a [`Caps`][crate::Caps] set for the template.
173 ///
174 /// # Returns
175 ///
176 /// a new [`PadTemplate`][crate::PadTemplate].
177 #[doc(alias = "gst_pad_template_new")]
178 pub fn new(
179 name_template: &str,
180 direction: PadDirection,
181 presence: PadPresence,
182 caps: &Caps,
183 ) -> Result<PadTemplate, glib::BoolError> {
184 assert_initialized_main_thread!();
185 unsafe {
186 Option::<_>::from_glib_none(ffi::gst_pad_template_new(
187 name_template.to_glib_none().0,
188 direction.into_glib(),
189 presence.into_glib(),
190 caps.to_glib_none().0,
191 ))
192 .ok_or_else(|| glib::bool_error!("Failed to create pad template"))
193 }
194 }
195
196 /// Creates a new pad template with a name according to the given template
197 /// and with the given arguments.
198 /// ## `name_template`
199 /// the name template.
200 /// ## `direction`
201 /// the [`PadDirection`][crate::PadDirection] of the template.
202 /// ## `presence`
203 /// the [`PadPresence`][crate::PadPresence] of the pad.
204 /// ## `caps`
205 /// a [`Caps`][crate::Caps] set for the template.
206 /// ## `pad_type`
207 /// The `GType` of the pad to create
208 ///
209 /// # Returns
210 ///
211 /// a new [`PadTemplate`][crate::PadTemplate].
212 #[doc(alias = "gst_pad_template_new_with_gtype")]
213 #[doc(alias = "new_with_gtype")]
214 pub fn with_gtype(
215 name_template: &str,
216 direction: PadDirection,
217 presence: PadPresence,
218 caps: &Caps,
219 pad_type: glib::types::Type,
220 ) -> Result<PadTemplate, glib::BoolError> {
221 assert_initialized_main_thread!();
222 unsafe {
223 Option::<_>::from_glib_none(ffi::gst_pad_template_new_with_gtype(
224 name_template.to_glib_none().0,
225 direction.into_glib(),
226 presence.into_glib(),
227 caps.to_glib_none().0,
228 pad_type.into_glib(),
229 ))
230 .ok_or_else(|| glib::bool_error!("Failed to create pad template"))
231 }
232 }
233
234 /// Emit the pad-created signal for this template when created by this pad.
235 /// ## `pad`
236 /// the [`Pad`][crate::Pad] that created it
237 #[doc(alias = "gst_pad_template_pad_created")]
238 pub fn pad_created(&self, pad: &impl IsA<Pad>) {
239 unsafe {
240 ffi::gst_pad_template_pad_created(self.to_glib_none().0, pad.as_ref().to_glib_none().0);
241 }
242 }
243
244 /// This signal is fired when an element creates a pad from this template.
245 /// ## `pad`
246 /// the pad that was created.
247 #[doc(alias = "pad-created")]
248 pub fn connect_pad_created<F: Fn(&Self, &Pad) + Send + Sync + 'static>(
249 &self,
250 f: F,
251 ) -> SignalHandlerId {
252 unsafe extern "C" fn pad_created_trampoline<
253 F: Fn(&PadTemplate, &Pad) + Send + Sync + 'static,
254 >(
255 this: *mut ffi::GstPadTemplate,
256 pad: *mut ffi::GstPad,
257 f: glib::ffi::gpointer,
258 ) {
259 let f: &F = &*(f as *const F);
260 f(&from_glib_borrow(this), &from_glib_borrow(pad))
261 }
262 unsafe {
263 let f: Box_<F> = Box_::new(f);
264 connect_raw(
265 self.as_ptr() as *mut _,
266 c"pad-created".as_ptr() as *const _,
267 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
268 pad_created_trampoline::<F> as *const (),
269 )),
270 Box_::into_raw(f),
271 )
272 }
273 }
274}
275
276unsafe impl Send for PadTemplate {}
277unsafe impl Sync for PadTemplate {}