From 9d792809296edd64121f30603f3a97c50d80293c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Wed, 23 Jan 2019 15:52:56 +0200 Subject: [PATCH] Add some more functions for generically handling tags --- gstreamer/src/lib.rs | 5 +++- gstreamer/src/tags.rs | 53 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/gstreamer/src/lib.rs b/gstreamer/src/lib.rs index 69b9fcd56..3588610b6 100644 --- a/gstreamer/src/lib.rs +++ b/gstreamer/src/lib.rs @@ -107,7 +107,10 @@ pub use caps_features::{ mod caps_features_serde; pub mod tags; -pub use tags::{Tag, TagList, TagListRef}; +pub use tags::{ + tag_exists, tag_get_description, tag_get_flag, tag_get_nick, tag_get_type, Tag, TagList, + TagListRef, +}; #[cfg(feature = "ser_de")] mod tags_serde; diff --git a/gstreamer/src/tags.rs b/gstreamer/src/tags.rs index b59519578..3a5844228 100644 --- a/gstreamer/src/tags.rs +++ b/gstreamer/src/tags.rs @@ -767,6 +767,42 @@ impl<'a> DoubleEndedIterator for Iter<'a> { impl<'a> ExactSizeIterator for Iter<'a> {} +pub fn tag_exists(name: &str) -> bool { + unsafe { from_glib(ffi::gst_tag_exists(name.to_glib_none().0)) } +} + +pub fn tag_get_type(name: &str) -> glib::Type { + unsafe { from_glib(ffi::gst_tag_get_type(name.to_glib_none().0)) } +} + +pub fn tag_get_nick(name: &str) -> Option<&'static str> { + unsafe { + let ptr = ffi::gst_tag_get_nick(name.to_glib_none().0); + + if ptr.is_null() { + None + } else { + Some(CStr::from_ptr(ptr).to_str().unwrap()) + } + } +} + +pub fn tag_get_description(name: &str) -> Option<&'static str> { + unsafe { + let ptr = ffi::gst_tag_get_description(name.to_glib_none().0); + + if ptr.is_null() { + None + } else { + Some(CStr::from_ptr(ptr).to_str().unwrap()) + } + } +} + +pub fn tag_get_flag(name: &str) -> ::TagFlag { + unsafe { from_glib(ffi::gst_tag_get_flag(name.to_glib_none().0)) } +} + pub trait CustomTag<'a>: Tag<'a> { const FLAG: ::TagFlag; const NICK: &'static str; @@ -778,6 +814,8 @@ pub trait CustomTag<'a>: Tag<'a> { } pub fn register CustomTag<'a>>() { + assert!(!tag_exists(T::tag_name())); + unsafe extern "C" fn merge_func_trampoline CustomTag<'a>>( dest: *mut gobject_ffi::GValue, src: *const gobject_ffi::GValue, @@ -997,6 +1035,21 @@ mod tests { register::(); + assert!(tag_exists(MyCustomTag::tag_name())); + assert_eq!( + tag_get_type(MyCustomTag::tag_name()), + ::TagType::static_type() + ); + assert_eq!( + tag_get_nick(MyCustomTag::tag_name()), + Some(MyCustomTag::NICK) + ); + assert_eq!( + tag_get_description(MyCustomTag::tag_name()), + Some(MyCustomTag::DESCRIPTION) + ); + assert_eq!(tag_get_flag(MyCustomTag::tag_name()), MyCustomTag::FLAG); + let mut tags = TagList::new(); { let tags = tags.get_mut().unwrap();