mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-13 13:01:07 +00:00
gstreamer/message: enhance Debug impl for Message[Ref]
When "{:?}" printing a Message[Ref], the following issues lower the experience: - If the Message seqnum is GST_SEQNUM_INVALID (0), a panic occurs due to an assertion failure in MessageRef::get_seqnum. - The src of the Message displays the GString address. Origin issue for an occurrence of the first case above fixed in https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/860
This commit is contained in:
parent
fa3f6eefc9
commit
c987bb0c7d
1 changed files with 14 additions and 2 deletions
|
@ -140,14 +140,26 @@ impl fmt::Debug for Message {
|
||||||
|
|
||||||
impl fmt::Debug for MessageRef {
|
impl fmt::Debug for MessageRef {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
// Don't retrieve `seqnum` using `MessageRef::get_seqnum`
|
||||||
|
// because it would generate a new seqnum if a buggy `Element`
|
||||||
|
// emitted a `Message` with an invalid `seqnum`.
|
||||||
|
// We want to help the user find out there is something wrong here,
|
||||||
|
// so they can investigate the origin.
|
||||||
|
let seqnum = unsafe { gst_sys::gst_message_get_seqnum(self.as_mut_ptr()) };
|
||||||
|
let seqnum = if seqnum != 0 {
|
||||||
|
&seqnum as &dyn fmt::Debug
|
||||||
|
} else {
|
||||||
|
&"INVALID (0)" as &dyn fmt::Debug
|
||||||
|
};
|
||||||
|
|
||||||
f.debug_struct("Message")
|
f.debug_struct("Message")
|
||||||
.field("ptr", unsafe { &self.as_ptr() })
|
.field("ptr", unsafe { &self.as_ptr() })
|
||||||
.field("type", &unsafe {
|
.field("type", &unsafe {
|
||||||
let type_ = gst_sys::gst_message_type_get_name((*self.as_ptr()).type_);
|
let type_ = gst_sys::gst_message_type_get_name((*self.as_ptr()).type_);
|
||||||
CStr::from_ptr(type_).to_str().unwrap()
|
CStr::from_ptr(type_).to_str().unwrap()
|
||||||
})
|
})
|
||||||
.field("seqnum", &self.get_seqnum())
|
.field("seqnum", seqnum)
|
||||||
.field("src", &self.get_src().map(|s| s.get_name()))
|
.field("src", &self.get_src().map(|s| s.get_name().to_owned()))
|
||||||
.field("structure", &self.get_structure())
|
.field("structure", &self.get_structure())
|
||||||
.finish()
|
.finish()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue