fixedjitterbuf.h File Reference

Jitterbuffering algorithm. More...

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

Go to the source code of this file.

Data Structures

struct  fixed_jb_conf
struct  fixed_jb_frame

Defines

#define FIXED_JB_RESYNCH_THRESHOLD_DEFAULT   1000
#define FIXED_JB_SIZE_DEFAULT   200

Enumerations

enum  { FIXED_JB_OK, FIXED_JB_DROP, FIXED_JB_INTERP, FIXED_JB_NOFRAME }

Functions

void fixed_jb_destroy (struct fixed_jb *jb)
int fixed_jb_get (struct fixed_jb *jb, struct fixed_jb_frame *frame, long now, long interpl)
struct fixed_jbfixed_jb_new (struct fixed_jb_conf *conf)
long fixed_jb_next (struct fixed_jb *jb)
int fixed_jb_put (struct fixed_jb *jb, void *data, long ms, long ts, long now)
int fixed_jb_put_first (struct fixed_jb *jb, void *data, long ms, long ts, long now)
int fixed_jb_remove (struct fixed_jb *jb, struct fixed_jb_frame *frameout)
void fixed_jb_set_force_resynch (struct fixed_jb *jb)


Detailed Description

Jitterbuffering algorithm.

Definition in file fixedjitterbuf.h.


Define Documentation

#define FIXED_JB_RESYNCH_THRESHOLD_DEFAULT   1000

Definition at line 45 of file fixedjitterbuf.h.

Referenced by fixed_jb_new().

#define FIXED_JB_SIZE_DEFAULT   200

Definition at line 44 of file fixedjitterbuf.h.

Referenced by fixed_jb_new().


Enumeration Type Documentation

anonymous enum

Enumerator:
FIXED_JB_OK 
FIXED_JB_DROP 
FIXED_JB_INTERP 
FIXED_JB_NOFRAME 

Definition at line 35 of file fixedjitterbuf.h.

00035      {
00036    FIXED_JB_OK,
00037    FIXED_JB_DROP,
00038    FIXED_JB_INTERP,
00039    FIXED_JB_NOFRAME
00040 };


Function Documentation

void fixed_jb_destroy ( struct fixed_jb jb  ) 

Definition at line 129 of file fixedjitterbuf.c.

References ASSERT, ast_free, fixed_jb::frames, and NULL.

Referenced by jb_destroy_fixed().

00130 {
00131    /* jitterbuf MUST be empty before it can be destroyed */
00132    ASSERT(jb->frames == NULL);
00133 
00134    ast_free(jb);
00135 }

int fixed_jb_get ( struct fixed_jb jb,
struct fixed_jb_frame frame,
long  now,
long  interpl 
)

Definition at line 294 of file fixedjitterbuf.c.

References ASSERT, fixed_jb_frame::delivery, FIXED_JB_DROP, FIXED_JB_INTERP, FIXED_JB_NOFRAME, FIXED_JB_OK, frames, fixed_jb::frames, get_jb_head(), fixed_jb_frame::ms, and fixed_jb::next_delivery.

Referenced by jb_get_fixed().

00295 {
00296    ASSERT(now >= 0);
00297    ASSERT(interpl >= 2);
00298 
00299    if (now < jb->next_delivery) {
00300       /* too early for the next frame */
00301       return FIXED_JB_NOFRAME;
00302    }
00303 
00304    /* Is the jb empty? */
00305    if (!jb->frames) {
00306       /* should interpolate a frame */
00307       /* update next */
00308       jb->next_delivery += interpl;
00309 
00310       return FIXED_JB_INTERP;
00311    }
00312 
00313    /* Isn't it too late for the first frame available in the jb? */
00314    if (now > jb->frames->delivery + jb->frames->ms) {
00315       /* yes - should drop this frame and update next to point the next frame (get_jb_head() does it) */
00316       get_jb_head(jb, frame);
00317 
00318       return FIXED_JB_DROP;
00319    }
00320 
00321    /* isn't it too early to play the first frame available? */
00322    if (now < jb->frames->delivery) {
00323       /* yes - should interpolate one frame */
00324       /* update next */
00325       jb->next_delivery += interpl;
00326 
00327       return FIXED_JB_INTERP;
00328    }
00329 
00330    /* we have a frame for playing now (get_jb_head() updates next) */
00331    get_jb_head(jb, frame);
00332 
00333    return FIXED_JB_OK;
00334 }

