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-07-12 10:25:11 +00:00
|
|
|
|
2023-01-03 18:58:25 +00:00
|
|
|
use std::{cmp, fmt, ops, slice};
|
2017-07-12 10:25:11 +00:00
|
|
|
|
2024-02-03 08:13:51 +00:00
|
|
|
use glib::{prelude::*, translate::*};
|
2023-01-03 18:58:25 +00:00
|
|
|
use num_rational::Rational32;
|
2017-07-12 10:25:11 +00:00
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq, Hash)]
|
|
|
|
pub struct Fraction(pub Rational32);
|
|
|
|
|
|
|
|
impl Fraction {
|
2024-03-01 03:57:58 +00:00
|
|
|
// rustdoc-stripper-ignore-next
|
|
|
|
/// Creates a new `Ratio`.
|
|
|
|
///
|
|
|
|
/// # Panics
|
|
|
|
///
|
|
|
|
/// Panics if `denom` is zero.
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-01-08 10:43:18 +00:00
|
|
|
pub fn new(num: i32, den: i32) -> Self {
|
2022-12-25 10:47:02 +00:00
|
|
|
skip_assert_initialized!();
|
2017-07-12 10:25:11 +00:00
|
|
|
(num, den).into()
|
|
|
|
}
|
|
|
|
|
2024-03-01 03:57:58 +00:00
|
|
|
// rustdoc-stripper-ignore-next
|
|
|
|
/// Creates a `Fraction` without checking for `denom == 0` or reducing.
|
|
|
|
///
|
|
|
|
/// While this does not panic, there are several methods that will panic
|
|
|
|
/// if used on a `Fraction` with `denom == 0`.
|
|
|
|
#[inline]
|
|
|
|
pub const fn new_raw(num: i32, den: i32) -> Self {
|
|
|
|
skip_assert_initialized!();
|
|
|
|
Self(Rational32::new_raw(num, den))
|
|
|
|
}
|
|
|
|
|
|
|
|
// rustdoc-stripper-ignore-next
|
|
|
|
/// Creates a `Fraction` representing the integer `t`.
|
|
|
|
#[inline]
|
|
|
|
pub const fn from_integer(t: i32) -> Self {
|
|
|
|
skip_assert_initialized!();
|
|
|
|
Self::new_raw(t, 1)
|
|
|
|
}
|
|
|
|
|
2021-01-08 10:43:18 +00:00
|
|
|
pub fn approximate_f32(x: f32) -> Option<Self> {
|
2022-12-25 10:47:02 +00:00
|
|
|
skip_assert_initialized!();
|
2017-07-12 10:25:11 +00:00
|
|
|
Rational32::approximate_float(x).map(|r| r.into())
|
|
|
|
}
|
|
|
|
|
2021-01-08 10:43:18 +00:00
|
|
|
pub fn approximate_f64(x: f64) -> Option<Self> {
|
2022-12-25 10:47:02 +00:00
|
|
|
skip_assert_initialized!();
|
2017-07-12 10:25:11 +00:00
|
|
|
Rational32::approximate_float(x).map(|r| r.into())
|
|
|
|
}
|
2021-11-05 20:40:05 +00:00
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-11-05 20:40:05 +00:00
|
|
|
pub fn numer(&self) -> i32 {
|
|
|
|
*self.0.numer()
|
|
|
|
}
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-11-05 20:40:05 +00:00
|
|
|
pub fn denom(&self) -> i32 {
|
|
|
|
*self.0.denom()
|
|
|
|
}
|
2023-07-04 14:19:52 +00:00
|
|
|
|
|
|
|
#[cfg(feature = "v1_24")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
|
|
|
|
#[doc(alias = "gst_util_simplify_fraction")]
|
|
|
|
pub fn simplify(&mut self, n_terms: u32, threshold: u32) {
|
|
|
|
skip_assert_initialized!();
|
|
|
|
unsafe {
|
|
|
|
let mut num = self.numer();
|
|
|
|
let mut den = self.denom();
|
|
|
|
ffi::gst_util_simplify_fraction(&mut num, &mut den, n_terms, threshold);
|
|
|
|
*self = Self::new(num, den);
|
|
|
|
}
|
|
|
|
}
|
2017-07-12 10:25:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for Fraction {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
self.0.fmt(f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ops::Deref for Fraction {
|
|
|
|
type Target = Rational32;
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-01-08 10:43:18 +00:00
|
|
|
fn deref(&self) -> &Self::Target {
|
2017-07-12 10:25:11 +00:00
|
|
|
&self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ops::DerefMut for Fraction {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2017-07-12 10:25:11 +00:00
|
|
|
fn deref_mut(&mut self) -> &mut Rational32 {
|
|
|
|
&mut self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AsRef<Rational32> for Fraction {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2017-07-12 10:25:11 +00:00
|
|
|
fn as_ref(&self) -> &Rational32 {
|
|
|
|
&self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-03 07:56:40 +00:00
|
|
|
macro_rules! impl_fraction_binop {
|
|
|
|
($name:ident, $f:ident, $name_assign:ident, $f_assign:ident) => {
|
|
|
|
impl ops::$name<Fraction> for Fraction {
|
|
|
|
type Output = Fraction;
|
2017-07-12 10:25:11 +00:00
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-01-08 10:43:18 +00:00
|
|
|
fn $f(self, other: Fraction) -> Self::Output {
|
2019-06-03 07:56:40 +00:00
|
|
|
Fraction((self.0).$f(other.0))
|
|
|
|
}
|
|
|
|
}
|
2017-07-12 10:25:11 +00:00
|
|
|
|
2019-06-03 07:56:40 +00:00
|
|
|
impl ops::$name<Fraction> for &Fraction {
|
|
|
|
type Output = Fraction;
|
2017-07-12 10:25:11 +00:00
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-01-08 10:43:18 +00:00
|
|
|
fn $f(self, other: Fraction) -> Self::Output {
|
2019-06-03 07:56:40 +00:00
|
|
|
Fraction((self.0).$f(other.0))
|
|
|
|
}
|
|
|
|
}
|
2017-07-12 10:25:11 +00:00
|
|
|
|
2019-06-03 07:56:40 +00:00
|
|
|
impl ops::$name<&Fraction> for Fraction {
|
|
|
|
type Output = Fraction;
|
2017-07-12 10:25:11 +00:00
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-01-08 10:43:18 +00:00
|
|
|
fn $f(self, other: &Fraction) -> Self::Output {
|
2019-06-03 07:56:40 +00:00
|
|
|
Fraction((self.0).$f(other.0))
|
|
|
|
}
|
|
|
|
}
|
2017-07-12 10:25:11 +00:00
|
|
|
|
2019-06-03 07:56:40 +00:00
|
|
|
impl ops::$name<&Fraction> for &Fraction {
|
|
|
|
type Output = Fraction;
|
2017-07-12 10:25:11 +00:00
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-01-08 10:43:18 +00:00
|
|
|
fn $f(self, other: &Fraction) -> Self::Output {
|
2019-06-03 07:56:40 +00:00
|
|
|
Fraction((self.0).$f(other.0))
|
|
|
|
}
|
|
|
|
}
|
2017-07-12 10:25:11 +00:00
|
|
|
|
2019-06-03 07:56:40 +00:00
|
|
|
impl ops::$name<i32> for Fraction {
|
|
|
|
type Output = Fraction;
|
2017-07-12 10:25:11 +00:00
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-01-08 10:43:18 +00:00
|
|
|
fn $f(self, other: i32) -> Self::Output {
|
2019-06-03 07:56:40 +00:00
|
|
|
self.$f(Fraction::from(other))
|
|
|
|
}
|
|
|
|
}
|
2017-07-12 10:25:11 +00:00
|
|
|
|
2019-06-03 07:56:40 +00:00
|
|
|
impl ops::$name<i32> for &Fraction {
|
|
|
|
type Output = Fraction;
|
2017-07-12 10:25:11 +00:00
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-01-08 10:43:18 +00:00
|
|
|
fn $f(self, other: i32) -> Self::Output {
|
2019-06-03 07:56:40 +00:00
|
|
|
self.$f(Fraction::from(other))
|
|
|
|
}
|
|
|
|
}
|
2017-07-12 10:25:11 +00:00
|
|
|
|
2019-06-03 07:56:40 +00:00
|
|
|
impl ops::$name<&i32> for Fraction {
|
|
|
|
type Output = Fraction;
|
2017-07-12 10:25:11 +00:00
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-01-08 10:43:18 +00:00
|
|
|
fn $f(self, other: &i32) -> Self::Output {
|
2019-06-03 07:56:40 +00:00
|
|
|
self.$f(Fraction::from(*other))
|
|
|
|
}
|
|
|
|
}
|
2017-07-12 10:25:11 +00:00
|
|
|
|
2019-06-03 07:56:40 +00:00
|
|
|
impl ops::$name<&i32> for &Fraction {
|
|
|
|
type Output = Fraction;
|
2017-07-12 10:25:11 +00:00
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-01-08 10:43:18 +00:00
|
|
|
fn $f(self, other: &i32) -> Self::Output {
|
2019-06-03 07:56:40 +00:00
|
|
|
self.$f(Fraction::from(*other))
|
|
|
|
}
|
|
|
|
}
|
2017-07-12 10:25:11 +00:00
|
|
|
|
2019-06-03 07:56:40 +00:00
|
|
|
impl ops::$name<Fraction> for i32 {
|
|
|
|
type Output = Fraction;
|
2017-07-12 10:25:11 +00:00
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-01-08 10:43:18 +00:00
|
|
|
fn $f(self, other: Fraction) -> Self::Output {
|
2019-06-03 07:56:40 +00:00
|
|
|
Fraction::from(self).$f(other)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ops::$name<&Fraction> for i32 {
|
|
|
|
type Output = Fraction;
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-01-08 10:43:18 +00:00
|
|
|
fn $f(self, other: &Fraction) -> Self::Output {
|
2019-06-03 07:56:40 +00:00
|
|
|
Fraction::from(self).$f(other)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ops::$name<Fraction> for &i32 {
|
|
|
|
type Output = Fraction;
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-01-08 10:43:18 +00:00
|
|
|
fn $f(self, other: Fraction) -> Self::Output {
|
2019-06-03 07:56:40 +00:00
|
|
|
Fraction::from(*self).$f(other)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ops::$name<&Fraction> for &i32 {
|
|
|
|
type Output = Fraction;
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-01-08 10:43:18 +00:00
|
|
|
fn $f(self, other: &Fraction) -> Self::Output {
|
2019-06-03 07:56:40 +00:00
|
|
|
Fraction::from(*self).$f(other)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ops::$name_assign<Fraction> for Fraction {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2019-06-03 07:56:40 +00:00
|
|
|
fn $f_assign(&mut self, other: Fraction) {
|
|
|
|
(self.0).$f_assign(other.0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ops::$name_assign<&Fraction> for Fraction {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2019-06-03 07:56:40 +00:00
|
|
|
fn $f_assign(&mut self, other: &Fraction) {
|
|
|
|
(self.0).$f_assign(other.0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ops::$name_assign<i32> for Fraction {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2019-06-03 07:56:40 +00:00
|
|
|
fn $f_assign(&mut self, other: i32) {
|
|
|
|
(self.0).$f_assign(other)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ops::$name_assign<&i32> for Fraction {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2019-06-03 07:56:40 +00:00
|
|
|
fn $f_assign(&mut self, other: &i32) {
|
|
|
|
(self.0).$f_assign(other)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2017-07-12 10:25:11 +00:00
|
|
|
}
|
|
|
|
|
2019-06-03 07:56:40 +00:00
|
|
|
impl_fraction_binop!(Add, add, AddAssign, add_assign);
|
|
|
|
impl_fraction_binop!(Sub, sub, SubAssign, sub_assign);
|
|
|
|
impl_fraction_binop!(Div, div, DivAssign, div_assign);
|
|
|
|
impl_fraction_binop!(Mul, mul, MulAssign, mul_assign);
|
|
|
|
impl_fraction_binop!(Rem, rem, RemAssign, rem_assign);
|
|
|
|
|
|
|
|
impl ops::Neg for Fraction {
|
2017-07-12 10:25:11 +00:00
|
|
|
type Output = Fraction;
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-01-08 10:43:18 +00:00
|
|
|
fn neg(self) -> Self::Output {
|
2019-06-03 07:56:40 +00:00
|
|
|
Fraction(self.0.neg())
|
2017-07-12 10:25:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-03 07:56:40 +00:00
|
|
|
impl ops::Neg for &Fraction {
|
2017-07-12 10:25:11 +00:00
|
|
|
type Output = Fraction;
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-01-08 10:43:18 +00:00
|
|
|
fn neg(self) -> Self::Output {
|
2017-07-12 10:25:11 +00:00
|
|
|
Fraction(self.0.neg())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<i32> for Fraction {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-01-08 10:43:18 +00:00
|
|
|
fn from(x: i32) -> Self {
|
2022-12-25 10:47:02 +00:00
|
|
|
skip_assert_initialized!();
|
2017-07-12 10:25:11 +00:00
|
|
|
Fraction(x.into())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<(i32, i32)> for Fraction {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-01-08 10:43:18 +00:00
|
|
|
fn from(x: (i32, i32)) -> Self {
|
2022-12-25 10:47:02 +00:00
|
|
|
skip_assert_initialized!();
|
2017-07-12 10:25:11 +00:00
|
|
|
Fraction(x.into())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-07 19:08:36 +00:00
|
|
|
impl From<Fraction> for (i32, i32) {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-01-07 19:08:36 +00:00
|
|
|
fn from(f: Fraction) -> Self {
|
2021-01-07 19:47:31 +00:00
|
|
|
skip_assert_initialized!();
|
2021-01-07 19:08:36 +00:00
|
|
|
f.0.into()
|
2017-07-12 10:25:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<Rational32> for Fraction {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-01-08 10:43:18 +00:00
|
|
|
fn from(x: Rational32) -> Self {
|
2022-12-25 10:47:02 +00:00
|
|
|
skip_assert_initialized!();
|
2017-07-12 10:25:11 +00:00
|
|
|
Fraction(x)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<Fraction> for Rational32 {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-01-08 10:43:18 +00:00
|
|
|
fn from(x: Fraction) -> Self {
|
2017-08-30 11:39:09 +00:00
|
|
|
skip_assert_initialized!();
|
2017-07-12 10:25:11 +00:00
|
|
|
x.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl glib::types::StaticType for Fraction {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2017-07-12 10:25:11 +00:00
|
|
|
fn static_type() -> glib::types::Type {
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { from_glib(ffi::gst_fraction_get_type()) }
|
2017-07-12 10:25:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-20 07:19:02 +00:00
|
|
|
impl glib::value::ValueType for Fraction {
|
|
|
|
type Type = Self;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe impl<'a> glib::value::FromValue<'a> for Fraction {
|
|
|
|
type Checker = glib::value::GenericValueTypeChecker<Self>;
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-04-20 07:19:02 +00:00
|
|
|
unsafe fn from_value(value: &'a glib::Value) -> Self {
|
|
|
|
skip_assert_initialized!();
|
|
|
|
let n = ffi::gst_value_get_fraction_numerator(value.to_glib_none().0);
|
|
|
|
let d = ffi::gst_value_get_fraction_denominator(value.to_glib_none().0);
|
2017-07-12 10:25:11 +00:00
|
|
|
|
|
|
|
Fraction::new(n, d)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-20 07:19:02 +00:00
|
|
|
impl glib::value::ToValue for Fraction {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-04-20 07:19:02 +00:00
|
|
|
fn to_value(&self) -> glib::Value {
|
2021-04-25 16:46:18 +00:00
|
|
|
let mut value = glib::Value::for_value_type::<Self>();
|
2021-04-20 07:19:02 +00:00
|
|
|
unsafe {
|
2021-11-05 20:40:05 +00:00
|
|
|
ffi::gst_value_set_fraction(value.to_glib_none_mut().0, self.numer(), self.denom());
|
2021-04-20 07:19:02 +00:00
|
|
|
}
|
|
|
|
value
|
2017-07-12 10:25:11 +00:00
|
|
|
}
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-04-20 07:19:02 +00:00
|
|
|
fn value_type(&self) -> glib::Type {
|
|
|
|
Self::static_type()
|
2017-07-12 10:25:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-26 11:56:53 +00:00
|
|
|
impl From<Fraction> for glib::Value {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2022-11-26 11:56:53 +00:00
|
|
|
fn from(v: Fraction) -> glib::Value {
|
|
|
|
skip_assert_initialized!();
|
|
|
|
glib::value::ToValue::to_value(&v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-28 13:52:35 +00:00
|
|
|
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
2022-09-12 16:32:16 +00:00
|
|
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
2017-07-28 13:52:35 +00:00
|
|
|
pub struct IntRange<T> {
|
|
|
|
min: T,
|
|
|
|
max: T,
|
|
|
|
step: T,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: Copy> IntRange<T> {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2017-07-28 13:52:35 +00:00
|
|
|
pub fn min(&self) -> T {
|
|
|
|
self.min
|
|
|
|
}
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2017-07-28 13:52:35 +00:00
|
|
|
pub fn max(&self) -> T {
|
|
|
|
self.max
|
|
|
|
}
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2017-07-28 13:52:35 +00:00
|
|
|
pub fn step(&self) -> T {
|
|
|
|
self.step
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-05 20:39:33 +00:00
|
|
|
#[doc(hidden)]
|
|
|
|
pub trait IntRangeType: Sized + Clone + Copy + 'static {
|
|
|
|
fn with_min_max(min: Self, max: Self) -> IntRange<Self>;
|
|
|
|
fn with_step(min: Self, max: Self, step: Self) -> IntRange<Self>;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl IntRangeType for i32 {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-11-05 20:39:33 +00:00
|
|
|
fn with_min_max(min: i32, max: i32) -> IntRange<Self> {
|
2017-08-30 11:39:09 +00:00
|
|
|
skip_assert_initialized!();
|
2021-11-05 20:39:33 +00:00
|
|
|
IntRange { min, max, step: 1 }
|
2017-07-28 13:52:35 +00:00
|
|
|
}
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-11-05 20:39:33 +00:00
|
|
|
fn with_step(min: i32, max: i32, step: i32) -> IntRange<Self> {
|
2022-12-25 10:47:02 +00:00
|
|
|
skip_assert_initialized!();
|
2017-08-30 11:39:09 +00:00
|
|
|
|
2017-07-28 13:52:35 +00:00
|
|
|
assert!(min <= max);
|
|
|
|
assert!(step > 0);
|
|
|
|
|
2021-11-05 20:39:33 +00:00
|
|
|
IntRange { min, max, step }
|
2017-07-28 13:52:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-05 20:39:33 +00:00
|
|
|
impl IntRangeType for i64 {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-11-05 20:39:33 +00:00
|
|
|
fn with_min_max(min: i64, max: i64) -> IntRange<Self> {
|
2017-08-30 11:39:09 +00:00
|
|
|
skip_assert_initialized!();
|
2021-11-05 20:39:33 +00:00
|
|
|
IntRange { min, max, step: 1 }
|
2017-07-28 13:52:35 +00:00
|
|
|
}
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-11-05 20:39:33 +00:00
|
|
|
fn with_step(min: i64, max: i64, step: i64) -> IntRange<Self> {
|
2022-12-25 10:47:02 +00:00
|
|
|
skip_assert_initialized!();
|
2017-08-30 11:39:09 +00:00
|
|
|
|
2017-07-28 13:52:35 +00:00
|
|
|
assert!(min <= max);
|
|
|
|
assert!(step > 0);
|
|
|
|
|
2021-11-05 20:39:33 +00:00
|
|
|
IntRange { min, max, step }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: IntRangeType> IntRange<T> {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-11-05 20:39:33 +00:00
|
|
|
pub fn new(min: T, max: T) -> IntRange<T> {
|
2022-12-25 10:47:02 +00:00
|
|
|
skip_assert_initialized!();
|
2021-11-05 20:39:33 +00:00
|
|
|
T::with_min_max(min, max)
|
|
|
|
}
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-11-05 20:39:33 +00:00
|
|
|
pub fn with_step(min: T, max: T, step: T) -> IntRange<T> {
|
2022-12-25 10:47:02 +00:00
|
|
|
skip_assert_initialized!();
|
2021-11-05 20:39:33 +00:00
|
|
|
T::with_step(min, max, step)
|
2017-07-28 13:52:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<(i32, i32)> for IntRange<i32> {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2017-07-28 13:52:35 +00:00
|
|
|
fn from((min, max): (i32, i32)) -> Self {
|
2017-08-30 11:39:09 +00:00
|
|
|
skip_assert_initialized!();
|
2017-07-28 13:52:35 +00:00
|
|
|
Self::new(min, max)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<(i32, i32, i32)> for IntRange<i32> {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2017-07-28 13:52:35 +00:00
|
|
|
fn from((min, max, step): (i32, i32, i32)) -> Self {
|
2017-08-30 11:39:09 +00:00
|
|
|
skip_assert_initialized!();
|
2020-06-11 08:53:35 +00:00
|
|
|
Self::with_step(min, max, step)
|
2017-07-28 13:52:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<(i64, i64)> for IntRange<i64> {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2017-07-28 13:52:35 +00:00
|
|
|
fn from((min, max): (i64, i64)) -> Self {
|
2017-08-30 11:39:09 +00:00
|
|
|
skip_assert_initialized!();
|
2017-07-28 13:52:35 +00:00
|
|
|
Self::new(min, max)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<(i64, i64, i64)> for IntRange<i64> {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2017-07-28 13:52:35 +00:00
|
|
|
fn from((min, max, step): (i64, i64, i64)) -> Self {
|
2017-08-30 11:39:09 +00:00
|
|
|
skip_assert_initialized!();
|
2020-06-11 08:53:35 +00:00
|
|
|
Self::with_step(min, max, step)
|
2017-07-28 13:52:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl glib::types::StaticType for IntRange<i32> {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2017-07-28 13:52:35 +00:00
|
|
|
fn static_type() -> glib::types::Type {
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { from_glib(ffi::gst_int_range_get_type()) }
|
2017-07-28 13:52:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-20 07:19:02 +00:00
|
|
|
impl glib::value::ValueType for IntRange<i32> {
|
|
|
|
type Type = Self;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe impl<'a> glib::value::FromValue<'a> for IntRange<i32> {
|
|
|
|
type Checker = glib::value::GenericValueTypeChecker<Self>;
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-04-20 07:19:02 +00:00
|
|
|
unsafe fn from_value(value: &'a glib::Value) -> Self {
|
|
|
|
skip_assert_initialized!();
|
|
|
|
let min = ffi::gst_value_get_int_range_min(value.to_glib_none().0);
|
|
|
|
let max = ffi::gst_value_get_int_range_max(value.to_glib_none().0);
|
|
|
|
let step = ffi::gst_value_get_int_range_step(value.to_glib_none().0);
|
2017-07-28 13:52:35 +00:00
|
|
|
|
2020-06-11 08:53:35 +00:00
|
|
|
Self::with_step(min, max, step)
|
2017-07-28 13:52:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-20 07:19:02 +00:00
|
|
|
impl glib::value::ToValue for IntRange<i32> {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-04-20 07:19:02 +00:00
|
|
|
fn to_value(&self) -> glib::Value {
|
2021-04-25 16:46:18 +00:00
|
|
|
let mut value = glib::Value::for_value_type::<Self>();
|
2021-04-20 07:19:02 +00:00
|
|
|
unsafe {
|
|
|
|
ffi::gst_value_set_int_range_step(
|
|
|
|
value.to_glib_none_mut().0,
|
|
|
|
self.min(),
|
|
|
|
self.max(),
|
|
|
|
self.step(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
value
|
2017-07-28 13:52:35 +00:00
|
|
|
}
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-04-20 07:19:02 +00:00
|
|
|
fn value_type(&self) -> glib::Type {
|
|
|
|
Self::static_type()
|
2017-07-28 13:52:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-26 11:56:53 +00:00
|
|
|
impl From<IntRange<i32>> for glib::Value {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2022-11-26 11:56:53 +00:00
|
|
|
fn from(v: IntRange<i32>) -> glib::Value {
|
|
|
|
skip_assert_initialized!();
|
|
|
|
glib::value::ToValue::to_value(&v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-28 13:52:35 +00:00
|
|
|
impl glib::types::StaticType for IntRange<i64> {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2017-07-28 13:52:35 +00:00
|
|
|
fn static_type() -> glib::types::Type {
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { from_glib(ffi::gst_int64_range_get_type()) }
|
2017-07-28 13:52:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-20 07:19:02 +00:00
|
|
|
impl glib::value::ValueType for IntRange<i64> {
|
|
|
|
type Type = Self;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe impl<'a> glib::value::FromValue<'a> for IntRange<i64> {
|
|
|
|
type Checker = glib::value::GenericValueTypeChecker<Self>;
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-04-20 07:19:02 +00:00
|
|
|
unsafe fn from_value(value: &'a glib::Value) -> Self {
|
|
|
|
skip_assert_initialized!();
|
|
|
|
let min = ffi::gst_value_get_int64_range_min(value.to_glib_none().0);
|
|
|
|
let max = ffi::gst_value_get_int64_range_max(value.to_glib_none().0);
|
|
|
|
let step = ffi::gst_value_get_int64_range_step(value.to_glib_none().0);
|
2017-07-28 13:52:35 +00:00
|
|
|
|
2020-06-11 08:53:35 +00:00
|
|
|
Self::with_step(min, max, step)
|
2017-07-28 13:52:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-20 07:19:02 +00:00
|
|
|
impl glib::value::ToValue for IntRange<i64> {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-04-20 07:19:02 +00:00
|
|
|
fn to_value(&self) -> glib::Value {
|
2021-04-25 16:46:18 +00:00
|
|
|
let mut value = glib::Value::for_value_type::<Self>();
|
2021-04-20 07:19:02 +00:00
|
|
|
unsafe {
|
|
|
|
ffi::gst_value_set_int64_range_step(
|
|
|
|
value.to_glib_none_mut().0,
|
|
|
|
self.min(),
|
|
|
|
self.max(),
|
|
|
|
self.step(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
value
|
2017-07-28 13:52:35 +00:00
|
|
|
}
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-04-20 07:19:02 +00:00
|
|
|
fn value_type(&self) -> glib::Type {
|
|
|
|
Self::static_type()
|
2017-07-28 13:52:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-26 11:56:53 +00:00
|
|
|
impl From<IntRange<i64>> for glib::Value {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2022-11-26 11:56:53 +00:00
|
|
|
fn from(v: IntRange<i64>) -> glib::Value {
|
|
|
|
skip_assert_initialized!();
|
|
|
|
glib::value::ToValue::to_value(&v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-28 13:52:35 +00:00
|
|
|
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
2022-09-12 16:32:16 +00:00
|
|
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
2017-07-28 13:52:35 +00:00
|
|
|
pub struct FractionRange {
|
|
|
|
min: Fraction,
|
|
|
|
max: Fraction,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FractionRange {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2017-07-28 13:52:35 +00:00
|
|
|
pub fn new<T: Into<Fraction>, U: Into<Fraction>>(min: T, max: U) -> Self {
|
2022-12-25 10:47:02 +00:00
|
|
|
skip_assert_initialized!();
|
2017-08-30 11:39:09 +00:00
|
|
|
|
2017-07-28 13:52:35 +00:00
|
|
|
let min = min.into();
|
|
|
|
let max = max.into();
|
|
|
|
|
|
|
|
assert!(min <= max);
|
|
|
|
|
2018-07-20 07:21:06 +00:00
|
|
|
FractionRange { min, max }
|
2017-07-28 13:52:35 +00:00
|
|
|
}
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2017-07-28 13:52:35 +00:00
|
|
|
pub fn min(&self) -> Fraction {
|
|
|
|
self.min
|
|
|
|
}
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2017-07-28 13:52:35 +00:00
|
|
|
pub fn max(&self) -> Fraction {
|
|
|
|
self.max
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<(Fraction, Fraction)> for FractionRange {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2017-07-28 13:52:35 +00:00
|
|
|
fn from((min, max): (Fraction, Fraction)) -> Self {
|
2017-08-30 11:39:09 +00:00
|
|
|
skip_assert_initialized!();
|
|
|
|
|
2017-07-28 13:52:35 +00:00
|
|
|
Self::new(min, max)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl glib::types::StaticType for FractionRange {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2017-07-28 13:52:35 +00:00
|
|
|
fn static_type() -> glib::types::Type {
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { from_glib(ffi::gst_fraction_range_get_type()) }
|
2017-07-28 13:52:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-20 07:19:02 +00:00
|
|
|
impl glib::value::ValueType for FractionRange {
|
|
|
|
type Type = Self;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe impl<'a> glib::value::FromValue<'a> for FractionRange {
|
|
|
|
type Checker = glib::value::GenericValueTypeChecker<Self>;
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-04-20 07:19:02 +00:00
|
|
|
unsafe fn from_value(value: &'a glib::Value) -> Self {
|
|
|
|
skip_assert_initialized!();
|
|
|
|
let min = ffi::gst_value_get_fraction_range_min(value.to_glib_none().0);
|
|
|
|
let max = ffi::gst_value_get_fraction_range_max(value.to_glib_none().0);
|
2017-07-28 13:52:35 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
let min_n = ffi::gst_value_get_fraction_numerator(min);
|
|
|
|
let min_d = ffi::gst_value_get_fraction_denominator(min);
|
|
|
|
let max_n = ffi::gst_value_get_fraction_numerator(max);
|
|
|
|
let max_d = ffi::gst_value_get_fraction_denominator(max);
|
2017-07-28 13:52:35 +00:00
|
|
|
|
|
|
|
Self::new((min_n, min_d), (max_n, max_d))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-20 07:19:02 +00:00
|
|
|
impl glib::value::ToValue for FractionRange {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-04-20 07:19:02 +00:00
|
|
|
fn to_value(&self) -> glib::Value {
|
2021-04-25 16:46:18 +00:00
|
|
|
let mut value = glib::Value::for_value_type::<Self>();
|
2021-04-20 07:19:02 +00:00
|
|
|
unsafe {
|
|
|
|
ffi::gst_value_set_fraction_range_full(
|
|
|
|
value.to_glib_none_mut().0,
|
2021-11-05 20:40:05 +00:00
|
|
|
self.min().numer(),
|
|
|
|
self.min().denom(),
|
|
|
|
self.max().numer(),
|
|
|
|
self.max().denom(),
|
2021-04-20 07:19:02 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
value
|
2017-07-28 13:52:35 +00:00
|
|
|
}
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-04-20 07:19:02 +00:00
|
|
|
fn value_type(&self) -> glib::Type {
|
|
|
|
Self::static_type()
|
2017-07-28 13:52:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-26 11:56:53 +00:00
|
|
|
impl From<FractionRange> for glib::Value {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2022-11-26 11:56:53 +00:00
|
|
|
fn from(v: FractionRange) -> glib::Value {
|
|
|
|
skip_assert_initialized!();
|
|
|
|
glib::value::ToValue::to_value(&v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-09 17:00:23 +00:00
|
|
|
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
2022-09-12 16:32:16 +00:00
|
|
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
2017-12-17 09:57:37 +00:00
|
|
|
pub struct Bitmask(pub u64);
|
2017-08-09 17:00:23 +00:00
|
|
|
|
|
|
|
impl Bitmask {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2017-08-09 17:00:23 +00:00
|
|
|
pub fn new(v: u64) -> Self {
|
2022-12-25 10:47:02 +00:00
|
|
|
skip_assert_initialized!();
|
2017-08-09 17:00:23 +00:00
|
|
|
Bitmask(v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ops::Deref for Bitmask {
|
|
|
|
type Target = u64;
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2017-08-09 17:00:23 +00:00
|
|
|
fn deref(&self) -> &u64 {
|
|
|
|
&self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ops::DerefMut for Bitmask {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2017-08-09 17:00:23 +00:00
|
|
|
fn deref_mut(&mut self) -> &mut u64 {
|
|
|
|
&mut self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ops::BitAnd for Bitmask {
|
|
|
|
type Output = Self;
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2017-08-09 17:00:23 +00:00
|
|
|
fn bitand(self, rhs: Self) -> Self {
|
|
|
|
Bitmask(self.0.bitand(rhs.0))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ops::BitOr for Bitmask {
|
|
|
|
type Output = Self;
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2017-08-09 17:00:23 +00:00
|
|
|
fn bitor(self, rhs: Self) -> Self {
|
|
|
|
Bitmask(self.0.bitor(rhs.0))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ops::BitXor for Bitmask {
|
|
|
|
type Output = Self;
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2017-08-09 17:00:23 +00:00
|
|
|
fn bitxor(self, rhs: Self) -> Self {
|
|
|
|
Bitmask(self.0.bitxor(rhs.0))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ops::Not for Bitmask {
|
|
|
|
type Output = Self;
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2017-08-09 17:00:23 +00:00
|
|
|
fn not(self) -> Self {
|
|
|
|
Bitmask(self.0.not())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<u64> for Bitmask {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2017-08-09 17:00:23 +00:00
|
|
|
fn from(v: u64) -> Self {
|
2017-08-30 11:39:09 +00:00
|
|
|
skip_assert_initialized!();
|
2017-08-09 17:00:23 +00:00
|
|
|
Self::new(v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl glib::types::StaticType for Bitmask {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2017-08-09 17:00:23 +00:00
|
|
|
fn static_type() -> glib::types::Type {
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { from_glib(ffi::gst_bitmask_get_type()) }
|
2017-08-09 17:00:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-20 07:19:02 +00:00
|
|
|
impl glib::value::ValueType for Bitmask {
|
|
|
|
type Type = Self;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe impl<'a> glib::value::FromValue<'a> for Bitmask {
|
|
|
|
type Checker = glib::value::GenericValueTypeChecker<Self>;
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-04-20 07:19:02 +00:00
|
|
|
unsafe fn from_value(value: &'a glib::Value) -> Self {
|
|
|
|
skip_assert_initialized!();
|
|
|
|
let v = ffi::gst_value_get_bitmask(value.to_glib_none().0);
|
2017-08-09 17:00:23 +00:00
|
|
|
Self::new(v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-20 07:19:02 +00:00
|
|
|
impl glib::value::ToValue for Bitmask {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-04-20 07:19:02 +00:00
|
|
|
fn to_value(&self) -> glib::Value {
|
2021-04-25 16:46:18 +00:00
|
|
|
let mut value = glib::Value::for_value_type::<Self>();
|
2021-04-20 07:19:02 +00:00
|
|
|
unsafe {
|
|
|
|
ffi::gst_value_set_bitmask(value.to_glib_none_mut().0, self.0);
|
|
|
|
}
|
|
|
|
value
|
2017-08-09 17:00:23 +00:00
|
|
|
}
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-04-20 07:19:02 +00:00
|
|
|
fn value_type(&self) -> glib::Type {
|
|
|
|
Self::static_type()
|
2017-08-09 17:00:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-26 11:56:53 +00:00
|
|
|
impl From<Bitmask> for glib::Value {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2022-11-26 11:56:53 +00:00
|
|
|
fn from(v: Bitmask) -> glib::Value {
|
|
|
|
skip_assert_initialized!();
|
|
|
|
glib::value::ToValue::to_value(&v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct Array(glib::SendValue);
|
2017-07-28 13:52:35 +00:00
|
|
|
|
2021-11-05 20:38:38 +00:00
|
|
|
unsafe impl Send for Array {}
|
|
|
|
unsafe impl Sync for Array {}
|
2017-11-15 17:18:58 +00:00
|
|
|
|
2022-11-26 11:56:53 +00:00
|
|
|
impl fmt::Debug for Array {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
f.debug_tuple("Array").field(&self.as_slice()).finish()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-05 20:38:38 +00:00
|
|
|
impl Array {
|
2022-11-26 11:56:53 +00:00
|
|
|
pub fn new(values: impl IntoIterator<Item = impl Into<glib::Value> + Send>) -> Self {
|
2017-08-30 11:39:09 +00:00
|
|
|
assert_initialized_main_thread!();
|
|
|
|
|
2022-11-26 11:56:53 +00:00
|
|
|
unsafe {
|
|
|
|
let mut value = glib::Value::for_value_type::<Array>();
|
|
|
|
for v in values.into_iter() {
|
|
|
|
let mut v = v.into().into_raw();
|
|
|
|
ffi::gst_value_array_append_and_take_value(value.to_glib_none_mut().0, &mut v);
|
|
|
|
}
|
|
|
|
|
|
|
|
Self(glib::SendValue::unsafe_from(value.into_raw()))
|
|
|
|
}
|
2017-07-28 13:52:35 +00:00
|
|
|
}
|
|
|
|
|
2021-11-05 20:38:38 +00:00
|
|
|
pub fn from_values(values: impl IntoIterator<Item = glib::SendValue>) -> Self {
|
2022-12-25 10:47:02 +00:00
|
|
|
skip_assert_initialized!();
|
2020-10-20 13:14:10 +00:00
|
|
|
|
2022-11-26 11:56:53 +00:00
|
|
|
Self::new(values)
|
2017-07-28 13:52:35 +00:00
|
|
|
}
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2017-12-17 12:06:22 +00:00
|
|
|
pub fn as_slice(&self) -> &[glib::SendValue] {
|
2022-11-26 11:56:53 +00:00
|
|
|
unsafe {
|
|
|
|
let arr = (*self.0.as_ptr()).data[0].v_pointer as *const glib::ffi::GArray;
|
|
|
|
if arr.is_null() || (*arr).len == 0 {
|
|
|
|
&[]
|
|
|
|
} else {
|
|
|
|
#[allow(clippy::cast_ptr_alignment)]
|
|
|
|
slice::from_raw_parts((*arr).data as *const glib::SendValue, (*arr).len as usize)
|
|
|
|
}
|
|
|
|
}
|
2017-07-28 13:52:35 +00:00
|
|
|
}
|
2022-11-26 22:52:32 +00:00
|
|
|
|
|
|
|
pub fn append_value(&mut self, value: glib::SendValue) {
|
|
|
|
unsafe {
|
|
|
|
ffi::gst_value_array_append_and_take_value(
|
|
|
|
self.0.to_glib_none_mut().0,
|
|
|
|
&mut value.into_raw(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn append(&mut self, value: impl Into<glib::Value> + Send) {
|
|
|
|
self.append_value(glib::SendValue::from_owned(value));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Array {
|
|
|
|
fn default() -> Self {
|
2022-12-25 10:47:02 +00:00
|
|
|
skip_assert_initialized!();
|
2022-11-26 22:52:32 +00:00
|
|
|
|
|
|
|
unsafe {
|
|
|
|
let value = glib::Value::for_value_type::<Array>();
|
|
|
|
|
|
|
|
Self(glib::SendValue::unsafe_from(value.into_raw()))
|
|
|
|
}
|
|
|
|
}
|
2017-07-28 13:52:35 +00:00
|
|
|
}
|
|
|
|
|
2021-11-05 20:38:38 +00:00
|
|
|
impl ops::Deref for Array {
|
2021-10-12 08:24:54 +00:00
|
|
|
type Target = [glib::SendValue];
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-10-12 08:24:54 +00:00
|
|
|
fn deref(&self) -> &[glib::SendValue] {
|
|
|
|
self.as_slice()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-05 20:38:38 +00:00
|
|
|
impl AsRef<[glib::SendValue]> for Array {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-11-05 20:38:38 +00:00
|
|
|
fn as_ref(&self) -> &[glib::SendValue] {
|
|
|
|
self.as_slice()
|
|
|
|
}
|
|
|
|
}
|
2017-08-30 11:39:09 +00:00
|
|
|
|
2021-11-05 20:38:38 +00:00
|
|
|
impl std::iter::FromIterator<glib::SendValue> for Array {
|
|
|
|
fn from_iter<T: IntoIterator<Item = glib::SendValue>>(iter: T) -> Self {
|
2022-12-25 10:47:02 +00:00
|
|
|
skip_assert_initialized!();
|
2021-11-05 20:38:38 +00:00
|
|
|
Self::from_values(iter)
|
2017-07-28 13:52:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-26 22:52:32 +00:00
|
|
|
impl std::iter::Extend<glib::SendValue> for Array {
|
|
|
|
fn extend<T: IntoIterator<Item = glib::SendValue>>(&mut self, iter: T) {
|
|
|
|
for v in iter.into_iter() {
|
|
|
|
self.append_value(v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-05 20:38:38 +00:00
|
|
|
impl glib::value::ValueType for Array {
|
2021-04-20 07:19:02 +00:00
|
|
|
type Type = Self;
|
|
|
|
}
|
|
|
|
|
2021-11-05 20:38:38 +00:00
|
|
|
unsafe impl<'a> glib::value::FromValue<'a> for Array {
|
2021-04-20 07:19:02 +00:00
|
|
|
type Checker = glib::value::GenericValueTypeChecker<Self>;
|
|
|
|
|
|
|
|
unsafe fn from_value(value: &'a glib::Value) -> Self {
|
|
|
|
skip_assert_initialized!();
|
2022-11-26 11:56:53 +00:00
|
|
|
Self(glib::SendValue::unsafe_from(value.clone().into_raw()))
|
2017-07-28 13:52:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-05 20:38:38 +00:00
|
|
|
impl glib::value::ToValue for Array {
|
2021-04-20 07:19:02 +00:00
|
|
|
fn to_value(&self) -> glib::Value {
|
2022-11-26 11:56:53 +00:00
|
|
|
self.0.clone().into()
|
2017-07-28 13:52:35 +00:00
|
|
|
}
|
|
|
|
|
2021-04-20 07:19:02 +00:00
|
|
|
fn value_type(&self) -> glib::Type {
|
|
|
|
Self::static_type()
|
2017-07-28 13:52:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-26 11:56:53 +00:00
|
|
|
impl From<Array> for glib::Value {
|
|
|
|
fn from(v: Array) -> glib::Value {
|
|
|
|
skip_assert_initialized!();
|
|
|
|
v.0.into()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-05 20:38:38 +00:00
|
|
|
impl glib::types::StaticType for Array {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2017-07-28 13:52:35 +00:00
|
|
|
fn static_type() -> glib::types::Type {
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { from_glib(ffi::gst_value_array_get_type()) }
|
2017-07-28 13:52:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-05 20:38:38 +00:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct ArrayRef<'a>(&'a [glib::SendValue]);
|
2017-07-28 13:52:35 +00:00
|
|
|
|
2021-11-05 20:38:38 +00:00
|
|
|
unsafe impl<'a> Send for ArrayRef<'a> {}
|
|
|
|
unsafe impl<'a> Sync for ArrayRef<'a> {}
|
2017-11-15 17:18:58 +00:00
|
|
|
|
2021-11-05 20:38:38 +00:00
|
|
|
impl<'a> ArrayRef<'a> {
|
|
|
|
pub fn new(values: &'a [glib::SendValue]) -> Self {
|
2022-12-25 10:47:02 +00:00
|
|
|
skip_assert_initialized!();
|
2017-08-30 11:39:09 +00:00
|
|
|
|
2021-11-05 20:38:38 +00:00
|
|
|
Self(values)
|
2017-07-28 13:52:35 +00:00
|
|
|
}
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-11-05 20:38:38 +00:00
|
|
|
pub fn as_slice(&self) -> &'a [glib::SendValue] {
|
|
|
|
self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> ops::Deref for ArrayRef<'a> {
|
|
|
|
type Target = [glib::SendValue];
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-11-05 20:38:38 +00:00
|
|
|
fn deref(&self) -> &[glib::SendValue] {
|
|
|
|
self.as_slice()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> AsRef<[glib::SendValue]> for ArrayRef<'a> {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-11-05 20:38:38 +00:00
|
|
|
fn as_ref(&self) -> &[glib::SendValue] {
|
|
|
|
self.as_slice()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe impl<'a> glib::value::FromValue<'a> for ArrayRef<'a> {
|
|
|
|
type Checker = glib::value::GenericValueTypeChecker<Self>;
|
2020-10-20 13:14:10 +00:00
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-11-05 20:38:38 +00:00
|
|
|
unsafe fn from_value(value: &'a glib::Value) -> Self {
|
|
|
|
skip_assert_initialized!();
|
2022-11-26 11:56:53 +00:00
|
|
|
let arr = (*value.as_ptr()).data[0].v_pointer as *const glib::ffi::GArray;
|
2022-02-07 10:21:13 +00:00
|
|
|
if arr.is_null() || (*arr).len == 0 {
|
2021-11-05 20:38:38 +00:00
|
|
|
Self(&[])
|
|
|
|
} else {
|
|
|
|
#[allow(clippy::cast_ptr_alignment)]
|
|
|
|
Self(slice::from_raw_parts(
|
|
|
|
(*arr).data as *const glib::SendValue,
|
|
|
|
(*arr).len as usize,
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> glib::value::ToValue for ArrayRef<'a> {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-11-05 20:38:38 +00:00
|
|
|
fn to_value(&self) -> glib::Value {
|
|
|
|
let mut value = glib::Value::for_value_type::<Array>();
|
|
|
|
unsafe {
|
|
|
|
for v in self.0 {
|
|
|
|
ffi::gst_value_array_append_value(value.to_glib_none_mut().0, v.to_glib_none().0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
value
|
|
|
|
}
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-11-05 20:38:38 +00:00
|
|
|
fn value_type(&self) -> glib::Type {
|
|
|
|
Self::static_type()
|
2020-10-20 13:14:10 +00:00
|
|
|
}
|
2021-11-05 20:38:38 +00:00
|
|
|
}
|
|
|
|
|
2022-11-26 11:56:53 +00:00
|
|
|
impl<'a> From<ArrayRef<'a>> for glib::Value {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2022-11-26 11:56:53 +00:00
|
|
|
fn from(v: ArrayRef<'a>) -> glib::Value {
|
|
|
|
skip_assert_initialized!();
|
|
|
|
glib::value::ToValue::to_value(&v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-05 20:38:38 +00:00
|
|
|
impl<'a> glib::types::StaticType for ArrayRef<'a> {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-11-05 20:38:38 +00:00
|
|
|
fn static_type() -> glib::types::Type {
|
|
|
|
unsafe { from_glib(ffi::gst_value_array_get_type()) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-26 11:56:53 +00:00
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct List(glib::SendValue);
|
2020-10-20 13:14:10 +00:00
|
|
|
|
2021-11-05 20:38:38 +00:00
|
|
|
unsafe impl Send for List {}
|
|
|
|
unsafe impl Sync for List {}
|
|
|
|
|
2022-11-26 11:56:53 +00:00
|
|
|
impl fmt::Debug for List {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
f.debug_tuple("List").field(&self.as_slice()).finish()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-05 20:38:38 +00:00
|
|
|
impl List {
|
2022-11-26 11:56:53 +00:00
|
|
|
pub fn new(values: impl IntoIterator<Item = impl Into<glib::Value> + Send>) -> Self {
|
2018-07-16 19:46:10 +00:00
|
|
|
assert_initialized_main_thread!();
|
|
|
|
|
2022-11-26 11:56:53 +00:00
|
|
|
unsafe {
|
|
|
|
let mut value = glib::Value::for_value_type::<List>();
|
|
|
|
for v in values.into_iter() {
|
|
|
|
let mut v = v.into().into_raw();
|
|
|
|
ffi::gst_value_list_append_and_take_value(value.to_glib_none_mut().0, &mut v);
|
|
|
|
}
|
|
|
|
|
|
|
|
Self(glib::SendValue::unsafe_from(value.into_raw()))
|
|
|
|
}
|
2018-07-16 19:46:10 +00:00
|
|
|
}
|
|
|
|
|
2021-11-05 20:38:38 +00:00
|
|
|
pub fn from_values(values: impl IntoIterator<Item = glib::SendValue>) -> Self {
|
2022-12-25 10:47:02 +00:00
|
|
|
skip_assert_initialized!();
|
2021-11-05 20:38:38 +00:00
|
|
|
|
2022-11-26 11:56:53 +00:00
|
|
|
Self::new(values)
|
2017-07-28 13:52:35 +00:00
|
|
|
}
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2017-12-17 12:06:22 +00:00
|
|
|
pub fn as_slice(&self) -> &[glib::SendValue] {
|
2022-11-26 11:56:53 +00:00
|
|
|
unsafe {
|
|
|
|
let arr = (*self.0.as_ptr()).data[0].v_pointer as *const glib::ffi::GArray;
|
|
|
|
if arr.is_null() || (*arr).len == 0 {
|
|
|
|
&[]
|
|
|
|
} else {
|
|
|
|
#[allow(clippy::cast_ptr_alignment)]
|
|
|
|
slice::from_raw_parts((*arr).data as *const glib::SendValue, (*arr).len as usize)
|
|
|
|
}
|
|
|
|
}
|
2017-07-28 13:52:35 +00:00
|
|
|
}
|
2022-11-26 22:52:32 +00:00
|
|
|
|
|
|
|
pub fn append_value(&mut self, value: glib::SendValue) {
|
|
|
|
unsafe {
|
|
|
|
ffi::gst_value_list_append_and_take_value(
|
|
|
|
self.0.to_glib_none_mut().0,
|
|
|
|
&mut value.into_raw(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn append(&mut self, value: impl Into<glib::Value> + Send) {
|
|
|
|
self.append_value(glib::SendValue::from_owned(value));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for List {
|
|
|
|
fn default() -> Self {
|
2022-12-25 10:47:02 +00:00
|
|
|
skip_assert_initialized!();
|
2022-11-26 22:52:32 +00:00
|
|
|
|
|
|
|
unsafe {
|
|
|
|
let value = glib::Value::for_value_type::<List>();
|
|
|
|
|
|
|
|
Self(glib::SendValue::unsafe_from(value.into_raw()))
|
|
|
|
}
|
|
|
|
}
|
2017-07-28 13:52:35 +00:00
|
|
|
}
|
|
|
|
|
2021-11-05 20:38:38 +00:00
|
|
|
impl ops::Deref for List {
|
2021-10-12 08:24:54 +00:00
|
|
|
type Target = [glib::SendValue];
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-10-12 08:24:54 +00:00
|
|
|
fn deref(&self) -> &[glib::SendValue] {
|
|
|
|
self.as_slice()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-05 20:38:38 +00:00
|
|
|
impl AsRef<[glib::SendValue]> for List {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-11-05 20:38:38 +00:00
|
|
|
fn as_ref(&self) -> &[glib::SendValue] {
|
|
|
|
self.as_slice()
|
|
|
|
}
|
|
|
|
}
|
2017-08-30 11:39:09 +00:00
|
|
|
|
2021-11-05 20:38:38 +00:00
|
|
|
impl std::iter::FromIterator<glib::SendValue> for List {
|
|
|
|
fn from_iter<T: IntoIterator<Item = glib::SendValue>>(iter: T) -> Self {
|
2022-12-25 10:47:02 +00:00
|
|
|
skip_assert_initialized!();
|
2021-11-05 20:38:38 +00:00
|
|
|
Self::from_values(iter)
|
2017-07-28 13:52:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-26 22:52:32 +00:00
|
|
|
impl std::iter::Extend<glib::SendValue> for List {
|
|
|
|
fn extend<T: IntoIterator<Item = glib::SendValue>>(&mut self, iter: T) {
|
|
|
|
for v in iter.into_iter() {
|
|
|
|
self.append_value(v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-05 20:38:38 +00:00
|
|
|
impl glib::value::ValueType for List {
|
2021-04-20 07:19:02 +00:00
|
|
|
type Type = Self;
|
|
|
|
}
|
|
|
|
|
2021-11-05 20:38:38 +00:00
|
|
|
unsafe impl<'a> glib::value::FromValue<'a> for List {
|
|
|
|
type Checker = glib::value::GenericValueTypeChecker<Self>;
|
|
|
|
|
|
|
|
unsafe fn from_value(value: &'a glib::Value) -> Self {
|
|
|
|
skip_assert_initialized!();
|
2022-11-26 11:56:53 +00:00
|
|
|
Self(glib::SendValue::unsafe_from(value.clone().into_raw()))
|
2021-11-05 20:38:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl glib::value::ToValue for List {
|
|
|
|
fn to_value(&self) -> glib::Value {
|
2022-11-26 11:56:53 +00:00
|
|
|
self.0.clone().into()
|
2021-11-05 20:38:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn value_type(&self) -> glib::Type {
|
|
|
|
Self::static_type()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-26 11:56:53 +00:00
|
|
|
impl From<List> for glib::Value {
|
|
|
|
fn from(v: List) -> glib::Value {
|
|
|
|
skip_assert_initialized!();
|
|
|
|
v.0.into()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-05 20:38:38 +00:00
|
|
|
impl glib::types::StaticType for List {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-11-05 20:38:38 +00:00
|
|
|
fn static_type() -> glib::types::Type {
|
|
|
|
unsafe { from_glib(ffi::gst_value_list_get_type()) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct ListRef<'a>(&'a [glib::SendValue]);
|
|
|
|
|
|
|
|
unsafe impl<'a> Send for ListRef<'a> {}
|
|
|
|
unsafe impl<'a> Sync for ListRef<'a> {}
|
|
|
|
|
|
|
|
impl<'a> ListRef<'a> {
|
|
|
|
pub fn new(values: &'a [glib::SendValue]) -> Self {
|
2022-12-25 10:47:02 +00:00
|
|
|
skip_assert_initialized!();
|
2021-11-05 20:38:38 +00:00
|
|
|
|
|
|
|
Self(values)
|
|
|
|
}
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-11-05 20:38:38 +00:00
|
|
|
pub fn as_slice(&self) -> &'a [glib::SendValue] {
|
|
|
|
self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> ops::Deref for ListRef<'a> {
|
|
|
|
type Target = [glib::SendValue];
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-11-05 20:38:38 +00:00
|
|
|
fn deref(&self) -> &[glib::SendValue] {
|
|
|
|
self.as_slice()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> AsRef<[glib::SendValue]> for ListRef<'a> {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-11-05 20:38:38 +00:00
|
|
|
fn as_ref(&self) -> &[glib::SendValue] {
|
|
|
|
self.as_slice()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe impl<'a> glib::value::FromValue<'a> for ListRef<'a> {
|
2021-04-20 07:19:02 +00:00
|
|
|
type Checker = glib::value::GenericValueTypeChecker<Self>;
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-04-20 07:19:02 +00:00
|
|
|
unsafe fn from_value(value: &'a glib::Value) -> Self {
|
|
|
|
skip_assert_initialized!();
|
2022-11-26 11:56:53 +00:00
|
|
|
let arr = (*value.as_ptr()).data[0].v_pointer as *const glib::ffi::GArray;
|
2022-02-07 10:21:13 +00:00
|
|
|
if arr.is_null() || (*arr).len == 0 {
|
2021-11-05 20:38:38 +00:00
|
|
|
Self(&[])
|
2017-07-28 13:52:35 +00:00
|
|
|
} else {
|
2019-02-28 08:32:13 +00:00
|
|
|
#[allow(clippy::cast_ptr_alignment)]
|
2021-11-05 20:38:38 +00:00
|
|
|
Self(slice::from_raw_parts(
|
2017-12-17 12:06:22 +00:00
|
|
|
(*arr).data as *const glib::SendValue,
|
2017-07-31 11:16:42 +00:00
|
|
|
(*arr).len as usize,
|
2021-11-05 20:38:38 +00:00
|
|
|
))
|
2017-07-28 13:52:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-05 20:38:38 +00:00
|
|
|
impl<'a> glib::value::ToValue for ListRef<'a> {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-04-20 07:19:02 +00:00
|
|
|
fn to_value(&self) -> glib::Value {
|
2021-11-05 20:38:38 +00:00
|
|
|
let mut value = glib::Value::for_value_type::<List>();
|
2021-04-20 07:19:02 +00:00
|
|
|
unsafe {
|
2021-11-05 20:38:38 +00:00
|
|
|
for v in self.0 {
|
2021-04-20 07:19:02 +00:00
|
|
|
ffi::gst_value_list_append_value(value.to_glib_none_mut().0, v.to_glib_none().0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
value
|
2017-07-28 13:52:35 +00:00
|
|
|
}
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-04-20 07:19:02 +00:00
|
|
|
fn value_type(&self) -> glib::Type {
|
|
|
|
Self::static_type()
|
2017-07-28 13:52:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-26 11:56:53 +00:00
|
|
|
impl<'a> From<ListRef<'a>> for glib::Value {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2022-11-26 11:56:53 +00:00
|
|
|
fn from(v: ListRef<'a>) -> glib::Value {
|
|
|
|
skip_assert_initialized!();
|
|
|
|
glib::value::ToValue::to_value(&v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-05 20:38:38 +00:00
|
|
|
impl<'a> glib::types::StaticType for ListRef<'a> {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2017-07-28 13:52:35 +00:00
|
|
|
fn static_type() -> glib::types::Type {
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { from_glib(ffi::gst_value_list_get_type()) }
|
2017-07-28 13:52:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-28 15:47:00 +00:00
|
|
|
pub trait GstValueExt: Sized {
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_value_can_compare")]
|
2017-07-28 15:47:00 +00:00
|
|
|
fn can_compare(&self, other: &Self) -> bool;
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_value_compare")]
|
2018-08-10 11:22:15 +00:00
|
|
|
fn compare(&self, other: &Self) -> Option<cmp::Ordering>;
|
|
|
|
fn eq(&self, other: &Self) -> bool;
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_value_can_intersect")]
|
2017-07-28 15:47:00 +00:00
|
|
|
fn can_intersect(&self, other: &Self) -> bool;
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_value_intersect")]
|
2017-07-28 15:47:00 +00:00
|
|
|
fn intersect(&self, other: &Self) -> Option<Self>;
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_value_can_subtract")]
|
2017-07-28 15:47:00 +00:00
|
|
|
fn can_subtract(&self, other: &Self) -> bool;
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_value_subtract")]
|
2017-07-28 15:47:00 +00:00
|
|
|
fn subtract(&self, other: &Self) -> Option<Self>;
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_value_can_union")]
|
2017-07-28 15:47:00 +00:00
|
|
|
fn can_union(&self, other: &Self) -> bool;
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_value_union")]
|
2017-07-28 15:47:00 +00:00
|
|
|
fn union(&self, other: &Self) -> Option<Self>;
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_value_fixate")]
|
2017-07-28 15:47:00 +00:00
|
|
|
fn fixate(&self) -> Option<Self>;
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_value_is_fixed")]
|
2017-07-28 15:47:00 +00:00
|
|
|
fn is_fixed(&self) -> bool;
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_value_is_subset")]
|
2017-07-28 15:47:00 +00:00
|
|
|
fn is_subset(&self, superset: &Self) -> bool;
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_value_serialize")]
|
2019-12-17 19:00:42 +00:00
|
|
|
fn serialize(&self) -> Result<glib::GString, glib::BoolError>;
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_value_deserialize")]
|
2021-11-05 15:33:14 +00:00
|
|
|
fn deserialize(s: &str, type_: glib::Type) -> Result<glib::Value, glib::BoolError>;
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_20")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
|
2021-08-17 05:47:26 +00:00
|
|
|
#[doc(alias = "gst_value_deserialize_with_pspec")]
|
2021-11-05 15:33:14 +00:00
|
|
|
fn deserialize_with_pspec(
|
|
|
|
s: &str,
|
2021-08-17 05:47:26 +00:00
|
|
|
pspec: &glib::ParamSpec,
|
|
|
|
) -> Result<glib::Value, glib::BoolError>;
|
2017-07-28 15:47:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl GstValueExt for glib::Value {
|
|
|
|
fn can_compare(&self, other: &Self) -> bool {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
from_glib(ffi::gst_value_can_compare(
|
2017-07-31 11:16:42 +00:00
|
|
|
self.to_glib_none().0,
|
|
|
|
other.to_glib_none().0,
|
|
|
|
))
|
2017-07-28 15:47:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-10 11:22:15 +00:00
|
|
|
fn compare(&self, other: &Self) -> Option<cmp::Ordering> {
|
2017-07-28 15:47:00 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let val = ffi::gst_value_compare(self.to_glib_none().0, other.to_glib_none().0);
|
2018-08-10 11:22:15 +00:00
|
|
|
|
|
|
|
match val {
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::GST_VALUE_LESS_THAN => Some(cmp::Ordering::Less),
|
|
|
|
ffi::GST_VALUE_EQUAL => Some(cmp::Ordering::Equal),
|
|
|
|
ffi::GST_VALUE_GREATER_THAN => Some(cmp::Ordering::Greater),
|
2018-08-10 11:22:15 +00:00
|
|
|
_ => None,
|
|
|
|
}
|
2017-07-28 15:47:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-10 11:22:15 +00:00
|
|
|
fn eq(&self, other: &Self) -> bool {
|
|
|
|
self.compare(other) == Some(cmp::Ordering::Equal)
|
|
|
|
}
|
|
|
|
|
2017-07-28 15:47:00 +00:00
|
|
|
fn can_intersect(&self, other: &Self) -> bool {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
from_glib(ffi::gst_value_can_intersect(
|
2017-07-31 11:16:42 +00:00
|
|
|
self.to_glib_none().0,
|
|
|
|
other.to_glib_none().0,
|
|
|
|
))
|
2017-07-28 15:47:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn intersect(&self, other: &Self) -> Option<Self> {
|
|
|
|
unsafe {
|
|
|
|
let mut value = glib::Value::uninitialized();
|
2020-11-21 13:46:48 +00:00
|
|
|
let ret: bool = from_glib(ffi::gst_value_intersect(
|
2017-07-31 11:16:42 +00:00
|
|
|
value.to_glib_none_mut().0,
|
|
|
|
self.to_glib_none().0,
|
|
|
|
other.to_glib_none().0,
|
|
|
|
));
|
2017-07-28 15:47:00 +00:00
|
|
|
if ret {
|
|
|
|
Some(value)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn can_subtract(&self, other: &Self) -> bool {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
from_glib(ffi::gst_value_can_subtract(
|
2017-07-31 11:16:42 +00:00
|
|
|
self.to_glib_none().0,
|
|
|
|
other.to_glib_none().0,
|
|
|
|
))
|
2017-07-28 15:47:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn subtract(&self, other: &Self) -> Option<Self> {
|
|
|
|
unsafe {
|
|
|
|
let mut value = glib::Value::uninitialized();
|
2020-11-21 13:46:48 +00:00
|
|
|
let ret: bool = from_glib(ffi::gst_value_subtract(
|
2017-07-31 11:16:42 +00:00
|
|
|
value.to_glib_none_mut().0,
|
|
|
|
self.to_glib_none().0,
|
|
|
|
other.to_glib_none().0,
|
|
|
|
));
|
2017-07-28 15:47:00 +00:00
|
|
|
if ret {
|
|
|
|
Some(value)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn can_union(&self, other: &Self) -> bool {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
from_glib(ffi::gst_value_can_union(
|
2017-07-31 11:16:42 +00:00
|
|
|
self.to_glib_none().0,
|
|
|
|
other.to_glib_none().0,
|
|
|
|
))
|
2017-07-28 15:47:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn union(&self, other: &Self) -> Option<Self> {
|
|
|
|
unsafe {
|
|
|
|
let mut value = glib::Value::uninitialized();
|
2020-11-21 13:46:48 +00:00
|
|
|
let ret: bool = from_glib(ffi::gst_value_union(
|
2017-07-31 11:16:42 +00:00
|
|
|
value.to_glib_none_mut().0,
|
|
|
|
self.to_glib_none().0,
|
|
|
|
other.to_glib_none().0,
|
|
|
|
));
|
2017-07-28 15:47:00 +00:00
|
|
|
if ret {
|
|
|
|
Some(value)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn fixate(&self) -> Option<Self> {
|
|
|
|
unsafe {
|
|
|
|
let mut value = glib::Value::uninitialized();
|
2020-11-21 13:46:48 +00:00
|
|
|
let ret: bool = from_glib(ffi::gst_value_fixate(
|
2017-07-31 11:16:42 +00:00
|
|
|
value.to_glib_none_mut().0,
|
|
|
|
self.to_glib_none().0,
|
|
|
|
));
|
2017-07-28 15:47:00 +00:00
|
|
|
if ret {
|
|
|
|
Some(value)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_fixed(&self) -> bool {
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { from_glib(ffi::gst_value_is_fixed(self.to_glib_none().0)) }
|
2017-07-28 15:47:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn is_subset(&self, superset: &Self) -> bool {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
from_glib(ffi::gst_value_is_subset(
|
2017-07-31 11:16:42 +00:00
|
|
|
self.to_glib_none().0,
|
|
|
|
superset.to_glib_none().0,
|
|
|
|
))
|
2017-07-28 15:47:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-17 19:00:42 +00:00
|
|
|
fn serialize(&self) -> Result<glib::GString, glib::BoolError> {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
Option::<_>::from_glib_full(ffi::gst_value_serialize(self.to_glib_none().0))
|
2020-12-17 22:38:06 +00:00
|
|
|
.ok_or_else(|| glib::bool_error!("Failed to serialize value"))
|
2019-12-17 19:00:42 +00:00
|
|
|
}
|
2017-07-28 15:47:00 +00:00
|
|
|
}
|
|
|
|
|
2021-11-05 15:33:14 +00:00
|
|
|
fn deserialize(s: &str, type_: glib::Type) -> Result<glib::Value, glib::BoolError> {
|
2022-12-25 10:47:02 +00:00
|
|
|
skip_assert_initialized!();
|
2017-08-30 11:39:09 +00:00
|
|
|
|
2017-07-28 15:47:00 +00:00
|
|
|
unsafe {
|
2021-08-17 05:47:02 +00:00
|
|
|
let mut value = glib::Value::from_type(type_);
|
2020-11-21 13:46:48 +00:00
|
|
|
let ret: bool = from_glib(ffi::gst_value_deserialize(
|
2017-07-31 11:16:42 +00:00
|
|
|
value.to_glib_none_mut().0,
|
|
|
|
s.to_glib_none().0,
|
|
|
|
));
|
2017-07-28 15:47:00 +00:00
|
|
|
if ret {
|
2019-12-17 19:00:42 +00:00
|
|
|
Ok(value)
|
2017-07-28 15:47:00 +00:00
|
|
|
} else {
|
2020-12-17 22:38:06 +00:00
|
|
|
Err(glib::bool_error!("Failed to deserialize value"))
|
2017-07-28 15:47:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-08-17 05:47:26 +00:00
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_20")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
|
2021-11-05 15:33:14 +00:00
|
|
|
fn deserialize_with_pspec(
|
|
|
|
s: &str,
|
2021-08-17 05:47:26 +00:00
|
|
|
pspec: &glib::ParamSpec,
|
|
|
|
) -> Result<glib::Value, glib::BoolError> {
|
2022-12-25 10:47:02 +00:00
|
|
|
skip_assert_initialized!();
|
2021-08-17 05:47:26 +00:00
|
|
|
|
|
|
|
unsafe {
|
2023-01-05 16:55:38 +00:00
|
|
|
let mut value = glib::Value::from_type_unchecked(pspec.value_type());
|
2021-08-17 05:47:26 +00:00
|
|
|
let ret: bool = from_glib(ffi::gst_value_deserialize_with_pspec(
|
|
|
|
value.to_glib_none_mut().0,
|
|
|
|
s.to_glib_none().0,
|
|
|
|
pspec.to_glib_none().0,
|
|
|
|
));
|
|
|
|
if ret {
|
|
|
|
Ok(value)
|
|
|
|
} else {
|
|
|
|
Err(glib::bool_error!("Failed to deserialize value"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-28 15:47:00 +00:00
|
|
|
}
|
2019-06-03 07:56:40 +00:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2021-08-17 05:47:02 +00:00
|
|
|
use super::*;
|
|
|
|
|
2019-06-03 07:56:40 +00:00
|
|
|
#[test]
|
|
|
|
fn test_fraction() {
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::init().unwrap();
|
2019-06-03 07:56:40 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
let f1 = crate::Fraction::new(1, 2);
|
|
|
|
let f2 = crate::Fraction::new(2, 3);
|
2019-06-03 07:56:40 +00:00
|
|
|
let mut f3 = f1 * f2;
|
2019-12-22 07:59:23 +00:00
|
|
|
let f4 = f1 * f2;
|
2019-06-03 07:56:40 +00:00
|
|
|
f3 *= f2;
|
2019-12-22 07:59:23 +00:00
|
|
|
f3 *= f4;
|
2019-06-03 07:56:40 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
assert_eq!(f3, crate::Fraction::new(2, 27));
|
2019-06-03 07:56:40 +00:00
|
|
|
}
|
2021-08-17 05:47:02 +00:00
|
|
|
|
2021-11-05 20:39:33 +00:00
|
|
|
#[test]
|
|
|
|
fn test_int_range_constructor() {
|
|
|
|
crate::init().unwrap();
|
|
|
|
|
|
|
|
// Type inference should figure out the type
|
|
|
|
let _r1 = crate::IntRange::new(1i32, 2i32);
|
|
|
|
let _r2 = crate::IntRange::with_step(2i64, 3i64, 4i64);
|
|
|
|
}
|
|
|
|
|
2021-08-17 05:47:02 +00:00
|
|
|
#[test]
|
|
|
|
fn test_deserialize() {
|
|
|
|
crate::init().unwrap();
|
|
|
|
|
|
|
|
let v = glib::Value::deserialize("123", i32::static_type()).unwrap();
|
|
|
|
assert_eq!(v.get::<i32>(), Ok(123));
|
|
|
|
}
|
2019-06-03 07:56:40 +00:00
|
|
|
}
|