40 #define JB_LONGMAX 2147483647L 41 #define JB_LONGMIN (-JB_LONGMAX - 1L) 43 #define jb_warn(...) (warnf ? warnf(__VA_ARGS__) : (void)0) 44 #define jb_err(...) (errf ? errf(__VA_ARGS__) : (void)0) 45 #define jb_dbg(...) (dbgf ? dbgf(__VA_ARGS__) : (void)0) 48 #define jb_dbg2(...) (dbgf ? dbgf(__VA_ARGS__) : (void)0) 50 #define jb_dbg2(...) ((void)0) 77 memset(jb, 0,
sizeof(*jb));
102 jb_dbg2(
"jb_destroy(%x)\n", jb);
106 while (frame !=
NULL) {
128 ast_debug(1,
"Attempting to exceed Jitterbuf max %ld timeslots\n",
148 jb_warn(
"Resyncing the jb. last_delay %ld, this delay %ld, threshold %ld, new offset %ld\n", jb->
info.
last_delay, *delay, threshold, ts - now);
242 if (toins > jb->
hist_maxbuf[JB_HISTORY_MAXBUF_SZ-1]) {
249 if (j != JB_HISTORY_MAXBUF_SZ - 1) {
261 if (toins < jb->hist_minbuf[JB_HISTORY_MAXBUF_SZ-1]) {
266 if (toins < jb->hist_minbuf[j]) {
268 if (j != JB_HISTORY_MAXBUF_SZ - 1) {
281 fprintf(stderr,
"toins = %ld\n", toins);
282 fprintf(stderr,
"maxbuf =");
285 fprintf(stderr,
"\nminbuf =");
288 fprintf(stderr,
"\n");
344 if ((frame = jb->
free)) {
346 }
else if (!(frame =
ast_malloc(
sizeof(*frame)))) {
347 jb_err(
"cannot allocate frame\n");
354 frame->
ts = resync_ts;
368 }
else if (resync_ts < jb->
frames->ts) {
386 while (resync_ts < p->prev->ts && p->
prev != jb->
frames)
424 if (all || ts >= frame->
ts) {
429 if (frame->
next == frame)
466 jb_dbg(
"\njb info: fin=%ld fout=%ld flate=%ld flost=%ld fdrop=%ld fcur=%ld\n",
469 jb_dbg(
"jitter=%ld current=%ld target=%ld min=%ld sil=%d len=%d len/fcur=%ld\n",
473 jb_dbg(
"jb info: Loss PCT = %ld%%, Late PCT = %ld%%\n",
476 jb_dbg(
"jb info: queue %d -> %d. last_ts %d (queue len: %d) last_ms %d\n",
497 jb_err(
"Queue is BROKEN at item [%d]", i);
528 jb_dbg2(
"jb_put(%x,%x,%ld,%ld,%ld)\n", jb, data, ms, ts, now);
554 static int dbg_cnt = 0;
559 if (dbg_cnt && dbg_cnt % 50 == 0) {
641 if (frame && frame->
ms > 0) {
649 if (diff < -jb->
info.conf.target_extra &&
727 if (diff < -jb->
info.conf.target_extra &&
790 int thists = ((ret ==
JB_OK) || (ret ==
JB_DROP)) ? frameout->
ts : 0;
791 jb_warn(
"jb_get(%x,%x,%ld) = %d (%d)\n", jb, frameout, now, ret, thists);
792 if (thists && thists < lastts)
jb_warn(
"XXXX timestamp roll-back!!!\n");
static void decrement_losspct(jitterbuf *jb)
long hist_minbuf[JB_HISTORY_MAXBUF_SZ]
Asterisk main include file. File version handling, generic pbx functions.
#define JB_HISTORY_DROPPCT
enum jb_return_code jb_getall(jitterbuf *jb, jb_frame *frameout)
unconditionally get frames from jitterbuf until empty
enum jb_return_code jb_put(jitterbuf *jb, void *data, const enum jb_frame_type type, long ms, long ts, long now)
queue a frame
static jb_output_function_t dbgf
void(* jb_output_function_t)(const char *fmt,...)
static jb_frame * _queue_get(jitterbuf *jb, long ts, int all)
static long queue_last(jitterbuf *jb)
long jb_next(jitterbuf *jb)
when is the next frame due out, in receiver's time (0=EMPTY) This value may change as frames are adde...
enum jb_return_code jb_getinfo(jitterbuf *jb, jb_info *stats)
get jitterbuf info: only "statistics" may be valid
All configuration options for statsd client.
enum jb_return_code jb_get(jitterbuf *jb, jb_frame *frameout, long now, long interpl)
get a frame for time now (receiver's time) return value is one of JB_OK: You've got frame! JB_DROP: H...
#define ast_debug(level,...)
Log a DEBUG message.
long hist_maxbuf[JB_HISTORY_MAXBUF_SZ]
static int history_put(jitterbuf *jb, long ts, long now, long ms, long delay)
static void increment_losspct(jitterbuf *jb)
static int queue_put(jitterbuf *jb, void *data, const enum jb_frame_type type, long ms, long ts)
#define ast_malloc(len)
A wrapper for malloc()
#define JB_HISTORY_MAXBUF_SZ
long history[JB_HISTORY_SZ]
jitterbuf: an application-independent jitterbuffer jitterbuf.c
static jb_output_function_t warnf
enum jb_return_code jb_setconf(jitterbuf *jb, jb_conf *conf)
set jitterbuf conf
int jb_is_late(jitterbuf *jb, long ts)
Checks if the given time stamp is late.
static jb_frame * queue_get(jitterbuf *jb, long ts)
void jb_setoutput(jb_output_function_t err, jb_output_function_t warn, jb_output_function_t dbg)
#define ast_calloc(num, len)
A wrapper for calloc()
static jb_frame * queue_getall(jitterbuf *jb)
static long queue_next(jitterbuf *jb)
static jb_output_function_t errf
void jb_destroy(jitterbuf *jb)
destroy jitterbuf
void jb_reset(jitterbuf *jb)
reset jitterbuf
static enum jb_return_code _jb_get(jitterbuf *jb, jb_frame *frameout, long now, long interpl)
static void history_calc_maxbuf(jitterbuf *jb)
static int check_resync(jitterbuf *jb, long ts, long now, long ms, const enum jb_frame_type type, long *delay)
static void history_get(jitterbuf *jb)
jitterbuf * jb_new()
new jitterbuf