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
// 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, Object, PluginFeature};
use glib::translate::*;

glib::wrapper! {
    /// These functions allow querying information about registered typefind
    /// functions. How to create and register these functions is described in
    /// the section <link linkend="gstreamer-Writing-typefind-functions">
    /// "Writing typefind functions"`</link>`.
    ///
    /// The following example shows how to write a very simple typefinder that
    /// identifies the given data. You can get quite a bit more complicated than
    /// that though.
    ///
    ///
    /// **⚠️ The following code is in C ⚠️**
    ///
    /// ```C
    ///   typedef struct {
    ///     guint8 *data;
    ///     guint size;
    ///     guint probability;
    ///     GstCaps *data;
    ///   } MyTypeFind;
    ///   static void
    ///   my_peek (gpointer data, gint64 offset, guint size)
    ///   {
    ///     MyTypeFind *find = (MyTypeFind *) data;
    ///     if (offset >= 0 && offset + size <= find->size) {
    ///       return find->data + offset;
    ///     }
    ///     return NULL;
    ///   }
    ///   static void
    ///   my_suggest (gpointer data, guint probability, GstCaps *caps)
    ///   {
    ///     MyTypeFind *find = (MyTypeFind *) data;
    ///     if (probability > find->probability) {
    ///       find->probability = probability;
    ///       gst_caps_replace (&find->caps, caps);
    ///     }
    ///   }
    ///   static GstCaps *
    ///   find_type (guint8 *data, guint size)
    ///   {
    ///     GList *walk, *type_list;
    ///     MyTypeFind find = {data, size, 0, NULL};
    ///     GstTypeFind gst_find = {my_peek, my_suggest, &find, };
    ///     walk = type_list = gst_type_find_factory_get_list ();
    ///     while (walk) {
    ///       GstTypeFindFactory *factory = GST_TYPE_FIND_FACTORY (walk->data);
    ///       walk = g_list_next (walk)
    ///       gst_type_find_factory_call_function (factory, &gst_find);
    ///     }
    ///     g_list_free (type_list);
    ///     return find.caps;
    ///   };
    /// ```
    ///
    /// # Implements
    ///
    /// [`PluginFeatureExt`][trait@crate::prelude::PluginFeatureExt], [`GstObjectExt`][trait@crate::prelude::GstObjectExt], [`trait@glib::ObjectExt`], [`PluginFeatureExtManual`][trait@crate::prelude::PluginFeatureExtManual]
    #[doc(alias = "GstTypeFindFactory")]
    pub struct TypeFindFactory(Object<ffi::GstTypeFindFactory, ffi::GstTypeFindFactoryClass>) @extends PluginFeature, Object;

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

impl TypeFindFactory {
    /// Gets the [`Caps`][crate::Caps] associated with a typefind factory.
    ///
    /// # Returns
    ///
    /// the [`Caps`][crate::Caps] associated with this factory
    #[doc(alias = "gst_type_find_factory_get_caps")]
    #[doc(alias = "get_caps")]
    pub fn caps(&self) -> Option<Caps> {
        unsafe { from_glib_none(ffi::gst_type_find_factory_get_caps(self.to_glib_none().0)) }
    }

    /// Gets the extensions associated with a [`TypeFindFactory`][crate::TypeFindFactory]. The returned
    /// array should not be changed. If you need to change stuff in it, you should
    /// copy it using `g_strdupv()`. This function may return [`None`] to indicate
    /// a 0-length list.
    ///
    /// # Returns
    ///
    ///
    ///  a [`None`]-terminated array of extensions associated with this factory
    #[doc(alias = "gst_type_find_factory_get_extensions")]
    #[doc(alias = "get_extensions")]
    pub fn extensions(&self) -> Vec<glib::GString> {
        unsafe {
            FromGlibPtrContainer::from_glib_none(ffi::gst_type_find_factory_get_extensions(
                self.to_glib_none().0,
            ))
        }
    }

    /// Check whether the factory has a typefind function. Typefind factories
    /// without typefind functions are a last-effort fallback mechanism to
    /// e.g. assume a certain media type based on the file extension.
    ///
    /// # Returns
    ///
    /// [`true`] if the factory has a typefind functions set, otherwise [`false`]
    #[doc(alias = "gst_type_find_factory_has_function")]
    pub fn has_function(&self) -> bool {
        unsafe {
            from_glib(ffi::gst_type_find_factory_has_function(
                self.to_glib_none().0,
            ))
        }
    }
}

unsafe impl Send for TypeFindFactory {}
unsafe impl Sync for TypeFindFactory {}