Index: pjproject/trunk/pjmedia/src/pjmedia/jbuf.c
===================================================================
--- pjproject/trunk/pjmedia/src/pjmedia/jbuf.c	(revision 4537)
+++ pjproject/trunk/pjmedia/src/pjmedia/jbuf.c	(revision 4728)
@@ -1,4 +1,4 @@
 /* $Id$ */
-/* 
+/*
  * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
  * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@@ -16,5 +16,5 @@
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 /*
@@ -36,5 +36,5 @@
 #define INVALID_OFFSET		-9999
 
-/* Maximum burst length, whenever an operation is bursting longer than 
+/* Maximum burst length, whenever an operation is bursting longer than
  * this value, JB will assume that the opposite operation was idle.
  */
@@ -47,6 +47,6 @@
 
 
-/* Minimal difference between JB size and 2*burst-level to perform 
- * JB shrinking in static discard algorithm. 
+/* Minimal difference between JB size and 2*burst-level to perform
+ * JB shrinking in static discard algorithm.
  */
 #define STA_DISC_SAFE_SHRINKING_DIFF	1
@@ -68,11 +68,11 @@
     pj_uint32_t	    *bit_info;		/**< frame bit info array	    */
     pj_uint32_t	    *ts;		/**< timestamp array		    */
-    
+
     /* States */
     unsigned	     head;		/**< index of head, pointed frame
 					     will be returned by next GET   */
-    unsigned	     size;		/**< current size of framelist, 
+    unsigned	     size;		/**< current size of framelist,
 					     including discarded frames.    */
-    unsigned	     discarded_num;	/**< current number of discarded 
+    unsigned	     discarded_num;	/**< current number of discarded
 					     frames.			    */
     int		     origin;		/**< original index of flist_head   */
@@ -92,5 +92,5 @@
     pj_size_t	    jb_frame_size;	/**< frame size			    */
     unsigned	    jb_frame_ptime;	/**< frame duration.		    */
-    pj_size_t	    jb_max_count;	/**< capacity of jitter buffer, 
+    pj_size_t	    jb_max_count;	/**< capacity of jitter buffer,
 					     in frames			    */
     int		    jb_init_prefetch;	/**< Initial prefetch		    */
@@ -98,6 +98,6 @@
     int		    jb_max_prefetch;	/**< Maximum allowable prefetch	    */
     int		    jb_max_burst;	/**< maximum possible burst, whenever
-					     burst exceeds this value, it 
-					     won't be included in level 
+					     burst exceeds this value, it
+					     won't be included in level
 					     calculation		    */
     int		    jb_min_shrink_gap;	/**< How often can we shrink	    */
@@ -108,25 +108,25 @@
 
     /* States */
-    int		    jb_level;		/**< delay between source & 
-					     destination (calculated according 
-					     of the number of burst get/put 
+    int		    jb_level;		/**< delay between source &
+					     destination (calculated according
+					     of the number of burst get/put
 					     operations)		    */
-    int		    jb_max_hist_level;  /**< max level during the last level 
+    int		    jb_max_hist_level;  /**< max level during the last level
 					     calculations		    */
-    int		    jb_stable_hist;	/**< num of times the delay has	been 
+    int		    jb_stable_hist;	/**< num of times the delay has	been
 					     lower then the prefetch num    */
-    int		    jb_last_op;		/**< last operation executed 
+    int		    jb_last_op;		/**< last operation executed
 					     (put/get)			    */
     int		    jb_eff_level;	/**< effective burst level	    */
-    int		    jb_prefetch;	/**< no. of frame to insert before 
-					     removing some (at the beginning 
-					     of the framelist->content 
+    int		    jb_prefetch;	/**< no. of frame to insert before
+					     removing some (at the beginning
+					     of the framelist->content
 					     operation), the value may be
 					     continuously updated based on
 					     current frame burst level.	    */
     pj_bool_t	    jb_prefetching;	/**< flag if jbuf is prefetching.   */
