1 | // Take a look at the license at the top of the repository in the LICENSE file. |
2 | |
3 | use std::mem; |
4 | |
5 | use glib::{prelude::*, translate::*}; |
6 | |
7 | #[doc (alias = "gst_type_find_helper_for_data" )] |
8 | pub fn type_find_helper_for_data( |
9 | obj: Option<&impl IsA<gst::Object>>, |
10 | data: impl AsRef<[u8]>, |
11 | ) -> Result<(gst::Caps, gst::TypeFindProbability), glib::error::BoolError> { |
12 | assert_initialized_main_thread!(); |
13 | unsafe { |
14 | let mut prob: MaybeUninit = mem::MaybeUninit::uninit(); |
15 | let data: &[u8] = data.as_ref(); |
16 | let (ptr: *const u8, len: usize) = (data.as_ptr(), data.len()); |
17 | let ret: *mut GstCaps = ffi::gst_type_find_helper_for_data( |
18 | obj:obj.map(|p| p.as_ref()).to_glib_none().0, |
19 | data:mut_override(ptr), |
20 | size:len, |
21 | prob:prob.as_mut_ptr(), |
22 | ); |
23 | if ret.is_null() { |
24 | Err(glib::bool_error!("No type could be found" )) |
25 | } else { |
26 | Ok((from_glib_full(ptr:ret), from_glib(val:prob.assume_init()))) |
27 | } |
28 | } |
29 | } |
30 | |
31 | #[cfg (feature = "v1_16" )] |
32 | #[cfg_attr (docsrs, doc(cfg(feature = "v1_16" )))] |
33 | #[doc (alias = "gst_type_find_helper_for_data_with_extension" )] |
34 | pub fn type_find_helper_for_data_with_extension( |
35 | obj: Option<&impl IsA<gst::Object>>, |
36 | data: impl AsRef<[u8]>, |
37 | extension: Option<&str>, |
38 | ) -> Result<(gst::Caps, gst::TypeFindProbability), glib::error::BoolError> { |
39 | assert_initialized_main_thread!(); |
40 | unsafe { |
41 | let mut prob = mem::MaybeUninit::uninit(); |
42 | let data = data.as_ref(); |
43 | let (ptr, len) = (data.as_ptr(), data.len()); |
44 | let ret = ffi::gst_type_find_helper_for_data_with_extension( |
45 | obj.map(|p| p.as_ref()).to_glib_none().0, |
46 | mut_override(ptr), |
47 | len, |
48 | extension.to_glib_none().0, |
49 | prob.as_mut_ptr(), |
50 | ); |
51 | if ret.is_null() { |
52 | Err(glib::bool_error!("No type could be found" )) |
53 | } else { |
54 | Ok((from_glib_full(ret), from_glib(prob.assume_init()))) |
55 | } |
56 | } |
57 | } |
58 | |
59 | #[doc (alias = "gst_type_find_helper_for_buffer" )] |
60 | pub fn type_find_helper_for_buffer<P: IsA<gst::Object>>( |
61 | obj: Option<&P>, |
62 | buf: &gst::BufferRef, |
63 | ) -> Result<(gst::Caps, gst::TypeFindProbability), glib::error::BoolError> { |
64 | skip_assert_initialized!(); |
65 | unsafe { |
66 | let mut prob: MaybeUninit = mem::MaybeUninit::uninit(); |
67 | let ret: *mut GstCaps = ffi::gst_type_find_helper_for_buffer( |
68 | obj:obj.map(|p| p.as_ref()).to_glib_none().0, |
69 | buf:mut_override(buf.as_ptr()), |
70 | prob:prob.as_mut_ptr(), |
71 | ); |
72 | if ret.is_null() { |
73 | Err(glib::bool_error!("No type could be found" )) |
74 | } else { |
75 | Ok((from_glib_full(ptr:ret), from_glib(val:prob.assume_init()))) |
76 | } |
77 | } |
78 | } |
79 | |
80 | #[cfg (feature = "v1_16" )] |
81 | #[cfg_attr (docsrs, doc(cfg(feature = "v1_16" )))] |
82 | #[doc (alias = "gst_type_find_helper_for_buffer_with_extension" )] |
83 | pub fn type_find_helper_for_buffer_with_extension<P: IsA<gst::Object>>( |
84 | obj: Option<&P>, |
85 | buf: &gst::BufferRef, |
86 | extension: Option<&str>, |
87 | ) -> Result<(gst::Caps, gst::TypeFindProbability), glib::error::BoolError> { |
88 | skip_assert_initialized!(); |
89 | unsafe { |
90 | let mut prob = mem::MaybeUninit::uninit(); |
91 | let ret = ffi::gst_type_find_helper_for_buffer_with_extension( |
92 | obj.map(|p| p.as_ref()).to_glib_none().0, |
93 | mut_override(buf.as_ptr()), |
94 | extension.to_glib_none().0, |
95 | prob.as_mut_ptr(), |
96 | ); |
97 | if ret.is_null() { |
98 | Err(glib::bool_error!("No type could be found" )) |
99 | } else { |
100 | Ok((from_glib_full(ret), from_glib(prob.assume_init()))) |
101 | } |
102 | } |
103 | } |
104 | |
105 | #[cfg (feature = "v1_22" )] |
106 | #[cfg_attr (docsrs, doc(cfg(feature = "v1_22" )))] |
107 | #[doc (alias = "gst_type_find_helper_for_buffer_with_caps" )] |
108 | pub fn type_find_helper_for_buffer_with_caps( |
109 | obj: Option<&impl IsA<gst::Object>>, |
110 | buf: &gst::BufferRef, |
111 | caps: &gst::CapsRef, |
112 | ) -> (Option<gst::Caps>, gst::TypeFindProbability) { |
113 | skip_assert_initialized!(); |
114 | unsafe { |
115 | let mut prob = mem::MaybeUninit::uninit(); |
116 | let ret = from_glib_full(ffi::gst_type_find_helper_for_buffer_with_caps( |
117 | obj.map(|p| p.as_ref()).to_glib_none().0, |
118 | mut_override(buf.as_ptr()), |
119 | mut_override(caps.as_ptr()), |
120 | prob.as_mut_ptr(), |
121 | )); |
122 | (ret, from_glib(prob.assume_init())) |
123 | } |
124 | } |
125 | |
126 | #[cfg (feature = "v1_22" )] |
127 | #[cfg_attr (docsrs, doc(cfg(feature = "v1_22" )))] |
128 | #[doc (alias = "gst_type_find_helper_for_data_with_caps" )] |
129 | pub fn type_find_helper_for_data_with_caps( |
130 | obj: Option<&impl IsA<gst::Object>>, |
131 | data: &[u8], |
132 | caps: &gst::CapsRef, |
133 | ) -> (Option<gst::Caps>, gst::TypeFindProbability) { |
134 | skip_assert_initialized!(); |
135 | let size = data.len() as _; |
136 | unsafe { |
137 | let mut prob = mem::MaybeUninit::uninit(); |
138 | let ret = from_glib_full(ffi::gst_type_find_helper_for_data_with_caps( |
139 | obj.map(|p| p.as_ref()).to_glib_none().0, |
140 | data.to_glib_none().0, |
141 | size, |
142 | mut_override(caps.as_ptr()), |
143 | prob.as_mut_ptr(), |
144 | )); |
145 | (ret, from_glib(prob.assume_init())) |
146 | } |
147 | } |
148 | |
149 | #[cfg (feature = "v1_22" )] |
150 | #[cfg_attr (docsrs, doc(cfg(feature = "v1_22" )))] |
151 | #[doc (alias = "gst_type_find_list_factories_for_caps" )] |
152 | pub fn type_find_list_factories_for_caps( |
153 | obj: Option<&impl IsA<gst::Object>>, |
154 | caps: &gst::CapsRef, |
155 | ) -> glib::List<gst::TypeFindFactory> { |
156 | skip_assert_initialized!(); |
157 | unsafe { |
158 | glib::collections::List::from_glib_full(ffi::gst_type_find_list_factories_for_caps( |
159 | obj.map(|p| p.as_ref()).to_glib_none().0, |
160 | mut_override(caps.as_ptr()), |
161 | )) |
162 | } |
163 | } |
164 | |