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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
// 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::Caps;
use crate::Element;
use crate::ElementFactoryListType;
use crate::Object;
use crate::PadDirection;
use crate::PluginFeature;
use crate::Rank;
use crate::StaticPadTemplate;
use crate::URIType;
use glib::translate::*;

glib::wrapper! {
    /// [`crate::ElementFactory`] is used to create instances of elements. A
    /// GstElementFactory can be added to a [`crate::Plugin`] as it is also a
    /// [`crate::PluginFeature`].
    ///
    /// Use the [`Self::find()`] and [`Self::create()`]
    /// functions to create element instances or use [`Self::make()`] as a
    /// convenient shortcut.
    ///
    /// The following code example shows you how to create a GstFileSrc element.
    ///
    /// ## Using an element factory
    ///
    /// ```C
    ///   #include <gst/gst.h>
    ///
    ///   GstElement *src;
    ///   GstElementFactory *srcfactory;
    ///
    ///   gst_init (&argc, &argv);
    ///
    ///   srcfactory = gst_element_factory_find ("filesrc");
    ///   g_return_if_fail (srcfactory != NULL);
    ///   src = gst_element_factory_create (srcfactory, "src");
    ///   g_return_if_fail (src != NULL);
    ///   ...
    /// ```
    ///
    /// # Implements
    ///
    /// [`trait@crate::prelude::PluginFeatureExt`], [`trait@crate::prelude::GstObjectExt`], [`trait@glib::object::ObjectExt`], [`trait@crate::prelude::PluginFeatureExtManual`]
    pub struct ElementFactory(Object<ffi::GstElementFactory, ffi::GstElementFactoryClass>) @extends PluginFeature, Object;

    match fn {
        type_ => || ffi::gst_element_factory_get_type(),
    }
}

impl ElementFactory {
    /// Checks if the factory can sink all possible capabilities.
    /// ## `caps`
    /// the caps to check
    ///
    /// # Returns
    ///
    /// [`true`] if the caps are fully compatible.
    #[doc(alias = "gst_element_factory_can_sink_all_caps")]
    pub fn can_sink_all_caps(&self, caps: &Caps) -> bool {
        unsafe {
            from_glib(ffi::gst_element_factory_can_sink_all_caps(
                self.to_glib_none().0,
                caps.to_glib_none().0,
            ))
        }
    }

    /// Checks if the factory can sink any possible capability.
    /// ## `caps`
    /// the caps to check
    ///
    /// # Returns
    ///
    /// [`true`] if the caps have a common subset.
    #[doc(alias = "gst_element_factory_can_sink_any_caps")]
    pub fn can_sink_any_caps(&self, caps: &Caps) -> bool {
        unsafe {
            from_glib(ffi::gst_element_factory_can_sink_any_caps(
                self.to_glib_none().0,
                caps.to_glib_none().0,
            ))
        }
    }

    /// Checks if the factory can src all possible capabilities.
    /// ## `caps`
    /// the caps to check
    ///
    /// # Returns
    ///
    /// [`true`] if the caps are fully compatible.
    #[doc(alias = "gst_element_factory_can_src_all_caps")]
    pub fn can_src_all_caps(&self, caps: &Caps) -> bool {
        unsafe {
            from_glib(ffi::gst_element_factory_can_src_all_caps(
                self.to_glib_none().0,
                caps.to_glib_none().0,
            ))
        }
    }

    /// Checks if the factory can src any possible capability.
    /// ## `caps`
    /// the caps to check
    ///
    /// # Returns
    ///
    /// [`true`] if the caps have a common subset.
    #[doc(alias = "gst_element_factory_can_src_any_caps")]
    pub fn can_src_any_caps(&self, caps: &Caps) -> bool {
        unsafe {
            from_glib(ffi::gst_element_factory_can_src_any_caps(
                self.to_glib_none().0,
                caps.to_glib_none().0,
            ))
        }
    }

    /// Create a new element of the type defined by the given elementfactory.
    /// It will be given the name supplied, since all elements require a name as
    /// their first argument.
    /// ## `name`
    /// name of new element, or [`None`] to automatically create
    ///  a unique name
    ///
    /// # Returns
    ///
    /// new [`crate::Element`] or [`None`]
    ///  if the element couldn't be created
    #[doc(alias = "gst_element_factory_create")]
    pub fn create(&self, name: Option<&str>) -> Result<Element, glib::BoolError> {
        unsafe {
            Option::<_>::from_glib_none(ffi::gst_element_factory_create(
                self.to_glib_none().0,
                name.to_glib_none().0,
            ))
            .ok_or_else(|| glib::bool_error!("Failed to create element from factory"))
        }
    }