struct fixed_jb* fixed_jb_new ( struct fixed_jb_conf conf  )  [read]

Definition at line 102 of file fixedjitterbuf.c.

References ast_calloc, fixed_jb::conf, fixed_jb::delay, FIXED_JB_RESYNCH_THRESHOLD_DEFAULT, FIXED_JB_SIZE_DEFAULT, fixed_jb_conf::jbsize, NULL, and fixed_jb_conf::resync_threshold.

Referenced by jb_create_fixed().

00103 {
00104    struct fixed_jb *jb;
00105 
00106    if (!(jb = ast_calloc(1, sizeof(*jb))))
00107       return NULL;
00108 
00109    /* First copy our config */
00110    memcpy(&jb->conf, conf, sizeof(struct fixed_jb_conf));
00111 
00112    /* we don't need the passed config anymore - continue working with the saved one */
00113    conf = &jb->conf;
00114 
00115    /* validate the configuration */
00116    if (conf->jbsize < 1)
00117       conf->jbsize = FIXED_JB_SIZE_DEFAULT;
00118 
00119    if (conf->resync_threshold < 1)
00120       conf->resync_threshold = FIXED_JB_RESYNCH_THRESHOLD_DEFAULT;
00121 
00122    /* Set the constant delay to the jitterbuf */
00123    jb->delay = conf->jbsize;
00124 
00125    return jb;
00126 }

long fixed_jb_next ( struct fixed_jb jb  ) 

Definition at line 337 of file fixedjitterbuf.c.

References fixed_jb::next_delivery.

Referenced by jb_next_fixed().

00338 {
00339    return jb->next_delivery;
00340 }

int fixed_jb_put ( struct fixed_jb jb,
void *  data,
long  ms,
long  ts,
long  now 
)

Definition at line 200 of file fixedjitterbuf.c.

References alloc_jb_frame(), ASSERT, fixed_jb::conf, fixed_jb_frame::data, fixed_jb::delay, fixed_jb_frame::delivery, FIXED_JB_OK, fixed_jb::force_resynch, fixed_jb::frames, fixed_jb_frame::ms, fixed_jb_frame::next, fixed_jb::next_delivery, NULL, fixed_jb_frame::prev, fixed_jb_conf::resync_threshold, resynch_jb(), fixed_jb::rxcore, fixed_jb::tail, and fixed_jb_frame::ts.

Referenced by fixed_jb_put_first(), jb_put_fixed(), and resynch_jb().

