From eb6d3a6c6c63f00b362c25fdc9a9ce548098ef2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Fri, 3 Nov 2023 11:49:41 +0200 Subject: [PATCH] gstreamer: meta: Add `as_meta_ref()` to `MetaRefMut` This reduces code duplication between `MetaRef` and `MetaRefMut`. Part-of: --- gstreamer/src/meta.rs | 43 +++++++++++++++---------------------------- 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/gstreamer/src/meta.rs b/gstreamer/src/meta.rs index 75a78e451..7f71487af 100644 --- a/gstreamer/src/meta.rs +++ b/gstreamer/src/meta.rs @@ -255,28 +255,17 @@ impl<'a, T, U> MetaRefMut<'a, T, U> { #[doc(alias = "get_api")] #[inline] pub fn api(&self) -> glib::Type { - unsafe { - let meta = self.meta as *const _ as *const ffi::GstMeta; - let info = (*meta).info; - glib::Type::from_glib((*info).api) - } + self.as_meta_ref().api() } #[inline] pub fn flags(&self) -> crate::MetaFlags { - unsafe { - let meta = self.meta as *const _ as *const ffi::GstMeta; - from_glib((*meta).flags) - } + self.as_meta_ref().flags() } #[inline] pub fn type_(&self) -> glib::Type { - unsafe { - let meta = self.meta as *const _ as *const ffi::GstMeta; - let info = (*meta).info; - glib::Type::from_glib((*info).type_) - } + self.as_meta_ref().type_() } #[cfg(feature = "v1_16")] @@ -284,30 +273,20 @@ impl<'a, T, U> MetaRefMut<'a, T, U> { #[doc(alias = "get_seqnum")] #[doc(alias = "gst_meta_get_seqnum")] #[inline] - pub fn seqnum(&self) -> u64 { - unsafe { - let meta = self.meta as *const _ as *const ffi::GstMeta; - ffi::gst_meta_get_seqnum(meta) - } + pub fn seqnum(&self) -> MetaSeqnum { + self.as_meta_ref().seqnum() } #[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(), - )) - } + self.as_meta_ref().has_tag(tag) } #[inline] #[doc(alias = "gst_meta_api_type_get_tags")] pub fn tags<'b>(&self) -> &'b [glib::GStringPtr] { - unsafe { - glib::StrV::from_glib_borrow(ffi::gst_meta_api_type_get_tags(self.api().into_glib())) - } + self.as_meta_ref().tags() } #[inline] @@ -320,6 +299,14 @@ impl<'a, T, U> MetaRefMut<'a, T, U> { unsafe { &mut *(self as *mut MetaRefMut<'a, T, U> as *mut MetaRefMut<'a, Meta, U>) } } + #[inline] + pub fn as_meta_ref(&self) -> MetaRef { + MetaRef { + meta: self.meta, + buffer: self.buffer, + } + } + #[inline] pub fn as_ptr(&self) -> *const T::GstType where