gstreamer: Add Stream::debug() and StreamCollection::debug()

These provide more helpful debug output than just the pointer when
printing.
This commit is contained in:
Sebastian Dröge 2020-04-14 20:29:43 +03:00
parent 43e7f9f589
commit d623bcdce5
3 changed files with 51 additions and 2 deletions

View file

@ -244,7 +244,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;

View file

@ -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()
}
}

View file

@ -9,6 +9,7 @@
use glib::object::IsA;
use glib::translate::*;
use gst_sys;
use std::fmt;
use Stream;
use StreamCollection;
@ -102,4 +103,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()
}
}