00201 {
00202    struct fixed_jb_frame *frame, *next, *newframe;
00203    long delivery;
00204 
00205    /* debug check the validity of the input params */
00206    ASSERT(data != NULL);
00207    /* do not allow frames shorter than 2 ms */
00208    ASSERT(ms >= 2);
00209    ASSERT(ts >= 0);
00210    ASSERT(now >= 0);
00211 
00212    delivery = jb->rxcore + jb->delay + ts;
00213 
00214    /* check if the new frame is not too late */
00215    if (delivery < jb->next_delivery) {
00216       /* should drop the frame, but let first resynch_jb() check if this is not a jump in ts, or
00217          the force resynch flag was not set. */
00218       return resynch_jb(jb, data, ms, ts, now);
00219    }
00220 
00221    /* what if the delivery time is bigger than next + delay? Seems like a frame for the future.
00222       However, allow more resync_threshold ms in advance */
00223    if (delivery > jb->next_delivery + jb->delay + jb->conf.resync_threshold) {
00224       /* should drop the frame, but let first resynch_jb() check if this is not a jump in ts, or
00225          the force resynch flag was not set. */
00226       return resynch_jb(jb, data, ms, ts, now);
00227    }
00228 
00229    /* find the right place in the frames list, sorted by delivery time */
00230    frame = jb->tail;
00231    while (frame && frame->delivery > delivery) {
00232       frame = frame->prev;
00233    }
00234 
00235    /* Check if the new delivery time is not covered already by the chosen frame */
00236    if (frame && (frame->delivery == delivery ||
00237                delivery < frame->delivery + frame->ms ||
00238                (frame->next && delivery + ms > frame->next->delivery)))
00239    {
00240       /* TODO: Should we check for resynch here? Be careful to do not allow threshold smaller than
00241          the size of the jb */
00242 
00243       /* should drop the frame, but let first resynch_jb() check if this is not a jump in ts, or
00244          the force resynch flag was not set. */
00245       return resynch_jb(jb, data, ms, ts, now);
00246    }
00247 
00248    /* Reset the force resynch flag */
00249    jb->force_resynch = 0;
00250 
00251    /* Get a new frame */
00252    newframe = alloc_jb_frame(jb);
00253    newframe->data = data;
00254    newframe->ts = ts;
00255    newframe->ms = ms;
00256    newframe->delivery = delivery;
00257 
00258    /* and insert it right on place */
00259    if (frame) {
00260       next = frame->next;
00261       frame->next = newframe;
00262       if (next) {
00263          newframe->next = next;
00264          next->prev = newframe;
00265       } else {
00266          /* insert after the last frame - should update tail */
00267          jb->tail = newframe;
00268          newframe->next = NULL;
00269       }
00270       newframe->prev = frame;
00271 
00272       return FIXED_JB_OK;
00273    } else if (!jb->frames) {
00274       /* the frame list is empty or thats just the first frame ever */
00275       /* tail should also be NULL is that case */
00276       ASSERT(jb->tail == NULL);
00277       jb->frames = jb->tail = newframe;
00278       newframe->next = NULL;
00279       newframe->prev = NULL;
00280 
00281       return FIXED_JB_OK;
00282    } else {
00283       /* insert on a first position - should update frames head */
00284       newframe->next = jb->frames;
00285       newframe->prev = NULL;
00286       jb->frames->prev = newframe;
00287       jb->frames = newframe;
00288 
00289       return FIXED_JB_OK;
00290    }
00291 }

int fixed_jb_put_first ( struct fixed_jb jb,
void *  data,
long  ms,
long  ts,
long  now 
)

Definition at line 187 of file fixedjitterbuf.c.

References fixed_jb::delay, fixed_jb_put(), fixed_jb::next_delivery, and fixed_jb::rxcore.

Referenced by jb_put_first_fixed(), and resynch_jb().

00188 {
00189    /* this is our first frame - set the base of the receivers time */
00190    jb->rxcore = now - ts;
00191 
00192    /* init next for a first time - it should be the time the first frame should be played */
00193    jb->next_delivery = now + jb->delay;
00194 
00195    /* put the frame */
00196    return fixed_jb_put(jb, data, ms, ts, now);
00197 }

int fixed_jb_remove ( struct fixed_jb jb,
struct fixed_jb_frame frameout 
)

Definition at line 343 of file fixedjitterbuf.c.

References FIXED_JB_NOFRAME, FIXED_JB_OK, fixed_jb::frames, and get_jb_head().

Referenced by jb_empty_and_reset_fixed(), and jb_remove_fixed().

00344 {
00345    if (!jb->frames)
00346       return FIXED_JB_NOFRAME;
00347 
00348    get_jb_head(jb, frameout);
00349 
00350    return FIXED_JB_OK;
00351 }

void fixed_jb_set_force_resynch ( struct fixed_jb jb  ) 

Definition at line 181 of file fixedjitterbuf.c.

References fixed_jb::force_resynch.

Referenced by jb_force_resynch_fixed().

00182 {
00183    jb->force_resynch = 1;
00184 }


Generated on Thu Apr 16 06:31:01 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6