From f27a2bddd6e3fd799101216b284439e3e56c7ce8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Sat, 6 Nov 2021 19:37:13 +0200 Subject: [PATCH] gstreamer: Add bindings for DebugCategory::all() to list all available debug categories --- gstreamer/Gir.toml | 2 ++ gstreamer/src/log.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/gstreamer/Gir.toml b/gstreamer/Gir.toml index 23293fe6d..dde28441a 100644 --- a/gstreamer/Gir.toml +++ b/gstreamer/Gir.toml @@ -65,6 +65,8 @@ manual = [ "GObject.Value", "Gst.AllocationParams", "Gst.CapsFeatures", + "Gst.DebugCategory", + "Gst.DebugMessage", "Gst.Segment", "Gst.StaticCaps", "Gst.StaticPadTemplate", diff --git a/gstreamer/src/log.rs b/gstreamer/src/log.rs index 4eac4ae08..cb0099692 100644 --- a/gstreamer/src/log.rs +++ b/gstreamer/src/log.rs @@ -44,6 +44,9 @@ impl DebugMessage { pub struct DebugCategory(Option>); impl DebugCategory { + #[doc(alias = "gst_debug_category_new")] + #[doc(alias = "GST_DEBUG_CATEGORY")] + #[doc(alias = "GST_DEBUG_CATEGORY_INIT")] pub fn new( name: &str, color: crate::DebugColorFlags, @@ -70,6 +73,7 @@ impl DebugCategory { } } + #[doc(alias = "gst_debug_get_category")] pub fn get(name: &str) -> Option { skip_assert_initialized!(); unsafe { @@ -188,11 +192,43 @@ impl DebugCategory { ); } } + + #[doc(alias = "get_all_categories")] + #[doc(alias = "gst_debug_get_all_categories")] + pub fn all_categories() -> DebugCategoryList { + unsafe { DebugCategoryList(ptr::NonNull::new(ffi::gst_debug_get_all_categories())) } + } } unsafe impl Sync for DebugCategory {} unsafe impl Send for DebugCategory {} +// checker-ignore-item +pub struct DebugCategoryList(Option>); + +unsafe impl Sync for DebugCategoryList {} +unsafe impl Send for DebugCategoryList {} + +impl Iterator for DebugCategoryList { + type Item = DebugCategory; + + fn next(&mut self) -> Option { + match self.0 { + None => None, + Some(cur) => unsafe { + let next = cur.as_ref().next; + self.0 = ptr::NonNull::new(next); + let cat = DebugCategory(Some( + ptr::NonNull::new(cur.as_ref().data as *mut ffi::GstDebugCategory).unwrap(), + )); + glib::ffi::g_slist_free_1(cur.as_ptr()); + + Some(cat) + }, + } + } +} + impl fmt::Debug for DebugCategory { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_tuple("DebugCategory").field(&self.name()).finish() @@ -519,6 +555,13 @@ mod tests { assert_eq!(perf_cat.name(), CAT_PERFORMANCE.name()); } + #[test] + fn all() { + crate::init().unwrap(); + + assert!(DebugCategory::all_categories().any(|c| c.name() == "GST_PERFORMANCE")); + } + #[test] fn new_and_log() { crate::init().unwrap();