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: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1337>
This commit is contained in:
Sebastian Dröge 2023-10-26 13:40:12 +03:00
parent 8027269c7b
commit 470b727252

View file

@ -17,27 +17,6 @@ pub unsafe trait MetaAPI: Sync + Send + Sized {
} }
pub trait MetaAPIExt: MetaAPI { 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] #[inline]
unsafe fn from_ptr(buffer: &BufferRef, ptr: *const Self::GstType) -> MetaRef<Self> { unsafe fn from_ptr(buffer: &BufferRef, ptr: *const Self::GstType) -> MetaRef<Self> {
debug_assert!(!ptr.is_null()); 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] #[inline]
pub fn upcast_ref(&self) -> &MetaRef<'a, Meta> { pub fn upcast_ref(&self) -> &MetaRef<'a, Meta> {
unsafe { &*(self as *const MetaRef<'a, T> as *const 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] #[inline]
pub fn upcast_ref(&self) -> &MetaRef<'a, Meta> { pub fn upcast_ref(&self) -> &MetaRef<'a, Meta> {
unsafe { &*(self as *const MetaRefMut<'a, T, U> as *const 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("video")));
assert!(metas[0].has_tag(glib::Quark::from_str("memory-reference"))); assert!(metas[0].has_tag(glib::Quark::from_str("memory-reference")));
assert_eq!(metas[0].tags().len(), 1); assert_eq!(metas[0].tags().len(), 1);
assert_eq!(metas[0].tags(), metas[0].upcast_ref().tags());
} }
{ {