Index: jitterbuf.c =================================================================== RCS file: /usr/cvsroot/asterisk/jitterbuf.c,v retrieving revision 1.14 diff -a -u -r1.14 jitterbuf.c --- jitterbuf.c 2 Jun 2005 17:45:38 -0000 1.14 +++ jitterbuf.c 2 Jun 2005 19:35:10 -0000 @@ -555,6 +555,10 @@ jb->info.next_voice_ts += interpl; jb->info.last_voice_ms = interpl; jb->info.last_adjustment = now; + jb->info.cnt_contig_interp++; + if (jb->info.conf.max_contig_interp && jb->info.cnt_contig_interp >= jb->info.conf.max_contig_interp) { + jb->info.silence_begin_ts = jb->info.next_voice_ts - jb->info.current; + } jb_dbg("G"); return JB_INTERP; } @@ -563,8 +567,10 @@ /* not a voice frame; just return it. */ if (frame && frame->type != JB_TYPE_VOICE) { - if (frame->type == JB_TYPE_SILENCE) + if (frame->type == JB_TYPE_SILENCE) { jb->info.silence_begin_ts = frame->ts; + jb->info.cnt_contig_interp = 0; + } *frameout = *frame; jb->info.frames_out++; @@ -583,6 +589,7 @@ jb->info.next_voice_ts = frame->ts + jb->info.current + frame->ms; jb->info.frames_out++; decrement_losspct(jb); + jb->info.cnt_contig_interp = 0; jb_dbg("v"); return JB_OK; } else { @@ -613,6 +620,7 @@ (jb->info.last_adjustment + 500 < now))) { jb->info.last_adjustment = now; + jb->info.cnt_contig_interp = 0; if (frame) { *frameout = *frame; @@ -660,6 +668,10 @@ increment_losspct(jb); jb->info.next_voice_ts += interpl; jb->info.last_voice_ms = interpl; + jb->info.cnt_contig_interp++; + if (jb->info.conf.max_contig_interp && jb->info.cnt_contig_interp >= jb->info.conf.max_contig_interp) { + jb->info.silence_begin_ts = jb->info.next_voice_ts - jb->info.current; + } jb_dbg("L"); return JB_INTERP; } @@ -668,6 +680,7 @@ *frameout = *frame; jb->info.next_voice_ts += frame->ms; jb->info.frames_out++; + jb->info.cnt_contig_interp = 0; decrement_losspct(jb); jb_dbg("v"); return JB_OK; @@ -786,6 +799,7 @@ jb->info.conf.max_jitterbuf = conf->max_jitterbuf; jb->info.conf.resync_threshold = conf->resync_threshold; + jb->info.conf.max_contig_interp = conf->max_contig_interp; return JB_OK; } Index: jitterbuf.h =================================================================== RCS file: /usr/cvsroot/asterisk/jitterbuf.h,v retrieving revision 1.7 diff -a -u -r1.7 jitterbuf.h --- jitterbuf.h 2 Jun 2005 17:45:38 -0000 1.7 +++ jitterbuf.h 2 Jun 2005 19:35:10 -0000 @@ -55,6 +55,7 @@ /* settings */ long max_jitterbuf; /* defines a hard clamp to use in setting the jitter buffer delay */ long resync_threshold; /* the jb will resync when delay increases to (2 * jitter) + this param */ + long max_contig_interp; /* the max interp frames to return in a row */ } jb_conf; typedef struct jb_info { @@ -80,6 +81,7 @@ long last_delay; /* the last now added to history */ long cnt_delay_discont; /* the count of discontinuous delays */ long resync_offset; /* the amount to offset ts to support resyncs */ + long cnt_contig_interp; /* the number of contiguous interp frames returned */ } jb_info; typedef struct jb_frame { Index: channels/chan_iax2.c =================================================================== RCS file: /usr/cvsroot/asterisk/channels/chan_iax2.c,v retrieving revision 1.297 diff -a -u -r1.297 chan_iax2.c --- channels/chan_iax2.c 2 Jun 2005 17:45:38 -0000 1.297 +++ channels/chan_iax2.c 2 Jun 2005 19:35:13 -0000 @@ -131,6 +131,7 @@ static int maxjitterbuffer=1000; #ifdef NEWJB static int resyncthreshold=1000; +static int maxjitterinterps=10; #endif static int jittershrinkrate=2; static int trunkfreq = 20; @@ -863,6 +864,7 @@ tmp->jbid = -1; jbconf.max_jitterbuf = maxjitterbuffer; jbconf.resync_threshold = resyncthreshold; + jbconf.max_contig_interp = maxjitterinterps; jb_setconf(tmp->jb,&jbconf); } #endif @@ -8421,6 +8423,8 @@ #ifdef NEWJB else if (!strcasecmp(v->name, "resyncthreshold")) resyncthreshold = atoi(v->value); + else if (!strcasecmp(v->name, "maxjitterinterps")) + maxjitterinterps = atoi(v->value); #endif else if (!strcasecmp(v->name, "jittershrinkrate")) jittershrinkrate = atoi(v->value); Index: configs/iax.conf.sample =================================================================== RCS file: /usr/cvsroot/asterisk/configs/iax.conf.sample,v retrieving revision 1.49 diff -a -u -r1.49 iax.conf.sample --- configs/iax.conf.sample 19 May 2005 00:34:28 -0000 1.49 +++ configs/iax.conf.sample 2 Jun 2005 19:35:13 -0000 @@ -110,6 +110,12 @@ ; Resycning can be disabled by setting this parameter to -1. ; [This option presently applies only to the new jitterbuffer implementation] ; +; maxjitterinterps: the maximum number of interpolation frames the jitterbuffer should +; return in a row. Since some clients do not send CNG/DTX frames to indicate +; silence, the jitterbuffer will assume silence has begun after returning this +; many interpolations. This prevents interpolating throughout a long silence. +; [This option presently applies only to the new jitterbuffer implementation] +; ; maxexcessbuffer: If conditions improve after a period of high jitter, ; the jitter buffer can end up bigger than necessary. If it ends up ; more than "maxexcessbuffer" bigger than needed, Asterisk will start @@ -132,6 +138,7 @@ forcejitterbuffer=no ;dropcount=2 ;maxjitterbuffer=1000 +;maxjitterinterps=10 ;resyncthreshold=1000 ;maxexcessbuffer=80 ;minexcessbuffer=10