From bcd469ff316086e0f6db0a5af2dc7cc3eea938fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Tue, 13 May 2014 12:25:04 -0700 Subject: [PATCH] rtpjitterbuffer: don't stop looping if event found in the queue 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 | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/gst/rtpmanager/rtpjitterbuffer.c b/gst/rtpmanager/rtpjitterbuffer.c index 1f05cd41cc..19a1ef3662 100644 --- a/gst/rtpmanager/rtpjitterbuffer.c +++ b/gst/rtpmanager/rtpjitterbuffer.c @@ -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;