[xiph-commits] r14212 - in trunk/speex: include/speex libspeex

jm at svn.xiph.org jm at svn.xiph.org
Wed Nov 21 20:35:44 PST 2007


Author: jm
Date: 2007-11-21 20:35:44 -0800 (Wed, 21 Nov 2007)
New Revision: 14212

Modified:
   trunk/speex/include/speex/speex_jitter.h
   trunk/speex/libspeex/jitter.c
Log:
jitter buffer will by default auto-adjust the delay.


Modified: trunk/speex/include/speex/speex_jitter.h
===================================================================
--- trunk/speex/include/speex/speex_jitter.h	2007-11-22 04:11:26 UTC (rev 14211)
+++ trunk/speex/include/speex/speex_jitter.h	2007-11-22 04:35:44 UTC (rev 14212)
@@ -72,8 +72,6 @@
 #define JITTER_BUFFER_MISSING 1
 /** A "fake" packet is meant to be inserted here to increase buffering */
 #define JITTER_BUFFER_INSERTION 2
-/** One (or more) packet got automatically deleted  */
-#define JITTER_BUFFER_DELETION 2
 /** There was an error in the jitter buffer */
 #define JITTER_BUFFER_INTERNAL_ERROR -1
 /** Invalid argument */

Modified: trunk/speex/libspeex/jitter.c
===================================================================
--- trunk/speex/libspeex/jitter.c	2007-11-22 04:11:26 UTC (rev 14211)
+++ trunk/speex/libspeex/jitter.c	2007-11-22 04:35:44 UTC (rev 14212)
@@ -153,7 +153,8 @@
    int buffer_margin;                                          /**< How many frames we want to keep in the buffer (lower bound) */
    int late_cutoff;                                            /**< How late must a packet be for it not to be considered at all */
    int interp_requested;                                       /**< An interpolation is requested by speex_jitter_update_delay() */
-
+   int auto_adjust;                                            /**< Whether to automatically adjust the delay at any time */
+   
    struct TimingBuffer _tb[MAX_BUFFERS];                       /**< Don't use those directly */
    struct TimingBuffer *timeBuffers[MAX_BUFFERS];              /**< Storing arrival time of latest frames so we can compute some stats */
    int window_size;                                            /**< Total window over which the late frames are counted */
@@ -284,6 +285,7 @@
       jitter->late_cutoff = 50;
       jitter->destroy = NULL;
       jitter->latency_tradeoff = 0;
+      jitter->auto_adjust = 1;
       tmp = 4;
       jitter_buffer_ctl(jitter, JITTER_BUFFER_SET_MAX_LATE_RATE, &tmp);
       jitter_buffer_reset(jitter);
@@ -706,6 +708,39 @@
    }
 }
 
+/* Let the jitter buffer know it's the right time to adjust the buffering delay to the network conditions */
+static int _jitter_buffer_update_delay(JitterBuffer *jitter, JitterBufferPacket *packet, spx_int32_t *start_offset)
+{
+   spx_int16_t opt = compute_opt_delay(jitter);
+   /*fprintf(stderr, "opt adjustment is %d ", opt);*/
+   
+   if (opt < 0)
+   {
+      shift_timings(jitter, -opt);
+      
+      jitter->pointer_timestamp += opt;
+      jitter->interp_requested = -opt;
+      /*fprintf (stderr, "Decision to interpolate %d samples\n", -opt);*/
+   } else if (opt > 0)
+   {
+      shift_timings(jitter, -opt);
+      jitter->pointer_timestamp += opt;
+      /*fprintf (stderr, "Decision to drop %d samples\n", opt);*/
+   }
+   
+   return opt;
+}
+
+/* Let the jitter buffer know it's the right time to adjust the buffering delay to the network conditions */
+int jitter_buffer_update_delay(JitterBuffer *jitter, JitterBufferPacket *packet, spx_int32_t *start_offset)
+{
+   /* If the programmer calls jitter_buffer_update_delay() directly, 
+      automatically disable auto-adjustment */
+   jitter->auto_adjust = 0;
+
+   return _jitter_buffer_update_delay(jitter, packet, start_offset);
+}
+
 /** Get pointer timestamp of jitter buffer */
 int jitter_buffer_get_pointer_timestamp(JitterBuffer *jitter)
 {
@@ -714,6 +749,10 @@
 
 void jitter_buffer_tick(JitterBuffer *jitter)
 {
+   /* Automatically-adjust the buffering delay if requested */
+   if (jitter->auto_adjust)
+      _jitter_buffer_update_delay(jitter, NULL, NULL);
+   
    if (jitter->buffered >= 0)
    {
       jitter->next_stop = jitter->pointer_timestamp - jitter->buffered;
@@ -726,33 +765,15 @@
 
 void jitter_buffer_remaining_span(JitterBuffer *jitter, spx_uint32_t rem)
 {
+   /* Automatically-adjust the buffering delay if requested */
+   if (jitter->auto_adjust)
+      _jitter_buffer_update_delay(jitter, NULL, NULL);
+   
    if (jitter->buffered < 0)
       speex_warning_int("jitter buffer sees negative buffering, your code might be broken. Value is ", jitter->buffered);
    jitter->next_stop = jitter->pointer_timestamp - rem;
 }
 
-/* Let the jitter buffer know it's the right time to adjust the buffering delay to the network conditions */
-int jitter_buffer_update_delay(JitterBuffer *jitter, JitterBufferPacket *packet, spx_int32_t *start_offset)
-{
-   spx_int16_t opt = compute_opt_delay(jitter);
-   /*fprintf(stderr, "opt adjustment is %d ", opt);*/
-   
-   if (opt < 0)
-   {
-      shift_timings(jitter, -opt);
-      
-      jitter->pointer_timestamp += opt;
-      jitter->interp_requested = -opt;
-      /*fprintf (stderr, "Decision to interpolate %d samples\n", -opt);*/
-   } else if (opt > 0)
-   {
-      shift_timings(jitter, -opt);
-      jitter->pointer_timestamp += opt;
-      /*fprintf (stderr, "Decision to drop %d samples\n", opt);*/
-   }
-   
-   return opt;
-}
 
 /* Used like the ioctl function to control the jitter buffer parameters */
 int jitter_buffer_ctl(JitterBuffer *jitter, int request, void *ptr)



More information about the commits mailing list