From eb6d552353f056bbeb9e2086823ae9ee9efaacc3 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 20 Dec 2010 15:54:45 +0100 Subject: [PATCH] jitterbuffer: get better buffering level When the jitterbuffer contains -1 timestamps, make sure we still calculate the buffer fill level by skipping the -1 buffers. Try to be more resilient to weird input timestamps. --- gst/rtpmanager/rtpjitterbuffer.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/gst/rtpmanager/rtpjitterbuffer.c b/gst/rtpmanager/rtpjitterbuffer.c index 2dee30c..59307df 100644 --- a/gst/rtpmanager/rtpjitterbuffer.c +++ b/gst/rtpmanager/rtpjitterbuffer.c @@ -212,11 +212,30 @@ rtp_jitter_buffer_resync (RTPJitterBuffer * jbuf, GstClockTime time, static guint64 get_buffer_level (RTPJitterBuffer * jbuf) { - GstBuffer *high_buf, *low_buf; + GstBuffer *high_buf = NULL, *low_buf = NULL; guint64 level; + GList *find; - high_buf = g_queue_peek_head (jbuf->packets); - low_buf = g_queue_peek_tail (jbuf->packets); + /* first first buffer with timestamp */ + find = g_queue_peek_head_link (jbuf->packets); + while (find) { + high_buf = find->data; + if (GST_BUFFER_TIMESTAMP (high_buf) != -1) + break; + + high_buf = NULL; + find = g_list_next (find); + } + + find = g_queue_peek_tail_link (jbuf->packets); + while (find) { + low_buf = find->data; + if (GST_BUFFER_TIMESTAMP (low_buf) != -1) + break; + + low_buf = NULL; + find = g_list_previous (find); + } if (!high_buf || !low_buf || high_buf == low_buf) { level = 0; @@ -230,6 +249,11 @@ get_buffer_level (RTPJitterBuffer * jbuf) level = high_ts - low_ts; else level = 0; + + GST_LOG_OBJECT (jbuf, + "low %" GST_TIME_FORMAT " high %" GST_TIME_FORMAT " level %" + G_GUINT64_FORMAT, GST_TIME_ARGS (low_ts), GST_TIME_ARGS (high_ts), + level); } return level; } @@ -394,6 +418,8 @@ calculate_skew (RTPJitterBuffer * jbuf, guint32 rtptime, GstClockTime time, } else { GST_WARNING ("backward timestamps at server but no timestamps"); send_diff = 0; + /* at least try to get a new timestamp.. */ + jbuf->base_time = -1; } GST_DEBUG ("extrtp %" G_GUINT64_FORMAT ", gstrtp %" GST_TIME_FORMAT ", base %" -- 2.7.4