From 0fa589a3dd5df5a588401c173a66db60860b557c Mon Sep 17 00:00:00 2001 From: Havard Graff Date: Mon, 31 Aug 2009 18:34:08 +0200 Subject: [PATCH] rtpmanager: provide additional statistics --- gst/rtpmanager/rtpsource.c | 42 ++++++++++++++++++++++---------------- gst/rtpmanager/rtpstats.c | 24 ++++++++++++++++++++++ gst/rtpmanager/rtpstats.h | 2 +- 3 files changed, 49 insertions(+), 19 deletions(-) diff --git a/gst/rtpmanager/rtpsource.c b/gst/rtpmanager/rtpsource.c index 247fa7a1af..b4b8572844 100644 --- a/gst/rtpmanager/rtpsource.c +++ b/gst/rtpmanager/rtpsource.c @@ -209,7 +209,9 @@ rtp_source_create_stats (RTPSource * src) "validated", G_TYPE_BOOLEAN, src->validated, "received-bye", G_TYPE_BOOLEAN, src->received_bye, "is-csrc", G_TYPE_BOOLEAN, src->is_csrc, - "is-sender", G_TYPE_BOOLEAN, is_sender, NULL); + "is-sender", G_TYPE_BOOLEAN, is_sender, + "seqnum-base", G_TYPE_INT, src->seqnum_base, + "clock-rate", G_TYPE_INT, src->clock_rate, NULL); /* add address and port */ if (src->have_rtp_from) { @@ -225,17 +227,18 @@ rtp_source_create_stats (RTPSource * src) if (internal) { /* our internal source */ - if (is_sender) { - /* if we are sending, report about how much we sent, other sources will - * have a RB with info on reception. */ - gst_structure_set (s, - "octets-sent", G_TYPE_UINT64, src->stats.octets_sent, - "packets-sent", G_TYPE_UINT64, src->stats.packets_sent, - "bitrate", G_TYPE_UINT64, src->bitrate, NULL); - } else { - /* if we are not sending we have nothing more to report */ - } + + /* report accumulated send statistics, other sources will have a RB with + * info on reception. */ + gst_structure_set (s, + "octets-sent", G_TYPE_UINT64, src->stats.octets_sent, + "packets-sent", G_TYPE_UINT64, src->stats.packets_sent, NULL); + + if (is_sender) + gst_structure_set (s, "bitrate", G_TYPE_UINT64, src->bitrate, NULL); + } else { + /* other sources */ gboolean have_rb; guint8 fractionlost = 0; gint32 packetslost = 0; @@ -245,7 +248,13 @@ rtp_source_create_stats (RTPSource * src) guint32 dlsr = 0; guint32 round_trip = 0; - /* other sources */ + gst_structure_set (s, + "octets-received", G_TYPE_UINT64, src->stats.octets_received, + "packets-received", G_TYPE_UINT64, src->stats.packets_received, + "bitrate", G_TYPE_UINT64, src->bitrate, + "packets-lost", G_TYPE_INT, (gint) rtp_stats_get_packets_lost (&src->stats), + "jitter", G_TYPE_UINT, (guint) (src->stats.jitter >> 4), NULL); + if (is_sender) { gboolean have_sr; GstClockTime time = 0; @@ -258,9 +267,6 @@ rtp_source_create_stats (RTPSource * src) have_sr = rtp_source_get_last_sr (src, &time, &ntptime, &rtptime, &packet_count, &octet_count); gst_structure_set (s, - "octets-received", G_TYPE_UINT64, src->stats.octets_received, - "packets-received", G_TYPE_UINT64, src->stats.packets_received, - "bitrate", G_TYPE_UINT64, src->bitrate, "have-sr", G_TYPE_BOOLEAN, have_sr, "sr-ntptime", G_TYPE_UINT64, ntptime, "sr-rtptime", G_TYPE_UINT, (guint) rtptime, @@ -899,11 +905,11 @@ do_bitrate_estimation (RTPSource * src, GstClockTime running_time, elapsed = running_time - src->prev_rtime; if (elapsed > (G_GINT64_CONSTANT (1) << 31)) { + const guint64 bits_per_byte = G_GUINT64_CONSTANT (8); guint64 rate; - rate = - gst_util_uint64_scale (*bytes_handled, elapsed, - (G_GINT64_CONSTANT (1) << 29)); + rate = gst_util_uint64_scale (*bytes_handled, + bits_per_byte * GST_SECOND, elapsed); GST_LOG ("Elapsed %" G_GUINT64_FORMAT ", bytes %" G_GUINT64_FORMAT ", rate %" G_GUINT64_FORMAT, elapsed, *bytes_handled, rate); diff --git a/gst/rtpmanager/rtpstats.c b/gst/rtpmanager/rtpstats.c index 245c6c007b..a6de7d880b 100644 --- a/gst/rtpmanager/rtpstats.c +++ b/gst/rtpmanager/rtpstats.c @@ -261,3 +261,27 @@ rtp_stats_calculate_bye_interval (RTPSessionStats * stats) return interval * GST_SECOND; } + +/** + * rtp_stats_get_packets_lost: + * @stats: an #RTPSourceStats struct + * + * Calculate the total number of RTP packets lost since beginning of + * reception. Packets that arrive late are not considered lost, and + * duplicates are not taken into account. Hence, the loss may be negative + * if there are duplicates. + * + * Returns: total RTP packets lost. + */ +gint64 +rtp_stats_get_packets_lost (const RTPSourceStats *stats) +{ + gint64 lost; + guint64 extended_max, expected; + + extended_max = stats->cycles + stats->max_seq; + expected = extended_max - stats->base_seq + 1; + lost = expected - stats->packets_received; + + return lost; +} \ No newline at end of file diff --git a/gst/rtpmanager/rtpstats.h b/gst/rtpmanager/rtpstats.h index cb447b80c7..d657cdfed0 100644 --- a/gst/rtpmanager/rtpstats.h +++ b/gst/rtpmanager/rtpstats.h @@ -194,5 +194,5 @@ void rtp_stats_set_bandwidths (RTPSessionStats *stats, GstClockTime rtp_stats_calculate_rtcp_interval (RTPSessionStats *stats, gboolean sender, gboolean first); GstClockTime rtp_stats_add_rtcp_jitter (RTPSessionStats *stats, GstClockTime interval); GstClockTime rtp_stats_calculate_bye_interval (RTPSessionStats *stats); - +gint64 rtp_stats_get_packets_lost (const RTPSourceStats *stats); #endif /* __RTP_STATS_H__ */