jitterbuffer: fix buffer level with invalid DTS
authorWim Taymans <wtaymans@redhat.com>
Mon, 3 Mar 2014 10:34:00 +0000 (11:34 +0100)
committerWim Taymans <wtaymans@redhat.com>
Mon, 3 Mar 2014 10:34:00 +0000 (11:34 +0100)
It is possible that the DTS is invalid (when we receive RTP packets from
TCP, for example). As a fallback, use the reconstructed PTS value to
calculate the buffer level.

gst/rtpmanager/rtpjitterbuffer.c

index ef50b4f..1262f7d 100644 (file)
@@ -253,7 +253,7 @@ get_buffer_level (RTPJitterBuffer * jbuf)
   /* first first buffer with timestamp */
   high_buf = (RTPJitterBufferItem *) g_queue_peek_tail_link (jbuf->packets);
   while (high_buf) {
-    if (high_buf->dts != -1)
+    if (high_buf->dts != -1 || high_buf->pts != -1)
       break;
 
     high_buf = (RTPJitterBufferItem *) g_list_previous (high_buf);
@@ -261,7 +261,7 @@ get_buffer_level (RTPJitterBuffer * jbuf)
 
   low_buf = (RTPJitterBufferItem *) g_queue_peek_head_link (jbuf->packets);
   while (low_buf) {
-    if (low_buf->dts != -1)
+    if (low_buf->dts != -1 || low_buf->pts != -1)
       break;
 
     low_buf = (RTPJitterBufferItem *) g_list_next (low_buf);
@@ -272,8 +272,8 @@ get_buffer_level (RTPJitterBuffer * jbuf)
   } else {
     guint64 high_ts, low_ts;
 
-    high_ts = high_buf->dts;
-    low_ts = low_buf->dts;
+    high_ts = high_buf->dts != -1 ? high_buf->dts : high_buf->pts;
+    low_ts = low_buf->dts != -1 ? low_buf->dts : low_buf->pts;
 
     if (high_ts > low_ts)
       level = high_ts - low_ts;