diff options
-rwxr-xr-x | channels/chan_iax2.c | 4 | ||||
-rwxr-xr-x | configs/iax.conf.sample | 7 | ||||
-rwxr-xr-x | jitterbuf.c | 16 | ||||
-rwxr-xr-x | jitterbuf.h | 2 |
4 files changed, 28 insertions, 1 deletions
diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c index bb824e321..e85024f4e 100755 --- a/channels/chan_iax2.c +++ b/channels/chan_iax2.c @@ -136,6 +136,7 @@ static int maxnontrunkcall = 1; static int maxjitterbuffer=1000; #ifdef NEWJB static int resyncthreshold=1000; +static int maxjitterinterps=10; #endif static int jittershrinkrate=2; static int trunkfreq = 20; @@ -870,6 +871,7 @@ static struct chan_iax2_pvt *new_iax(struct sockaddr_in *sin, int lockpeer, cons tmp->jbid = -1; jbconf.max_jitterbuf = maxjitterbuffer; jbconf.resync_threshold = resyncthreshold; + jbconf.max_contig_interp = maxjitterinterps; jb_setconf(tmp->jb,&jbconf); } #endif @@ -8343,6 +8345,8 @@ static int set_config(char *config_file, int reload) #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); diff --git a/configs/iax.conf.sample b/configs/iax.conf.sample index f70579cd9..0701dd184 100755 --- a/configs/iax.conf.sample +++ b/configs/iax.conf.sample @@ -110,6 +110,12 @@ disallow=lpc10 ; Icky sound quality... Mr. Roboto. ; 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 @@ jitterbuffer=no forcejitterbuffer=no ;dropcount=2 ;maxjitterbuffer=1000 +;maxjitterinterps=10 ;resyncthreshold=1000 ;maxexcessbuffer=80 ;minexcessbuffer=10 diff --git a/jitterbuf.c b/jitterbuf.c index 7e6232df0..16dd4bfe7 100755 --- a/jitterbuf.c +++ b/jitterbuf.c @@ -564,6 +564,10 @@ static int _jb_get(jitterbuf *jb, jb_frame *frameout, long now, long interpl) 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; } @@ -572,8 +576,10 @@ static int _jb_get(jitterbuf *jb, jb_frame *frameout, long now, long interpl) /* 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++; @@ -592,6 +598,7 @@ static int _jb_get(jitterbuf *jb, jb_frame *frameout, long now, long interpl) 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 { @@ -622,6 +629,7 @@ static int _jb_get(jitterbuf *jb, jb_frame *frameout, long now, long interpl) (jb->info.last_adjustment + 500 < now))) { jb->info.last_adjustment = now; + jb->info.cnt_contig_interp = 0; if (frame) { *frameout = *frame; @@ -669,6 +677,10 @@ static int _jb_get(jitterbuf *jb, jb_frame *frameout, long now, long interpl) 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; } @@ -677,6 +689,7 @@ static int _jb_get(jitterbuf *jb, jb_frame *frameout, long now, long interpl) *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; @@ -795,6 +808,7 @@ int jb_setconf(jitterbuf *jb, jb_conf *conf) 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; } diff --git a/jitterbuf.h b/jitterbuf.h index 89d21e20a..cd8be0d0d 100755 --- a/jitterbuf.h +++ b/jitterbuf.h @@ -55,6 +55,7 @@ typedef struct jb_conf { /* 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 @@ typedef struct jb_info { 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 { |