forked from mirrors/gstreamer-rs
Implement fmt::Debug more consistently for miniobjects and various other types
This commit is contained in:
parent
ec900d7e3f
commit
affc53a515
13 changed files with 168 additions and 4 deletions
|
@ -371,7 +371,15 @@ impl ToOwned for BufferRef {
|
|||
|
||||
impl fmt::Debug for BufferRef {
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ use ffi;
|
|||
use glib;
|
||||
use glib::StaticType;
|
||||
use glib::translate::{from_glib, from_glib_full};
|
||||
use std::fmt;
|
||||
|
||||
use miniobject::*;
|
||||
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 {
|
||||
fn static_type() -> glib::Type {
|
||||
unsafe { from_glib(ffi::gst_buffer_list_get_type()) }
|
||||
|
|
|
@ -344,6 +344,14 @@ define_iter!(Iter, &'a CapsRef, &'a StructureRef);
|
|||
define_iter!(IterMut, &'a mut CapsRef, &'a mut StructureRef);
|
||||
|
||||
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 {
|
||||
f.write_str(&self.to_string())
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::fmt;
|
||||
use std::ffi::CStr;
|
||||
|
||||
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 {
|
||||
type Owned = GstRc<ContextRef>;
|
||||
|
||||
|
|
16
gstreamer/src/date_time.rs
Normal file
16
gstreamer/src/date_time.rs
Normal 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())
|
||||
}
|
||||
}
|
|
@ -13,6 +13,7 @@ use structure::*;
|
|||
use std::ptr;
|
||||
use std::mem;
|
||||
use std::cmp;
|
||||
use std::fmt;
|
||||
use std::ffi::CStr;
|
||||
|
||||
use glib;
|
||||
|
@ -368,6 +369,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 {
|
||||
type Owned = GstRc<EventRef>;
|
||||
|
||||
|
|
|
@ -106,6 +106,7 @@ mod parse_context;
|
|||
mod enums;
|
||||
mod clock_time;
|
||||
mod format;
|
||||
mod date_time;
|
||||
pub use object::GstObjectExtManual;
|
||||
pub use element::{ElementExtManual, ElementMessageType, NotifyWatchId};
|
||||
pub use element::{ELEMENT_METADATA_AUTHOR, ELEMENT_METADATA_DESCRIPTION, ELEMENT_METADATA_DOC_URI,
|
||||
|
|
|
@ -121,7 +121,9 @@ unsafe impl Send for DebugCategory {}
|
|||
|
||||
impl fmt::Debug for DebugCategory {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.write_str(self.get_name())
|
||||
f.debug_tuple("DebugCategory")
|
||||
.field(&self.get_name())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,9 +11,11 @@ use Object;
|
|||
use miniobject::*;
|
||||
use structure::*;
|
||||
use TagList;
|
||||
use GstObjectExt;
|
||||
|
||||
use std::ptr;
|
||||
use std::mem;
|
||||
use std::fmt;
|
||||
use std::ffi::CStr;
|
||||
|
||||
use glib;
|
||||
|
@ -342,6 +344,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 {
|
||||
type Owned = GstRc<MessageRef>;
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ use structure::*;
|
|||
|
||||
use std::ptr;
|
||||
use std::mem;
|
||||
use std::fmt;
|
||||
use std::ffi::CStr;
|
||||
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 {
|
||||
type Owned = GstRc<QueryRef>;
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
// except according to those terms.
|
||||
|
||||
use Format;
|
||||
use ClockTime;
|
||||
use SeekFlags;
|
||||
use SeekType;
|
||||
use ffi;
|
||||
|
@ -16,6 +17,7 @@ use gobject_ffi;
|
|||
use glib;
|
||||
use std::mem;
|
||||
use std::ptr;
|
||||
use std::fmt;
|
||||
|
||||
pub struct Segment(ffi::GstSegment);
|
||||
|
||||
|
@ -233,11 +235,11 @@ impl Segment {
|
|||
self.0.applied_rate = applied_rate;
|
||||
}
|
||||
|
||||
pub fn get_format(&self) -> ::Format {
|
||||
pub fn get_format(&self) -> 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();
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
fn static_type() -> glib::types::Type {
|
||||
unsafe { glib::translate::from_glib(ffi::gst_segment_get_type()) }
|
||||
|
|
|
@ -115,6 +115,14 @@ impl Drop 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 {
|
||||
f.write_str(&self.to_string())
|
||||
}
|
||||
|
|
|
@ -327,6 +327,14 @@ impl 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 {
|
||||
f.write_str(&self.to_string())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue