[xiph-commits] r14091 - in trunk/speex: include/speex libspeex
speexclient
jm at svn.xiph.org
jm at svn.xiph.org
Sat Nov 3 14:59:23 PDT 2007
Author: jm
Date: 2007-11-03 14:59:22 -0700 (Sat, 03 Nov 2007)
New Revision: 14091
Modified:
trunk/speex/include/speex/speex_jitter.h
trunk/speex/libspeex/jitter.c
trunk/speex/speexclient/speex_jitter_buffer.c
trunk/speex/speexclient/speexclient.c
Log:
jitter buffer: Cleaned up the remaining of the Speex-specific buffer and fixed
a bug in the timestamp adjustment when interpolating.
Modified: trunk/speex/include/speex/speex_jitter.h
===================================================================
--- trunk/speex/include/speex/speex_jitter.h 2007-11-02 10:45:21 UTC (rev 14090)
+++ trunk/speex/include/speex/speex_jitter.h 2007-11-03 21:59:22 UTC (rev 14091)
@@ -41,8 +41,7 @@
* @{
*/
-#include "speex.h"
-#include "speex_bits.h"
+#include "speex/speex_types.h"
#ifdef __cplusplus
extern "C" {
@@ -178,45 +177,8 @@
/* @} */
-/** @defgroup SpeexJitter SpeexJitter: Adaptive jitter buffer specifically for Speex
- * This is the jitter buffer that reorders UDP/RTP packets and adjusts the buffer size
- * to maintain good quality and low latency. This is a simplified version that works only
- * with Speex, but is much easier to use.
- * @{
-*/
-
-/** Speex jitter-buffer state. Never use it directly! */
-typedef struct SpeexJitter {
- SpeexBits current_packet; /**< Current Speex packet */
- int valid_bits; /**< True if Speex bits are valid */
- JitterBuffer *packets; /**< Generic jitter buffer state */
- void *dec; /**< Pointer to Speex decoder */
- spx_int32_t frame_size; /**< Frame size of Speex decoder */
-} SpeexJitter;
-
-/** Initialise jitter buffer
- *
- * @param jitter State of the Speex jitter buffer
- * @param decoder Speex decoder to call
- * @param sampling_rate Sampling rate used by the decoder
-*/
-void speex_jitter_init(SpeexJitter *jitter, void *decoder, int sampling_rate);
-
-/** Destroy jitter buffer */
-void speex_jitter_destroy(SpeexJitter *jitter);
-
-/** Put one packet into the jitter buffer */
-void speex_jitter_put(SpeexJitter *jitter, char *packet, int len, int timestamp);
-
-/** Get one packet from the jitter buffer */
-void speex_jitter_get(SpeexJitter *jitter, spx_int16_t *out, int *start_offset);
-
-/** Get pointer timestamp of jitter buffer */
-int speex_jitter_get_pointer_timestamp(SpeexJitter *jitter);
-
#ifdef __cplusplus
}
#endif
-/* @} */
#endif
Modified: trunk/speex/libspeex/jitter.c
===================================================================
--- trunk/speex/libspeex/jitter.c 2007-11-02 10:45:21 UTC (rev 14090)
+++ trunk/speex/libspeex/jitter.c 2007-11-03 21:59:22 UTC (rev 14091)
@@ -87,6 +87,7 @@
int resolution; /**< Time resolution for histogram (timestamp units) */
int delay_step; /**< Size of the steps when adjusting buffering (timestamp units) */
+ int res_delay_step; /**< Size of the steps when adjusting buffering (resolution units) */
int reset_state; /**< True if state was just reset */
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 */
@@ -116,6 +117,7 @@
jitter->packets[i].data=NULL;
jitter->resolution = resolution;
jitter->delay_step = resolution;
+ jitter->res_delay_step = 1;
//FIXME: Should this be 0 or 1?
jitter->buffer_margin = 1;
jitter->late_cutoff = 50;
@@ -243,13 +245,20 @@
jitter->late_ratio_short += jitter->shortterm_margin[i];
jitter->late_ratio_long += jitter->longterm_margin[i];
}
+
/* Count the proportion of packets that are just on time */
- jitter->ontime_ratio_short = jitter->shortterm_margin[LATE_BINS];
- jitter->ontime_ratio_long = jitter->longterm_margin[LATE_BINS];
+ jitter->ontime_ratio_short = 0;
+ jitter->ontime_ratio_long = 0;
+ for (;i<LATE_BINS+jitter->res_delay_step;i++)
+ {
+ jitter->ontime_ratio_short = jitter->shortterm_margin[i];
+ jitter->ontime_ratio_long = jitter->longterm_margin[i];
+ }
+
jitter->early_ratio_short = 0;
jitter->early_ratio_long = 0;
/* Count the proportion of packets that are early */
- for (i=LATE_BINS+1;i<MAX_MARGIN;i++)
+ for (;i<MAX_MARGIN;i++)
{
jitter->early_ratio_short += jitter->shortterm_margin[i];
jitter->early_ratio_long += jitter->longterm_margin[i];
@@ -522,14 +531,14 @@
/* Increase buffering */
/* Shift histogram to compensate */
- shift_histogram(jitter, 1);
+ shift_histogram(jitter, jitter->res_delay_step);
packet->timestamp = jitter->pointer_timestamp;
packet->span = jitter->delay_step;
/* Don't move the pointer_timestamp forward */
packet->len = 0;
- jitter->pointer_timestamp -= jitter->delay_step;
+ /*jitter->pointer_timestamp -= jitter->delay_step;*/
fprintf (stderr, "Forced to interpolate\n");
} else {
/* Normal packet loss */
@@ -605,7 +614,7 @@
if (jitter->late_ratio_short > .1 || jitter->late_ratio_long > .03)
{
/* If too many packets are arriving late */
- shift_histogram(jitter, 1);
+ shift_histogram(jitter, jitter->res_delay_step);
jitter->pointer_timestamp -= jitter->delay_step;
jitter->interp_requested = 1;
@@ -615,7 +624,7 @@
} else if (jitter->late_ratio_short + jitter->ontime_ratio_short < .005 && jitter->late_ratio_long + jitter->ontime_ratio_long < .01 && jitter->early_ratio_short > .8)
{
/* Many frames arriving early */
- shift_histogram(jitter, -1);
+ shift_histogram(jitter, -jitter->res_delay_step);
jitter->pointer_timestamp += jitter->delay_step;
fprintf (stderr, "Decision to drop\n");
@@ -656,6 +665,7 @@
break;
case JITTER_BUFFER_SET_DELAY_STEP:
jitter->delay_step = *(spx_int32_t*)ptr;
+ jitter->res_delay_step = jitter->delay_step/jitter->resolution;
break;
case JITTER_BUFFER_GET_DELAY_STEP:
*(spx_int32_t*)ptr = jitter->delay_step;
Modified: trunk/speex/speexclient/speex_jitter_buffer.c
===================================================================
--- trunk/speex/speexclient/speex_jitter_buffer.c 2007-11-02 10:45:21 UTC (rev 14090)
+++ trunk/speex/speexclient/speex_jitter_buffer.c 2007-11-03 21:59:22 UTC (rev 14091)
@@ -1,4 +1,5 @@
#include <speex/speex_jitter.h>
+#include "speex_jitter_buffer.h"
#ifndef NULL
#define NULL 0
Modified: trunk/speex/speexclient/speexclient.c
===================================================================
--- trunk/speex/speexclient/speexclient.c 2007-11-02 10:45:21 UTC (rev 14090)
+++ trunk/speex/speexclient/speexclient.c 2007-11-03 21:59:22 UTC (rev 14091)
@@ -51,6 +51,7 @@
#include <speex/speex_jitter.h>
#include <speex/speex_preprocess.h>
#include <speex/speex_echo.h>
+#include "speex_jitter_buffer.h"
#include <sched.h>
More information about the commits
mailing list