gstreamer/auto/type_find_factory.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, PluginFeature, ffi};
7use glib::translate::*;
8
9glib::wrapper! {
10 /// These functions allow querying information about registered typefind
11 /// functions. How to create and register these functions is described in
12 /// the section <link linkend="gstreamer-Writing-typefind-functions">
13 /// "Writing typefind functions"`</link>`.
14 ///
15 /// The following example shows how to write a very simple typefinder that
16 /// identifies the given data. You can get quite a bit more complicated than
17 /// that though.
18 ///
19 ///
20 /// **⚠️ The following code is in C ⚠️**
21 ///
22 /// ```C
23 /// typedef struct {
24 /// guint8 *data;
25 /// guint size;
26 /// guint probability;
27 /// GstCaps *data;
28 /// } MyTypeFind;
29 /// static void
30 /// my_peek (gpointer data, gint64 offset, guint size)
31 /// {
32 /// MyTypeFind *find = (MyTypeFind *) data;
33 /// if (offset >= 0 && offset + size <= find->size) {
34 /// return find->data + offset;
35 /// }
36 /// return NULL;
37 /// }
38 /// static void
39 /// my_suggest (gpointer data, guint probability, GstCaps *caps)
40 /// {
41 /// MyTypeFind *find = (MyTypeFind *) data;
42 /// if (probability > find->probability) {
43 /// find->probability = probability;
44 /// gst_caps_replace (&find->caps, caps);
45 /// }
46 /// }
47 /// static GstCaps *
48 /// find_type (guint8 *data, guint size)
49 /// {
50 /// GList *walk, *type_list;
51 /// MyTypeFind find = {data, size, 0, NULL};
52 /// GstTypeFind gst_find = {my_peek, my_suggest, &find, };
53 /// walk = type_list = gst_type_find_factory_get_list ();
54 /// while (walk) {
55 /// GstTypeFindFactory *factory = GST_TYPE_FIND_FACTORY (walk->data);
56 /// walk = g_list_next (walk)
57 /// gst_type_find_factory_call_function (factory, &gst_find);
58 /// }
59 /// g_list_free (type_list);
60 /// return find.caps;
61 /// };
62 /// ```
63 ///
64 /// # Implements
65 ///
66 /// [`PluginFeatureExt`][trait@crate::prelude::PluginFeatureExt], [`GstObjectExt`][trait@crate::prelude::GstObjectExt], [`trait@glib::ObjectExt`], [`PluginFeatureExtManual`][trait@crate::prelude::PluginFeatureExtManual], [`GstObjectExtManual`][trait@crate::prelude::GstObjectExtManual]
67 #[doc(alias = "GstTypeFindFactory")]
68 pub struct TypeFindFactory(Object<ffi::GstTypeFindFactory, ffi::GstTypeFindFactoryClass>) @extends PluginFeature, Object;
69
70 match fn {
71 type_ => || ffi::gst_type_find_factory_get_type(),
72 }
73}
74
75impl TypeFindFactory {
76 /// Gets the [`Caps`][crate::Caps] associated with a typefind factory.
77 ///
78 /// # Returns
79 ///
80 /// the [`Caps`][crate::Caps] associated with this factory
81 #[doc(alias = "gst_type_find_factory_get_caps")]
82 #[doc(alias = "get_caps")]
83 pub fn caps(&self) -> Option<Caps> {
84 unsafe { from_glib_none(ffi::gst_type_find_factory_get_caps(self.to_glib_none().0)) }
85 }
86
87 /// Gets the extensions associated with a [`TypeFindFactory`][crate::TypeFindFactory]. The returned
88 /// array should not be changed. If you need to change stuff in it, you should
89 /// copy it using `g_strdupv()`. This function may return [`None`] to indicate
90 /// a 0-length list.
91 ///
92 /// # Returns
93 ///
94 ///
95 /// a [`None`]-terminated array of extensions associated with this factory
96 #[doc(alias = "gst_type_find_factory_get_extensions")]
97 #[doc(alias = "get_extensions")]
98 pub fn extensions(&self) -> Vec<glib::GString> {
99 unsafe {
100 FromGlibPtrContainer::from_glib_none(ffi::gst_type_find_factory_get_extensions(
101 self.to_glib_none().0,
102 ))
103 }
104 }
105
106 /// Check whether the factory has a typefind function. Typefind factories
107 /// without typefind functions are a last-effort fallback mechanism to
108 /// e.g. assume a certain media type based on the file extension.
109 ///
110 /// # Returns
111 ///
112 /// [`true`] if the factory has a typefind functions set, otherwise [`false`]
113 #[doc(alias = "gst_type_find_factory_has_function")]
114 pub fn has_function(&self) -> bool {
115 unsafe {
116 from_glib(ffi::gst_type_find_factory_has_function(
117 self.to_glib_none().0,
118 ))
119 }
120 }
121}
122
123unsafe impl Send for TypeFindFactory {}
124unsafe impl Sync for TypeFindFactory {}