2017-08-17 13:17:02 +00:00
|
|
|
// Copyright (C) 2017 Sebastian Dröge <sebastian@centricular.com>
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
use glib::translate::*;
|
2019-03-19 07:58:20 +00:00
|
|
|
use gst_sys;
|
2019-07-16 21:24:13 +00:00
|
|
|
use std::mem;
|
2017-08-17 13:17:02 +00:00
|
|
|
use std::ptr;
|
|
|
|
|
|
|
|
use Element;
|
|
|
|
use Error;
|
2018-04-01 08:30:03 +00:00
|
|
|
use ParseContext;
|
|
|
|
use ParseFlags;
|
2017-08-17 13:17:02 +00:00
|
|
|
|
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,
|
|
|
|
) -> Result<Element, Error> {
|
|
|
|
assert_initialized_main_thread!();
|
|
|
|
unsafe {
|
|
|
|
let mut error = ptr::null_mut();
|
2019-03-19 07:58:20 +00:00
|
|
|
let ret = gst_sys::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))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
) -> Result<Element, Error> {
|
|
|
|
assert_initialized_main_thread!();
|
|
|
|
unsafe {
|
|
|
|
let mut error = ptr::null_mut();
|
2019-03-19 07:58:20 +00:00
|
|
|
let ret = gst_sys::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,
|
|
|
|
) -> Result<Element, Error> {
|
|
|
|
assert_initialized_main_thread!();
|
|
|
|
unsafe {
|
|
|
|
let mut error = ptr::null_mut();
|
2019-03-19 07:58:20 +00:00
|
|
|
let ret = gst_sys::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
|
|
|
|
|
|
|
pub fn util_group_id_next() -> ::GroupId {
|
|
|
|
assert_initialized_main_thread!();
|
|
|
|
unsafe {
|
2019-03-19 07:58:20 +00:00
|
|
|
let v = from_glib(gst_sys::gst_util_group_id_next());
|
2017-12-05 19:32:16 +00:00
|
|
|
if v == ::GROUP_ID_INVALID {
|
2019-03-19 07:58:20 +00:00
|
|
|
return from_glib(gst_sys::gst_util_group_id_next());
|
2017-12-05 19:32:16 +00:00
|
|
|
}
|
|
|
|
v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn util_seqnum_next() -> ::Seqnum {
|
|
|
|
assert_initialized_main_thread!();
|
|
|
|
unsafe {
|
2019-03-19 07:58:20 +00:00
|
|
|
let v = from_glib(gst_sys::gst_util_seqnum_next());
|
2017-12-05 19:32:16 +00:00
|
|
|
if v == ::SEQNUM_INVALID {
|
2019-03-19 07:58:20 +00:00
|
|
|
return from_glib(gst_sys::gst_util_seqnum_next());
|
2017-12-05 19:32:16 +00:00
|
|
|
}
|
|
|
|
v
|
|
|
|
}
|
|
|
|
}
|
2019-07-16 21:24:13 +00:00
|
|
|
|
|
|
|
#[cfg(any(feature = "v1_12", feature = "dox"))]
|
|
|
|
pub fn calculate_linear_regression(
|
|
|
|
xy: &[(u64, u64)],
|
|
|
|
temp: Option<&mut [(u64, u64)]>,
|
|
|
|
) -> Option<(u64, u64, u64, u64, f64)> {
|
|
|
|
unsafe {
|
|
|
|
assert_eq!(mem::size_of::<u64>() * 2, mem::size_of::<(u64, u64)>());
|
|
|
|
assert_eq!(mem::align_of::<u64>(), mem::align_of::<(u64, u64)>());
|
|
|
|
assert!(temp.as_ref().map(|temp| temp.len()).unwrap_or(xy.len()) >= xy.len());
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
let res = from_glib(gst_sys::gst_calculate_linear_regression(
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_calculate_linear_regression() {
|
|
|
|
::init().unwrap();
|
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|