Wed Aug 15 01:25:19 2007

Asterisk developer's documentation


jitterbuf.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  jb_conf
struct  jb_frame
struct  jb_info
struct  jitterbuf

Defines

#define JB_ADJUST_DELAY   40
#define JB_HISTORY_DROPPCT   3
#define JB_HISTORY_DROPPCT_MAX   4
#define JB_HISTORY_MAXBUF_SZ   JB_HISTORY_SZ * JB_HISTORY_DROPPCT_MAX / 100
#define JB_HISTORY_SZ   500
#define JB_TARGET_EXTRA   40

Typedefs

typedef void(* jb_output_function_t )(const char *fmt,...)

Enumerations

enum  jb_frame_type { JB_TYPE_CONTROL, JB_TYPE_VOICE, JB_TYPE_VIDEO, JB_TYPE_SILENCE }
enum  jb_return_code {
  JB_OK, JB_EMPTY, JB_NOFRAME, JB_INTERP,
  JB_DROP, JB_SCHED
}

Functions

void jb_destroy (jitterbuf *jb)
enum jb_return_code jb_get (jitterbuf *jb, jb_frame *frame, long now, long interpl)
enum jb_return_code jb_getall (jitterbuf *jb, jb_frame *frameout)
enum jb_return_code jb_getinfo (jitterbuf *jb, jb_info *stats)
jitterbufjb_new (void)
long jb_next (jitterbuf *jb)
enum jb_return_code jb_put (jitterbuf *jb, void *data, const enum jb_frame_type type, long ms, long ts, long now)
void jb_reset (jitterbuf *jb)
enum jb_return_code jb_setconf (jitterbuf *jb, jb_conf *conf)
void jb_setoutput (jb_output_function_t err, jb_output_function_t warn, jb_output_function_t dbg)


Define Documentation

#define JB_ADJUST_DELAY   40

Definition at line 36 of file jitterbuf.h.

Referenced by _jb_get().

#define JB_HISTORY_DROPPCT   3

Definition at line 28 of file jitterbuf.h.

Referenced by history_get().

#define JB_HISTORY_DROPPCT_MAX   4

Definition at line 30 of file jitterbuf.h.

#define JB_HISTORY_MAXBUF_SZ   JB_HISTORY_SZ * JB_HISTORY_DROPPCT_MAX / 100

Definition at line 32 of file jitterbuf.h.

Referenced by history_calc_maxbuf(), history_get(), and history_put().

#define JB_HISTORY_SZ   500

Definition at line 25 of file jitterbuf.h.

Referenced by history_calc_maxbuf(), history_get(), and history_put().

#define JB_TARGET_EXTRA   40

Definition at line 34 of file jitterbuf.h.

Referenced by _jb_get(), jb_next(), and jb_reset().


Typedef Documentation

typedef void(* jb_output_function_t)(const char *fmt,...)

Definition at line 154 of file jitterbuf.h.


Enumeration Type Documentation

enum jb_frame_type

Enumerator:
JB_TYPE_CONTROL 
JB_TYPE_VOICE 
JB_TYPE_VIDEO 
JB_TYPE_SILENCE 

Definition at line 48 of file jitterbuf.h.

00048                    {
00049    /* frame types */
00050    JB_TYPE_CONTROL,  /* 0            */
00051    JB_TYPE_VOICE,    /* 1            */
00052    JB_TYPE_VIDEO,    /* 2 - reserved */
00053    JB_TYPE_SILENCE   /* 3            */
00054 };

enum jb_return_code

Enumerator:
JB_OK 
JB_EMPTY 
JB_NOFRAME 
JB_INTERP 
JB_DROP 
JB_SCHED 

Definition at line 38 of file jitterbuf.h.

00038                     {
00039    /* return codes */
00040    JB_OK,            /* 0 */
00041    JB_EMPTY,         /* 1 */
00042    JB_NOFRAME,       /* 2 */
00043    JB_INTERP,        /* 3 */
00044    JB_DROP,          /* 4 */
00045    JB_SCHED          /* 5 */
00046 };


Function Documentation

void jb_destroy ( jitterbuf jb  ) 

Definition at line 100 of file jitterbuf.c.

References free, jitterbuf::free, jb_dbg2, and jb_frame::next.

00101 {
00102    jb_frame *frame; 
00103    jb_dbg2("jb_destroy(%x)\n", jb);
00104 
00105    /* free all the frames on the "free list" */
00106    frame = jb->free;
00107    while (frame != NULL) {
00108       jb_frame *next = frame->next;
00109       free(frame);
00110       frame = next;
00111    }
00112 
00113    /* free ourselves! */ 
00114    free(jb);
00115 }

enum jb_return_code jb_get ( jitterbuf jb,
jb_frame frame,
long  now,
long  interpl 
)

Definition at line 788 of file jitterbuf.c.

References _jb_get(), jitterbuf::info, JB_DROP, JB_INTERP, JB_OK, jb_warn, jb_info::last_voice_ms, jb_frame::ms, and jb_frame::ts.

00789 {
00790    enum jb_return_code ret = _jb_get(jb, frameout, now, interpl);
00791 #if 0
00792    static int lastts=0;
00793    int thists = ((ret == JB_OK) || (ret == JB_DROP)) ? frameout->ts : 0;
00794    jb_warn("jb_get(%x,%x,%ld) = %d (%d)\n", jb, frameout, now, ret, thists);
00795    if (thists && thists < lastts) jb_warn("XXXX timestamp roll-back!!!\n");
00796    lastts = thists;
00797 #endif
00798    if(ret == JB_INTERP) 
00799       frameout->ms = jb->info.last_voice_ms;
00800    
00801    return ret;
00802 }

enum jb_return_code jb_getall ( jitterbuf jb,
jb_frame frameout 
)

