rtpjitterbuffer: don't stop looping if event found in the queue
authorAleix Conchillo FlaquƩ <aleix@oblong.com>
Tue, 13 May 2014 19:25:04 +0000 (12:25 -0700)
committerWim Taymans <wtaymans@redhat.com>
Wed, 14 May 2014 08:23:28 +0000 (10:23 +0200)
If we are inserting a packet into the jitter queue we need to keep
looping through the items until the right position is found. Currently,
the code stops as soon as an event is found in the queue.

Regarding events, we should only move packets before an event if there
is another packet before the event that has a larger seqnum.

Fixes https://bugzilla.gnome.org/show_bug.cgi?id=730078

gst/rtpmanager/rtpjitterbuffer.c

index 1f05cd4..19a1ef3 100644 (file)
@@ -664,7 +664,7 @@ gboolean
 rtp_jitter_buffer_insert (RTPJitterBuffer * jbuf, RTPJitterBufferItem * item,
     gboolean * head, gint * percent)
 {
-  GList *list;
+  GList *list, *event = NULL;
   guint32 rtptime;
   guint16 seqnum;
   GstClockTime dts;
@@ -686,8 +686,14 @@ rtp_jitter_buffer_insert (RTPJitterBuffer * jbuf, RTPJitterBufferItem * item,
     gint gap;
     RTPJitterBufferItem *qitem = (RTPJitterBufferItem *) list;
 
-    if (qitem->seqnum == -1)
-      break;
+    if (qitem->seqnum == -1) {
+      /* keep a pointer to the first consecutive event if not already
+       * set. we will insert the packet after the event if we can't find
+       * a packet with lower sequence number before the event. */
+      if (event == NULL)
+        event = list;
+      continue;
+    }
 
     qseq = qitem->seqnum;
 
@@ -701,8 +707,17 @@ rtp_jitter_buffer_insert (RTPJitterBuffer * jbuf, RTPJitterBufferItem * item,
     /* seqnum > qseq, we can stop looking */
     if (G_LIKELY (gap < 0))
       break;
+
+    /* if we've found a packet with greater sequence number, cleanup the
+     * event pointer as the packet will be inserted before the event */
+    event = NULL;
   }
 
+  /* if event is set it means that packets before the event had smaller
+   * sequence number, so we will insert our packet after the event */
+  if (event)
+    list = event;
+
   dts = item->dts;
   if (item->rtptime == -1)
     goto append;