Index: main/jitterbuf.c =================================================================== --- main/jitterbuf.c (revision 347650) +++ main/jitterbuf.c (working copy) @@ -31,6 +31,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") +#include "asterisk/frame.h" #include "jitterbuf.h" #include "asterisk/utils.h" @@ -67,6 +68,15 @@ jb->info.losspct = (499 * jb->info.losspct)/500; } +void jb_empty(jitterbuf *jb) +{ + jb_frame f; + + while (jb_getall(jb, &f) == JB_OK) { + ast_frfree(f.data); + } +} + void jb_reset(jitterbuf *jb) { /* only save settings */ @@ -143,6 +153,8 @@ jb->hist_maxbuf_valid = 0; 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); + jb_empty(jb); + jb_reset(jb); jb->info.resync_offset = ts - now; jb->info.last_delay = delay = 0; /* after resync, frame is right on time */ } else { Index: include/jitterbuf.h =================================================================== --- include/jitterbuf.h (revision 347650) +++ include/jitterbuf.h (working copy) @@ -126,6 +126,9 @@ /*! \brief destroy jitterbuf */ void jb_destroy(jitterbuf *jb); +/*! \brief empty jitterbuf */ +void jb_empty(jitterbuf *jb); + /*! \brief reset jitterbuf * \note The jitterbuffer should be empty before you call this, otherwise * you will leak queued frames, and some internal structures */