gstreamer: event: manually implement Debug

Allow us to display more useful information.

Fix #467

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1268>
This commit is contained in:
Guillaume Desmottes 2023-05-22 14:20:29 +02:00
parent 53173eb46c
commit fadca54d51

View file

@ -360,7 +360,6 @@ macro_rules! declare_concrete_event {
}
};
($name:ident, $param:ident) => {
#[derive(Debug)]
#[repr(transparent)]
pub struct $name<$param = EventRef>($param);
@ -445,6 +444,16 @@ impl FlushStart<Event> {
}
}
impl std::fmt::Debug for FlushStart {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("FlushStart")
.field("seqnum", &self.event().seqnum())
.field("running-time-offset", &self.event().running_time_offset())
.field("structure", &self.event().structure())
.finish()
}
}
declare_concrete_event!(FlushStop, T);
impl FlushStop<Event> {
#[doc(alias = "gst_event_new_flush_stop")]
@ -474,6 +483,17 @@ impl FlushStop {
}
}
impl std::fmt::Debug for FlushStop {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("FlushStop")
.field("seqnum", &self.event().seqnum())
.field("running-time-offset", &self.event().running_time_offset())
.field("structure", &self.event().structure())
.field("resets-time", &self.resets_time())
.finish()
}
}
declare_concrete_event!(@sticky StreamStart, T);
impl StreamStart<Event> {
#[doc(alias = "gst_event_new_stream_start")]
@ -541,6 +561,20 @@ impl StreamStart {
}
}
impl std::fmt::Debug for StreamStart {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("StreamStart")
.field("seqnum", &self.event().seqnum())
.field("running-time-offset", &self.event().running_time_offset())
.field("structure", &self.event().structure())
.field("stream-id", &self.stream_id())
.field("stream-flags", &self.stream_flags())
.field("group-id", &self.group_id())
.field("stream", &self.stream())
.finish()
}
}
declare_concrete_event!(@sticky Caps, T);
impl Caps<Event> {
#[doc(alias = "gst_event_new_caps")]
@ -575,6 +609,17 @@ impl Caps {
}
}
impl std::fmt::Debug for Caps {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Caps")
.field("seqnum", &self.event().seqnum())
.field("running-time-offset", &self.event().running_time_offset())
.field("structure", &self.event().structure())
.field("caps", &self.caps())
.finish()
}
}
declare_concrete_event!(@sticky Segment, T);
impl Segment<Event> {
#[doc(alias = "gst_event_new_segment")]
@ -605,6 +650,17 @@ impl Segment {
}
}
impl std::fmt::Debug for Segment {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Segment")
.field("seqnum", &self.event().seqnum())
.field("running-time-offset", &self.event().running_time_offset())
.field("structure", &self.event().structure())
.field("segment", &self.segment())
.finish()
}
}
declare_concrete_event!(@sticky StreamCollection, T);
impl StreamCollection<Event> {
#[doc(alias = "gst_event_new_stream_collection")]
@ -633,6 +689,17 @@ impl StreamCollection {
}
}
impl std::fmt::Debug for StreamCollection {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("StreamCollection")
.field("seqnum", &self.event().seqnum())
.field("running-time-offset", &self.event().running_time_offset())
.field("structure", &self.event().structure())
.field("stream-collection", &self.stream_collection())
.finish()
}
}
declare_concrete_event!(@sticky Tag, T);
impl Tag<Event> {
#[doc(alias = "gst_event_new_tag")]
@ -667,6 +734,17 @@ impl Tag {
}
}
impl std::fmt::Debug for Tag {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Tag")
.field("seqnum", &self.event().seqnum())
.field("running-time-offset", &self.event().running_time_offset())
.field("structure", &self.event().structure())
.field("tag", &self.tag())
.finish()
}
}
declare_concrete_event!(@sticky Buffersize, T);
impl Buffersize<Event> {
#[doc(alias = "gst_event_new_buffer_size")]
@ -717,6 +795,20 @@ impl Buffersize {
}
}
impl std::fmt::Debug for Buffersize {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let (minsize, maxsize, async_) = self.get();
f.debug_struct("Buffersize")
.field("seqnum", &self.event().seqnum())
.field("running-time-offset", &self.event().running_time_offset())
.field("structure", &self.event().structure())
.field("min-size", &minsize)
.field("max-size", &maxsize)
.field("async", &async_)
.finish()
}
}
declare_concrete_event!(@sticky SinkMessage, T);
impl SinkMessage<Event> {
#[doc(alias = "gst_event_new_sink_message")]
@ -745,6 +837,17 @@ impl SinkMessage {
}
}
impl std::fmt::Debug for SinkMessage {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("SinkMessage")
.field("seqnum", &self.event().seqnum())
.field("running-time-offset", &self.event().running_time_offset())
.field("structure", &self.event().structure())
.field("message", &self.message())
.finish()
}
}
declare_concrete_event!(@sticky StreamGroupDone, T);
impl StreamGroupDone<Event> {
#[doc(alias = "gst_event_new_stream_group_done")]
@ -776,6 +879,17 @@ impl StreamGroupDone {
}
}
impl std::fmt::Debug for StreamGroupDone {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("StreamGroupDone")
.field("seqnum", &self.event().seqnum())
.field("running-time-offset", &self.event().running_time_offset())
.field("structure", &self.event().structure())
.field("group-id", &self.group_id())
.finish()
}
}
declare_concrete_event!(@sticky Eos, T);
impl Eos<Event> {
#[doc(alias = "gst_event_new_eos")]
@ -791,6 +905,16 @@ impl Eos<Event> {
}
}
impl std::fmt::Debug for Eos {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Eos")
.field("seqnum", &self.event().seqnum())
.field("running-time-offset", &self.event().running_time_offset())
.field("structure", &self.event().structure())
.finish()
}
}
declare_concrete_event!(@sticky Toc, T);
impl Toc<Event> {
// FIXME could use false for updated as default
@ -834,6 +958,17 @@ impl Toc {
}
}
impl std::fmt::Debug for Toc {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Toc")
.field("seqnum", &self.event().seqnum())
.field("running-time-offset", &self.event().running_time_offset())
.field("structure", &self.event().structure())
.field("toc", &self.toc())
.finish()
}
}
declare_concrete_event!(@sticky Protection, T);
impl Protection<Event> {
#[doc(alias = "gst_event_new_protection")]
@ -885,6 +1020,20 @@ impl Protection {
}
}
impl std::fmt::Debug for Protection {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let (system_id, buffer, origin) = self.get();
f.debug_struct("Protection")
.field("seqnum", &self.event().seqnum())
.field("running-time-offset", &self.event().running_time_offset())
.field("structure", &self.event().structure())
.field("system-id", &system_id)
.field("buffer", &buffer)
.field("origin", &origin)
.finish()
}
}
declare_concrete_event!(SegmentDone, T);
impl SegmentDone<Event> {
#[doc(alias = "gst_event_new_segment_done")]
@ -918,6 +1067,17 @@ impl SegmentDone {
}
}
impl std::fmt::Debug for SegmentDone {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("SegmentDone")
.field("seqnum", &self.event().seqnum())
.field("running-time-offset", &self.event().running_time_offset())
.field("structure", &self.event().structure())
.field("segment", &self.get())
.finish()
}
}
declare_concrete_event!(Gap, T);
impl Gap<Event> {
#[doc(alias = "gst_event_new_gap")]
@ -965,6 +1125,21 @@ impl Gap {
}
}
impl std::fmt::Debug for Gap {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let (timestamp, duration) = self.get();
let mut f = f.debug_struct("Gap");
f.field("seqnum", &self.event().seqnum())
.field("running-time-offset", &self.event().running_time_offset())
.field("structure", &self.event().structure())
.field("timestamp", &timestamp)
.field("duration", &duration);
#[cfg(feature = "v1_20")]
f.field("flags", &self.gap_flags());
f.finish()
}
}
#[cfg(feature = "v1_18")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
declare_concrete_event!(@sticky InstantRateChange, T);
@ -1007,6 +1182,20 @@ impl InstantRateChange {
}
}
#[cfg(feature = "v1_18")]
impl std::fmt::Debug for InstantRateChange {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let (multiplier, new_flags) = self.get();
f.debug_struct("InstantRateChange")
.field("seqnum", &self.event().seqnum())
.field("running-time-offset", &self.event().running_time_offset())
.field("structure", &self.event().structure())
.field("multiplier", &multiplier)
.field("new-flags", &new_flags)
.finish()
}
}
declare_concrete_event!(Qos, T);
impl Qos<Event> {
#[doc(alias = "gst_event_new_qos")]
@ -1056,6 +1245,21 @@ impl Qos {
}
}
impl std::fmt::Debug for Qos {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let (type_, proportion, diff, timestamp) = self.get();
f.debug_struct("Qos")
.field("seqnum", &self.event().seqnum())
.field("running-time-offset", &self.event().running_time_offset())
.field("structure", &self.event().structure())
.field("type", &type_)
.field("proportion", &proportion)
.field("diff", &diff)
.field("timestamp", &timestamp)
.finish()
}
}
declare_concrete_event!(Seek, T);
impl Seek<Event> {
#[doc(alias = "gst_event_new_seek")]
@ -1155,6 +1359,23 @@ impl Seek {
}
}
impl std::fmt::Debug for Seek {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let (rate, flags, start_type, start, stop_type, stop) = self.get();
f.debug_struct("Seek")
.field("seqnum", &self.event().seqnum())
.field("running-time-offset", &self.event().running_time_offset())
.field("structure", &self.event().structure())
.field("rate", &rate)
.field("flags", &flags)
.field("start-type", &start_type)
.field("start", &start)
.field("stop-type", &stop_type)
.field("stop", &stop)
.finish()
}
}
declare_concrete_event!(Navigation, T);
impl Navigation<Event> {
#[doc(alias = "gst_event_new_navigation")]
@ -1170,6 +1391,16 @@ impl Navigation<Event> {
}
}
impl std::fmt::Debug for Navigation {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Navigation")
.field("seqnum", &self.event().seqnum())
.field("running-time-offset", &self.event().running_time_offset())
.field("structure", &self.event().structure())
.finish()
}
}
declare_concrete_event!(Latency, T);
impl Latency<Event> {
#[doc(alias = "gst_event_new_latency")]
@ -1199,6 +1430,17 @@ impl Latency {
}
}
impl std::fmt::Debug for Latency {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Latency")
.field("seqnum", &self.event().seqnum())
.field("running-time-offset", &self.event().running_time_offset())
.field("structure", &self.event().structure())
.field("latency", &self.latency())
.finish()
}
}
declare_concrete_event!(Step, T);
impl Step<Event> {
#[doc(alias = "gst_event_new_step")]
@ -1251,6 +1493,21 @@ impl Step {
}
}
impl std::fmt::Debug for Step {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let (amount, rate, flush, intermediate) = self.get();
f.debug_struct("Step")
.field("seqnum", &self.event().seqnum())
.field("running-time-offset", &self.event().running_time_offset())
.field("structure", &self.event().structure())
.field("amount", &amount)
.field("rate", &rate)
.field("flush", &flush)
.field("intermediate", &intermediate)
.finish()
}
}
declare_concrete_event!(Reconfigure, T);
impl Reconfigure<Event> {
#[doc(alias = "gst_event_new_reconfigure")]
@ -1266,6 +1523,16 @@ impl Reconfigure<Event> {
}
}
impl std::fmt::Debug for Reconfigure {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Reconfigure")
.field("seqnum", &self.event().seqnum())
.field("running-time-offset", &self.event().running_time_offset())
.field("structure", &self.event().structure())
.finish()
}
}
declare_concrete_event!(TocSelect, T);
impl TocSelect<Event> {
#[doc(alias = "gst_event_new_toc_select")]
@ -1294,6 +1561,17 @@ impl TocSelect {
}
}
impl std::fmt::Debug for TocSelect {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("TocSelect")
.field("seqnum", &self.event().seqnum())
.field("running-time-offset", &self.event().running_time_offset())
.field("structure", &self.event().structure())
.field("uid", &self.uid())
.finish()
}
}
declare_concrete_event!(SelectStreams, T);
impl SelectStreams<Event> {
#[doc(alias = "gst_event_new_select_streams")]
@ -1323,6 +1601,17 @@ impl SelectStreams {
}
}
impl std::fmt::Debug for SelectStreams {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("SelectStreams")
.field("seqnum", &self.event().seqnum())
.field("running-time-offset", &self.event().running_time_offset())
.field("structure", &self.event().structure())
.field("streams", &self.streams())
.finish()
}
}
#[cfg(feature = "v1_18")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
declare_concrete_event!(InstantRateSyncTime, T);
@ -1377,6 +1666,21 @@ impl InstantRateSyncTime {
}
}
#[cfg(feature = "v1_18")]
impl std::fmt::Debug for InstantRateSyncTime {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let (rate_multiplier, running_time, upstream_running_time) = self.get();
f.debug_struct("InstantRateSyncTime")
.field("seqnum", &self.event().seqnum())
.field("running-time-offset", &self.event().running_time_offset())
.field("structure", &self.event().structure())
.field("rate-multiplier", &rate_multiplier)
.field("running-time", &running_time)
.field("upstream-running-time", &upstream_running_time)
.finish()
}
}
declare_concrete_event!(CustomUpstream, T);
impl CustomUpstream<Event> {
#[doc(alias = "gst_event_new_custom")]
@ -1392,6 +1696,16 @@ impl CustomUpstream<Event> {
}
}
impl std::fmt::Debug for CustomUpstream {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("CustomUpstream")
.field("seqnum", &self.event().seqnum())
.field("running-time-offset", &self.event().running_time_offset())
.field("structure", &self.event().structure())
.finish()
}
}
declare_concrete_event!(CustomDownstream, T);
impl CustomDownstream<Event> {
#[doc(alias = "gst_event_new_custom")]
@ -1407,6 +1721,16 @@ impl CustomDownstream<Event> {
}
}
impl std::fmt::Debug for CustomDownstream {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("CustomDownstream")
.field("seqnum", &self.event().seqnum())
.field("running-time-offset", &self.event().running_time_offset())
.field("structure", &self.event().structure())
.finish()
}
}
declare_concrete_event!(CustomDownstreamOob, T);
impl CustomDownstreamOob<Event> {
#[doc(alias = "gst_event_new_custom")]
@ -1422,6 +1746,16 @@ impl CustomDownstreamOob<Event> {
}
}
impl std::fmt::Debug for CustomDownstreamOob {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("CustomDownstreamOob")
.field("seqnum", &self.event().seqnum())
.field("running-time-offset", &self.event().running_time_offset())
.field("structure", &self.event().structure())
.finish()
}
}
declare_concrete_event!(@sticky CustomDownstreamSticky, T);
impl CustomDownstreamSticky<Event> {
#[doc(alias = "gst_event_new_custom")]
@ -1437,6 +1771,16 @@ impl CustomDownstreamSticky<Event> {
}
}
impl std::fmt::Debug for CustomDownstreamSticky {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("CustomDownstreamSticky")
.field("seqnum", &self.event().seqnum())
.field("running-time-offset", &self.event().running_time_offset())
.field("structure", &self.event().structure())
.finish()
}
}
declare_concrete_event!(CustomBoth, T);
impl CustomBoth<Event> {
#[doc(alias = "gst_event_new_custom")]
@ -1452,6 +1796,16 @@ impl CustomBoth<Event> {
}
}
impl std::fmt::Debug for CustomBoth {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("CustomBoth")
.field("seqnum", &self.event().seqnum())
.field("running-time-offset", &self.event().running_time_offset())
.field("structure", &self.event().structure())
.finish()
}
}
declare_concrete_event!(CustomBothOob, T);
impl CustomBothOob<Event> {
#[doc(alias = "gst_event_new_custom")]
@ -1467,8 +1821,28 @@ impl CustomBothOob<Event> {
}
}
impl std::fmt::Debug for CustomBothOob {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("CustomBothOob")
.field("seqnum", &self.event().seqnum())
.field("running-time-offset", &self.event().running_time_offset())
.field("structure", &self.event().structure())
.finish()
}
}
declare_concrete_event!(Other, T);
impl std::fmt::Debug for Other {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Other")
.field("seqnum", &self.event().seqnum())
.field("running-time-offset", &self.event().running_time_offset())
.field("structure", &self.event().structure())
.finish()
}
}
struct EventBuilder<'a> {
seqnum: Option<Seqnum>,
running_time_offset: Option<i64>,