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
// Take a look at the license at the top of the repository in the LICENSE file.
use std::mem;
pub use crate::auto::functions::*;
use crate::ffi;
use glib::{prelude::*, translate::*};
/// Tries to find what type of data is contained in the given `data`, the
/// assumption being that the data represents the beginning of the stream or
/// file.
///
/// All available typefinders will be called on the data in order of rank. If
/// a typefinding function returns a probability of [`gst::TypeFindProbability::Maximum`][crate::gst::TypeFindProbability::Maximum],
/// typefinding is stopped immediately and the found caps will be returned
/// right away. Otherwise, all available typefind functions will the tried,
/// and the caps with the highest probability will be returned, or [`None`] if
/// the content of `data` could not be identified.
///
/// Free-function: gst_caps_unref
/// ## `obj`
/// object doing the typefinding, or [`None`] (used for logging)
/// ## `data`
/// * a pointer with data to typefind
///
/// # Returns
///
/// the [`gst::Caps`][crate::gst::Caps] corresponding to the data,
/// or [`None`] if no type could be found. The caller should free the caps
/// returned with `gst_caps_unref()`.
///
/// ## `prob`
/// location to store the probability of the found
/// caps, or [`None`]
#[doc(alias = "gst_type_find_helper_for_data")]
pub fn type_find_helper_for_data(
obj: Option<&impl IsA<gst::Object>>,
data: impl AsRef<[u8]>,
) -> Result<(gst::Caps, gst::TypeFindProbability), glib::error::BoolError> {
assert_initialized_main_thread!();
unsafe {
let mut prob = mem::MaybeUninit::uninit();
let data = data.as_ref();
let (ptr, len) = (data.as_ptr(), data.len());
let ret = ffi::gst_type_find_helper_for_data(
obj.map(|p| p.as_ref()).to_glib_none().0,
mut_override(ptr),
len,
prob.as_mut_ptr(),
);
if ret.is_null() {
Err(glib::bool_error!("No type could be found"))
} else {
Ok((from_glib_full(ret), from_glib(prob.assume_init())))
}
}
}
/// Tries to find what type of data is contained in the given `data`, the
/// assumption being that the data represents the beginning of the stream or
/// file.
///
/// All available typefinders will be called on the data in order of rank. If
/// a typefinding function returns a probability of [`gst::TypeFindProbability::Maximum`][crate::gst::TypeFindProbability::Maximum],
/// typefinding is stopped immediately and the found caps will be returned
/// right away. Otherwise, all available typefind functions will the tried,
/// and the caps with the highest probability will be returned, or [`None`] if
/// the content of `data` could not be identified.
///
/// When `extension` is not [`None`], this function will first try the typefind
/// functions for the given extension, which might speed up the typefinding
/// in many cases.
///
/// Free-function: gst_caps_unref
/// ## `obj`
/// object doing the typefinding, or [`None`] (used for logging)
/// ## `data`
/// * a pointer with data to typefind
/// ## `extension`
/// extension of the media, or [`None`]
///
/// # Returns
///
/// the [`gst::Caps`][crate::gst::Caps] corresponding to the data,
/// or [`None`] if no type could be found. The caller should free the caps
/// returned with `gst_caps_unref()`.
///
/// ## `prob`
/// location to store the probability of the found
/// caps, or [`None`]
#[cfg(feature = "v1_16")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
#[doc(alias = "gst_type_find_helper_for_data_with_extension")]
pub fn type_find_helper_for_data_with_extension(
obj: Option<&impl IsA<gst::Object>>,
data: impl AsRef<[u8]>,
extension: Option<&str>,
) -> Result<(gst::Caps, gst::TypeFindProbability), glib::error::BoolError> {
assert_initialized_main_thread!();
unsafe {
let mut prob = mem::MaybeUninit::uninit();
let data = data.as_ref();
let (ptr, len) = (data.as_ptr(), data.len());
let ret = ffi::gst_type_find_helper_for_data_with_extension(
obj.map(|p| p.as_ref()).to_glib_none().0,
mut_override(ptr),
len,
extension.to_glib_none().0,
prob.as_mut_ptr(),
);
if ret.is_null() {
Err(glib::bool_error!("No type could be found"))
} else {
Ok((from_glib_full(ret), from_glib(prob.assume_init())))
}
}
}
/// Tries to find what type of data is contained in the given [`gst::Buffer`][crate::gst::Buffer], the
/// assumption being that the buffer represents the beginning of the stream or
/// file.
///
/// All available typefinders will be called on the data in order of rank. If
/// a typefinding function returns a probability of [`gst::TypeFindProbability::Maximum`][crate::gst::TypeFindProbability::Maximum],
/// typefinding is stopped immediately and the found caps will be returned
/// right away. Otherwise, all available typefind functions will the tried,
/// and the caps with the highest probability will be returned, or [`None`] if
/// the content of the buffer could not be identified.
///
/// Free-function: gst_caps_unref
/// ## `obj`
/// object doing the typefinding, or [`None`] (used for logging)
/// ## `buf`
/// a [`gst::Buffer`][crate::gst::Buffer] with data to typefind
///
/// # Returns
///
/// the [`gst::Caps`][crate::gst::Caps] corresponding to the data,
/// or [`None`] if no type could be found. The caller should free the caps
/// returned with `gst_caps_unref()`.
///
/// ## `prob`
/// location to store the probability of the found
/// caps, or [`None`]
#[doc(alias = "gst_type_find_helper_for_buffer")]
pub fn type_find_helper_for_buffer<P: IsA<gst::Object>>(
obj: Option<&P>,
buf: &gst::BufferRef,
) -> Result<(gst::Caps, gst::TypeFindProbability), glib::error::BoolError> {
skip_assert_initialized!();
unsafe {
let mut prob = mem::MaybeUninit::uninit();
let ret = ffi::gst_type_find_helper_for_buffer(
obj.map(|p| p.as_ref()).to_glib_none().0,
mut_override(buf.as_ptr()),
prob.as_mut_ptr(),
);
if ret.is_null() {
Err(glib::bool_error!("No type could be found"))
} else {
Ok((from_glib_full(ret), from_glib(prob.assume_init())))
}
}
}
/// Tries to find what type of data is contained in the given [`gst::Buffer`][crate::gst::Buffer], the
/// assumption being that the buffer represents the beginning of the stream or
/// file.
///
/// All available typefinders will be called on the data in order of rank. If
/// a typefinding function returns a probability of [`gst::TypeFindProbability::Maximum`][crate::gst::TypeFindProbability::Maximum],
/// typefinding is stopped immediately and the found caps will be returned
/// right away. Otherwise, all available typefind functions will the tried,
/// and the caps with the highest probability will be returned, or [`None`] if
/// the content of the buffer could not be identified.
///
/// When `extension` is not [`None`], this function will first try the typefind
/// functions for the given extension, which might speed up the typefinding
/// in many cases.
///
/// Free-function: gst_caps_unref
/// ## `obj`
/// object doing the typefinding, or [`None`] (used for logging)
/// ## `buf`
/// a [`gst::Buffer`][crate::gst::Buffer] with data to typefind
/// ## `extension`
/// extension of the media, or [`None`]
///
/// # Returns
///
/// the [`gst::Caps`][crate::gst::Caps] corresponding to the data,
/// or [`None`] if no type could be found. The caller should free the caps
/// returned with `gst_caps_unref()`.
///
/// ## `prob`
/// location to store the probability of the found
/// caps, or [`None`]
#[cfg(feature = "v1_16")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
#[doc(alias = "gst_type_find_helper_for_buffer_with_extension")]
pub fn type_find_helper_for_buffer_with_extension<P: IsA<gst::Object>>(
obj: Option<&P>,
buf: &gst::BufferRef,
extension: Option<&str>,
) -> Result<(gst::Caps, gst::TypeFindProbability), glib::error::BoolError> {
skip_assert_initialized!();
unsafe {
let mut prob = mem::MaybeUninit::uninit();
let ret = ffi::gst_type_find_helper_for_buffer_with_extension(
obj.map(|p| p.as_ref()).to_glib_none().0,
mut_override(buf.as_ptr()),
extension.to_glib_none().0,
prob.as_mut_ptr(),
);
if ret.is_null() {
Err(glib::bool_error!("No type could be found"))
} else {
Ok((from_glib_full(ret), from_glib(prob.assume_init())))
}
}
}
/// Tries to find if type of media contained in the given [`gst::Buffer`][crate::gst::Buffer], matches
/// `caps` specified, assumption being that the buffer represents the beginning
/// of the stream or file.
///
/// Tries to find what type of data is contained in the given `data`, the
/// assumption being that the data represents the beginning of the stream or
/// file.
///
/// Only the typefinder matching the given caps will be called, if found. The
/// caps with the highest probability will be returned, or [`None`] if the content
/// of the `data` could not be identified.
///
/// Free-function: gst_caps_unref
/// ## `obj`
/// object doing the typefinding, or [`None`] (used for logging)
/// ## `buf`
/// a [`gst::Buffer`][crate::gst::Buffer] with data to typefind
/// ## `caps`
/// caps of the media
///
/// # Returns
///
/// the [`gst::Caps`][crate::gst::Caps] corresponding to the data,
/// or [`None`] if no type could be found. The caller should free the caps
/// returned with `gst_caps_unref()`.
///
/// ## `prob`
/// location to store the probability of the found
/// caps, or [`None`]
#[cfg(feature = "v1_22")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
#[doc(alias = "gst_type_find_helper_for_buffer_with_caps")]
pub fn type_find_helper_for_buffer_with_caps(
obj: Option<&impl IsA<gst::Object>>,
buf: &gst::BufferRef,
caps: &gst::CapsRef,
) -> (Option<gst::Caps>, gst::TypeFindProbability) {
skip_assert_initialized!();
unsafe {
let mut prob = mem::MaybeUninit::uninit();
let ret = from_glib_full(ffi::gst_type_find_helper_for_buffer_with_caps(
obj.map(|p| p.as_ref()).to_glib_none().0,
mut_override(buf.as_ptr()),
mut_override(caps.as_ptr()),
prob.as_mut_ptr(),
));
(ret, from_glib(prob.assume_init()))
}
}
/// Tries to find if type of media contained in the given `data`, matches the
/// `caps` specified, assumption being that the data represents the beginning
/// of the stream or file.
///
/// Only the typefinder matching the given caps will be called, if found. The
/// caps with the highest probability will be returned, or [`None`] if the content
/// of the `data` could not be identified.
///
/// Free-function: gst_caps_unref
/// ## `obj`
/// object doing the typefinding, or [`None`] (used for logging)
/// ## `data`
/// a pointer with data to typefind
/// ## `caps`
/// caps of the media
///
/// # Returns
///
/// the [`gst::Caps`][crate::gst::Caps] corresponding to the data,
/// or [`None`] if no type could be found. The caller should free the caps
/// returned with `gst_caps_unref()`.
///
/// ## `prob`
/// location to store the probability of the found
/// caps, or [`None`]
#[cfg(feature = "v1_22")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
#[doc(alias = "gst_type_find_helper_for_data_with_caps")]
pub fn type_find_helper_for_data_with_caps(
obj: Option<&impl IsA<gst::Object>>,
data: &[u8],
caps: &gst::CapsRef,
) -> (Option<gst::Caps>, gst::TypeFindProbability) {
skip_assert_initialized!();
let size = data.len() as _;
unsafe {
let mut prob = mem::MaybeUninit::uninit();
let ret = from_glib_full(ffi::gst_type_find_helper_for_data_with_caps(
obj.map(|p| p.as_ref()).to_glib_none().0,
data.to_glib_none().0,
size,
mut_override(caps.as_ptr()),
prob.as_mut_ptr(),
));
(ret, from_glib(prob.assume_init()))
}
}
/// Tries to find the best `GstTypeFindFactory` associated with `caps`.
///
/// The typefinder that can handle `caps` will be returned.
///
/// Free-function: g_list_free
/// ## `obj`
/// object doing the typefinding, or [`None`] (used for logging)
/// ## `caps`
/// caps of the media
///
/// # Returns
///
/// the list of `GstTypeFindFactory`
/// corresponding to `caps`, or [`None`] if no typefinder could be
/// found. Caller should free the returned list with `g_list_free()`
/// and list elements with `gst_object_unref()`.
#[cfg(feature = "v1_22")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
#[doc(alias = "gst_type_find_list_factories_for_caps")]
pub fn type_find_list_factories_for_caps(
obj: Option<&impl IsA<gst::Object>>,
caps: &gst::CapsRef,
) -> glib::List<gst::TypeFindFactory> {
skip_assert_initialized!();
unsafe {
glib::collections::List::from_glib_full(ffi::gst_type_find_list_factories_for_caps(
obj.map(|p| p.as_ref()).to_glib_none().0,
mut_override(caps.as_ptr()),
))
}
}