From bd9b1d6e382c8bac4476668613ba677081af72e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Thu, 26 Oct 2023 13:40:12 +0300 Subject: [PATCH] gstreamer: meta: Move `has_tag()` and `tags()` getters to `MetaRef` On `MetaAPI` only the static meta API type is known and based on that it's not possible to work with the tags of a specific meta instance's API. As the methods take a `&self` anyway they would be expected to check the value at hand instead. Part-of: --- gstreamer/src/meta.rs | 61 ++++++++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 21 deletions(-) diff --git a/gstreamer/src/meta.rs b/gstreamer/src/meta.rs index ebf774bea..d6e19daec 100644 --- a/gstreamer/src/meta.rs +++ b/gstreamer/src/meta.rs @@ -17,27 +17,6 @@ pub unsafe trait MetaAPI: Sync + Send + Sized { } pub trait MetaAPIExt: MetaAPI { - #[inline] - #[doc(alias = "gst_meta_api_type_has_tag")] - fn has_tag(&self, tag: glib::Quark) -> bool { - unsafe { - from_glib(ffi::gst_meta_api_type_has_tag( - Self::meta_api().into_glib(), - tag.into_glib(), - )) - } - } - - #[inline] - #[doc(alias = "gst_meta_api_type_get_tags")] - fn tags(&self) -> &[glib::GStringPtr] { - unsafe { - glib::StrV::from_glib_borrow(ffi::gst_meta_api_type_get_tags( - Self::meta_api().into_glib(), - )) - } - } - #[inline] unsafe fn from_ptr(buffer: &BufferRef, ptr: *const Self::GstType) -> MetaRef { debug_assert!(!ptr.is_null()); @@ -212,6 +191,25 @@ impl<'a, T> MetaRef<'a, T> { } } + #[inline] + #[doc(alias = "gst_meta_api_type_has_tag")] + pub fn has_tag(&self, tag: glib::Quark) -> bool { + unsafe { + from_glib(ffi::gst_meta_api_type_has_tag( + self.api().into_glib(), + tag.into_glib(), + )) + } + } + + #[inline] + #[doc(alias = "gst_meta_api_type_get_tags")] + pub fn tags(&self) -> &[glib::GStringPtr] { + unsafe { + glib::StrV::from_glib_borrow(ffi::gst_meta_api_type_get_tags(self.api().into_glib())) + } + } + #[inline] pub fn upcast_ref(&self) -> &MetaRef<'a, Meta> { unsafe { &*(self as *const MetaRef<'a, T> as *const MetaRef<'a, Meta>) } @@ -293,6 +291,25 @@ impl<'a, T, U> MetaRefMut<'a, T, U> { } } + #[inline] + #[doc(alias = "gst_meta_api_type_has_tag")] + pub fn has_tag(&self, tag: glib::Quark) -> bool { + unsafe { + from_glib(ffi::gst_meta_api_type_has_tag( + self.api().into_glib(), + tag.into_glib(), + )) + } + } + + #[inline] + #[doc(alias = "gst_meta_api_type_get_tags")] + pub fn tags(&self) -> &[glib::GStringPtr] { + unsafe { + glib::StrV::from_glib_borrow(ffi::gst_meta_api_type_get_tags(self.api().into_glib())) + } + } + #[inline] pub fn upcast_ref(&self) -> &MetaRef<'a, Meta> { unsafe { &*(self as *const MetaRefMut<'a, T, U> as *const MetaRef<'a, Meta>) } @@ -824,6 +841,8 @@ mod tests { assert!(!metas[0].has_tag(glib::Quark::from_str("video"))); assert!(metas[0].has_tag(glib::Quark::from_str("memory-reference"))); assert_eq!(metas[0].tags().len(), 1); + + assert_eq!(metas[0].tags(), metas[0].upcast_ref().tags()); } {