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
|
|
|
|
|
|
|
use std::ptr;
|
|
|
|
|
2023-12-01 15:53:44 +00:00
|
|
|
use glib::translate::*;
|
2023-01-03 18:58:25 +00:00
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_18")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
|
2021-11-15 09:45:30 +00:00
|
|
|
use crate::Tracer;
|
2023-08-28 17:03:27 +00:00
|
|
|
|
2023-12-01 15:53:44 +00:00
|
|
|
// import only functions which do not have their own module as namespace
|
|
|
|
pub use crate::auto::functions::{
|
2023-12-04 16:07:21 +00:00
|
|
|
main_executable_path, util_get_timestamp as get_timestamp, version, version_string,
|
2023-12-01 15:53:44 +00:00
|
|
|
};
|
2024-06-02 08:48:53 +00:00
|
|
|
use crate::ffi;
|
2017-08-17 13:17:02 +00:00
|
|
|
|
2024-02-06 07:53:15 +00:00
|
|
|
#[cfg(feature = "v1_24")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
|
|
|
|
pub use crate::auto::functions::util_ceil_log2 as ceil_log2;
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_calculate_linear_regression")]
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_18")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
|
2021-11-15 09:45:30 +00:00
|
|
|
#[doc(alias = "gst_tracing_get_active_tracers")]
|
|
|
|
pub fn active_tracers() -> glib::List<Tracer> {
|
|
|
|
assert_initialized_main_thread!();
|
|
|
|
unsafe { FromGlibPtrContainer::from_glib_full(ffi::gst_tracing_get_active_tracers()) }
|
|
|
|
}
|
|
|
|
|
2024-02-06 07:53:15 +00:00
|
|
|
#[cfg(feature = "v1_24")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
|
|
|
|
#[doc(alias = "gst_util_filename_compare")]
|
|
|
|
pub fn filename_compare(a: &std::path::Path, b: &std::path::Path) -> std::cmp::Ordering {
|
|
|
|
skip_assert_initialized!();
|
|
|
|
unsafe {
|
|
|
|
from_glib(ffi::gst_util_filename_compare(
|
|
|
|
a.to_glib_none().0,
|
|
|
|
b.to_glib_none().0,
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-16 21:24:13 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2020-07-15 18:24:18 +00:00
|
|
|
use super::*;
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|