From ae48646d8eda08ac21aaa0a7826043b1bc875615 Mon Sep 17 00:00:00 2001 From: Antonio Ospite Date: Thu, 4 Apr 2019 13:17:34 +0200 Subject: [PATCH] rtpsource: fix receiver source stats to consider previously queued packets When it is not clear yet if a packet relative to a source should be pushed, the packet is put into a queue, this happens in two cases: - the source is still in probation; - there is a large jump in seqnum, and it is not clear what the cause is, future packets will help making a guess. In either case stats about received packets are not updated at all; and even if they were, when init_seq() is called it resets all receiver stats, effectively loosing any possible stat about previously received packets. Fix this by taking into account the queued packets and update the stats when calling init_seq(). --- gst/rtpmanager/rtpsource.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/gst/rtpmanager/rtpsource.c b/gst/rtpmanager/rtpsource.c index f4755c7130..1f9ffb102b 100644 --- a/gst/rtpmanager/rtpsource.c +++ b/gst/rtpmanager/rtpsource.c @@ -1017,6 +1017,28 @@ no_clock_rate: } } +static void +update_queued_stats (GstBuffer * buffer, RTPSource * src) +{ + GstRTPBuffer rtp = { NULL }; + guint payload_len; + guint64 bytes; + + /* no need to check the return value, a queued packet is a valid RTP one */ + gst_rtp_buffer_map (buffer, GST_MAP_READ, &rtp); + payload_len = gst_rtp_buffer_get_payload_len (&rtp); + + bytes = gst_buffer_get_size (buffer) + UDP_IP_HEADER_OVERHEAD; + + src->stats.octets_received += payload_len; + src->stats.bytes_received += bytes; + src->stats.packets_received++; + /* for the bitrate estimation consider all lower level headers */ + src->bytes_received += bytes; + + gst_rtp_buffer_unmap (&rtp); +} + static void init_seq (RTPSource * src, guint16 seq) { @@ -1032,6 +1054,9 @@ init_seq (RTPSource * src, guint16 seq) src->stats.recv_pli_count = 0; src->stats.recv_fir_count = 0; + /* if there are queued packets, consider them too in the stats */ + g_queue_foreach (src->packets, (GFunc) update_queued_stats, src); + GST_DEBUG ("base_seq %d", seq); }