Index: jitterbuf.c =================================================================== RCS file: /usr/cvsroot/asterisk/jitterbuf.c,v retrieving revision 1.11 diff -a -u -r1.11 jitterbuf.c --- jitterbuf.c 15 May 2005 00:03:17 -0000 1.11 +++ jitterbuf.c 18 May 2005 16:08:11 -0000 @@ -277,10 +277,12 @@ jb->info.jitter = jitter; } -static void queue_put(jitterbuf *jb, void *data, int type, long ms, long ts) +/* returns 1 if frame was inserted into head of queue, 0 otherwise */ +static int queue_put(jitterbuf *jb, void *data, int type, long ms, long ts) { jb_frame *frame; jb_frame *p; + int head = 0; frame = jb->free; if (frame) { @@ -291,7 +293,7 @@ if (!frame) { jb_err("cannot allocate frame\n"); - return; + return 0; } jb->info.frames_cur++; @@ -310,6 +312,7 @@ jb->frames = frame; frame->next = frame; frame->prev = frame; + head = 1; } else if (ts < jb->frames->ts) { frame->next = jb->frames; frame->prev = jb->frames->prev; @@ -321,6 +324,7 @@ jb->info.frames_ooo++; jb->frames = frame; + head = 1; } else { p = jb->frames; @@ -336,6 +340,7 @@ frame->next->prev = frame; frame->prev->next = frame; } + return head; } static long queue_next(jitterbuf *jb) @@ -477,8 +482,10 @@ history_put(jb,ts,now); } - queue_put(jb,data,type,ms,ts); - + /* if put into head of queue, caller needs to reschedule */ + if (queue_put(jb,data,type,ms,ts)) { + return JB_SCHED; + } return JB_OK; } Index: jitterbuf.h =================================================================== RCS file: /usr/cvsroot/asterisk/jitterbuf.h,v retrieving revision 1.4 diff -a -u -r1.4 jitterbuf.h --- jitterbuf.h 12 May 2005 19:01:03 -0000 1.4 +++ jitterbuf.h 18 May 2005 16:08:11 -0000 @@ -42,6 +42,7 @@ #define JB_NOFRAME 2 #define JB_INTERP 3 #define JB_DROP 4 +#define JB_SCHED 5 /* frame types */ #define JB_TYPE_CONTROL 0 @@ -108,7 +109,11 @@ void jb_reset(jitterbuf *jb); /* queue a frame data=frame data, timings (in ms): ms=length of frame (for voice), ts=ts (sender's time) - * now=now (in receiver's time)*/ + * now=now (in receiver's time) return value is one of + * JB_OK: Frame added. Last call to jb_next() still valid + * JB_DROP: Drop this frame immediately + * JB_SCHED: Frame added. Call jb_next() to get a new time for the next frame + */ int jb_put(jitterbuf *jb, void *data, int type, long ms, long ts, long now); /* get a frame for time now (receiver's time) return value is one of Index: channels/chan_iax2.c =================================================================== RCS file: /usr/cvsroot/asterisk/channels/chan_iax2.c,v retrieving revision 1.288 diff -a -u -r1.288 chan_iax2.c --- channels/chan_iax2.c 17 May 2005 19:41:09 -0000 1.288 +++ channels/chan_iax2.c 18 May 2005 16:08:12 -0000 @@ -2179,6 +2179,7 @@ int x; #ifdef NEWJB int type, len; + int ret; #else int ms; int delay; @@ -2343,11 +2344,13 @@ /* insert into jitterbuffer */ /* TODO: Perhaps we could act immediately if it's not droppable and late */ - if(jb_put(iaxs[fr->callno]->jb, fr, type, len, fr->ts, - calc_rxstamp(iaxs[fr->callno],fr->ts)) == JB_DROP) { + ret = jb_put(iaxs[fr->callno]->jb, fr, type, len, fr->ts, + calc_rxstamp(iaxs[fr->callno],fr->ts)); + if (ret == JB_DROP) { iax2_frame_free(fr); + } else if (ret == JB_SCHED) { + update_jbsched(iaxs[fr->callno]); } - update_jbsched(iaxs[fr->callno]); #else /* Just for reference, keep the "jitter" value, the difference between the earliest and the latest. */