Implement fmt::Debug more consistently for miniobjects and various other types

This commit is contained in:
Sebastian Dröge 2017-12-01 11:21:20 +02:00
parent c57d5523d2
commit fccb1eca5e
13 changed files with 168 additions and 4 deletions

View file

@ -371,7 +371,15 @@ impl ToOwned for BufferRef {
impl fmt::Debug for BufferRef { impl fmt::Debug for BufferRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}", unsafe { self.as_ptr() }) f.debug_struct("Buffer")
.field("pts", &self.get_pts())
.field("dts", &self.get_dts())
.field("duration", &self.get_duration())
.field("size", &self.get_size())
.field("offset", &self.get_offset())
.field("offset_end", &self.get_offset_end())
.field("flags", &self.get_flags())
.finish()
} }
} }

View file

@ -10,6 +10,7 @@ use ffi;
use glib; use glib;
use glib::StaticType; use glib::StaticType;
use glib::translate::{from_glib, from_glib_full}; use glib::translate::{from_glib, from_glib_full};
use std::fmt;
use miniobject::*; use miniobject::*;
use Buffer; use Buffer;
@ -94,6 +95,20 @@ impl ToOwned for BufferListRef {
} }
} }
impl fmt::Debug for BufferListRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let size = self.iter().map(|b| b.get_size()).sum::<usize>();
let (pts, dts) = self.get(0).map(|b| (b.get_pts(), b.get_dts())).unwrap_or((::ClockTime::none(), ::ClockTime::none()));
f.debug_struct("BufferList")
.field("buffers", &self.len())
.field("pts", &pts)
.field("dts", &dts)
.field("size", &size)
.finish()
}
}
impl StaticType for BufferListRef { impl StaticType for BufferListRef {
fn static_type() -> glib::Type { fn static_type() -> glib::Type {
unsafe { from_glib(ffi::gst_buffer_list_get_type()) } unsafe { from_glib(ffi::gst_buffer_list_get_type()) }

View file

@ -344,6 +344,14 @@ define_iter!(Iter, &'a CapsRef, &'a StructureRef);
define_iter!(IterMut, &'a mut CapsRef, &'a mut StructureRef); define_iter!(IterMut, &'a mut CapsRef, &'a mut StructureRef);
impl fmt::Debug for CapsRef { impl fmt::Debug for CapsRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_tuple("Caps")
.field(&self.to_string())
.finish()
}
}
impl fmt::Display for CapsRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(&self.to_string()) f.write_str(&self.to_string())
} }

View file

@ -6,6 +6,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use std::fmt;
use std::ffi::CStr; use std::ffi::CStr;
use ffi; use ffi;
@ -76,6 +77,15 @@ impl StaticType for ContextRef {
} }
} }
impl fmt::Debug for ContextRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Context")
.field("type", &self.get_context_type())
.field("structure", &self.get_structure())
.finish()
}
}
impl ToOwned for ContextRef { impl ToOwned for ContextRef {
type Owned = GstRc<ContextRef>; type Owned = GstRc<ContextRef>;

View file

@ -0,0 +1,16 @@
// Copyright (C) 2017 Sebastian Dröge <sebastian@centricular.com>
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use DateTime;
use std::fmt;
impl fmt::Display for DateTime {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(self.to_iso8601_string().unwrap_or(String::from("None")).as_str())
}
}

View file

@ -13,6 +13,7 @@ use structure::*;
use std::ptr; use std::ptr;
use std::mem; use std::mem;
use std::cmp; use std::cmp;
use std::fmt;
use std::ffi::CStr; use std::ffi::CStr;
use glib; use glib;
@ -372,6 +373,19 @@ impl glib::types::StaticType for EventRef {
} }
} }
impl fmt::Debug for EventRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Event")
.field("type", & unsafe {
let type_ = ffi::gst_event_type_get_name((*self.as_ptr()).type_);
CStr::from_ptr(type_).to_str().unwrap()
})
.field("seqnum", &self.get_seqnum())
.field("structure", &self.get_structure())
.finish()
}
}
impl ToOwned for EventRef { impl ToOwned for EventRef {
type Owned = GstRc<EventRef>; type Owned = GstRc<EventRef>;

View file

@ -106,6 +106,7 @@ mod parse_context;
mod enums; mod enums;
mod clock_time; mod clock_time;
mod format; mod format;
mod date_time;
pub use object::GstObjectExtManual; pub use object::GstObjectExtManual;
pub use element::{ElementExtManual, ElementMessageType, NotifyWatchId}; pub use element::{ElementExtManual, ElementMessageType, NotifyWatchId};
pub use element::{ELEMENT_METADATA_AUTHOR, ELEMENT_METADATA_DESCRIPTION, ELEMENT_METADATA_DOC_URI, pub use element::{ELEMENT_METADATA_AUTHOR, ELEMENT_METADATA_DESCRIPTION, ELEMENT_METADATA_DOC_URI,

View file

@ -121,7 +121,9 @@ unsafe impl Send for DebugCategory {}
impl fmt::Debug for DebugCategory { impl fmt::Debug for DebugCategory {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(self.get_name()) f.debug_tuple("DebugCategory")
.field(&self.get_name())
.finish()
} }
} }

View file

@ -11,9 +11,11 @@ use Object;
use miniobject::*; use miniobject::*;
use structure::*; use structure::*;
use TagList; use TagList;
use GstObjectExt;
use std::ptr; use std::ptr;
use std::mem; use std::mem;
use std::fmt;
use std::ffi::CStr; use std::ffi::CStr;
use glib; use glib;
@ -346,6 +348,20 @@ impl glib::types::StaticType for MessageRef {
} }
} }
impl fmt::Debug for MessageRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Message")
.field("type", & unsafe {
let type_ = ffi::gst_message_type_get_name((*self.as_ptr()).type_);
CStr::from_ptr(type_).to_str().unwrap()
})
.field("seqnum", &self.get_seqnum())
.field("src", &self.get_src().map(|s| s.get_name()))
.field("structure", &self.get_structure())
.finish()
}
}
impl ToOwned for MessageRef { impl ToOwned for MessageRef {
type Owned = GstRc<MessageRef>; type Owned = GstRc<MessageRef>;

View file

@ -12,6 +12,7 @@ use structure::*;
use std::ptr; use std::ptr;
use std::mem; use std::mem;
use std::fmt;
use std::ffi::CStr; use std::ffi::CStr;
use std::ops::Deref; use std::ops::Deref;
@ -182,6 +183,18 @@ impl glib::types::StaticType for QueryRef {
} }
} }
impl fmt::Debug for QueryRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Query")
.field("type", & unsafe {
let type_ = ffi::gst_query_type_get_name((*self.as_ptr()).type_);
CStr::from_ptr(type_).to_str().unwrap()
})
.field("structure", &self.get_structure())
.finish()
}
}
impl ToOwned for QueryRef { impl ToOwned for QueryRef {
type Owned = GstRc<QueryRef>; type Owned = GstRc<QueryRef>;

View file

@ -7,6 +7,7 @@
// except according to those terms. // except according to those terms.
use Format; use Format;
use ClockTime;
use SeekFlags; use SeekFlags;
use SeekType; use SeekType;
use ffi; use ffi;
@ -16,6 +17,7 @@ use gobject_ffi;
use glib; use glib;
use std::mem; use std::mem;
use std::ptr; use std::ptr;
use std::fmt;
pub struct Segment(ffi::GstSegment); pub struct Segment(ffi::GstSegment);
@ -233,11 +235,11 @@ impl Segment {
self.0.applied_rate = applied_rate; self.0.applied_rate = applied_rate;
} }
pub fn get_format(&self) -> ::Format { pub fn get_format(&self) -> Format {
from_glib(self.0.format) from_glib(self.0.format)
} }
pub fn set_format(&mut self, format: ::Format) { pub fn set_format(&mut self, format: Format) {
self.0.format = format.to_glib(); self.0.format = format.to_glib();
} }
@ -315,6 +317,49 @@ impl Clone for Segment {
} }
} }
impl fmt::Debug for Segment {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.get_format() {
Format::Undefined => {
f.debug_struct("Segment")
.field("format", &Format::Undefined)
.finish()
},
Format::Time => {
f.debug_struct("Segment")
.field("format", &Format::Time)
.field("start", &ClockTime::from(self.get_start()))
.field("offset", &ClockTime::from(self.get_offset()))
.field("stop", &ClockTime::from(self.get_stop()))
.field("rate", &self.get_rate())
.field("applied_rate", &self.get_applied_rate())
.field("flags", &self.get_flags())
.field("time", &ClockTime::from(self.get_time()))
.field("base", &ClockTime::from(self.get_base()))
.field("position", &ClockTime::from(self.get_position()))
.field("duration", &ClockTime::from(self.get_duration()))
.finish()
},
_ => {
f.debug_struct("Segment")
.field("format", &self.get_format())
.field("start", &self.get_start())
.field("offset", &self.get_offset())
.field("stop", &self.get_stop())
.field("rate", &self.get_rate())
.field("applied_rate", &self.get_applied_rate())
.field("flags", &self.get_flags())
.field("time", &self.get_time())
.field("base", &self.get_base())
.field("position", &self.get_position())
.field("duration", &self.get_duration())
.finish()
}
}
}
}
impl glib::types::StaticType for Segment { impl glib::types::StaticType for Segment {
fn static_type() -> glib::types::Type { fn static_type() -> glib::types::Type {
unsafe { glib::translate::from_glib(ffi::gst_segment_get_type()) } unsafe { glib::translate::from_glib(ffi::gst_segment_get_type()) }

View file

@ -115,6 +115,14 @@ impl Drop for Structure {
} }
impl fmt::Debug for Structure { impl fmt::Debug for Structure {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_tuple("Structure")
.field(&self.to_string())
.finish()
}
}
impl fmt::Display for Structure {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(&self.to_string()) f.write_str(&self.to_string())
} }

View file

@ -327,6 +327,14 @@ impl TagListRef {
} }
impl fmt::Debug for TagListRef { impl fmt::Debug for TagListRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_tuple("TagList")
.field(&self.to_string())
.finish()
}
}
impl fmt::Display for TagListRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(&self.to_string()) f.write_str(&self.to_string())
} }