[xiph-commits] r14700 - trunk/speex/libspeex
jm at svn.xiph.org
jm at svn.xiph.org
Thu Apr 10 20:48:31 PDT 2008
Author: jm
Date: 2008-04-10 20:48:31 -0700 (Thu, 10 Apr 2008)
New Revision: 14700
Added:
trunk/speex/libspeex/testjitter.c
Modified:
trunk/speex/libspeex/Makefile.am
trunk/speex/libspeex/jitter.c
Log:
Thorvald Natvig contributed a fix the the jitter buffer resync and a testcase
for the jitter buffer.
Modified: trunk/speex/libspeex/Makefile.am
===================================================================
--- trunk/speex/libspeex/Makefile.am 2008-04-11 02:47:37 UTC (rev 14699)
+++ trunk/speex/libspeex/Makefile.am 2008-04-11 03:48:31 UTC (rev 14700)
@@ -32,7 +32,7 @@
libspeex_la_LDFLAGS = -no-undefined -version-info @SPEEX_LT_CURRENT@:@SPEEX_LT_REVISION@:@SPEEX_LT_AGE@
libspeexdsp_la_LDFLAGS = -no-undefined -version-info @SPEEX_LT_CURRENT@:@SPEEX_LT_REVISION@:@SPEEX_LT_AGE@
-noinst_PROGRAMS = testenc testenc_wb testenc_uwb testdenoise testecho
+noinst_PROGRAMS = testenc testenc_wb testenc_uwb testdenoise testecho testjitter
testenc_SOURCES = testenc.c
testenc_LDADD = libspeex.la
testenc_wb_SOURCES = testenc_wb.c
@@ -43,3 +43,5 @@
testdenoise_LDADD = libspeexdsp.la
testecho_SOURCES = testecho.c
testecho_LDADD = libspeexdsp.la
+testjitter_SOURCES = testjitter.c
+testjitter_LDADD = libspeexdsp.la
Modified: trunk/speex/libspeex/jitter.c
===================================================================
--- trunk/speex/libspeex/jitter.c 2008-04-11 02:47:37 UTC (rev 14699)
+++ trunk/speex/libspeex/jitter.c 2008-04-11 03:48:31 UTC (rev 14700)
@@ -398,6 +398,13 @@
} else {
late = 0;
}
+
+ /* For some reason, the consumer has failed the last 20 fetches. Make sure this packet is
+ * used to resync. */
+ if (jitter->lost_count>20)
+ {
+ jitter_buffer_reset(jitter);
+ }
/* Only insert the packet if it's not hopelessly late (i.e. totally useless) */
if (jitter->reset_state || GE32(packet->timestamp+packet->span+jitter->delay_step, jitter->pointer_timestamp))
@@ -428,10 +435,6 @@
else
speex_free(jitter->packets[i].data);
jitter->packets[i].data=NULL;
- if (jitter->lost_count>20)
- {
- jitter_buffer_reset(jitter);
- }
/*fprintf (stderr, "Buffer is full, discarding earliest frame %d (currently at %d)\n", timestamp, jitter->pointer_timestamp);*/
}
Added: trunk/speex/libspeex/testjitter.c
===================================================================
--- trunk/speex/libspeex/testjitter.c (rev 0)
+++ trunk/speex/libspeex/testjitter.c 2008-04-11 03:48:31 UTC (rev 14700)
@@ -0,0 +1,75 @@
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <speex/speex_jitter.h>
+#include <stdio.h>
+
+union jbpdata {
+ unsigned int idx;
+ unsigned char data[4];
+};
+
+void synthIn(JitterBufferPacket *in, int idx, int span) {
+ union jbpdata d;
+ d.idx = idx;
+
+ in->data = d.data;
+ in->len = sizeof(d);
+ in->timestamp = idx * 10;
+ in->span = span * 10;
+ in->sequence = idx;
+ in->user_data = 0;
+}
+
+void jitterFill(JitterBuffer *jb) {
+ char buffer[65536];
+ JitterBufferPacket in, out;
+ int i;
+
+ out.data = buffer;
+
+ jitter_buffer_reset(jb);
+
+ for(i=0;i<100;++i) {
+ synthIn(&in, i, 1);
+ jitter_buffer_put(jb, &in);
+
+ out.len = 65536;
+ if (jitter_buffer_get(jb, &out, 10, NULL) != JITTER_BUFFER_OK) {
+ printf("Fill test failed iteration %d\n", i);
+ }
+ if (out.timestamp != i * 10) {
+ printf("Fill test expected %d got %d\n", i*10, out.timestamp);
+ }
+ jitter_buffer_tick(jb);
+ }
+}
+
+int main()
+{
+ char buffer[65536];
+ JitterBufferPacket in, out;
+ int i;
+
+ JitterBuffer *jb = jitter_buffer_init(10);
+
+ out.data = buffer;
+
+ /* Frozen sender case */
+ jitterFill(jb);
+ for(i=0;i<100;++i) {
+ out.len = 65536;
+ jitter_buffer_get(jb, &out, 10, NULL);
+ jitter_buffer_tick(jb);
+ }
+ synthIn(&in, 100, 1);
+ jitter_buffer_put(jb, &in);
+ out.len = 65536;
+ if (jitter_buffer_get(jb, &out, 10, NULL) != JITTER_BUFFER_OK) {
+ printf("Failed frozen sender resynchronize\n");
+ } else {
+ printf("Frozen sender: Jitter %d\n", out.timestamp - 100*10);
+ }
+ return 0;
+}
More information about the commits
mailing list