-    int		    jb_status;		/**< status is 'init' until the	first 
+    int		    jb_status;		/**< status is 'init' until the	first
 					     'put' operation		    */
-    int		    jb_init_cycle_cnt;	/**< status is 'init' until the	first 
+    int		    jb_init_cycle_cnt;	/**< status is 'init' until the	first
 					     'put' operation		    */
 
@@ -137,5 +137,5 @@
 
     /* Statistics */
-    pj_math_stat    jb_delay;		/**< Delay statistics of jitter buffer 
+    pj_math_stat    jb_delay;		/**< Delay statistics of jitter buffer
 					     (in ms)			    */
     pj_math_stat    jb_burst;		/**< Burst statistics (in frames)   */
@@ -165,5 +165,5 @@
 
 
-/* Enabling this would log the jitter buffer state about once per 
+/* Enabling this would log the jitter buffer state about once per
  * second.
  */
@@ -181,5 +181,5 @@
 				      jb_framelist_t *framelist,
 				      unsigned frame_size,
-				      unsigned max_count) 
+				      unsigned max_count)
 {
     PJ_ASSERT_RETURN(pool && framelist, PJ_EINVAL);
@@ -189,22 +189,22 @@
     framelist->frame_size   = frame_size;
     framelist->max_count    = max_count;
-    framelist->content	    = (char*) 
+    framelist->content	    = (char*)
 			      pj_pool_alloc(pool,
-					    framelist->frame_size* 
+					    framelist->frame_size*
 					    framelist->max_count);
     framelist->frame_type   = (int*)
-			      pj_pool_alloc(pool, 
+			      pj_pool_alloc(pool,
 					    sizeof(framelist->frame_type[0])*
 					    framelist->max_count);
     framelist->content_len  = (pj_size_t*)
-			      pj_pool_alloc(pool, 
+			      pj_pool_alloc(pool,
 					    sizeof(framelist->content_len[0])*
 					    framelist->max_count);
     framelist->bit_info	    = (pj_uint32_t*)
-			      pj_pool_alloc(pool, 
+			      pj_pool_alloc(pool,
 					    sizeof(framelist->bit_info[0])*
 					    framelist->max_count);
     framelist->ts	    = (pj_uint32_t*)
-			      pj_pool_alloc(pool, 
+			      pj_pool_alloc(pool,
 					    sizeof(framelist->ts[0])*
 					    framelist->max_count);
@@ -214,5 +214,5 @@
 }
 
-static pj_status_t jb_framelist_destroy(jb_framelist_t *framelist) 
+static pj_status_t jb_framelist_destroy(jb_framelist_t *framelist)
 {
     PJ_UNUSED_ARG(framelist);
@@ -220,5 +220,5 @@
 }
 
-static pj_status_t jb_framelist_reset(jb_framelist_t *framelist) 
+static pj_status_t jb_framelist_reset(jb_framelist_t *framelist)
 {
     framelist->head = 0;
@@ -228,19 +228,19 @@
 
 
-    //pj_bzero(framelist->content, 
-    //	     framelist->frame_size * 
+    //pj_bzero(framelist->content,
+    //	     framelist->frame_size *
     //	     framelist->max_count);
 
     pj_memset(framelist->frame_type,
 	      PJMEDIA_JB_MISSING_FRAME,
-	      sizeof(framelist->frame_type[0]) * 
+	      sizeof(framelist->frame_type[0]) *
 	      framelist->max_count);
 
-    pj_bzero(framelist->content_len, 
-	     sizeof(framelist->content_len[0]) * 
+    pj_bzero(framelist->content_len,
+	     sizeof(framelist->content_len[0]) *
 	     framelist->max_count);
 
     //pj_bzero(framelist->bit_info,
-    //	     sizeof(framelist->bit_info[0]) * 
+    //	     sizeof(framelist->bit_info[0]) *
     //	     framelist->max_count);
 
@@ -249,5 +249,5 @@
 
 
-static unsigned jb_framelist_size(const jb_framelist_t *framelist) 
+static unsigned jb_framelist_size(const jb_framelist_t *framelist)
 {
     return framelist->size;
@@ -255,10 +255,10 @@
 
 
-static unsigned jb_framelist_eff_size(const jb_framelist_t *framelist) 
+static unsigned jb_framelist_eff_size(const jb_framelist_t *framelist)
 {
     return (framelist->size - framelist->discarded_num);
 }
 
-static int jb_framelist_origin(const jb_framelist_t *framelist) 
+static int jb_framelist_origin(const jb_framelist_t *framelist)
 {
     return framelist->origin;
@@ -271,5 +271,5 @@
 				  pj_uint32_t *bit_info,
 				  pj_uint32_t *ts,
-				  int *seq) 
+				  int *seq)
 {
     if (framelist->size) {
@@ -296,9 +296,9 @@
 		    *bit_info = 0;
 	    } else {
-		pj_memcpy(frame, 
-			  framelist->content + 
+		pj_memcpy(frame,
+			  framelist->content +
 			  framelist->head * framelist->frame_size,
 			  framelist->frame_size);
-		*p_type = (pjmedia_jb_frame_type) 
+		*p_type = (pjmedia_jb_frame_type)
 			  framelist->frame_type[framelist->head];
 		if (size)
@@ -312,5 +312,5 @@
 		*seq = framelist->origin;
 
-	    //pj_bzero(framelist->content + 
+	    //pj_bzero(framelist->content +
 	    //	 framelist->head * framelist->frame_size,
 	    //	 framelist->frame_size);
@@ -323,5 +323,5 @@
 	    framelist->head = (framelist->head + 1) % framelist->max_count;
 	    framelist->size--;
-    	
+
 	    return PJ_TRUE;
 	}
@@ -342,5 +342,5 @@
 				   pj_uint32_t *bit_info,
 				   pj_uint32_t *ts,
-				   int *seq) 
+				   int *seq)
 {
     unsigned pos, idx;
@@ -367,5 +367,5 @@
 	*frame = framelist->content + pos*framelist->frame_size;
     if (type)
-	*type = (pjmedia_jb_frame_type) 
+	*type = (pjmedia_jb_frame_type)
 		framelist->frame_type[pos];
     if (size)
@@ -384,7 +384,7 @@
 /* Remove oldest frames as many as param 'count' */
 static unsigned jb_framelist_remove_head(jb_framelist_t *framelist,
-					 unsigned count) 
-{
-    if (count > framelist->size) 
+					 unsigned count)
+{
+    if (count > framelist->size)
 	count = framelist->size;
 
@@ -410,5 +410,5 @@
 	}
 
-	//pj_bzero(framelist->content + 
+	//pj_bzero(framelist->content +
 	//	    framelist->head * framelist->frame_size,
 	//          step1*framelist->frame_size);
@@ -440,5 +440,5 @@
 	framelist->size -= count;
     }
-    
+
     return count;
 }
@@ -549,7 +549,7 @@
 
 
-PJ_DEF(pj_status_t) pjmedia_jbuf_create(pj_pool_t *pool, 
+PJ_DEF(pj_status_t) pjmedia_jbuf_create(pj_pool_t *pool,
 					const pj_str_t *name,
-					unsigned frame_size, 
+					unsigned frame_size,
 					unsigned ptime,
 					unsigned max_count,
@@ -597,5 +597,5 @@
     PJ_ASSERT_RETURN(prefetch <= jb->jb_max_count, PJ_EINVAL);
 
-    jb->jb_min_prefetch = jb->jb_max_prefetch = 
+    jb->jb_min_prefetch = jb->jb_max_prefetch =
 	jb->jb_prefetch = jb->jb_init_prefetch = prefetch;
 
@@ -676,10 +676,10 @@
 	       "  burst (min/max/avg/dev)=%d/%d/%d/%d frames\n"
 	       "  lost=%d discard=%d empty=%d",
-	       jb_framelist_size(&jb->jb_framelist), 
-	       jb_framelist_eff_size(&jb->jb_framelist), 
+	       jb_framelist_size(&jb->jb_framelist),
+	       jb_framelist_eff_size(&jb->jb_framelist),
 	       jb->jb_prefetch, jb->jb_eff_level,
-	       jb->jb_delay.min, jb->jb_delay.max, jb->jb_delay.mean, 
+	       jb->jb_delay.min, jb->jb_delay.max, jb->jb_delay.mean,
 	       pj_math_stat_get_stddev(&jb->jb_delay),
-	       jb->jb_burst.min, jb->jb_burst.max, jb->jb_burst.mean, 
+	       jb->jb_burst.min, jb->jb_burst.max, jb->jb_burst.mean,
 	       pj_math_stat_get_stddev(&jb->jb_burst),
 	       jb->jb_lost, jb->jb_discard, jb->jb_empty));
@@ -705,12 +705,12 @@
 
 	enum { STABLE_HISTORY_LIMIT = 20 };
-        
+
 	jb->jb_stable_hist++;
-        
-	/* Only update the effective level (and prefetch) if 'stable' 
+
+	/* Only update the effective level (and prefetch) if 'stable'
 	 * condition is reached (not just short time impulse)
 	 */
 	if (jb->jb_stable_hist > STABLE_HISTORY_LIMIT) {
-    	
+
 	    diff = (jb->jb_eff_level - jb->jb_max_hist_level) / 3;
 
@@ -724,5 +724,5 @@
 	    if (jb->jb_init_prefetch) {
 		jb->jb_prefetch = jb->jb_eff_level;
-		if (jb->jb_prefetch < jb->jb_min_prefetch) 
+		if (jb->jb_prefetch < jb->jb_min_prefetch)
 		    jb->jb_prefetch = jb->jb_min_prefetch;
 		if (jb->jb_prefetch > jb->jb_max_prefetch)
@@ -736,4 +736,5 @@
 	    TRACE__((jb->jb_name.ptr,"jb updated(1), lvl=%d pre=%d, size=%d",
 		     jb->jb_eff_level, jb->jb_prefetch, cur_size));
+	    PJ_UNUSED_ARG(cur_size); /* Warning about unused var */
 	}
     }
@@ -759,5 +760,5 @@
 	//jb->jb_max_hist_level = 0;
 
-	TRACE__((jb->jb_name.ptr,"jb updated(2), lvl=%d pre=%d, size=%d", 
+	TRACE__((jb->jb_name.ptr,"jb updated(2), lvl=%d pre=%d, size=%d",
 		 jb->jb_eff_level, jb->jb_prefetch, cur_size));
     }
@@ -778,9 +779,9 @@
      *
      * Moreover, normally drift level is quite low, so JB shouldn't need
-     * to shrink aggresively, it will shrink maximum one frame per 
-     * PJMEDIA_JBUF_DISC_MIN_GAP ms. Theoritically, JB may handle drift level 
+     * to shrink aggresively, it will shrink maximum one frame per
+     * PJMEDIA_JBUF_DISC_MIN_GAP ms. Theoritically, JB may handle drift level
      * as much as = FRAME_PTIME/PJMEDIA_JBUF_DISC_MIN_GAP * 100%
      *
-     * Whenever there is drift, where PUT > GET, this method will keep 
+     * Whenever there is drift, where PUT > GET, this method will keep
      * the latency (JB size) as much as twice of burst level.
      */
@@ -797,6 +798,6 @@
 	int seq_origin;
 
-	/* Check and adjust jb_discard_ref, in case there was 
-	 * seq restart 
+	/* Check and adjust jb_discard_ref, in case there was
+	 * seq restart
 	 */
 	seq_origin = jb_framelist_origin(&jb->jb_framelist);
@@ -814,5 +815,5 @@
 	    jb->jb_discard += diff;
 
-	    TRACE__((jb->jb_name.ptr, 
+	    TRACE__((jb->jb_name.ptr,
 		     "JB shrinking %d frame(s), cur size=%d", diff,
 		     jb_framelist_eff_size(&jb->jb_framelist)));
@@ -846,5 +847,5 @@
 	T = PJMEDIA_JBUF_PRO_DISC_T2;
     else
-	T = PJMEDIA_JBUF_PRO_DISC_T1 + 
+	T = PJMEDIA_JBUF_PRO_DISC_T1 +
 	    (PJMEDIA_JBUF_PRO_DISC_T2 - PJMEDIA_JBUF_PRO_DISC_T1) *
 	    (burst_level - PJMEDIA_JBUF_PRO_DISC_MIN_BURST) /
@@ -874,5 +875,5 @@
     if (last_seq >= (jb->jb_discard_ref + (int)jb->jb_discard_dist)) {
 	int discard_seq;
-	
+
 	discard_seq = jb->jb_discard_ref + jb->jb_discard_dist;
 	if (discard_seq < jb_framelist_origin(&jb->jb_framelist))
@@ -881,5 +882,5 @@
 	jb_framelist_discard(&jb->jb_framelist, discard_seq);
 
-	TRACE__((jb->jb_name.ptr, 
+	TRACE__((jb->jb_name.ptr,
 		"Discard #%d: ref=#%d dist=%d orig=%d size=%d/%d "
 		"burst=%d/%d",
@@ -897,5 +898,5 @@
     }
 }
-    
+
 
 PJ_INLINE(void) jbuf_update(pjmedia_jbuf *jb, int oper)
@@ -905,6 +906,6 @@
 
 	if (jb->jb_status == JB_STATUS_INITIALIZING) {
-	    /* Switch status 'initializing' -> 'processing' after some OP 
-	     * switch cycles and current OP is GET (burst level is calculated 
+	    /* Switch status 'initializing' -> 'processing' after some OP
+	     * switch cycles and current OP is GET (burst level is calculated
 	     * based on PUT burst), so burst calculation is guaranted to be
 	     * performed right after the status switching.
@@ -922,8 +923,8 @@
 	}
 
-	/* Perform jitter calculation based on PUT burst-level only, since 
+	/* Perform jitter calculation based on PUT burst-level only, since
 	 * GET burst-level may not be accurate, e.g: when VAD is active.
 	 * Note that when burst-level is too big, i.e: exceeds jb_max_burst,
-	 * the GET op may be idle, in this case, we better skip the jitter 
+	 * the GET op may be idle, in this case, we better skip the jitter
 	 * calculation.
 	 */
@@ -940,7 +941,7 @@
 }
 
-PJ_DEF(void) pjmedia_jbuf_put_frame( pjmedia_jbuf *jb, 
-				     const void *frame, 
-				     pj_size_t frame_size, 
+PJ_DEF(void) pjmedia_jbuf_put_frame( pjmedia_jbuf *jb,
+				     const void *frame,
+				     pj_size_t frame_size,
 				     int frame_seq)
 {
@@ -948,18 +949,18 @@
 }
 
-PJ_DEF(void) pjmedia_jbuf_put_frame2(pjmedia_jbuf *jb, 
-				     const void *frame, 
-				     pj_size_t frame_size, 
+PJ_DEF(void) pjmedia_jbuf_put_frame2(pjmedia_jbuf *jb,
+				     const void *frame,
+				     pj_size_t frame_size,
 				     pj_uint32_t bit_info,
 				     int frame_seq,
 				     pj_bool_t *discarded)
 {
-    pjmedia_jbuf_put_frame3(jb, frame, frame_size, bit_info, frame_seq, 0, 
+    pjmedia_jbuf_put_frame3(jb, frame, frame_size, bit_info, frame_seq, 0,
 			    discarded);
 }
 
-PJ_DEF(void) pjmedia_jbuf_put_frame3(pjmedia_jbuf *jb, 
-				     const void *frame, 
-				     pj_size_t frame_size, 
+PJ_DEF(void) pjmedia_jbuf_put_frame3(pjmedia_jbuf *jb,
+				     const void *frame,
+				     pj_size_t frame_size,
 				     pj_uint32_t bit_info,
 				     int frame_seq,
@@ -978,5 +979,5 @@
 				 (unsigned)min_frame_size, bit_info, ts,
 				 PJMEDIA_JB_NORMAL_FRAME);
-    
+
     /* Jitter buffer is full, remove some older frames */
     while (status == PJ_ETOOMANY) {
@@ -1010,5 +1011,5 @@
     if (status == PJ_SUCCESS) {
 	if (jb->jb_prefetching) {
-	    TRACE__((jb->jb_name.ptr, "PUT prefetch_cnt=%d/%d", 
+	    TRACE__((jb->jb_name.ptr, "PUT prefetch_cnt=%d/%d",
 		     new_size, jb->jb_prefetch));
 	    if (new_size >= jb->jb_prefetch)
@@ -1024,6 +1025,6 @@
  * Get frame from jitter buffer.
  */
-PJ_DEF(void) pjmedia_jbuf_get_frame( pjmedia_jbuf *jb, 
-				     void *frame, 
+PJ_DEF(void) pjmedia_jbuf_get_frame( pjmedia_jbuf *jb,
+				     void *frame,
 				     char *p_frame_type)
 {
@@ -1035,6 +1036,6 @@
  * Get frame from jitter buffer.
  */
-PJ_DEF(void) pjmedia_jbuf_get_frame2(pjmedia_jbuf *jb, 
-				     void *frame, 
+PJ_DEF(void) pjmedia_jbuf_get_frame2(pjmedia_jbuf *jb,
+				     void *frame,
 				     pj_size_t *size,
 				     char *p_frame_type,
@@ -1048,6 +1049,6 @@
  * Get frame from jitter buffer.
  */
-PJ_DEF(void) pjmedia_jbuf_get_frame3(pjmedia_jbuf *jb, 
-				     void *frame, 
+PJ_DEF(void) pjmedia_jbuf_get_frame3(pjmedia_jbuf *jb,
+				     void *frame,
 				     pj_size_t *size,
 				     char *p_frame_type,
@@ -1078,5 +1079,5 @@
 
 	/* Try to retrieve a frame from frame list */
-	res = jb_framelist_get(&jb->jb_framelist, frame, size, &ftype, 
+	res = jb_framelist_get(&jb->jb_framelist, frame, size, &ftype,
 			       bit_info, ts, seq);
 	if (res) {
@@ -1097,5 +1098,5 @@
 		/* We've just retrieved one frame, so add one to cur_size */
 		cur_size = jb_framelist_eff_size(&jb->jb_framelist) + 1;
-		pj_math_stat_update(&jb->jb_delay, 
+		pj_math_stat_update(&jb->jb_delay,
 				    cur_size*jb->jb_frame_ptime);
 	    }
@@ -1129,14 +1130,14 @@
     state->min_prefetch = jb->jb_min_prefetch;
     state->max_prefetch = jb->jb_max_prefetch;
-    
+
     state->burst = jb->jb_eff_level;
     state->prefetch = jb->jb_prefetch;
     state->size = jb_framelist_eff_size(&jb->jb_framelist);
-    
+
     state->avg_delay = jb->jb_delay.mean;
     state->min_delay = jb->jb_delay.min;
     state->max_delay = jb->jb_delay.max;
     state->dev_delay = pj_math_stat_get_stddev(&jb->jb_delay);
-    
+
     state->avg_burst = jb->jb_burst.mean;
     state->empty = jb->jb_empty;
@@ -1150,6 +1151,6 @@
 PJ_DEF(void) pjmedia_jbuf_peek_frame( pjmedia_jbuf *jb,
 				      unsigned offset,
-				      const void **frame, 
-				      pj_size_t *size, 
+				      const void **frame,
+				      pj_size_t *size,
 				      char *p_frm_type,
 				      pj_uint32_t *bit_info,
@@ -1171,5 +1172,5 @@
 
 
-PJ_DEF(unsigned) pjmedia_jbuf_remove_frame(pjmedia_jbuf *jb, 
+PJ_DEF(unsigned) pjmedia_jbuf_remove_frame(pjmedia_jbuf *jb,
 					   unsigned frame_cnt)
 {
