rtpsource: fix receiver source stats to consider previously queued packets
authorAntonio Ospite <antonio.ospite@collabora.com>
Thu, 4 Apr 2019 11:17:34 +0000 (13:17 +0200)
committerAntonio Ospite <antonio.ospite@collabora.com>
Fri, 2 Aug 2019 15:22:51 +0000 (17:22 +0200)
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

index f4755c7..1f9ffb1 100644 (file)
@@ -1018,6 +1018,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)
 {
   src->stats.base_seq = 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);
 }