    /// Get the [`crate::glib::Type`] for elements managed by this factory. The type can
    /// only be retrieved if the element factory is loaded, which can be
    /// assured with [`crate::PluginFeature::load()`].
    ///
    /// # Returns
    ///
    /// the [`crate::glib::Type`] for elements managed by this factory or 0 if
    /// the factory is not loaded.
    #[doc(alias = "gst_element_factory_get_element_type")]
    #[doc(alias = "get_element_type")]
    pub fn element_type(&self) -> glib::types::Type {
        unsafe {
            from_glib(ffi::gst_element_factory_get_element_type(
                self.to_glib_none().0,
            ))
        }
    }

    /// Get the metadata on `self` with `key`.
    /// ## `key`
    /// a key
    ///
    /// # Returns
    ///
    /// the metadata with `key` on `self` or [`None`]
    /// when there was no metadata with the given `key`.
    #[doc(alias = "gst_element_factory_get_metadata")]
    #[doc(alias = "get_metadata")]
    pub fn metadata(&self, key: &str) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::gst_element_factory_get_metadata(
                self.to_glib_none().0,
                key.to_glib_none().0,
            ))
        }
    }

    /// Get the available keys for the metadata on `self`.
    ///
    /// # Returns
    ///
    ///
    /// a [`None`]-terminated array of key strings, or [`None`] when there is no
    /// metadata. Free with `g_strfreev()` when no longer needed.
    #[doc(alias = "gst_element_factory_get_metadata_keys")]
    #[doc(alias = "get_metadata_keys")]
    pub fn metadata_keys(&self) -> Vec<glib::GString> {
        unsafe {
            FromGlibPtrContainer::from_glib_full(ffi::gst_element_factory_get_metadata_keys(
                self.to_glib_none().0,
            ))
        }
    }

    /// Gets the number of pad_templates in this factory.
    ///
    /// # Returns
    ///
    /// the number of pad_templates
    #[doc(alias = "gst_element_factory_get_num_pad_templates")]
    #[doc(alias = "get_num_pad_templates")]
    pub fn num_pad_templates(&self) -> u32 {
        unsafe { ffi::gst_element_factory_get_num_pad_templates(self.to_glib_none().0) }
    }

    /// Gets the [`crate::glib::List`] of [`crate::StaticPadTemplate`] for this factory.
    ///
    /// # Returns
    ///
    /// the
    ///  static pad templates
    #[doc(alias = "gst_element_factory_get_static_pad_templates")]
    #[doc(alias = "get_static_pad_templates")]
    pub fn static_pad_templates(&self) -> Vec<StaticPadTemplate> {
        unsafe {
            FromGlibPtrContainer::from_glib_none(ffi::gst_element_factory_get_static_pad_templates(
                self.to_glib_none().0,
            ))
        }
    }

    /// Gets a [`None`]-terminated array of protocols this element supports or [`None`] if
    /// no protocols are supported. You may not change the contents of the returned
    /// array, as it is still owned by the element factory. Use `g_strdupv()` to
    /// make a copy of the protocol string array if you need to.
    ///
    /// # Returns
    ///
    /// the supported protocols
    ///  or [`None`]
    #[doc(alias = "gst_element_factory_get_uri_protocols")]
    #[doc(alias = "get_uri_protocols")]
    pub fn uri_protocols(&self) -> Vec<glib::GString> {
        unsafe {
            FromGlibPtrContainer::from_glib_none(ffi::gst_element_factory_get_uri_protocols(
                self.to_glib_none().0,
            ))
        }
    }

    /// Gets the type of URIs the element supports or [`crate::URIType::Unknown`] if none.
    ///
    /// # Returns
    ///
    /// type of URIs this element supports
    #[doc(alias = "gst_element_factory_get_uri_type")]
    #[doc(alias = "get_uri_type")]
    pub fn uri_type(&self) -> URIType {
        unsafe { from_glib(ffi::gst_element_factory_get_uri_type(self.to_glib_none().0)) }
    }

    /// Check if `self` implements the interface with name `interfacename`.
    /// ## `interfacename`
    /// an interface name
    ///
    /// # Returns
    ///
    /// [`true`] when `self` implement the interface.
    #[doc(alias = "gst_element_factory_has_interface")]
    pub fn has_interface(&self, interfacename: &str) -> bool {
        unsafe {
            from_glib(ffi::gst_element_factory_has_interface(
                self.to_glib_none().0,
                interfacename.to_glib_none().0,
            ))
        }
    }

    /// Check if `self` is of the given types.
    /// ## `type_`
    /// a [`crate::ElementFactoryListType`]
    ///
    /// # Returns
    ///
    /// [`true`] if `self` is of `type_`.
    #[doc(alias = "gst_element_factory_list_is_type")]
    pub fn list_is_type(&self, type_: ElementFactoryListType) -> bool {
        unsafe {
            from_glib(ffi::gst_element_factory_list_is_type(
                self.to_glib_none().0,
                type_.into_glib(),
            ))
        }
    }

    /// Search for an element factory of the given name. Refs the returned
    /// element factory; caller is responsible for unreffing.
    /// ## `name`
    /// name of factory to find
    ///
    /// # Returns
    ///
    /// [`crate::ElementFactory`] if found,
    /// [`None`] otherwise
    #[doc(alias = "gst_element_factory_find")]
    pub fn find(name: &str) -> Option<ElementFactory> {
        assert_initialized_main_thread!();
        unsafe { from_glib_full(ffi::gst_element_factory_find(name.to_glib_none().0)) }
    }

    /// Filter out all the elementfactories in `list` that can handle `caps` in
    /// the given direction.
    ///
    /// If `subsetonly` is [`true`], then only the elements whose pads templates
    /// are a complete superset of `caps` will be returned. Else any element
    /// whose pad templates caps can intersect with `caps` will be returned.
    /// ## `list`
    /// a [`crate::glib::List`] of
    ///  [`crate::ElementFactory`] to filter
    /// ## `caps`
    /// a [`crate::Caps`]
    /// ## `direction`
    /// a [`crate::PadDirection`] to filter on
    /// ## `subsetonly`
    /// whether to filter on caps subsets or not.
    ///
    /// # Returns
    ///
    /// a [`crate::glib::List`] of
    ///  [`crate::ElementFactory`] elements that match the given requisites.
    ///  Use [`crate::PluginFeature::list_free`] after usage.
    #[doc(alias = "gst_element_factory_list_filter")]
    pub fn list_filter(
        list: &[ElementFactory],
        caps: &Caps,
        direction: PadDirection,
        subsetonly: bool,
    ) -> Vec<ElementFactory> {
        assert_initialized_main_thread!();
        unsafe {
            FromGlibPtrContainer::from_glib_full(ffi::gst_element_factory_list_filter(
                list.to_glib_none().0,
                caps.to_glib_none().0,
                direction.into_glib(),
                subsetonly.into_glib(),
            ))
        }
    }

    /// Get a list of factories that match the given `type_`. Only elements
    /// with a rank greater or equal to `minrank` will be returned.
    /// The list of factories is returned by decreasing rank.
    /// ## `type_`
    /// a [`crate::ElementFactoryListType`]
    /// ## `minrank`
    /// Minimum rank
    ///
    /// # Returns
    ///
    /// a [`crate::glib::List`] of
    ///  [`crate::ElementFactory`] elements. Use [`crate::PluginFeature::list_free()`] after
    ///  usage.
    #[doc(alias = "gst_element_factory_list_get_elements")]
    pub fn list_get_elements(type_: ElementFactoryListType, minrank: Rank) -> Vec<ElementFactory> {
        assert_initialized_main_thread!();
        unsafe {
            FromGlibPtrContainer::from_glib_full(ffi::gst_element_factory_list_get_elements(
                type_.into_glib(),
                minrank.into_glib(),
            ))
        }
    }

    /// Create a new element of the type defined by the given element factory.
    /// If name is [`None`], then the element will receive a guaranteed unique name,
    /// consisting of the element factory name and a number.
    /// If name is given, it will be given the name supplied.
    /// ## `factoryname`
    /// a named factory to instantiate
    /// ## `name`
    /// name of new element, or [`None`] to automatically create
    ///  a unique name
    ///
    /// # Returns
    ///
    /// new [`crate::Element`] or [`None`]
    /// if unable to create element
    #[doc(alias = "gst_element_factory_make")]
    pub fn make(factoryname: &str, name: Option<&str>) -> Result<Element, glib::BoolError> {
        assert_initialized_main_thread!();
        unsafe {
            Option::<_>::from_glib_none(ffi::gst_element_factory_make(
                factoryname.to_glib_none().0,
                name.to_glib_none().0,
            ))
            .ok_or_else(|| glib::bool_error!("Failed to create element from factory name"))
        }
    }
}

unsafe impl Send for ElementFactory {}
unsafe impl Sync for ElementFactory {}