From 0e41414926f17824fa27acc910bf46bd728b2ac3 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 1 Aug 2013 23:26:06 +0200 Subject: [PATCH] jitterbuffer: unschedule old expected packets When we receive a new packet, unschedule old outstanding packets when their seqnum is too far away. --- gst/rtpmanager/gstrtpjitterbuffer.c | 33 ++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/gst/rtpmanager/gstrtpjitterbuffer.c b/gst/rtpmanager/gstrtpjitterbuffer.c index 6c0cc7fc42..f8d85c4393 100644 --- a/gst/rtpmanager/gstrtpjitterbuffer.c +++ b/gst/rtpmanager/gstrtpjitterbuffer.c @@ -1422,6 +1422,9 @@ remove_all_timers (GstRtpJitterBuffer * jitterbuffer) } /* we just received a packet with seqnum and dts. + * + * First check for old seqnum that we are still expecting. If the gap with the + * current timestamp is too big, unschedule the timeouts. * * If we have a valid packet spacing estimate we can set a timer for when we * should receive the next packet. @@ -1433,10 +1436,34 @@ update_timers (GstRtpJitterBuffer * jitterbuffer, guint16 seqnum, GstClockTime dts) { GstRtpJitterBufferPrivate *priv = jitterbuffer->priv; - TimerData *timer; + TimerData *timer = NULL; + gint i, len; + + /* go through all timers and unschedule the ones with a large gap, also find + * the timer for the seqnum */ + len = priv->timers->len; + for (i = 0; i < len; i++) { + TimerData *test = &g_array_index (priv->timers, TimerData, i); + gint gap; + + if (test->type != TIMER_TYPE_EXPECTED) + continue; + + gap = gst_rtp_buffer_compare_seqnum (test->seqnum, seqnum); + + GST_DEBUG_OBJECT (jitterbuffer, "%d, #%d<->#%d gap %d", i, + test->seqnum, seqnum, gap); + + if (gap == 0) { + /* the timer for the current seqnum */ + timer = test; + } else if (gap > 5) { + /* max gap, we exceeded the max reorder distance and we don't expect the + * missing packet to be this reordered */ + reschedule_timer (jitterbuffer, test, test->seqnum, -1); + } + } - /* find the timer for the current seqnum. */ - timer = find_timer (jitterbuffer, TIMER_TYPE_EXPECTED, seqnum); if (priv->packet_spacing > 0) { GstClockTime expected;