38 #include "jitterbuf.h"
42 #define JB_LONGMAX 2147483647L
43 #define JB_LONGMIN (-JB_LONGMAX - 1L)
45 #define jb_warn(...) (warnf ? warnf(__VA_ARGS__) : (void)0)
46 #define jb_err(...) (errf ? errf(__VA_ARGS__) : (void)0)
47 #define jb_dbg(...) (dbgf ? dbgf(__VA_ARGS__) : (void)0)
50 #define jb_dbg2(...) (dbgf ? dbgf(__VA_ARGS__) : (void)0)
52 #define jb_dbg2(...) ((void)0)
79 memset(jb, 0,
sizeof(*jb));
104 jb_dbg2(
"jb_destroy(%x)\n", jb);
108 while (frame != NULL) {
130 ast_debug(1,
"Attempting to exceed Jitterbuf max %ld timeslots\n",
150 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);
244 if (toins > jb->
hist_maxbuf[JB_HISTORY_MAXBUF_SZ-1]) {
251 if (j != JB_HISTORY_MAXBUF_SZ - 1) {
263 if (toins < jb->hist_minbuf[JB_HISTORY_MAXBUF_SZ-1]) {
268 if (toins < jb->hist_minbuf[j]) {
270 if (j != JB_HISTORY_MAXBUF_SZ - 1) {
283 fprintf(stderr,
"toins = %ld\n", toins);
284 fprintf(stderr,
"maxbuf =");
287 fprintf(stderr,
"\nminbuf =");
290 fprintf(stderr,
"\n");
299 long max, min, jitter;
346 if ((frame = jb->
free)) {
348 }
else if (!(frame =
ast_malloc(
sizeof(*frame)))) {
349 jb_err(
"cannot allocate frame\n");
356 frame->
ts = resync_ts;
370 }
else if (resync_ts < jb->
frames->ts) {
388 while (resync_ts < p->prev->ts && p->
prev != jb->
frames)
426 if (all || ts >= frame->
ts) {
431 if (frame->
next == frame)
468 jb_dbg(
"\njb info: fin=%ld fout=%ld flate=%ld flost=%ld fdrop=%ld fcur=%ld\n",
471 jb_dbg(
"jitter=%ld current=%ld target=%ld min=%ld sil=%d len=%d len/fcur=%ld\n",
475 jb_dbg(
"jb info: Loss PCT = %ld%%, Late PCT = %ld%%\n",
478 jb_dbg(
"jb info: queue %d -> %d. last_ts %d (queue len: %d) last_ms %d\n",
498 if (p->
next == NULL) {
499 jb_err(
"Queue is BROKEN at item [%d]", i);
530 jb_dbg2(
"jb_put(%x,%x,%ld,%ld,%ld)\n", jb, data, ms, ts, now);
556 static int dbg_cnt = 0;
561 if (dbg_cnt && dbg_cnt % 50 == 0) {
643 if (frame && frame->
ms > 0) {
651 if (diff < -jb->info.conf.target_extra &&
729 if (diff < -jb->info.conf.target_extra &&
792 int thists = ((ret ==
JB_OK) || (ret ==
JB_DROP)) ? frameout->
ts : 0;
793 jb_warn(
"jb_get(%x,%x,%ld) = %d (%d)\n", jb, frameout, now, ret, thists);
794 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
static jb_output_function_t dbgf
void jb_setoutput(jb_output_function_t err, jb_output_function_t warn, jb_output_function_t dbg)
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_frame * _queue_get(jitterbuf *jb, long ts, int all)
static long queue_last(jitterbuf *jb)
enum jb_return_code jb_get(jitterbuf *jb, jb_frame *frame, 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...
jitterbuf * jb_new(void)
new jitterbuf
#define ast_debug(level,...)
Log a DEBUG message.
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...
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 JB_HISTORY_MAXBUF_SZ
long history[JB_HISTORY_SZ]
static jb_output_function_t warnf
enum jb_return_code jb_setconf(jitterbuf *jb, jb_conf *conf)
set jitterbuf conf
static jb_frame * queue_get(jitterbuf *jb, long ts)
if(yyss+yystacksize-1<=yyssp)
void(* jb_output_function_t)(const char *fmt,...)
static jb_frame * queue_getall(jitterbuf *jb)
static long queue_next(jitterbuf *jb)
static jb_output_function_t errf
enum jb_return_code jb_getinfo(jitterbuf *jb, jb_info *stats)
get jitterbuf info: only "statistics" may be valid
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)
void jb_destroy(jitterbuf *jb)
destroy jitterbuf
static void history_get(jitterbuf *jb)
enum jb_return_code jb_getall(jitterbuf *jb, jb_frame *frameout)
unconditionally get frames from jitterbuf until empty
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
void jb_reset(jitterbuf *jb)
reset jitterbuf