From a316d610eb3676f4ae235b294352e0be460fed2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Thu, 25 Feb 2021 12:38:10 +0200 Subject: [PATCH] gstreamer: Update for glib::Type API changes --- examples/src/bin/custom_meta.rs | 2 +- gstreamer/src/buffer.rs | 2 +- gstreamer/src/iterator.rs | 6 ++-- gstreamer/src/meta.rs | 10 +++---- gstreamer/src/pad.rs | 6 ++-- gstreamer/src/structure.rs | 4 +-- gstreamer/src/subclass/element.rs | 4 +-- gstreamer/src/tags_serde.rs | 23 ++++---------- gstreamer/src/value_serde.rs | 50 +++++++++++-------------------- 9 files changed, 41 insertions(+), 66 deletions(-) diff --git a/examples/src/bin/custom_meta.rs b/examples/src/bin/custom_meta.rs index f5de129f9..40a2d1ec2 100644 --- a/examples/src/bin/custom_meta.rs +++ b/examples/src/bin/custom_meta.rs @@ -95,7 +95,7 @@ mod custom_meta { [ptr::null::()].as_ptr() as *mut *const _, )); - assert_ne!(t, glib::Type::Invalid); + assert_ne!(t, glib::Type::INVALID); t }); diff --git a/gstreamer/src/buffer.rs b/gstreamer/src/buffer.rs index e7c5a672b..ae5b75ba3 100644 --- a/gstreamer/src/buffer.rs +++ b/gstreamer/src/buffer.rs @@ -727,7 +727,7 @@ macro_rules! define_meta_iter( if meta.is_null() { return None; - } else if self.meta_api == glib::Type::Invalid || glib::Type::from_glib((*(*meta).info).api) == self.meta_api { + } else if self.meta_api == glib::Type::INVALID || glib::Type::from_glib((*(*meta).info).api) == self.meta_api { // FIXME: Workaround for a lifetime issue with the mutable iterator only let buffer = $prepare_buffer(self.buffer.as_mut_ptr()); let item = $from_ptr(buffer, meta); diff --git a/gstreamer/src/iterator.rs b/gstreamer/src/iterator.rs index 280d86a4e..807c19006 100644 --- a/gstreamer/src/iterator.rs +++ b/gstreamer/src/iterator.rs @@ -139,7 +139,7 @@ where let func_ptr = &mut func as *mut F as gpointer; let mut accum = Some(init); - let mut ret = glib::Value::from_type(glib::Type::Pointer); + let mut ret = glib::Value::from_type(glib::Type::POINTER); glib::gobject_ffi::g_value_set_pointer( ret.to_glib_none_mut().0, &mut accum as *mut _ as gpointer, @@ -357,7 +357,7 @@ unsafe extern "C" fn filter_boxed_get_type() -> glib::f let mut types = TYPES.lock().unwrap(); let type_name = T::static_type().name(); - if let Some(type_) = types.get(&type_name) { + if let Some(type_) = types.get(type_name) { return *type_; } @@ -389,7 +389,7 @@ unsafe extern "C" fn filter_boxed_get_type() -> glib::f type_ }; - types.insert(type_name, type_); + types.insert(String::from(type_name), type_); type_ } diff --git a/gstreamer/src/meta.rs b/gstreamer/src/meta.rs index 3b36c3ee2..bacee8c32 100644 --- a/gstreamer/src/meta.rs +++ b/gstreamer/src/meta.rs @@ -30,7 +30,7 @@ pub unsafe trait MetaAPI: Sync + Send + Sized { assert!(!ptr.is_null()); let meta_api = Self::get_meta_api(); - if meta_api != glib::Type::Invalid { + if meta_api != glib::Type::INVALID { assert_eq!( meta_api, from_glib((*(*(ptr as *const ffi::GstMeta)).info).api) @@ -50,7 +50,7 @@ pub unsafe trait MetaAPI: Sync + Send + Sized { assert!(!ptr.is_null()); let meta_api = Self::get_meta_api(); - if meta_api != glib::Type::Invalid { + if meta_api != glib::Type::INVALID { assert_eq!( meta_api, from_glib((*(*(ptr as *const ffi::GstMeta)).info).api) @@ -165,7 +165,7 @@ impl<'a> MetaRef<'a, Meta> { let target_type = T::get_meta_api(); let type_ = self.get_api(); - if type_ == glib::Type::Invalid || target_type == type_ { + if type_ == glib::Type::INVALID || target_type == type_ { Some(unsafe { &*(self as *const MetaRef<'a, Meta> as *const MetaRef<'a, T>) }) } else { None @@ -217,7 +217,7 @@ impl<'a, U> MetaRefMut<'a, Meta, U> { let target_type = T::get_meta_api(); let type_ = self.get_api(); - if type_ == glib::Type::Invalid || target_type == type_ { + if type_ == glib::Type::INVALID || target_type == type_ { Some(unsafe { &*(self as *mut MetaRefMut<'a, Meta, U> as *const MetaRefMut<'a, T, U>) }) } else { None @@ -241,7 +241,7 @@ unsafe impl MetaAPI for Meta { type GstType = ffi::GstMeta; fn get_meta_api() -> glib::Type { - glib::Type::Invalid + glib::Type::INVALID } } diff --git a/gstreamer/src/pad.rs b/gstreamer/src/pad.rs index 2f972701f..1ceec71ee 100644 --- a/gstreamer/src/pad.rs +++ b/gstreamer/src/pad.rs @@ -1666,15 +1666,15 @@ impl + IsA> PadBuilder { .get_some::() .unwrap(); - if gtype == glib::Type::Unit { + if gtype == glib::Type::UNIT { // Nothing to be done, we can create any kind of pad - } else if gtype.is_a(&type_) { + } else if gtype.is_a(type_) { // We were asked to create a parent type of the template type, e.g. a gst::Pad for // a template that wants a gst_base::AggregatorPad. Not a problem: update the type type_ = gtype; } else { // Otherwise the requested type must be a subclass of the template pad type - assert!(type_.is_a(>ype)); + assert!(type_.is_a(gtype)); } } diff --git a/gstreamer/src/structure.rs b/gstreamer/src/structure.rs index a983d07f4..206e75f99 100644 --- a/gstreamer/src/structure.rs +++ b/gstreamer/src/structure.rs @@ -769,14 +769,14 @@ mod tests { s.get::("f2"), Err(GetError::from_value_get_error( "f2", - value::GetError::new_type_mismatch(Type::String, Type::I32), + value::GetError::new_type_mismatch(Type::STRING, Type::I32), )) ); assert_eq!( s.get_some::("f3"), Err(GetError::from_value_get_error( "f3", - value::GetError::new_type_mismatch(Type::I32, Type::Bool), + value::GetError::new_type_mismatch(Type::I32, Type::BOOL), )) ); assert_eq!( diff --git a/gstreamer/src/subclass/element.rs b/gstreamer/src/subclass/element.rs index 067a338d7..578b8f4f9 100644 --- a/gstreamer/src/subclass/element.rs +++ b/gstreamer/src/subclass/element.rs @@ -323,7 +323,7 @@ where f: F, ) -> R { unsafe { - assert!(element.get_type().is_a(&T::get_type())); + assert!(element.get_type().is_a(T::get_type())); let ptr: *mut ffi::GstElement = element.as_ptr() as *mut _; let instance = &*(ptr as *mut T::Instance); let imp = instance.get_impl(); @@ -339,7 +339,7 @@ where ) -> R { unsafe { let wrap = parent.as_ref().unwrap().downcast_ref::().unwrap(); - assert!(wrap.get_type().is_a(&T::get_type())); + assert!(wrap.get_type().is_a(T::get_type())); let ptr: *mut ffi::GstElement = wrap.to_glib_none().0; let instance = &*(ptr as *mut T::Instance); let imp = instance.get_impl(); diff --git a/gstreamer/src/tags_serde.rs b/gstreamer/src/tags_serde.rs index 5633bc98d..1d982d4dd 100644 --- a/gstreamer/src/tags_serde.rs +++ b/gstreamer/src/tags_serde.rs @@ -58,7 +58,7 @@ impl<'a> Serialize for TagValuesSer<'a> { for value in tag_iter.deref_mut() { match value.type_() { glib::Type::F64 => ser_some_tag!(value, seq, f64), - glib::Type::String => { + glib::Type::STRING => { // See above comment about `Tag`s with `String` values ser_opt_value!(value, String, |_, value: Option| { seq.serialize_element(&value.expect("String tag ser")) @@ -66,7 +66,7 @@ impl<'a> Serialize for TagValuesSer<'a> { } glib::Type::U32 => ser_some_tag!(value, seq, u32), glib::Type::U64 => ser_some_tag!(value, seq, u64), - glib::Type::Other(type_id) => { + type_id => { if *DATE_OTHER_TYPE_ID == type_id { // See above comment about `Tag`s with `Date` values ser_opt_value!(value, Date, |_, value: Option| { @@ -83,14 +83,10 @@ impl<'a> Serialize for TagValuesSer<'a> { } else { Err(ser::Error::custom(format!( "unimplemented `Tag` serialization for type {}", - glib::Type::Other(type_id), + type_id, ))) } } - type_ => Err(ser::Error::custom(format!( - "unimplemented `Tag` serialization for type {}", - type_ - ))), }?; } seq.end() @@ -181,13 +177,13 @@ impl<'de, 'a> Visitor<'de> for TagValuesVisitor<'a> { loop { let tag_value = match tag_type { glib::Type::F64 => de_some_tag!(self.0, seq, f64), - glib::Type::String => { + glib::Type::STRING => { // See comment above `TagValuesSer` definition about `Tag`s with `String` values de_some_tag!(self.0, seq, String) } glib::Type::U32 => de_some_tag!(self.0, seq, u32), glib::Type::U64 => de_some_tag!(self.0, seq, u64), - glib::Type::Other(type_id) => { + type_id => { if *DATE_OTHER_TYPE_ID == type_id { // See comment above `TagValuesSer` definition about `Tag`s with `Date` values // Need to deserialize as `date_time_serde::Date` new type @@ -200,17 +196,10 @@ impl<'de, 'a> Visitor<'de> for TagValuesVisitor<'a> { } else { return Err(de::Error::custom(format!( "unimplemented deserialization for `Tag` {} with type `{}`", - self.0, - glib::Type::Other(type_id), + self.0, type_id, ))); } } - type_ => { - return Err(de::Error::custom(format!( - "unimplemented deserialization for `Tag` {} with type `{}`", - self.0, type_, - ))); - } }?; match tag_value { diff --git a/gstreamer/src/value_serde.rs b/gstreamer/src/value_serde.rs index a697148e9..ed0e2c60b 100644 --- a/gstreamer/src/value_serde.rs +++ b/gstreamer/src/value_serde.rs @@ -20,27 +20,20 @@ use crate::Sample; use crate::date_time_serde; use crate::value::*; -fn get_other_type_id() -> usize { - match T::static_type() { - glib::Type::Other(type_id) => type_id, - type_ => panic!("Expecting `Other` variant, found `{}`", type_), - } -} - -pub(crate) static ARRAY_OTHER_TYPE_ID: Lazy = Lazy::new(get_other_type_id::); -pub(crate) static BITMASK_OTHER_TYPE_ID: Lazy = Lazy::new(get_other_type_id::); -pub(crate) static DATE_OTHER_TYPE_ID: Lazy = Lazy::new(get_other_type_id::); -pub(crate) static DATE_TIME_OTHER_TYPE_ID: Lazy = Lazy::new(get_other_type_id::); -pub(crate) static FRACTION_OTHER_TYPE_ID: Lazy = Lazy::new(get_other_type_id::); -pub(crate) static FRACTION_RANGE_OTHER_TYPE_ID: Lazy = - Lazy::new(get_other_type_id::); -pub(crate) static INT_RANGE_I32_OTHER_TYPE_ID: Lazy = - Lazy::new(get_other_type_id::>); -pub(crate) static INT_RANGE_I64_OTHER_TYPE_ID: Lazy = - Lazy::new(get_other_type_id::>); -pub(crate) static LIST_OTHER_TYPE_ID: Lazy = Lazy::new(get_other_type_id::); -pub(crate) static SAMPLE_OTHER_TYPE_ID: Lazy = Lazy::new(get_other_type_id::); -pub(crate) static BUFFER_OTHER_TYPE_ID: Lazy = Lazy::new(get_other_type_id::); +pub(crate) static ARRAY_OTHER_TYPE_ID: Lazy = Lazy::new(Array::static_type); +pub(crate) static BITMASK_OTHER_TYPE_ID: Lazy = Lazy::new(Bitmask::static_type); +pub(crate) static DATE_OTHER_TYPE_ID: Lazy = Lazy::new(Date::static_type); +pub(crate) static DATE_TIME_OTHER_TYPE_ID: Lazy = Lazy::new(DateTime::static_type); +pub(crate) static FRACTION_OTHER_TYPE_ID: Lazy = Lazy::new(Fraction::static_type); +pub(crate) static FRACTION_RANGE_OTHER_TYPE_ID: Lazy = + Lazy::new(FractionRange::static_type); +pub(crate) static INT_RANGE_I32_OTHER_TYPE_ID: Lazy = + Lazy::new(IntRange::::static_type); +pub(crate) static INT_RANGE_I64_OTHER_TYPE_ID: Lazy = + Lazy::new(IntRange::::static_type); +pub(crate) static LIST_OTHER_TYPE_ID: Lazy = Lazy::new(List::static_type); +pub(crate) static SAMPLE_OTHER_TYPE_ID: Lazy = Lazy::new(Sample::static_type); +pub(crate) static BUFFER_OTHER_TYPE_ID: Lazy = Lazy::new(Buffer::static_type); impl<'a> Serialize for Fraction { fn serialize(&self, serializer: S) -> Result { @@ -77,15 +70,15 @@ macro_rules! ser_value ( match $value.type_() { glib::Type::I8 => ser_some_value!($value, i8, $ser_closure), glib::Type::U8 => ser_some_value!($value, u8, $ser_closure), - glib::Type::Bool => ser_some_value!($value, bool, $ser_closure), + glib::Type::BOOL => ser_some_value!($value, bool, $ser_closure), glib::Type::I32 => ser_some_value!($value, i32, $ser_closure), glib::Type::U32 => ser_some_value!($value, u32, $ser_closure), glib::Type::I64 => ser_some_value!($value, i64, $ser_closure), glib::Type::U64 => ser_some_value!($value, u64, $ser_closure), glib::Type::F32 => ser_some_value!($value, f32, $ser_closure), glib::Type::F64 => ser_some_value!($value, f64, $ser_closure), - glib::Type::String => ser_opt_value!($value, String, $ser_closure), - glib::Type::Other(type_id) => { + glib::Type::STRING => ser_opt_value!($value, String, $ser_closure), + type_id => { if *ARRAY_OTHER_TYPE_ID == type_id { ser_some_value!($value, Array, $ser_closure) } else if *BITMASK_OTHER_TYPE_ID == type_id { @@ -116,19 +109,12 @@ macro_rules! ser_value ( Err( ser::Error::custom( format!("unimplemented `Value` serialization for type {}", - glib::Type::Other(type_id), + type_id, ) ) ) } } - type_ => { - Err( - ser::Error::custom( - format!("unimplemented `Value` serialization for type {}", type_) - ) - ) - } } ); );