mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-25 11:01:10 +00:00
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:
parent
22796cee0c
commit
b10f395c2c
5 changed files with 74 additions and 18 deletions
24
Cargo.lock
generated
24
Cargo.lock
generated
|
@ -170,7 +170,7 @@ checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223"
|
|||
[[package]]
|
||||
name = "cairo-rs"
|
||||
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 = [
|
||||
"bitflags 2.4.2",
|
||||
"cairo-sys-rs",
|
||||
|
@ -182,7 +182,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "cairo-sys-rs"
|
||||
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 = [
|
||||
"glib-sys",
|
||||
"libc",
|
||||
|
@ -678,7 +678,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "gio"
|
||||
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 = [
|
||||
"futures-channel",
|
||||
"futures-core",
|
||||
|
@ -695,7 +695,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "gio-sys"
|
||||
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 = [
|
||||
"glib-sys",
|
||||
"gobject-sys",
|
||||
|
@ -724,7 +724,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "glib"
|
||||
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 = [
|
||||
"bitflags 2.4.2",
|
||||
"futures-channel",
|
||||
|
@ -745,7 +745,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "glib-macros"
|
||||
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 = [
|
||||
"heck",
|
||||
"proc-macro-crate",
|
||||
|
@ -757,7 +757,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "glib-sys"
|
||||
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 = [
|
||||
"libc",
|
||||
"system-deps",
|
||||
|
@ -820,7 +820,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "gobject-sys"
|
||||
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 = [
|
||||
"glib-sys",
|
||||
"libc",
|
||||
|
@ -1892,7 +1892,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "pango"
|
||||
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 = [
|
||||
"gio",
|
||||
"glib",
|
||||
|
@ -1903,7 +1903,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "pango-sys"
|
||||
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 = [
|
||||
"glib-sys",
|
||||
"gobject-sys",
|
||||
|
@ -1914,7 +1914,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "pangocairo"
|
||||
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 = [
|
||||
"cairo-rs",
|
||||
"glib",
|
||||
|
@ -1926,7 +1926,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "pangocairo-sys"
|
||||
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 = [
|
||||
"cairo-sys-rs",
|
||||
"glib-sys",
|
||||
|
|
|
@ -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)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
@ -319,6 +327,8 @@ mod tests {
|
|||
let cmeta = buffer.meta::<AudioClippingMeta>().unwrap();
|
||||
assert_eq!(cmeta.start().try_into(), Ok(Some(start)));
|
||||
assert_eq!(cmeta.end().try_into(), Ok(Some(stop)));
|
||||
|
||||
assert!(cmeta.has_tag::<tags::Audio>());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
@ -1187,6 +1194,10 @@ mod tests {
|
|||
assert_eq!(meta.n_planes(), 1);
|
||||
assert_eq!(meta.offset(), &[0]);
|
||||
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>());
|
||||
}
|
||||
|
||||
{
|
||||
|
|
|
@ -109,6 +109,7 @@ pub use crate::tags::{
|
|||
#[cfg(feature = "serde")]
|
||||
mod tags_serde;
|
||||
|
||||
#[macro_use]
|
||||
pub mod meta;
|
||||
#[cfg(feature = "v1_16")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
|
||||
|
@ -339,7 +340,7 @@ pub mod prelude {
|
|||
gobject::GObjectExtManualGst,
|
||||
memory::MemoryType,
|
||||
message::MessageErrorDomain,
|
||||
meta::{MetaAPI, MetaAPIExt},
|
||||
meta::{MetaAPI, MetaAPIExt, MetaTag},
|
||||
miniobject::IsMiniObject,
|
||||
object::GstObjectExtManual,
|
||||
pad::PadExtManual,
|
||||
|
|
|
@ -206,7 +206,12 @@ impl<'a, T> MetaRef<'a, T> {
|
|||
|
||||
#[inline]
|
||||
#[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 {
|
||||
from_glib(ffi::gst_meta_api_type_has_tag(
|
||||
self.api().into_glib(),
|
||||
|
@ -457,8 +462,13 @@ 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 {
|
||||
self.as_meta_ref().has_tag(tag)
|
||||
pub fn has_tag<MT: MetaTag>(&self) -> bool {
|
||||
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]
|
||||
|
@ -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)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
@ -1086,8 +1120,8 @@ mod tests {
|
|||
.collect::<Vec<_>>();
|
||||
assert_eq!(metas.len(), 1);
|
||||
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(glib::Quark::from_str("memory-reference")));
|
||||
assert!(!metas[0].has_tag_by_quark(glib::Quark::from_str("video")));
|
||||
assert!(metas[0].has_tag::<tags::MemoryReference>());
|
||||
assert_eq!(metas[0].tags().len(), 1);
|
||||
|
||||
assert_eq!(metas[0].tags(), metas[0].upcast_ref().tags());
|
||||
|
|
Loading…
Reference in a new issue