[xiph-commits] r14161 - trunk/speex/libspeex

jm at svn.xiph.org jm at svn.xiph.org
Thu Nov 15 18:40:09 PST 2007


Author: jm
Date: 2007-11-15 18:40:08 -0800 (Thu, 15 Nov 2007)
New Revision: 14161

Modified:
   trunk/speex/libspeex/jitter.c
Log:
jitter buffer: make tick() a tiny bit smarter.


Modified: trunk/speex/libspeex/jitter.c
===================================================================
--- trunk/speex/libspeex/jitter.c	2007-11-16 01:53:59 UTC (rev 14160)
+++ trunk/speex/libspeex/jitter.c	2007-11-16 02:40:08 UTC (rev 14161)
@@ -34,7 +34,6 @@
 
 /*
 TODO:
-- Make tick() smarter by using the desired and returned span of the last get()
 - Add short-term estimate
 - Defensive programming
   + warn when last returned < last desired (begative buffering)
@@ -145,6 +144,8 @@
    spx_uint32_t last_returned_timestamp;
    spx_uint32_t next_stop;
    
+   spx_int32_t buffered;                                       /**< Amount of data we think is still buffered by the application (timestamp units)*/
+   
    JitterBufferPacket packets[SPEEX_JITTER_MAX_BUFFER_SIZE];   /**< Packets stored in the buffer */
    spx_uint32_t arrival[SPEEX_JITTER_MAX_BUFFER_SIZE];         /**< Packet arrival time (0 means it was late, even though it's a valid timestamp) */
    
@@ -274,7 +275,6 @@
       /*FIXME: Should this be 0 or 1?*/
       jitter->buffer_margin = 0;
       jitter->late_cutoff = 50;
-      jitter->auto_tradeoff = 32000;
       jitter->destroy = NULL;
       jitter->latency_tradeoff = 0;
       tmp = 4;
@@ -304,6 +304,8 @@
    jitter->next_stop = 0;
    jitter->reset_state = 1;
    jitter->lost_count = 0;
+   jitter->buffered = 0;
+   jitter->auto_tradeoff = 32000;
    
    for (i=0;i<MAX_BUFFERS;i++)
    {
@@ -473,6 +475,8 @@
       
       jitter->interp_requested = 0;
       
+      jitter->buffered = packet->span - desired_span;
+
       return JITTER_BUFFER_MISSING;
    }
    
@@ -574,6 +578,8 @@
       /* Point to the end of the current packet */
       jitter->pointer_timestamp = jitter->packets[i].timestamp+jitter->packets[i].span;
 
+      jitter->buffered = *start_offset + packet->span - desired_span;
+
       if (incomplete)
          return JITTER_BUFFER_INCOMPLETE;
       else
@@ -618,6 +624,7 @@
       /*fprintf (stderr, "Normal loss\n");*/
    }
 
+   jitter->buffered = packet->span - desired_span;
    return JITTER_BUFFER_MISSING;
 
 }
@@ -664,11 +671,20 @@
 
 void jitter_buffer_tick(JitterBuffer *jitter)
 {
-   jitter->next_stop = jitter->pointer_timestamp;
+   if (jitter->buffered >= 0)
+   {
+      jitter->next_stop = jitter->pointer_timestamp - jitter->buffered;
+   } else {
+      jitter->next_stop = jitter->pointer_timestamp;
+      speex_warning_int("jitter buffer sees negative buffering, you code might be broken. Value is ", jitter->buffered);
+   }
+   jitter->buffered = 0;
 }
 
 void jitter_buffer_remaining_span(JitterBuffer *jitter, spx_uint32_t rem)
 {
+   if (jitter->buffered < 0)
+      speex_warning_int("jitter buffer sees negative buffering, you code might be broken. Value is ", jitter->buffered);
    jitter->next_stop = jitter->pointer_timestamp - rem;
 }
 



More information about the commits mailing list