ristsrc: Implement per session stats

As we can now have multiple sessions, stats need to be implemented per
session. This follow RTPSession model with sources. The stats are now:

    dropped: 0
    received: 0
    recovered: 0
    permanently-lost: 0
    duplicates: 0
    retransmission-requests-sent: 0
    rtx-roundtrip-time: 0
    session-stats:
        session-id=0
            rtp-from=""
            rtcp-from=""
            dropped=0
            received=0
        session-id=1
            rtp-from=""
            rtcp-from=""
            dropped=0
            received=0
        . . .

session-stats is a GValueArray as there is no better alternatives.
This commit is contained in:
Nicolas Dufresne 2019-05-07 11:32:00 -04:00 committed by Nicolas Dufresne
parent 0c26aaa614
commit 9a443c04bc

View file

@ -47,6 +47,8 @@
* ]| * ]|
*/ */
/* using GValueArray, which has not replacement */
#define GLIB_DISABLE_DEPRECATION_WARNINGS
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
@ -636,31 +638,64 @@ gst_rist_src_start (GstRistSrc * src)
static GstStructure * static GstStructure *
gst_rist_src_create_stats (GstRistSrc * src) gst_rist_src_create_stats (GstRistSrc * src)
{ {
GObject *session = NULL, *source = NULL; GstStructure *ret;
GstStructure *stats = NULL, *ret; GValueArray *session_stats;
guint64 dropped = 0, received = 0, recovered = 0, lost = 0; guint64 total_dropped = 0, total_received = 0, recovered = 0, lost = 0;
guint64 duplicates = 0, rtx_sent = 0, rtt = 0; guint64 duplicates = 0, rtx_sent = 0, rtt = 0;
gint i;
ret = gst_structure_new_empty ("rist/x-receiver-stats"); ret = gst_structure_new_empty ("rist/x-receiver-stats");
session_stats = g_value_array_new (src->bonds->len);
g_signal_emit_by_name (src->rtpbin, "get-internal-session", 0, &session); for (i = 0; i < src->bonds->len; i++) {
GObject *session = NULL, *source = NULL;
GstStructure *sstats = NULL, *stats;
const gchar *rtp_from = NULL, *rtcp_from = NULL;
guint64 dropped = 0, received = 0;
GValue value = G_VALUE_INIT;
g_signal_emit_by_name (src->rtpbin, "get-internal-session", i, &session);
if (!session) if (!session)
return ret; continue;
g_signal_emit_by_name (session, "get-source-by-ssrc", src->rtp_ssrc, &source); stats = gst_structure_new_empty ("rist/x-receiver-session-stats");
g_signal_emit_by_name (session, "get-source-by-ssrc", src->rtp_ssrc,
&source);
if (source) { if (source) {
gint packets_lost; gint packet_lost;
g_object_get (source, "stats", &stats, NULL); g_object_get (source, "stats", &sstats, NULL);
gst_structure_get_int (stats, "packets-lost", &packets_lost); gst_structure_get_int (sstats, "packets-lost", &packet_lost);
gst_structure_free (stats); dropped = MAX (packet_lost, 0);
g_clear_object (&source); gst_structure_get_uint64 (sstats, "packets-received", &received);
dropped = MAX (packets_lost, 0); rtp_from = gst_structure_get_string (sstats, "rtp-from");
rtcp_from = gst_structure_get_string (sstats, "rtcp-from");
} }
g_object_unref (session); g_object_unref (session);
gst_structure_set (stats, "session-id", G_TYPE_INT, i,
"rtp-from", G_TYPE_STRING, rtp_from ? rtp_from : "",
"rtcp-from", G_TYPE_STRING, rtcp_from ? rtcp_from : "",
"dropped", G_TYPE_UINT64, MAX (dropped, 0),
"received", G_TYPE_UINT64, received, NULL);
if (sstats)
gst_structure_free (sstats);
g_clear_object (&source);
g_value_init (&value, GST_TYPE_STRUCTURE);
g_value_take_boxed (&value, stats);
g_value_array_append (session_stats, &value);
g_value_unset (&value);
total_dropped += dropped;
}
if (src->jitterbuffer) { if (src->jitterbuffer) {
GstStructure *stats;
g_object_get (src->jitterbuffer, "stats", &stats, NULL); g_object_get (src->jitterbuffer, "stats", &stats, NULL);
gst_structure_get (stats, "num-pushed", G_TYPE_UINT64, &received, gst_structure_get (stats,
"num-pushed", G_TYPE_UINT64, &total_received,
"num-lost", G_TYPE_UINT64, &lost, "num-lost", G_TYPE_UINT64, &lost,
"rtx-count", G_TYPE_UINT64, &rtx_sent, "rtx-count", G_TYPE_UINT64, &rtx_sent,
"num-duplicates", G_TYPE_UINT64, &duplicates, "num-duplicates", G_TYPE_UINT64, &duplicates,
@ -669,13 +704,15 @@ gst_rist_src_create_stats (GstRistSrc * src)
gst_structure_free (stats); gst_structure_free (stats);
} }
gst_structure_set (ret, "dropped", G_TYPE_UINT64, dropped, gst_structure_set (ret, "dropped", G_TYPE_UINT64, total_dropped,
"received", G_TYPE_UINT64, received, "received", G_TYPE_UINT64, total_received,
"recovered", G_TYPE_UINT64, recovered, "recovered", G_TYPE_UINT64, recovered,
"permanently-lost", G_TYPE_UINT64, lost, "permanently-lost", G_TYPE_UINT64, lost,
"duplicates", G_TYPE_UINT64, duplicates, "duplicates", G_TYPE_UINT64, duplicates,
"retransmission-requests-sent", G_TYPE_UINT64, rtx_sent, "retransmission-requests-sent", G_TYPE_UINT64, rtx_sent,
"rtx-roundtrip-time", G_TYPE_UINT64, rtt, NULL); "rtx-roundtrip-time", G_TYPE_UINT64, rtt,
"session-stats", G_TYPE_VALUE_ARRAY, session_stats, NULL);
g_value_array_free (session_stats);
return ret; return ret;
} }