From a0f9540728ad6defca11c243a0cb402734db10ab Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Tue, 7 May 2024 12:56:49 +0800 Subject: GStreamer: improve readability of debugging output MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * don't print "invalid" timestamps * print timepoints via printf Pick-to: 6.5 6.7 Change-Id: Iffc7cfa338ba73581662177eebed083757b98466 Reviewed-by: Jøger Hansegård Reviewed-by: Artem Dyomin --- .../multimedia/gstreamer/common/qgst_debug.cpp | 65 ++++++++++++++++------ 1 file changed, 48 insertions(+), 17 deletions(-) diff --git a/src/plugins/multimedia/gstreamer/common/qgst_debug.cpp b/src/plugins/multimedia/gstreamer/common/qgst_debug.cpp index ea749c817..6a7fdce6f 100644 --- a/src/plugins/multimedia/gstreamer/common/qgst_debug.cpp +++ b/src/plugins/multimedia/gstreamer/common/qgst_debug.cpp @@ -4,6 +4,8 @@ #include "qgst_debug_p.h" #include "qgstreamermessage_p.h" +#include + QT_BEGIN_NAMESPACE // NOLINTBEGIN(performance-unnecessary-value-param) @@ -155,20 +157,40 @@ QDebug operator<<(QDebug dbg, const GstDevice *device) return dbg; } +namespace { + +struct Timepoint +{ + explicit Timepoint(guint64 us) : ts{ us } { } + guint64 ts; +}; + +QDebug operator<<(QDebug dbg, Timepoint ts) +{ + char buffer[128]; + snprintf(buffer, sizeof(buffer), "%" GST_TIME_FORMAT, GST_TIME_ARGS(ts.ts)); + dbg << buffer; + return dbg; +} + +} // namespace + QDebug operator<<(QDebug dbg, const GstMessage *msg) { QDebugStateSaver saver(dbg); dbg.nospace(); + dbg << GST_MESSAGE_TYPE_NAME(msg) << ", Source: " << GST_MESSAGE_SRC_NAME(msg); + if (GST_MESSAGE_TIMESTAMP(msg) != 0xFFFFFFFFFFFFFFFF) + dbg << ", Timestamp: " << GST_MESSAGE_TIMESTAMP(msg); + switch (msg->type) { case GST_MESSAGE_ERROR: { QUniqueGErrorHandle err; QGString debug; gst_message_parse_error(const_cast(msg), &err, &debug); - dbg << GST_MESSAGE_TYPE_NAME(msg) << ", Source: " << GST_MESSAGE_SRC_NAME(msg) - << ", Timestamp: " << GST_MESSAGE_TIMESTAMP(msg) << ", Error: " << err << " (" << debug - << ")"; + dbg << ", Error: " << err << " (" << debug << ")"; break; } @@ -177,9 +199,7 @@ QDebug operator<<(QDebug dbg, const GstMessage *msg) QGString debug; gst_message_parse_warning(const_cast(msg), &err, &debug); - dbg << GST_MESSAGE_TYPE_NAME(msg) << ", Source: " << GST_MESSAGE_SRC_NAME(msg) - << ", Timestamp: " << GST_MESSAGE_TIMESTAMP(msg) << ", Warning: " << err << " (" - << debug << ")"; + dbg << ", Warning: " << err << " (" << debug << ")"; break; } @@ -188,9 +208,23 @@ QDebug operator<<(QDebug dbg, const GstMessage *msg) QGString debug; gst_message_parse_info(const_cast(msg), &err, &debug); - dbg << GST_MESSAGE_TYPE_NAME(msg) << ", Source: " << GST_MESSAGE_SRC_NAME(msg) - << ", Timestamp: " << GST_MESSAGE_TIMESTAMP(msg) << ", Info: " << err << " (" << debug - << ")"; + dbg << ", Info: " << err << " (" << debug << ")"; + break; + } + + case GST_MESSAGE_QOS: { + gboolean live; + guint64 running_time; + guint64 stream_time; + guint64 timestamp; + guint64 duration; + + gst_message_parse_qos(const_cast(msg), &live, &running_time, &stream_time, + ×tamp, &duration); + + dbg << ", Live: " << bool(live) << ", Running time: " << Timepoint{ running_time } + << ", Stream time: " << Timepoint{ stream_time } + << ", Timestamp: " << Timepoint{ timestamp } << ", Duration: " << Timepoint{ duration }; break; } @@ -202,16 +236,13 @@ QDebug operator<<(QDebug dbg, const GstMessage *msg) gst_message_parse_state_changed(const_cast(msg), &oldState, &newState, &pending); - dbg << GST_MESSAGE_TYPE_NAME(msg) << ", Source: " << GST_MESSAGE_SRC_NAME(msg) - << ", Timestamp: " << GST_MESSAGE_TIMESTAMP(msg) << ", OldState: " << oldState - << ", NewState: " << newState << "Pending State: " << pending; + dbg << ", OldState: " << oldState << ", NewState: " << newState + << ", Pending State: " << pending; break; } - default: { - dbg << GST_MESSAGE_TYPE_NAME(msg) << ", Source: " << GST_MESSAGE_SRC_NAME(msg) - << ", Timestamp: " << GST_MESSAGE_TIMESTAMP(msg); - } + default: + break; } return dbg; } @@ -404,7 +435,7 @@ QDebug operator<<(QDebug dbg, const QCompactGstMessageAdaptor &m) gst_message_parse_state_changed(m.msg, &oldState, &newState, &pending); - dbg << oldState << "->" << newState << "(pending: " << pending << ")"; + dbg << oldState << " -> " << newState << " (pending: " << pending << ")"; return dbg; } -- cgit v1.2.3