Sat Aug 6 00:39:58 2011

Asterisk developer's documentation


jitterbuf.h File Reference

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(), 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.

Referenced by jb_destroy_adaptive(), and pvt_destructor().

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 794 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.

Referenced by __get_from_jb(), and jb_get_adaptive().

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

enum jb_return_code jb_getall ( jitterbuf jb,
jb_frame frameout 
)

Definition at line 810 of file jitterbuf.c.

References JB_NOFRAME, JB_OK, and queue_getall().

Referenced by complete_transfer(), jb_empty_and_reset_adaptive(), jb_remove_adaptive(), pvt_destructor(), and schedule_delivery().

00811 {
00812    jb_frame *frame;
00813    frame = queue_getall(jb);
00814 
00815    if (!frame) {
00816       return JB_NOFRAME;
00817    }
00818 
00819    *frameout = *frame;
00820    return JB_OK;
00821 }

enum jb_return_code jb_getinfo ( jitterbuf jb,
jb_info stats 
)

Definition at line 824 of file jitterbuf.c.

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

Referenced by ast_cli_netstats(), construct_rr(), and iax2_show_channels().

00825 {
00826 
00827    history_get(jb);
00828 
00829    *stats = jb->info;
00830 
00831    return JB_OK;
00832 }

jitterbuf* jb_new ( void   ) 

Definition at line 87 of file jitterbuf.c.

References ast_malloc, jb_dbg2, and jb_reset().

Referenced by jb_create_adaptive(), and new_iax().

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 776 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.

Referenced by __get_from_jb(), jb_next_adaptive(), and update_jbsched().

00777 {
00778    if (jb->info.silence_begin_ts) {
00779       if (jb->frames) {
00780          long next = queue_next(jb);
00781          history_get(jb);
00782          /* shrink during silence */
00783          if (jb->info.target - jb->info.current < -JB_TARGET_EXTRA)
00784             return jb->info.last_adjustment + 10;
00785          return next + jb->info.target;
00786       }
00787       else 
00788          return JB_LONGMAX;
00789    } else {
00790       return jb->info.next_voice_ts;
00791    }
00792 }

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_dropped, 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.

Referenced by jb_put_adaptive(), and schedule_delivery().

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

void jb_reset ( jitterbuf jb  ) 

Definition at line 75 of file jitterbuf.c.

References jb_info::conf, jitterbuf::info, JB_TARGET_EXTRA, and s.

Referenced by complete_transfer(), jb_empty_and_reset_adaptive(), jb_new(), and schedule_delivery().

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 834 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.

Referenced by jb_create_adaptive(), and new_iax().

00835 {
00836    /* take selected settings from the struct */
00837 
00838    jb->info.conf.max_jitterbuf = conf->max_jitterbuf;
00839    jb->info.conf.resync_threshold = conf->resync_threshold;
00840    jb->info.conf.max_contig_interp = conf->max_contig_interp;
00841 
00842    return JB_OK;
00843 }

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.

Referenced by iax2_do_jb_debug(), iax2_no_jb_debug(), and load_module().

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


Generated on Sat Aug 6 00:39:58 2011 for Asterisk - the Open Source PBX by  doxygen 1.4.7