jitterbuffer: correctly check for invalid values
authorWim Taymans <wtaymans@redhat.com>
Mon, 9 Dec 2013 22:34:10 +0000 (23:34 +0100)
committerWim Taymans <wtaymans@redhat.com>
Mon, 9 Dec 2013 22:34:10 +0000 (23:34 +0100)
Check for -1 on the guint from the buffer item instead of on the guint16
or guint32.
Also insert -1 seqnum at the head of the jitterbuffer.

gst/rtpmanager/rtpjitterbuffer.c
gst/rtpmanager/rtpjitterbuffer.h

index 639e227..e40bece 100644 (file)
@@ -653,10 +653,13 @@ rtp_jitter_buffer_insert (RTPJitterBuffer * jbuf, RTPJitterBufferItem * item,
   g_return_val_if_fail (jbuf != NULL, FALSE);
   g_return_val_if_fail (item != NULL, FALSE);
 
-  seqnum = item->seqnum;
   /* no seqnum, simply append then */
-  if (seqnum == -1)
+  if (item->seqnum == -1) {
+    list = jbuf->packets->head;
     goto append;
+  }
+
+  seqnum = item->seqnum;
 
   /* loop the list to skip strictly smaller seqnum buffers */
   for (list = jbuf->packets->head; list; list = g_list_next (list)) {
@@ -664,10 +667,11 @@ rtp_jitter_buffer_insert (RTPJitterBuffer * jbuf, RTPJitterBufferItem * item,
     gint gap;
     RTPJitterBufferItem *qitem = (RTPJitterBufferItem *) list;
 
-    qseq = qitem->seqnum;
-    if (qseq == -1)
+    if (qitem->seqnum == -1)
       continue;
 
+    qseq = qitem->seqnum;
+
     /* compare the new seqnum to the one in the buffer */
     gap = gst_rtp_buffer_compare_seqnum (seqnum, qseq);
 
@@ -681,11 +685,11 @@ rtp_jitter_buffer_insert (RTPJitterBuffer * jbuf, RTPJitterBufferItem * item,
   }
 
   dts = item->dts;
-  rtptime = item->rtptime;
-
-  if (rtptime == -1)
+  if (item->rtptime == -1)
     goto append;
 
+  rtptime = item->rtptime;
+
   /* rtp time jumps are checked for during skew calculation, but bypassed
    * in other mode, so mind those here and reset jb if needed.
    * Only reset if valid input time, which is likely for UDP input
index 845c136..63eff02 100644 (file)
@@ -111,10 +111,12 @@ struct _RTPJitterBufferClass {
  * @data: the data of the item
  * @next: pointer to next item
  * @prev: pointer to previous item
- * @type: the type of @data
+ * @type: the type of @data, used freely by caller
  * @dts: input DTS
  * @pts: output PTS
- * @seqnum: seqnum
+ * @seqnum: seqnum, the seqnum is used to insert the item in the
+ *   right position in the jitterbuffer and detect duplicates. Use -1 to
+ *   append.
  * @count: amount of seqnum in this item
  * @rtptime: rtp timestamp
  *