Asterisk - The Open Source Telephony Project  21.4.1
Macros | Functions | Variables
jitterbuf.c File Reference

jitterbuf: an application-independent jitterbuffer More...

#include "asterisk.h"
#include "jitterbuf.h"
#include "asterisk/utils.h"

Go to the source code of this file.

Macros

#define jb_dbg(...)   (dbgf ? dbgf(__VA_ARGS__) : (void)0)
 
#define jb_dbg2(...)   ((void)0)
 
#define jb_err(...)   (errf ? errf(__VA_ARGS__) : (void)0)
 
#define JB_LONGMAX   2147483647L
 
#define JB_LONGMIN   (-JB_LONGMAX - 1L)
 
#define jb_warn(...)   (warnf ? warnf(__VA_ARGS__) : (void)0)
 

Functions

static enum jb_return_code _jb_get (jitterbuf *jb, jb_frame *frameout, long now, long interpl)
 
static jb_frame_queue_get (jitterbuf *jb, long ts, int all)
 
static int check_resync (jitterbuf *jb, long ts, long now, long ms, const enum jb_frame_type type, long *delay)
 
static void decrement_losspct (jitterbuf *jb)
 
static void history_calc_maxbuf (jitterbuf *jb)
 
static void history_get (jitterbuf *jb)
 
static int history_put (jitterbuf *jb, long ts, long now, long ms, long delay)
 
static void increment_losspct (jitterbuf *jb)
 
void jb_destroy (jitterbuf *jb)
 destroy jitterbuf
 
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: Here's an audio frame you should just drop. Ask me again for this time.. JB_NOFRAME: There's no frame scheduled for this time. JB_INTERP: Please interpolate an interpl-length frame for this time (either we need to grow, or there was a lost frame) JB_EMPTY: The jb is empty.
 
enum jb_return_code jb_getall (jitterbuf *jb, jb_frame *frameout)
 unconditionally get frames from jitterbuf until empty
 
enum jb_return_code jb_getinfo (jitterbuf *jb, jb_info *stats)
 get jitterbuf info: only "statistics" may be valid
 
int jb_is_late (jitterbuf *jb, long ts)
 Checks if the given time stamp is late.
 
jitterbufjb_new ()
 new jitterbuf
 
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 added (esp non-audio frames)
 
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 More...
 
void jb_reset (jitterbuf *jb)
 reset jitterbuf More...
 
enum jb_return_code jb_setconf (jitterbuf *jb, jb_conf *conf)
 set jitterbuf conf
 
void jb_setoutput (jb_output_function_t err, jb_output_function_t warn, jb_output_function_t dbg)
 
static jb_framequeue_get (jitterbuf *jb, long ts)
 
static jb_framequeue_getall (jitterbuf *jb)
 
static long queue_last (jitterbuf *jb)
 
static long queue_next (jitterbuf *jb)
 
static int queue_put (jitterbuf *jb, void *data, const enum jb_frame_type type, long ms, long ts)
 

Variables

static jb_output_function_t dbgf
 
static jb_output_function_t errf
 
static jb_output_function_t warnf
 

Detailed Description

jitterbuf: an application-independent jitterbuffer

Author
Steve Kann steve.nosp@m.k@st.nosp@m.evek..nosp@m.com

Definition in file jitterbuf.c.

Macro Definition Documentation

#define JB_LONGMAX   2147483647L

define these here, just for ancient compiler systems

Definition at line 40 of file jitterbuf.c.

Referenced by jb_next().

Function Documentation

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

data=frame data, timings (in ms): ms=length of frame (for voice), ts=ts (sender'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

Definition at line 525 of file jitterbuf.c.

References jb_info::frames_in, JB_TYPE_VOICE, and jb_info::resync_offset.

Referenced by schedule_delivery().

526 {
527  long delay = now - (ts - jb->info.resync_offset);
528  jb_dbg2("jb_put(%x,%x,%ld,%ld,%ld)\n", jb, data, ms, ts, now);
529 
530  if (check_resync(jb, ts, now, ms, type, &delay)) {
531  return JB_DROP;
532  }
533 
534  if (type == JB_TYPE_VOICE) {
535  /* presently, I'm only adding VOICE frames to history and drift calculations; mostly because with the
536  * IAX integrations, I'm sending retransmitted control frames with their awkward timestamps through */
537  history_put(jb, ts, now, ms, delay);
538  }
539 
540  jb->info.frames_in++;
541 
542  /* if put into head of queue, caller needs to reschedule */
543  if (queue_put(jb,data,type,ms,ts)) {
544  return JB_SCHED;
545  }
546  return JB_OK;
547 }
long frames_in
Definition: jitterbuf.h:79
long resync_offset
Definition: jitterbuf.h:97
void jb_reset ( jitterbuf jb)

reset jitterbuf

Note
The jitterbuffer should be empty before you call this, otherwise you will leak queued frames, and some internal structures

Definition at line 72 of file jitterbuf.c.

References jb_info::current, jitterbuf::free, JB_TARGET_EXTRA, jb_info::silence_begin_ts, jb_info::target, and jb_conf::target_extra.

Referenced by jb_new().

73 {
74  /* only save settings and free list */
75  jb_conf s = jb->info.conf;
76  jb_frame *fr = jb->free;
77  memset(jb, 0, sizeof(*jb));
78  jb->info.conf = s;
79  jb->free = fr;
80 
81  /* initialize length, using the default value */
82  jb->info.current = jb->info.target = jb->info.conf.target_extra = JB_TARGET_EXTRA;
83  jb->info.silence_begin_ts = -1;
84 }
#define JB_TARGET_EXTRA
Definition: jitterbuf.h:43
long silence_begin_ts
Definition: jitterbuf.h:93
jb_frame * free
Definition: jitterbuf.h:121
long target_extra
Definition: jitterbuf.h:72
long target
Definition: jitterbuf.h:89
long current
Definition: jitterbuf.h:88