{
#ifdef NEWJB
int type, len;
+ int ret;
#else
int x;
int ms;
/* 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 {
+ } else if (ret == JB_SCHED) {
update_jbsched(iaxs[fr->callno]);
}
#else
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;
long resync_ts = ts - jb->info.resync_offset;
frame = jb->free;
if (!frame) {
jb_err("cannot allocate frame\n");
- return;
+ return 0;
}
jb->info.frames_cur++;
jb->frames = frame;
frame->next = frame;
frame->prev = frame;
+ head = 1;
} else if (resync_ts < jb->frames->ts) {
frame->next = jb->frames;
frame->prev = jb->frames->prev;
jb->info.frames_ooo++;
jb->frames = frame;
+ head = 1;
} else {
p = jb->frames;
frame->next->prev = frame;
frame->prev->next = frame;
}
+ return head;
}
static long queue_next(jitterbuf *jb)
return JB_DROP;
}
- 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;
}
#define JB_NOFRAME 2
#define JB_INTERP 3
#define JB_DROP 4
+#define JB_SCHED 5
/* frame types */
#define JB_TYPE_CONTROL 0
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