meta: Add modules containing the tags

Export the tags as both quark or string

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1387>
This commit is contained in:
Olivier Crête 2024-02-08 18:07:06 -05:00 committed by GStreamer Marge Bot
parent 22796cee0c
commit b10f395c2c
5 changed files with 74 additions and 18 deletions

24
Cargo.lock generated
View file

@ -170,7 +170,7 @@ checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223"
[[package]] [[package]]
name = "cairo-rs" name = "cairo-rs"
version = "0.20.0" version = "0.20.0"
source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#8e574d3a8e445ff9184b00bd490e6f403cd5aa9c" source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#03c5a850037c582a0a5fca07f8e1cd1cf924c4fc"
dependencies = [ dependencies = [
"bitflags 2.4.2", "bitflags 2.4.2",
"cairo-sys-rs", "cairo-sys-rs",
@ -182,7 +182,7 @@ dependencies = [
[[package]] [[package]]
name = "cairo-sys-rs" name = "cairo-sys-rs"
version = "0.20.0" version = "0.20.0"
source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#8e574d3a8e445ff9184b00bd490e6f403cd5aa9c" source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#03c5a850037c582a0a5fca07f8e1cd1cf924c4fc"
dependencies = [ dependencies = [
"glib-sys", "glib-sys",
"libc", "libc",
@ -678,7 +678,7 @@ dependencies = [
[[package]] [[package]]
name = "gio" name = "gio"
version = "0.20.0" version = "0.20.0"
source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#8e574d3a8e445ff9184b00bd490e6f403cd5aa9c" source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#03c5a850037c582a0a5fca07f8e1cd1cf924c4fc"
dependencies = [ dependencies = [
"futures-channel", "futures-channel",
"futures-core", "futures-core",
@ -695,7 +695,7 @@ dependencies = [
[[package]] [[package]]
name = "gio-sys" name = "gio-sys"
version = "0.20.0" version = "0.20.0"
source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#8e574d3a8e445ff9184b00bd490e6f403cd5aa9c" source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#03c5a850037c582a0a5fca07f8e1cd1cf924c4fc"
dependencies = [ dependencies = [
"glib-sys", "glib-sys",
"gobject-sys", "gobject-sys",
@ -724,7 +724,7 @@ dependencies = [
[[package]] [[package]]
name = "glib" name = "glib"
version = "0.20.0" version = "0.20.0"
source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#8e574d3a8e445ff9184b00bd490e6f403cd5aa9c" source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#03c5a850037c582a0a5fca07f8e1cd1cf924c4fc"
dependencies = [ dependencies = [
"bitflags 2.4.2", "bitflags 2.4.2",
"futures-channel", "futures-channel",
@ -745,7 +745,7 @@ dependencies = [
[[package]] [[package]]
name = "glib-macros" name = "glib-macros"
version = "0.20.0" version = "0.20.0"
source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#8e574d3a8e445ff9184b00bd490e6f403cd5aa9c" source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#03c5a850037c582a0a5fca07f8e1cd1cf924c4fc"
dependencies = [ dependencies = [
"heck", "heck",
"proc-macro-crate", "proc-macro-crate",
@ -757,7 +757,7 @@ dependencies = [
[[package]] [[package]]
name = "glib-sys" name = "glib-sys"
version = "0.20.0" version = "0.20.0"
source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#8e574d3a8e445ff9184b00bd490e6f403cd5aa9c" source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#03c5a850037c582a0a5fca07f8e1cd1cf924c4fc"
dependencies = [ dependencies = [
"libc", "libc",
"system-deps", "system-deps",
@ -820,7 +820,7 @@ dependencies = [
[[package]] [[package]]
name = "gobject-sys" name = "gobject-sys"
version = "0.20.0" version = "0.20.0"
source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#8e574d3a8e445ff9184b00bd490e6f403cd5aa9c" source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#03c5a850037c582a0a5fca07f8e1cd1cf924c4fc"
dependencies = [ dependencies = [
"glib-sys", "glib-sys",
"libc", "libc",
@ -1892,7 +1892,7 @@ dependencies = [
[[package]] [[package]]
name = "pango" name = "pango"
version = "0.20.0" version = "0.20.0"
source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#8e574d3a8e445ff9184b00bd490e6f403cd5aa9c" source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#03c5a850037c582a0a5fca07f8e1cd1cf924c4fc"
dependencies = [ dependencies = [
"gio", "gio",
"glib", "glib",
@ -1903,7 +1903,7 @@ dependencies = [
[[package]] [[package]]
name = "pango-sys" name = "pango-sys"
version = "0.20.0" version = "0.20.0"
source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#8e574d3a8e445ff9184b00bd490e6f403cd5aa9c" source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#03c5a850037c582a0a5fca07f8e1cd1cf924c4fc"
dependencies = [ dependencies = [
"glib-sys", "glib-sys",
"gobject-sys", "gobject-sys",
@ -1914,7 +1914,7 @@ dependencies = [
[[package]] [[package]]
name = "pangocairo" name = "pangocairo"
version = "0.20.0" version = "0.20.0"
source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#8e574d3a8e445ff9184b00bd490e6f403cd5aa9c" source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#03c5a850037c582a0a5fca07f8e1cd1cf924c4fc"
dependencies = [ dependencies = [
"cairo-rs", "cairo-rs",
"glib", "glib",
@ -1926,7 +1926,7 @@ dependencies = [
[[package]] [[package]]
name = "pangocairo-sys" name = "pangocairo-sys"
version = "0.20.0" version = "0.20.0"
source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#8e574d3a8e445ff9184b00bd490e6f403cd5aa9c" source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#03c5a850037c582a0a5fca07f8e1cd1cf924c4fc"
dependencies = [ dependencies = [
"cairo-sys-rs", "cairo-sys-rs",
"glib-sys", "glib-sys",

View file

@ -294,6 +294,14 @@ impl fmt::Debug for AudioLevelMeta {
} }
} }
pub mod tags {
gst::impl_meta_tag!(Audio, GST_META_TAG_AUDIO_STR);
gst::impl_meta_tag!(Channels, GST_META_TAG_AUDIO_CHANNELS_STR);
gst::impl_meta_tag!(Rate, GST_META_TAG_AUDIO_RATE_STR);
#[cfg(feature = "v1_24")]
gst::impl_meta_tag!(DSDPlaneOffsets, GST_META_TAG_DSD_PLANE_OFFSETS_STR);
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
@ -319,6 +327,8 @@ mod tests {
let cmeta = buffer.meta::<AudioClippingMeta>().unwrap(); let cmeta = buffer.meta::<AudioClippingMeta>().unwrap();
assert_eq!(cmeta.start().try_into(), Ok(Some(start))); assert_eq!(cmeta.start().try_into(), Ok(Some(start)));
assert_eq!(cmeta.end().try_into(), Ok(Some(stop))); assert_eq!(cmeta.end().try_into(), Ok(Some(stop)));
assert!(cmeta.has_tag::<tags::Audio>());
} }
} }

View file

@ -1161,6 +1161,13 @@ impl fmt::Debug for AncillaryMeta {
} }
} }
pub mod tags {
gst::impl_meta_tag!(Video, GST_META_TAG_VIDEO_STR);
gst::impl_meta_tag!(Size, GST_META_TAG_VIDEO_SIZE_STR);
gst::impl_meta_tag!(Orientation, GST_META_TAG_VIDEO_ORIENTATION_STR);
gst::impl_meta_tag!(Colorspace, GST_META_TAG_VIDEO_COLORSPACE_STR);
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
@ -1187,6 +1194,10 @@ mod tests {
assert_eq!(meta.n_planes(), 1); assert_eq!(meta.n_planes(), 1);
assert_eq!(meta.offset(), &[0]); assert_eq!(meta.offset(), &[0]);
assert_eq!(meta.stride(), &[320 * 4]); assert_eq!(meta.stride(), &[320 * 4]);
assert!(meta.has_tag::<gst::meta::tags::Memory>());
assert!(meta.has_tag::<tags::Video>());
assert!(meta.has_tag::<tags::Colorspace>());
assert!(meta.has_tag::<tags::Size>());
} }
{ {

View file

@ -109,6 +109,7 @@ pub use crate::tags::{
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
mod tags_serde; mod tags_serde;
#[macro_use]
pub mod meta; pub mod meta;
#[cfg(feature = "v1_16")] #[cfg(feature = "v1_16")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))] #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
@ -339,7 +340,7 @@ pub mod prelude {
gobject::GObjectExtManualGst, gobject::GObjectExtManualGst,
memory::MemoryType, memory::MemoryType,
message::MessageErrorDomain, message::MessageErrorDomain,
meta::{MetaAPI, MetaAPIExt}, meta::{MetaAPI, MetaAPIExt, MetaTag},
miniobject::IsMiniObject, miniobject::IsMiniObject,
object::GstObjectExtManual, object::GstObjectExtManual,
pad::PadExtManual, pad::PadExtManual,

View file

@ -206,7 +206,12 @@ impl<'a, T> MetaRef<'a, T> {
#[inline] #[inline]
#[doc(alias = "gst_meta_api_type_has_tag")] #[doc(alias = "gst_meta_api_type_has_tag")]
pub fn has_tag(&self, tag: glib::Quark) -> bool { pub fn has_tag<MT: MetaTag>(&self) -> bool {
self.has_tag_by_quark(MT::quark())
}
#[inline]
pub fn has_tag_by_quark(&self, tag: glib::Quark) -> bool {
unsafe { unsafe {
from_glib(ffi::gst_meta_api_type_has_tag( from_glib(ffi::gst_meta_api_type_has_tag(
self.api().into_glib(), self.api().into_glib(),
@ -457,8 +462,13 @@ impl<'a, T, U> MetaRefMut<'a, T, U> {
#[inline] #[inline]
#[doc(alias = "gst_meta_api_type_has_tag")] #[doc(alias = "gst_meta_api_type_has_tag")]
pub fn has_tag(&self, tag: glib::Quark) -> bool { pub fn has_tag<MT: MetaTag>(&self) -> bool {
self.as_meta_ref().has_tag(tag) self.as_meta_ref().has_tag::<MT>()
}
#[inline]
pub fn has_tag_by_quark(&self, tag: glib::Quark) -> bool {
self.as_meta_ref().has_tag_by_quark(tag)
} }
#[inline] #[inline]
@ -1050,6 +1060,30 @@ impl CustomMeta {
} }
} }
pub trait MetaTag {
const TAG_NAME: &'static glib::GStr;
fn quark() -> glib::Quark;
}
#[macro_export]
macro_rules! impl_meta_tag(
($name:ident, $gst_tag:ident) => {
pub enum $name {}
impl $crate::meta::MetaTag for $name {
const TAG_NAME: &'static glib::GStr = unsafe { glib::GStr::from_utf8_with_nul_unchecked(ffi::$gst_tag) };
fn quark() -> glib::Quark {
static QUARK: std::sync::OnceLock<glib::Quark> = std::sync::OnceLock::new();
*QUARK.get_or_init(|| glib::Quark::from_static_str(Self::TAG_NAME))
}
}
};
);
pub mod tags {
impl_meta_tag!(Memory, GST_META_TAG_MEMORY_STR);
impl_meta_tag!(MemoryReference, GST_META_TAG_MEMORY_REFERENCE_STR);
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
@ -1086,8 +1120,8 @@ mod tests {
.collect::<Vec<_>>(); .collect::<Vec<_>>();
assert_eq!(metas.len(), 1); assert_eq!(metas.len(), 1);
assert_eq!(metas[0].parent().as_ptr(), parent.as_ptr()); assert_eq!(metas[0].parent().as_ptr(), parent.as_ptr());
assert!(!metas[0].has_tag(glib::Quark::from_str("video"))); assert!(!metas[0].has_tag_by_quark(glib::Quark::from_str("video")));
assert!(metas[0].has_tag(glib::Quark::from_str("memory-reference"))); assert!(metas[0].has_tag::<tags::MemoryReference>());
assert_eq!(metas[0].tags().len(), 1); assert_eq!(metas[0].tags().len(), 1);
assert_eq!(metas[0].tags(), metas[0].upcast_ref().tags()); assert_eq!(metas[0].tags(), metas[0].upcast_ref().tags());