From ba0dfa52d2ab7795543d5454b544b3cc301198b4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Olivier=20Cr=C3=AAte?= Date: Fri, 9 Oct 2020 20:27:40 -0400 Subject: [PATCH] webrtcstats: Extract statistics from the rtpjitterbuffer And expose them as standardised webrtc statistics Part-of: --- ext/webrtc/gstwebrtcstats.c | 46 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/ext/webrtc/gstwebrtcstats.c b/ext/webrtc/gstwebrtcstats.c index 09f2688..ea8c6e5 100644 --- a/ext/webrtc/gstwebrtcstats.c +++ b/ext/webrtc/gstwebrtcstats.c @@ -89,8 +89,8 @@ _get_peer_connection_stats (GstWebRTCBin * webrtc) https://www.w3.org/TR/webrtc-stats/#outboundrtpstats-dict* */ static void _get_stats_from_rtp_source_stats (GstWebRTCBin * webrtc, - const GstStructure * source_stats, const gchar * codec_id, - const gchar * transport_id, GstStructure * s) + TransportStream * stream, const GstStructure * source_stats, + const gchar * codec_id, const gchar * transport_id, GstStructure * s) { guint ssrc, fir, pli, nack, jitter; int lost, clock_rate; @@ -265,9 +265,33 @@ _get_stats_from_rtp_source_stats (GstWebRTCBin * webrtc, GstStructure *in, *r_out; gchar *r_out_id, *in_id; gboolean have_sr = FALSE; + GstStructure *jb_stats = NULL; + guint i; + guint64 jb_lost, duplicates, late, rtx_success; gst_structure_get (source_stats, "have-sr", G_TYPE_BOOLEAN, &have_sr, NULL); + for (i = 0; i < stream->remote_ssrcmap->len; i++) { + SsrcMapItem *item = + &g_array_index (stream->remote_ssrcmap, SsrcMapItem, i); + + if (item->ssrc == ssrc) { + GObject *jb = g_weak_ref_get (&item->rtpjitterbuffer); + + if (jb) { + g_object_get (jb, "stats", &jb_stats, NULL); + g_object_unref (jb); + } + break; + } + } + + if (jb_stats) + gst_structure_get (jb_stats, "num-lost", G_TYPE_UINT64, &jb_lost, + "num-duplicates", G_TYPE_UINT64, &duplicates, "num-late", + G_TYPE_UINT64, &late, "rtx-success-count", G_TYPE_UINT64, + &rtx_success, NULL); + in_id = g_strdup_printf ("rtp-inbound-stream-stats_%u", ssrc); r_out_id = g_strdup_printf ("rtp-remote-outbound-stream-stats_%u", ssrc); @@ -285,18 +309,21 @@ _get_stats_from_rtp_source_stats (GstWebRTCBin * webrtc, if (gst_structure_get_uint64 (source_stats, "packets-received", &packets)) gst_structure_set (in, "packets-received", G_TYPE_UINT64, packets, NULL); - if (gst_structure_get_int (source_stats, "packets-lost", &lost)) - gst_structure_set (in, "packets-lost", G_TYPE_INT, lost, NULL); + if (jb_stats) + gst_structure_set (in, "packets-lost", G_TYPE_UINT64, jb_lost, NULL); if (gst_structure_get_uint (source_stats, "jitter", &jitter)) gst_structure_set (in, "jitter", G_TYPE_DOUBLE, CLOCK_RATE_VALUE_TO_SECONDS (jitter, clock_rate), NULL); + if (jb_stats) + gst_structure_set (in, "packets-discarded", G_TYPE_UINT64, late, + "packets-repaired", G_TYPE_UINT64, rtx_success, NULL); + /* RTCReceivedRtpStreamStats To be added: - unsigned long long packetsRepaired; unsigned long long burstPacketsLost; unsigned long long burstPacketsDiscarded; unsigned long burstLossCount; @@ -325,7 +352,9 @@ _get_stats_from_rtp_source_stats (GstWebRTCBin * webrtc, gst_structure_set (in, "pli-count", G_TYPE_UINT, pli, NULL); if (gst_structure_get_uint (source_stats, "recv-nack-count", &nack)) gst_structure_set (in, "nack-count", G_TYPE_UINT, nack, NULL); - /* XXX: mediaType, trackId, sliCount, qpSum */ + if (jb_stats) + gst_structure_set (in, "packets-duplicated", G_TYPE_UINT64, duplicates, + NULL); /* RTCInboundRtpStreamStats: @@ -461,6 +490,8 @@ _get_stats_from_rtp_source_stats (GstWebRTCBin * webrtc, reportsSent */ + gst_structure_free (jb_stats); + gst_structure_set (s, in_id, GST_TYPE_STRUCTURE, in, NULL); gst_structure_set (s, r_out_id, GST_TYPE_STRUCTURE, r_out, NULL); @@ -642,7 +673,8 @@ _get_stats_from_transport_channel (GstWebRTCBin * webrtc, if (ssrc && stats_ssrc && ssrc != stats_ssrc) continue; - _get_stats_from_rtp_source_stats (webrtc, stats, codec_id, transport_id, s); + _get_stats_from_rtp_source_stats (webrtc, stream, stats, codec_id, + transport_id, s); } g_object_unref (rtp_session); -- 2.7.4