2020-12-15 10:53:31 +00:00
|
|
|
// Take a look at the license at the top of the repository in the LICENSE file.
|
2017-08-17 13:17:02 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
use crate::auto::functions::parse_bin_from_description;
|
2021-04-26 12:15:53 +00:00
|
|
|
use glib::prelude::*;
|
2017-08-17 13:17:02 +00:00
|
|
|
use glib::translate::*;
|
|
|
|
use std::ptr;
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
use crate::Bin;
|
|
|
|
use crate::Element;
|
|
|
|
use crate::Object;
|
|
|
|
use crate::ParseContext;
|
|
|
|
use crate::ParseFlags;
|
2017-08-17 13:17:02 +00:00
|
|
|
|
2020-07-15 18:24:18 +00:00
|
|
|
pub fn parse_bin_from_description_with_name(
|
|
|
|
bin_description: &str,
|
|
|
|
ghost_unlinked_pads: bool,
|
|
|
|
bin_name: &str,
|
|
|
|
) -> Result<Bin, glib::Error> {
|
|
|
|
assert_initialized_main_thread!();
|
|
|
|
let bin = parse_bin_from_description(bin_description, ghost_unlinked_pads)?;
|
|
|
|
if !bin_name.is_empty() {
|
|
|
|
let obj = bin.clone().upcast::<Object>();
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_object_set_name(obj.to_glib_none().0, bin_name.to_glib_none().0);
|
2020-07-15 18:24:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(bin)
|
|
|
|
}
|
|
|
|
|
2019-05-23 18:19:24 +00:00
|
|
|
pub fn parse_bin_from_description_full(
|
2017-08-17 13:17:02 +00:00
|
|
|
bin_description: &str,
|
|
|
|
ghost_unlinked_pads: bool,
|
2019-05-23 18:19:24 +00:00
|
|
|
mut context: Option<&mut ParseContext>,
|
2017-08-17 13:17:02 +00:00
|
|
|
flags: ParseFlags,
|
2019-11-10 17:00:00 +00:00
|
|
|
) -> Result<Element, glib::Error> {
|
2017-08-17 13:17:02 +00:00
|
|
|
assert_initialized_main_thread!();
|
|
|
|
unsafe {
|
|
|
|
let mut error = ptr::null_mut();
|
2020-11-21 13:46:48 +00:00
|
|
|
let ret = ffi::gst_parse_bin_from_description_full(
|
2017-08-17 13:17:02 +00:00
|
|
|
bin_description.to_glib_none().0,
|
|
|
|
ghost_unlinked_pads.to_glib(),
|
|
|
|
context.to_glib_none_mut().0,
|
|
|
|
flags.to_glib(),
|
|
|
|
&mut error,
|
|
|
|
);
|
|
|
|
if error.is_null() {
|
|
|
|
Ok(from_glib_none(ret))
|
|
|
|
} else {
|
|
|
|
Err(from_glib_full(error))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-27 07:38:31 +00:00
|
|
|
pub fn parse_bin_from_description_with_name_full(
|
|
|
|
bin_description: &str,
|
|
|
|
ghost_unlinked_pads: bool,
|
|
|
|
bin_name: &str,
|
|
|
|
context: Option<&mut ParseContext>,
|
|
|
|
flags: ParseFlags,
|
|
|
|
) -> Result<Element, glib::Error> {
|
|
|
|
assert_initialized_main_thread!();
|
|
|
|
let bin =
|
|
|
|
parse_bin_from_description_full(bin_description, ghost_unlinked_pads, context, flags)?;
|
|
|
|
if !bin_name.is_empty() {
|
|
|
|
let obj = bin.clone().upcast::<Object>();
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_object_set_name(obj.to_glib_none().0, bin_name.to_glib_none().0);
|
2020-07-27 07:38:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(bin)
|
|
|
|
}
|
|
|
|
|
2019-05-23 18:19:24 +00:00
|
|
|
pub fn parse_launch_full(
|
2017-08-17 13:17:02 +00:00
|
|
|
pipeline_description: &str,
|
2019-05-23 18:19:24 +00:00
|
|
|
mut context: Option<&mut ParseContext>,
|
2017-08-17 13:17:02 +00:00
|
|
|
flags: ParseFlags,
|
2019-11-10 17:00:00 +00:00
|
|
|
) -> Result<Element, glib::Error> {
|
2017-08-17 13:17:02 +00:00
|
|
|
assert_initialized_main_thread!();
|
|
|
|
unsafe {
|
|
|
|
let mut error = ptr::null_mut();
|
2020-11-21 13:46:48 +00:00
|
|
|
let ret = ffi::gst_parse_launch_full(
|
2017-08-17 13:17:02 +00:00
|
|
|
pipeline_description.to_glib_none().0,
|
|
|
|
context.to_glib_none_mut().0,
|
|
|
|
flags.to_glib(),
|
|
|
|
&mut error,
|
|
|
|
);
|
|
|
|
if error.is_null() {
|
|
|
|
Ok(from_glib_none(ret))
|
|
|
|
} else {
|
|
|
|
Err(from_glib_full(error))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-23 18:19:24 +00:00
|
|
|
pub fn parse_launchv_full(
|
2017-08-17 13:17:02 +00:00
|
|
|
argv: &[&str],
|
2019-05-23 18:19:24 +00:00
|
|
|
mut context: Option<&mut ParseContext>,
|
2017-08-17 13:17:02 +00:00
|
|
|
flags: ParseFlags,
|
2019-11-10 17:00:00 +00:00
|
|
|
) -> Result<Element, glib::Error> {
|
2017-08-17 13:17:02 +00:00
|
|
|
assert_initialized_main_thread!();
|
|
|
|
unsafe {
|
|
|
|
let mut error = ptr::null_mut();
|
2020-11-21 13:46:48 +00:00
|
|
|
let ret = ffi::gst_parse_launchv_full(
|
2017-08-17 13:17:02 +00:00
|
|
|
argv.to_glib_none().0,
|
|
|
|
context.to_glib_none_mut().0,
|
|
|
|
flags.to_glib(),
|
|
|
|
&mut error,
|
|
|
|
);
|
|
|
|
if error.is_null() {
|
|
|
|
Ok(from_glib_none(ret))
|
|
|
|
} else {
|
|
|
|
Err(from_glib_full(error))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-12-05 19:32:16 +00:00
|
|
|
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_12", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_12")))]
|
2019-07-16 21:24:13 +00:00
|
|
|
pub fn calculate_linear_regression(
|
|
|
|
xy: &[(u64, u64)],
|
|
|
|
temp: Option<&mut [(u64, u64)]>,
|
|
|
|
) -> Option<(u64, u64, u64, u64, f64)> {
|
2020-03-22 14:18:47 +00:00
|
|
|
skip_assert_initialized!();
|
2019-08-08 14:14:43 +00:00
|
|
|
use std::mem;
|
|
|
|
|
2019-07-16 21:24:13 +00:00
|
|
|
unsafe {
|
|
|
|
assert_eq!(mem::size_of::<u64>() * 2, mem::size_of::<(u64, u64)>());
|
|
|
|
assert_eq!(mem::align_of::<u64>(), mem::align_of::<(u64, u64)>());
|
2019-09-07 10:08:09 +00:00
|
|
|
assert!(
|
|
|
|
temp.as_ref()
|
|
|
|
.map(|temp| temp.len())
|
|
|
|
.unwrap_or_else(|| xy.len())
|
|
|
|
>= xy.len()
|
|
|
|
);
|
2019-07-16 21:24:13 +00:00
|
|
|
|
|
|
|
let mut m_num = mem::MaybeUninit::uninit();
|
|
|
|
let mut m_denom = mem::MaybeUninit::uninit();
|
|
|
|
let mut b = mem::MaybeUninit::uninit();
|
|
|
|
let mut xbase = mem::MaybeUninit::uninit();
|
|
|
|
let mut r_squared = mem::MaybeUninit::uninit();
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
let res = from_glib(ffi::gst_calculate_linear_regression(
|
2019-07-16 21:24:13 +00:00
|
|
|
xy.as_ptr() as *const u64,
|
|
|
|
temp.map(|temp| temp.as_mut_ptr() as *mut u64)
|
|
|
|
.unwrap_or(ptr::null_mut()),
|
|
|
|
xy.len() as u32,
|
|
|
|
m_num.as_mut_ptr(),
|
|
|
|
m_denom.as_mut_ptr(),
|
|
|
|
b.as_mut_ptr(),
|
|
|
|
xbase.as_mut_ptr(),
|
|
|
|
r_squared.as_mut_ptr(),
|
|
|
|
));
|
|
|
|
if res {
|
|
|
|
Some((
|
|
|
|
m_num.assume_init(),
|
|
|
|
m_denom.assume_init(),
|
|
|
|
b.assume_init(),
|
|
|
|
xbase.assume_init(),
|
|
|
|
r_squared.assume_init(),
|
|
|
|
))
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_18", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn type_is_plugin_api(type_: glib::types::Type) -> Option<crate::PluginAPIFlags> {
|
2020-07-06 08:37:01 +00:00
|
|
|
assert_initialized_main_thread!();
|
|
|
|
unsafe {
|
|
|
|
use std::mem;
|
|
|
|
|
|
|
|
let mut flags = mem::MaybeUninit::uninit();
|
2020-11-21 13:46:48 +00:00
|
|
|
let ret = from_glib(ffi::gst_type_is_plugin_api(
|
2020-07-06 08:37:01 +00:00
|
|
|
type_.to_glib(),
|
|
|
|
flags.as_mut_ptr(),
|
|
|
|
));
|
|
|
|
let flags = flags.assume_init();
|
|
|
|
if ret {
|
|
|
|
Some(from_glib(flags))
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-16 21:24:13 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2020-07-15 18:24:18 +00:00
|
|
|
use super::*;
|
2020-11-21 13:46:48 +00:00
|
|
|
use crate::prelude::*;
|
2020-07-15 18:24:18 +00:00
|
|
|
|
2019-08-08 14:14:43 +00:00
|
|
|
#[cfg(feature = "v1_12")]
|
2019-07-16 21:24:13 +00:00
|
|
|
#[test]
|
|
|
|
fn test_calculate_linear_regression() {
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::init().unwrap();
|
2019-07-16 21:24:13 +00:00
|
|
|
|
|
|
|
let values = [(0, 0), (1, 1), (2, 2), (3, 3)];
|
|
|
|
|
|
|
|
let (m_num, m_denom, b, xbase, _) = calculate_linear_regression(&values, None).unwrap();
|
|
|
|
assert_eq!((m_num, m_denom, b, xbase), (10, 10, 3, 3));
|
|
|
|
|
|
|
|
let mut temp = [(0, 0); 4];
|
|
|
|
let (m_num, m_denom, b, xbase, _) =
|
|
|
|
calculate_linear_regression(&values, Some(&mut temp)).unwrap();
|
|
|
|
assert_eq!((m_num, m_denom, b, xbase), (10, 10, 3, 3));
|
|
|
|
}
|
2020-07-15 18:24:18 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_parse_bin_from_description_with_name() {
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::init().unwrap();
|
2020-07-15 18:24:18 +00:00
|
|
|
|
|
|
|
let bin =
|
|
|
|
parse_bin_from_description_with_name("fakesrc ! fakesink", false, "all_fake").unwrap();
|
2021-04-11 19:39:50 +00:00
|
|
|
let name = bin.name();
|
2020-07-15 18:24:18 +00:00
|
|
|
assert_eq!(name, "all_fake");
|
|
|
|
|
|
|
|
let bin = parse_bin_from_description_with_name("fakesrc ! fakesink", false, "").unwrap();
|
2021-04-11 19:39:50 +00:00
|
|
|
let name = bin.name();
|
2020-07-15 18:24:18 +00:00
|
|
|
assert_ne!(name, "");
|
|
|
|
}
|
2019-07-16 21:24:13 +00:00
|
|
|
}
|