Definition at line 804 of file jitterbuf.c.

References JB_NOFRAME, JB_OK, and queue_getall().

00805 {
00806    jb_frame *frame;
00807    frame = queue_getall(jb);
00808 
00809    if (!frame) {
00810       return JB_NOFRAME;
00811    }
00812 
00813    *frameout = *frame;
00814    return JB_OK;
00815 }

enum jb_return_code jb_getinfo ( jitterbuf jb,
jb_info stats 
)

Definition at line 818 of file jitterbuf.c.

References history_get(), jitterbuf::info, and JB_OK.

00819 {
00820 
00821    history_get(jb);
00822 
00823    *stats = jb->info;
00824 
00825    return JB_OK;
00826 }

jitterbuf* jb_new ( void   ) 

Definition at line 87 of file jitterbuf.c.

References ast_malloc, jb_dbg2, and jb_reset().

00088 {
00089    jitterbuf *jb;
00090 
00091    if (!(jb = ast_malloc(sizeof(*jb)))) 
00092       return NULL;
00093 
00094    jb_reset(jb);
00095 
00096    jb_dbg2("jb_new() = %x\n", jb);
00097    return jb;
00098 }

long jb_next ( jitterbuf jb  ) 

Definition at line 770 of file jitterbuf.c.

References jb_info::current, jitterbuf::frames, history_get(), jitterbuf::info, JB_LONGMAX, JB_TARGET_EXTRA, jb_info::last_adjustment, jb_info::next_voice_ts, queue_next(), jb_info::silence_begin_ts, and jb_info::target.

00771 {
00772    if (jb->info.silence_begin_ts) {
00773       if (jb->frames) {
00774          long next = queue_next(jb);
00775          history_get(jb);
00776          /* shrink during silence */
00777          if (jb->info.target - jb->info.current < -JB_TARGET_EXTRA)
00778             return jb->info.last_adjustment + 10;
00779          return next + jb->info.target;
00780       }
00781       else 
00782          return JB_LONGMAX;
00783    } else {
00784       return jb->info.next_voice_ts;
00785    }
00786 }

enum jb_return_code jb_put ( jitterbuf jb,
void *  data,
const enum jb_frame_type  type,
long  ms,
long  ts,
long  now 
)

Definition at line 513 of file jitterbuf.c.

References ast_log(), jb_info::conf, jitterbuf::dropem, jitterbuf::frames, jb_info::frames_in, history_put(), jitterbuf::info, jb_dbg2, JB_DROP, JB_OK, JB_SCHED, JB_TYPE_VOICE, LOG_DEBUG, jb_conf::max_jitterbuf, jb_frame::prev, queue_put(), and jb_frame::ts.

00514 {
00515    long numts;
00516 
00517    jb_dbg2("jb_put(%x,%x,%ld,%ld,%ld)\n", jb, data, ms, ts, now);
00518 
00519    jb->info.frames_in++;
00520 
00521    if (jb->frames && jb->dropem) 
00522       return JB_DROP;
00523    jb->dropem = 0;
00524 
00525    if (type == JB_TYPE_VOICE) {
00526       /* presently, I'm only adding VOICE frames to history and drift calculations; mostly because with the
00527        * IAX integrations, I'm sending retransmitted control frames with their awkward timestamps through */
00528       if (history_put(jb,ts,now,ms))
00529          return JB_DROP;
00530    }
00531    numts = 0;
00532    if (jb->frames)
00533       numts = jb->frames->prev->ts - jb->frames->ts;
00534    if (numts >= jb->info.conf.max_jitterbuf) {
00535       ast_log(LOG_DEBUG, "Attempting to exceed Jitterbuf max %ld timeslots\n",
00536          jb->info.conf.max_jitterbuf);
00537       jb->dropem = 1;
00538       return JB_DROP;
00539    }
00540    /* if put into head of queue, caller needs to reschedule */
00541    if (queue_put(jb,data,type,ms,ts)) {
00542       return JB_SCHED;
00543    }
00544    return JB_OK;
00545 }

void jb_reset ( jitterbuf jb  ) 

Definition at line 75 of file jitterbuf.c.

References jb_info::conf, jb_info::current, jitterbuf::info, JB_TARGET_EXTRA, s, jb_info::silence_begin_ts, and jb_info::target.

00076 {
00077    /* only save settings */
00078    jb_conf s = jb->info.conf;
00079    memset(jb, 0, sizeof(*jb));
00080    jb->info.conf = s;
00081 
00082    /* initialize length */
00083    jb->info.current = jb->info.target = JB_TARGET_EXTRA; 
00084    jb->info.silence_begin_ts = -1; 
00085 }

enum jb_return_code jb_setconf ( jitterbuf jb,
jb_conf conf 
)

Definition at line 828 of file jitterbuf.c.

References jb_info::conf, jitterbuf::info, JB_OK, jb_conf::max_contig_interp, jb_conf::max_jitterbuf, and jb_conf::resync_threshold.

00829 {
00830    /* take selected settings from the struct */
00831 
00832    jb->info.conf.max_jitterbuf = conf->max_jitterbuf;
00833    jb->info.conf.resync_threshold = conf->resync_threshold;
00834    jb->info.conf.max_contig_interp = conf->max_contig_interp;
00835 
00836    return JB_OK;
00837 }

void jb_setoutput ( jb_output_function_t  err,
jb_output_function_t  warn,
jb_output_function_t  dbg 
)

Definition at line 58 of file jitterbuf.c.

00059 {
00060    errf = err;
00061    warnf = warn;
00062    dbgf = dbg;
00063 }


Generated on Wed Aug 15 01:25:19 2007 for Asterisk - the Open Source PBX by  doxygen 1.5.3