From aea43c428c33894ff35502ed6c9802170414bb4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 14 Apr 2020 20:29:43 +0300 Subject: [PATCH] gstreamer: Add Stream::debug() and StreamCollection::debug() These provide more helpful debug output than just the pointer when printing. --- gstreamer/src/lib.rs | 2 +- gstreamer/src/stream.rs | 20 ++++++++++++++++++- gstreamer/src/stream_collection.rs | 31 ++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/gstreamer/src/lib.rs b/gstreamer/src/lib.rs index c61028850..694ed5a7e 100644 --- a/gstreamer/src/lib.rs +++ b/gstreamer/src/lib.rs @@ -249,7 +249,7 @@ pub use tag_setter::TagSetterExtManual; mod plugin; pub use plugin::GstPluginExtManual; #[cfg(any(feature = "v1_10", feature = "dox"))] -mod stream; +pub mod stream; #[cfg(any(feature = "v1_10", feature = "dox"))] pub mod stream_collection; diff --git a/gstreamer/src/stream.rs b/gstreamer/src/stream.rs index efaaeac1d..79caa4f71 100644 --- a/gstreamer/src/stream.rs +++ b/gstreamer/src/stream.rs @@ -8,13 +8,13 @@ use glib::translate::*; use gst_sys; +use std::fmt; use Caps; use Stream; use StreamFlags; use StreamType; impl Stream { - #[cfg(any(feature = "v1_10", feature = "dox"))] pub fn new( stream_id: Option<&str>, caps: Option<&Caps>, @@ -47,4 +47,22 @@ impl Stream { } } } + + pub fn debug(&self) -> Debug { + Debug(self) + } +} + +pub struct Debug<'a>(&'a Stream); + +impl<'a> fmt::Debug for Debug<'a> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Stream") + .field("stream_id", &self.0.get_stream_id()) + .field("stream_type", &self.0.get_stream_type()) + .field("stream_flags", &self.0.get_stream_flags()) + .field("caps", &self.0.get_caps()) + .field("tags", &self.0.get_tags()) + .finish() + } } diff --git a/gstreamer/src/stream_collection.rs b/gstreamer/src/stream_collection.rs index 1ae746e00..7607556ff 100644 --- a/gstreamer/src/stream_collection.rs +++ b/gstreamer/src/stream_collection.rs @@ -8,6 +8,7 @@ use glib::translate::*; use gst_sys; +use std::fmt; use Stream; use StreamCollection; @@ -126,4 +127,34 @@ impl StreamCollection { pub fn is_empty(&self) -> bool { self.len() == 0 } + + pub fn debug(&self) -> Debug { + Debug(self) + } +} + +pub struct Debug<'a>(&'a StreamCollection); + +impl<'a> fmt::Debug for Debug<'a> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + struct Streams<'a>(&'a StreamCollection); + + impl<'a> fmt::Debug for Streams<'a> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let mut f = f.debug_list(); + + for stream in self.0.iter() { + f.entry(&stream.debug()); + } + + f.finish() + } + } + + let streams = Streams(self.0); + + f.debug_struct("StreamCollection") + .field("streams", &streams) + .finish() + } }