From 5b7b39c448da746364b82ea59f634ff281153945 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Mon, 26 Apr 2021 10:54:06 +0300 Subject: [PATCH] gstreamer: Add CapsFeatures API using glib::Quarks instead of strings The same API for Structures already exists. Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/141 --- gstreamer/src/caps_features.rs | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/gstreamer/src/caps_features.rs b/gstreamer/src/caps_features.rs index a4d471c39..0b8fcabf5 100644 --- a/gstreamer/src/caps_features.rs +++ b/gstreamer/src/caps_features.rs @@ -29,6 +29,17 @@ impl CapsFeatures { f } + pub fn from_quarks(features: &[glib::Quark]) -> Self { + assert_initialized_main_thread!(); + let mut f = Self::new_empty(); + + for feature in features { + f.add_from_quark(*feature); + } + + f + } + pub fn new_empty() -> Self { assert_initialized_main_thread!(); unsafe { @@ -306,6 +317,15 @@ impl CapsFeaturesRef { } } + pub fn contains_quark(&self, feature: glib::Quark) -> bool { + unsafe { + from_glib(ffi::gst_caps_features_contains_id( + self.as_ptr(), + feature.to_glib(), + )) + } + } + pub fn size(&self) -> u32 { unsafe { ffi::gst_caps_features_get_size(self.as_ptr()) } } @@ -325,6 +345,17 @@ impl CapsFeaturesRef { } } + pub fn nth_quark(&self, idx: u32) -> Option { + if idx >= self.size() { + return None; + } + + unsafe { + let feature = ffi::gst_caps_features_get_nth_id(self.as_ptr(), idx); + Some(from_glib(feature)) + } + } + pub fn add(&mut self, feature: &str) { unsafe { ffi::gst_caps_features_add(self.as_mut_ptr(), feature.to_glib_none().0) } } @@ -333,6 +364,14 @@ impl CapsFeaturesRef { unsafe { ffi::gst_caps_features_remove(self.as_mut_ptr(), feature.to_glib_none().0) } } + pub fn add_from_quark(&mut self, feature: glib::Quark) { + unsafe { ffi::gst_caps_features_add_id(self.as_mut_ptr(), feature.to_glib()) } + } + + pub fn remove_by_quark(&mut self, feature: glib::Quark) { + unsafe { ffi::gst_caps_features_remove_id(self.as_mut_ptr(), feature.to_glib()) } + } + pub fn iter(&self) -> Iter { Iter::new(self) }