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