mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2025-02-02 04:12:25 +00:00
Update for GLib constructor renames
See https://github.com/gtk-rs/gtk-rs-core/pull/384
This commit is contained in:
parent
ddf398e3da
commit
3b28bccf03
7 changed files with 166 additions and 57 deletions
|
@ -613,7 +613,7 @@ mod tests {
|
|||
let mut buffer = gst::Buffer::new();
|
||||
{
|
||||
let datetime =
|
||||
glib::DateTime::new_utc(2021, 2, 4, 10, 53, 17.0).expect("can't create datetime");
|
||||
glib::DateTime::from_utc(2021, 2, 4, 10, 53, 17.0).expect("can't create datetime");
|
||||
let time_code = crate::VideoTimeCode::from_date_time(
|
||||
gst::Fraction::new(30, 1),
|
||||
&datetime,
|
||||
|
@ -629,7 +629,7 @@ mod tests {
|
|||
);
|
||||
|
||||
let datetime =
|
||||
glib::DateTime::new_utc(2021, 2, 4, 10, 53, 17.0).expect("can't create datetime");
|
||||
glib::DateTime::from_utc(2021, 2, 4, 10, 53, 17.0).expect("can't create datetime");
|
||||
let mut time_code_2 = crate::ValidVideoTimeCode::try_from(
|
||||
crate::VideoTimeCode::from_date_time(
|
||||
gst::Fraction::new(30, 1),
|
||||
|
|
|
@ -118,7 +118,7 @@ impl TryFrom<DateTimeVariants> for Date {
|
|||
return Err(glib::bool_error!("Out of range `month` for `Date`"));
|
||||
}
|
||||
|
||||
Ok(Date(glib::Date::new_dmy(
|
||||
Ok(Date(glib::Date::from_dmy(
|
||||
d.try_into()
|
||||
.map_err(|_| glib::bool_error!("Out of range `day` for `Date`"))?,
|
||||
month,
|
||||
|
|
|
@ -307,7 +307,6 @@ pub mod prelude {
|
|||
pub use crate::message::MessageErrorDomain;
|
||||
pub use crate::object::GstObjectExtManual;
|
||||
pub use crate::pad::PadExtManual;
|
||||
pub use crate::param_spec::GstParamSpecExt;
|
||||
pub use crate::pipeline::GstPipelineExtManual;
|
||||
pub use crate::plugin::GstPluginExtManual;
|
||||
pub use crate::plugin_feature::PluginFeatureExtManual;
|
||||
|
|
|
@ -1,52 +1,45 @@
|
|||
// Take a look at the license at the top of the repository in the LICENSE file.
|
||||
|
||||
use glib::gobject_ffi;
|
||||
use glib::translate::*;
|
||||
use glib::ParamSpec;
|
||||
|
||||
pub trait GstParamSpecExt {
|
||||
#[cfg(any(feature = "v1_14", feature = "dox"))]
|
||||
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
|
||||
fn new_array(
|
||||
name: &str,
|
||||
nick: &str,
|
||||
blurb: &str,
|
||||
element_spec: &glib::ParamSpec,
|
||||
flags: glib::ParamFlags,
|
||||
) -> Self;
|
||||
glib::wrapper! {
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
#[doc(alias = "GstParamSpecFraction")]
|
||||
pub struct ParamSpecFraction(Shared<ffi::GstParamSpecFraction>);
|
||||
|
||||
fn new_fraction(
|
||||
name: &str,
|
||||
nick: &str,
|
||||
blurb: &str,
|
||||
min: crate::Fraction,
|
||||
max: crate::Fraction,
|
||||
default: crate::Fraction,
|
||||
flags: glib::ParamFlags,
|
||||
) -> Self;
|
||||
match fn {
|
||||
ref => |ptr| gobject_ffi::g_param_spec_ref_sink(ptr as *mut gobject_ffi::GParamSpec),
|
||||
unref => |ptr| gobject_ffi::g_param_spec_unref(ptr as *mut gobject_ffi::GParamSpec),
|
||||
type_ => || ffi::gst_param_spec_fraction_get_type(),
|
||||
}
|
||||
}
|
||||
|
||||
impl GstParamSpecExt for glib::ParamSpec {
|
||||
#[cfg(any(feature = "v1_14", feature = "dox"))]
|
||||
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
|
||||
fn new_array(
|
||||
name: &str,
|
||||
nick: &str,
|
||||
blurb: &str,
|
||||
element_spec: &glib::ParamSpec,
|
||||
flags: glib::ParamFlags,
|
||||
) -> glib::ParamSpec {
|
||||
assert_initialized_main_thread!();
|
||||
unsafe {
|
||||
from_glib_full(ffi::gst_param_spec_array(
|
||||
name.to_glib_none().0,
|
||||
nick.to_glib_none().0,
|
||||
blurb.to_glib_none().0,
|
||||
element_spec.to_glib_none().0,
|
||||
flags.into_glib(),
|
||||
))
|
||||
}
|
||||
}
|
||||
unsafe impl Send for ParamSpecFraction {}
|
||||
unsafe impl Sync for ParamSpecFraction {}
|
||||
|
||||
fn new_fraction(
|
||||
impl std::ops::Deref for ParamSpecFraction {
|
||||
type Target = ParamSpec;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
unsafe { &*(self as *const ParamSpecFraction as *const ParamSpec) }
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl glib::ParamSpecType for ParamSpecFraction {}
|
||||
|
||||
#[doc(hidden)]
|
||||
impl FromGlibPtrFull<*mut gobject_ffi::GParamSpec> for ParamSpecFraction {
|
||||
unsafe fn from_glib_full(ptr: *mut gobject_ffi::GParamSpec) -> Self {
|
||||
from_glib_full(ptr as *mut ffi::GstParamSpecFraction)
|
||||
}
|
||||
}
|
||||
|
||||
impl ParamSpecFraction {
|
||||
#[allow(clippy::new_ret_no_self)]
|
||||
#[doc(alias = "gst_param_spec_fraction")]
|
||||
pub fn new(
|
||||
name: &str,
|
||||
nick: &str,
|
||||
blurb: &str,
|
||||
|
@ -57,7 +50,7 @@ impl GstParamSpecExt for glib::ParamSpec {
|
|||
) -> glib::ParamSpec {
|
||||
assert_initialized_main_thread!();
|
||||
unsafe {
|
||||
from_glib_full(ffi::gst_param_spec_fraction(
|
||||
from_glib_none(ffi::gst_param_spec_fraction(
|
||||
name.to_glib_none().0,
|
||||
nick.to_glib_none().0,
|
||||
blurb.to_glib_none().0,
|
||||
|
@ -71,17 +64,134 @@ impl GstParamSpecExt for glib::ParamSpec {
|
|||
))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn minimum(&self) -> crate::Fraction {
|
||||
unsafe {
|
||||
let ptr = self.to_glib_none().0;
|
||||
|
||||
crate::Fraction::new((*ptr).min_num, (*ptr).min_den)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn maximum(&self) -> crate::Fraction {
|
||||
unsafe {
|
||||
let ptr = self.to_glib_none().0;
|
||||
|
||||
crate::Fraction::new((*ptr).max_num, (*ptr).max_den)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn default_value(&self) -> crate::Fraction {
|
||||
unsafe {
|
||||
let ptr = self.to_glib_none().0;
|
||||
|
||||
crate::Fraction::new((*ptr).def_num, (*ptr).def_den)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn upcast(self) -> ParamSpec {
|
||||
unsafe { from_glib_full(self.to_glib_full() as *mut gobject_ffi::GParamSpec) }
|
||||
}
|
||||
|
||||
pub fn upcast_ref(&self) -> &ParamSpec {
|
||||
&*self
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "v1_14", feature = "dox"))]
|
||||
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
|
||||
glib::wrapper! {
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
#[doc(alias = "GstParamSpecArray")]
|
||||
pub struct ParamSpecArray(Shared<ffi::GstParamSpecArray>);
|
||||
|
||||
match fn {
|
||||
ref => |ptr| gobject_ffi::g_param_spec_ref_sink(ptr as *mut gobject_ffi::GParamSpec),
|
||||
unref => |ptr| gobject_ffi::g_param_spec_unref(ptr as *mut gobject_ffi::GParamSpec),
|
||||
type_ => || ffi::gst_param_spec_fraction_get_type(),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "v1_14", feature = "dox"))]
|
||||
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
|
||||
unsafe impl Send for ParamSpecArray {}
|
||||
#[cfg(any(feature = "v1_14", feature = "dox"))]
|
||||
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
|
||||
unsafe impl Sync for ParamSpecArray {}
|
||||
|
||||
#[cfg(any(feature = "v1_14", feature = "dox"))]
|
||||
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
|
||||
impl std::ops::Deref for ParamSpecArray {
|
||||
type Target = ParamSpec;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
unsafe { &*(self as *const ParamSpecArray as *const ParamSpec) }
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "v1_14", feature = "dox"))]
|
||||
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
|
||||
unsafe impl glib::ParamSpecType for ParamSpecArray {}
|
||||
|
||||
#[cfg(any(feature = "v1_14", feature = "dox"))]
|
||||
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
|
||||
#[doc(hidden)]
|
||||
impl FromGlibPtrFull<*mut gobject_ffi::GParamSpec> for ParamSpecArray {
|
||||
unsafe fn from_glib_full(ptr: *mut gobject_ffi::GParamSpec) -> Self {
|
||||
from_glib_full(ptr as *mut ffi::GstParamSpecArray)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "v1_14", feature = "dox"))]
|
||||
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
|
||||
impl ParamSpecArray {
|
||||
#[allow(clippy::new_ret_no_self)]
|
||||
#[doc(alias = "gst_param_spec_array")]
|
||||
pub fn new_array(
|
||||
name: &str,
|
||||
nick: &str,
|
||||
blurb: &str,
|
||||
element_spec: Option<&glib::ParamSpec>,
|
||||
flags: glib::ParamFlags,
|
||||
) -> glib::ParamSpec {
|
||||
assert_initialized_main_thread!();
|
||||
unsafe {
|
||||
from_glib_none(ffi::gst_param_spec_array(
|
||||
name.to_glib_none().0,
|
||||
nick.to_glib_none().0,
|
||||
blurb.to_glib_none().0,
|
||||
element_spec.to_glib_none().0,
|
||||
flags.into_glib(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn element_spec(&self) -> Option<ParamSpec> {
|
||||
unsafe {
|
||||
let ptr = self.to_glib_none().0;
|
||||
|
||||
from_glib_none((*ptr).element_spec)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn upcast(self) -> ParamSpec {
|
||||
unsafe { from_glib_full(self.to_glib_full() as *mut gobject_ffi::GParamSpec) }
|
||||
}
|
||||
|
||||
pub fn upcast_ref(&self) -> &ParamSpec {
|
||||
&*self
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::prelude::*;
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_trait() {
|
||||
crate::init().unwrap();
|
||||
|
||||
let _pspec = glib::ParamSpec::new_fraction(
|
||||
let _pspec = ParamSpecFraction::new(
|
||||
"foo",
|
||||
"Foo",
|
||||
"Foo Bar",
|
||||
|
|
|
@ -180,7 +180,7 @@ mod tests {
|
|||
.field("f2", &String::from("bcd"))
|
||||
.field("f3", 123i32)
|
||||
.field("fraction", Fraction::new(1, 2))
|
||||
.field("date", Date::new_dmy(19, DateMonth::August, 2019).unwrap())
|
||||
.field("date", Date::from_dmy(19, DateMonth::August, 2019).unwrap())
|
||||
.field(
|
||||
"date_time",
|
||||
DateTime::new(2f32, 2019, 8, 19, 13, 34, 42f64).unwrap(),
|
||||
|
@ -235,7 +235,7 @@ mod tests {
|
|||
.field("f1", "abc")
|
||||
.field("f2", "bcd")
|
||||
.field("f3", 123)
|
||||
.field("date", Date::new_dmy(19, DateMonth::August, 2019).unwrap())
|
||||
.field("date", Date::from_dmy(19, DateMonth::August, 2019).unwrap())
|
||||
.field(
|
||||
"date_time",
|
||||
DateTime::new(2f32, 2019, 8, 19, 13, 34, 42f64).unwrap()
|
||||
|
@ -256,7 +256,7 @@ mod tests {
|
|||
.field("f2", "bcd".to_owned())
|
||||
.field("f3", 123i32)
|
||||
.field("fraction", Fraction::new(1, 2))
|
||||
.field("date", Date::new_dmy(19, DateMonth::August, 2019).unwrap())
|
||||
.field("date", Date::from_dmy(19, DateMonth::August, 2019).unwrap())
|
||||
.field(
|
||||
"date_time",
|
||||
DateTime::new(2f32, 2019, 8, 19, 13, 34, 42f64).unwrap(),
|
||||
|
|
|
@ -332,7 +332,7 @@ mod tests {
|
|||
tags.add::<Bitrate>(&96_000, TagMergeMode::Append); // u32
|
||||
tags.add::<TrackGain>(&1f64, TagMergeMode::Append); // f64
|
||||
tags.add::<Date>(
|
||||
&glib::Date::new_dmy(28, glib::DateMonth::May, 2018).unwrap(),
|
||||
&glib::Date::from_dmy(28, glib::DateMonth::May, 2018).unwrap(),
|
||||
TagMergeMode::Append,
|
||||
);
|
||||
tags.add::<DateTime>(
|
||||
|
@ -477,7 +477,7 @@ mod tests {
|
|||
assert!((tags.index::<TrackGain>(0).unwrap().get() - 1f64).abs() < std::f64::EPSILON);
|
||||
assert_eq!(
|
||||
tags.index::<Date>(0).unwrap().get(),
|
||||
glib::Date::new_dmy(28, glib::DateMonth::May, 2018).unwrap()
|
||||
glib::Date::from_dmy(28, glib::DateMonth::May, 2018).unwrap()
|
||||
);
|
||||
assert_eq!(
|
||||
tags.index::<DateTime>(0).unwrap().get(),
|
||||
|
@ -513,7 +513,7 @@ mod tests {
|
|||
assert!((tags.index::<TrackGain>(0).unwrap().get() - 1f64).abs() < std::f64::EPSILON);
|
||||
assert_eq!(
|
||||
tags.index::<Date>(0).unwrap().get(),
|
||||
glib::Date::new_dmy(28, glib::DateMonth::May, 2018).unwrap()
|
||||
glib::Date::from_dmy(28, glib::DateMonth::May, 2018).unwrap()
|
||||
);
|
||||
assert_eq!(
|
||||
tags.index::<DateTime>(0).unwrap().get(),
|
||||
|
@ -542,7 +542,7 @@ mod tests {
|
|||
tags.add::<Bitrate>(&96_000, TagMergeMode::Append); // u32
|
||||
tags.add::<TrackGain>(&1f64, TagMergeMode::Append); // f64
|
||||
tags.add::<Date>(
|
||||
&glib::Date::new_dmy(28, glib::DateMonth::May, 2018).unwrap(),
|
||||
&glib::Date::from_dmy(28, glib::DateMonth::May, 2018).unwrap(),
|
||||
TagMergeMode::Append,
|
||||
);
|
||||
tags.add::<DateTime>(
|
||||
|
|
|
@ -506,7 +506,7 @@ mod tests {
|
|||
.is_none());
|
||||
|
||||
assert_eq!(
|
||||
Date::new_dmy(19, DateMonth::August, 2019).unwrap(),
|
||||
Date::from_dmy(19, DateMonth::August, 2019).unwrap(),
|
||||
slice[4].get::<Date>().expect("slice[4]")
|
||||
);
|
||||
|
||||
|
@ -536,7 +536,7 @@ mod tests {
|
|||
.is_none());
|
||||
|
||||
assert_eq!(
|
||||
Date::new_dmy(19, DateMonth::August, 2019).unwrap(),
|
||||
Date::from_dmy(19, DateMonth::August, 2019).unwrap(),
|
||||
slice[4].get::<Date>().expect("slice[4]")
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in a new issue