Index: /pjproject/trunk/pjlib/include/pjlib.h
===================================================================
--- /pjproject/trunk/pjlib/include/pjlib.h	(revision 1960)
+++ /pjproject/trunk/pjlib/include/pjlib.h	(revision 1961)
@@ -43,4 +43,5 @@
 #include <pj/lock.h>
 #include <pj/log.h>
+#include <pj/math.h>
 #include <pj/os.h>
 #include <pj/pool.h>
Index: /pjproject/trunk/pjmedia/include/pjmedia/jbuf.h
===================================================================
--- /pjproject/trunk/pjmedia/include/pjmedia/jbuf.h	(revision 1960)
+++ /pjproject/trunk/pjmedia/include/pjmedia/jbuf.h	(revision 1961)
@@ -77,5 +77,8 @@
     unsigned	max_prefetch;	    /**< Maximum allowed prefetch, in frms. */
     unsigned	size;		    /**< Current buffer size, in frames.    */
-    unsigned	max_size;	    /**< Maximum size ever.		    */
+    unsigned	avg_delay;	    /**< Average delay, in ms.		    */
+    unsigned	min_delay;	    /**< Minimum delay, in ms.		    */
+    unsigned	max_delay;	    /**< Maximum delay, in ms.		    */
+    unsigned	dev_delay;	    /**< Standard deviation of delay, in ms. */
 };
 
Index: /pjproject/trunk/pjmedia/include/pjmedia/rtcp.h
===================================================================
--- /pjproject/trunk/pjmedia/include/pjmedia/rtcp.h	(revision 1960)
+++ /pjproject/trunk/pjmedia/include/pjmedia/rtcp.h	(revision 1961)
@@ -28,5 +28,4 @@
 #include <pjmedia/rtcp_xr.h>
 #include <pjmedia/rtp.h>
-
 
 PJ_BEGIN_DECL
@@ -181,11 +180,5 @@
     unsigned	    dup;	/**< Total number of duplicates packets	    */
 
-    struct {
-	unsigned    count;	/**< Number of period samples(to calc avg)  */
-	unsigned    min;	/**< Minimum loss period (in usec)	    */
-	unsigned    avg;	/**< Average loss period (in usec)	    */
-	unsigned    max;	/**< Maximum loss period (in usec)	    */
-	unsigned    last;	/**< Last loss period (in usec)		    */
-    } loss_period;		/**< Lost period history.		    */
+    pj_math_stat    loss_period;/**< Loss period statistics (in usec)	    */
 
     struct {
@@ -194,11 +187,5 @@
     } loss_type;		/**< Types of loss detected.		    */
 
-    struct {
-	unsigned    count;	/**< Number of updates.			    */
-	unsigned    min;	/**< Minimum jitter (in usec)		    */
-	unsigned    avg;	/**< Average jitter (in usec)		    */
-	unsigned    max;	/**< Maximum jitter (in usec)		    */
-	unsigned    last;	/**< Last jitter (in usec)		    */
-    } jitter;			/**< Jitter history.			    */
+    pj_math_stat    jitter;	/**< Jitter statistics (in usec)	    */
 };
 
@@ -221,12 +208,5 @@
     pjmedia_rtcp_stream_stat rx;    /**< Decoder stream statistics.	    */
     
-    struct {
-	unsigned    min;	    /**< Minimum round-trip delay (in usec) */
-	unsigned    avg;	    /**< Average round-trip delay (in usec) */
-	unsigned    max;	    /**< Maximum round-trip delay (in usec) */
-	unsigned    last;	    /**< Last round-trip delay (in usec)    */
-    } rtt;			    /**< Round trip delay history.	    */
-
-    unsigned	    rtt_update_cnt; /**< Nb of times rtt is updated.	    */
+    pj_math_stat	     rtt;   /**< Round trip delay statistic(in usec)*/
 };
 
Index: /pjproject/trunk/pjmedia/include/pjmedia/rtcp_xr.h
===================================================================
--- /pjproject/trunk/pjmedia/include/pjmedia/rtcp_xr.h	(revision 1960)
+++ /pjproject/trunk/pjmedia/include/pjmedia/rtcp_xr.h	(revision 1961)
@@ -26,4 +26,5 @@
 
 #include <pjmedia/types.h>
+#include <pj/math.h>
 
 
@@ -247,20 +248,6 @@
 	unsigned	    lost;	/**< Number of packets lost	    */
 	unsigned	    dup;	/**< Number of duplicated packets   */
-	
-	struct {
-	    unsigned	    min;	/**< Minimum jitter (in usec)	    */
-	    unsigned	    max;	/**< Maximum jitter (in usec)	    */
-	    unsigned	    dev;	/**< Jitter deviation (in usec)	    */
-	    unsigned	    mean;	/**< Average jitter (in usec)	    */
-	    unsigned	    count;	/**< Update count		    */
-	} jitter;			/**< Jitter history.		    */
-
-	struct {
-	    unsigned	    min;	/**< Minimum ToH		    */
-	    unsigned	    max;	/**< Maximum ToH		    */
-	    unsigned	    dev;	/**< ToH deviation		    */
-	    unsigned	    mean;	/**< Average ToH		    */
-	    unsigned	    count;	/**< Update count		    */
-	} toh;				/**< TTL of hop limit history.	    */
+	pj_math_stat	    jitter;	/**< Jitter statistics (in usec)    */
+	pj_math_stat	    toh;	/**< TTL of hop limit statistics.   */
     } stat_sum;
 
@@ -301,16 +288,9 @@
 typedef struct pjmedia_rtcp_xr_stat
 {
-    pjmedia_rtcp_xr_stream_stat	 rx;
-    pjmedia_rtcp_xr_stream_stat	 tx;
-
-    /* RTT calculated from receiver side */
-    struct {
-	unsigned    min;	    /**< Minimum round-trip delay (in usec) */
-	unsigned    avg;	    /**< Average round-trip delay (in usec) */
-	unsigned    max;	    /**< Maximum round-trip delay (in usec) */
-	unsigned    last;	    /**< Last round-trip delay (in usec)    */
-	unsigned    update_cnt;	    /**< Nb of times rtt is updated.	    */
-    } rtt;			    /**< Round trip delay history.	    */
-
+    pjmedia_rtcp_xr_stream_stat	 rx;  /**< Decoding direction statistics.   */
+    pjmedia_rtcp_xr_stream_stat	 tx;  /**< Encoding direction statistics.   */
+    pj_math_stat		 rtt; /**< Round-trip delay stat (in usec) 
+					   the value is calculated from 
+					   receiver side.		    */
 } pjmedia_rtcp_xr_stat;
 
Index: /pjproject/trunk/pjmedia/src/pjmedia/jbuf.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia/jbuf.c	(revision 1960)
+++ /pjproject/trunk/pjmedia/src/pjmedia/jbuf.c	(revision 1961)
@@ -25,4 +25,5 @@
 #include <pj/assert.h>
 #include <pj/log.h>
+#include <pj/math.h>
 #include <pj/string.h>
 
@@ -67,6 +68,5 @@
     int		    jb_max_prefetch;	  // Maximum allowable prefetch
     int		    jb_status;		  // status is 'init' until the	first 'put' operation
-
-    int		    jb_max_size;	  // Maximum frames buffered ever
+    pj_math_stat    jb_delay;		  // Delay statistics of jitter buffer (in frame unit)
 };
 
@@ -74,9 +74,4 @@
 #define JB_STATUS_INITIALIZING	0
 #define JB_STATUS_PROCESSING	1
-
-#define	PJ_ABS(x)	((x > 0) ? (x) : -(x))
-#define	PJ_MAX(x, y)	((x > y) ? (x) : (y))
-#define	PJ_MIN(x, y)	((x < y) ? (x) : (y))
-
 
 /* Enabling this would log the jitter buffer state about once per 
@@ -314,4 +309,6 @@
     jb->jb_max_count	 = max_count;
 
+    pj_math_stat_init(&jb->jb_delay);
+
     *p_jb = jb;
     return PJ_SUCCESS;
@@ -369,8 +366,10 @@
     jb->jb_status	 = JB_STATUS_INITIALIZING;
     jb->jb_max_hist_level = 0;
-    jb->jb_max_size	 = 0;
 
     jb_framelist_remove_head(&jb->jb_framelist, 
 			     jb_framelist_size(&jb->jb_framelist));
+
+    pj_math_stat_init(&jb->jb_delay);
+    
     return PJ_SUCCESS;
 }
@@ -389,6 +388,4 @@
     /* Update jb_max_size */
     cur_size = jb_framelist_size(&jb->jb_framelist);
-    if (cur_size > jb->jb_max_size)
-	jb->jb_max_size = cur_size;
 
     /* Only apply burst-level calculation on PUT operation since if VAD is 
@@ -457,7 +454,11 @@
 	jb_framelist_remove_head(&jb->jb_framelist, diff);
 
+	pj_math_stat_update(&jb->jb_delay, cur_size - diff);
+
 	TRACE__((jb->name.ptr, 
 		 "JB shrinking %d frame(s), size=%d", diff,
 		 jb_framelist_size(&jb->jb_framelist)));
+    } else {
+	pj_math_stat_update(&jb->jb_delay, cur_size);
     }
 
@@ -612,7 +613,10 @@
     state->max_prefetch = jb->jb_max_prefetch;
     state->size = jb_framelist_size(&jb->jb_framelist);
-    state->max_size = jb->jb_max_size;
+    state->avg_delay = jb->jb_delay.mean * jb->jb_frame_ptime;
+    state->min_delay = jb->jb_delay.min * jb->jb_frame_ptime;
+    state->max_delay = jb->jb_delay.max * jb->jb_frame_ptime;
+    state->dev_delay = pj_math_stat_get_stddev(&jb->jb_delay) * 
+		       jb->jb_frame_ptime;
 
     return PJ_SUCCESS;
 }
-
Index: /pjproject/trunk/pjmedia/src/pjmedia/rtcp.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia/rtcp.c	(revision 1960)
+++ /pjproject/trunk/pjmedia/src/pjmedia/rtcp.c	(revision 1961)
@@ -167,4 +167,11 @@
     pj_get_timestamp_freq(&sess->ts_freq);
 
+    /* Initialize statistics states */
+    pj_math_stat_init(&sess->stat.rtt);
+    pj_math_stat_init(&sess->stat.rx.loss_period);
+    pj_math_stat_init(&sess->stat.rx.jitter);
+    pj_math_stat_init(&sess->stat.tx.loss_period);
+    pj_math_stat_init(&sess->stat.tx.jitter);
+
     /* RR will be initialized on receipt of the first RTP packet. */
 }
@@ -275,16 +282,5 @@
 
 	/* Update loss period stat */
-	if (sess->stat.rx.loss_period.count == 0 ||
-	    period < sess->stat.rx.loss_period.min)
-	{
-	    sess->stat.rx.loss_period.min = period;
-	}
-	if (period > sess->stat.rx.loss_period.max)
-	    sess->stat.rx.loss_period.max = period;
-	sess->stat.rx.loss_period.avg = 
-	    (sess->stat.rx.loss_period.avg * sess->stat.rx.loss_period.count +
-	     period) / (sess->stat.rx.loss_period.count + 1);
-	sess->stat.rx.loss_period.last = period;
-	++sess->stat.rx.loss_period.count;
+	pj_math_stat_update(&sess->stat.rx.loss_period, period);
     }
 
@@ -330,18 +326,6 @@
 	    }
 
-	    /* Add to average */
-	    sess->avg_jitter = 
-		(jitter + sess->avg_jitter * sess->stat.rx.jitter.count) /
-		(sess->stat.rx.jitter.count + 1);
-	    sess->stat.rx.jitter.avg = (unsigned)sess->avg_jitter;
-	    ++sess->stat.rx.jitter.count;
-
 	    /* Update jitter stat */
-	    if (jitter < sess->stat.rx.jitter.min)
-		sess->stat.rx.jitter.min = jitter;
-	    if (jitter > sess->stat.rx.jitter.max)
-		sess->stat.rx.jitter.max = jitter;
-
-	    sess->stat.rx.jitter.last = jitter;
+	    pj_math_stat_update(&sess->stat.rx.jitter, jitter);
 
 #if defined(PJMEDIA_HAS_RTCP_XR) && (PJMEDIA_HAS_RTCP_XR != 0)
@@ -464,15 +448,6 @@
 	period *= 1000;
 
-	if (sess->stat.tx.update_cnt==0||sess->stat.tx.loss_period.min==0)
-	    sess->stat.tx.loss_period.min = period;
-	if (period < sess->stat.tx.loss_period.min)
-	    sess->stat.tx.loss_period.min = period;
-	if (period > sess->stat.tx.loss_period.max)
-	    sess->stat.tx.loss_period.max = period;
-
-	sess->stat.tx.loss_period.avg = 
-	    (sess->stat.tx.loss_period.avg*sess->stat.tx.update_cnt+period)
-	    / (sess->stat.tx.update_cnt + 1);
-	sess->stat.tx.loss_period.last = period;
+	/* Update loss period stat */
+	pj_math_stat_update(&sess->stat.tx.loss_period, period);
     }
 
@@ -488,16 +463,5 @@
 
     /* Update jitter statistics */
-    if (sess->stat.tx.jitter.count == 0)
-	sess->stat.tx.jitter.min = jitter;
-    if (jitter < sess->stat.tx.jitter.min && jitter)
-	sess->stat.tx.jitter.min = jitter;
-    if (jitter > sess->stat.tx.jitter.max)
-	sess->stat.tx.jitter.max = jitter;
-    sess->stat.tx.jitter.avg = 
-	(sess->stat.tx.jitter.avg * sess->stat.tx.jitter.count + jitter) /
-	(sess->stat.tx.jitter.count + 1);
-    ++sess->stat.tx.jitter.count;
-    sess->stat.tx.jitter.last = jitter;
-
+    pj_math_stat_update(&sess->stat.tx.jitter, jitter);
 
     /* Can only calculate if LSR and DLSR is present in RR */
@@ -553,14 +517,12 @@
 	    }
 
-	    if (sess->stat.rtt_update_cnt == 0)
-		sess->stat.rtt.min = rtt;
-
 	    /* "Normalize" rtt value that is exceptionally high.
 	     * For such values, "normalize" the rtt to be three times
 	     * the average value.
 	     */
-	    if (rtt > (sess->stat.rtt.avg*3) && sess->stat.rtt_update_cnt!=0) {
+	    if (rtt > ((unsigned)sess->stat.rtt.mean*3) && sess->stat.rtt.n!=0)
+	    {
 		unsigned orig_rtt = rtt;
-		rtt = sess->stat.rtt.avg*3;
+		rtt = sess->stat.rtt.mean*3;
 		PJ_LOG(5,(sess->name, 
 			  "RTT value %d usec is normalized to %d usec",
@@ -570,15 +532,6 @@
 	    TRACE_((sess->name, "RTCP RTT is set to %d usec", rtt));
 
-	    if (rtt < sess->stat.rtt.min && rtt)
-		sess->stat.rtt.min = rtt;
-	    if (rtt > sess->stat.rtt.max)
-		sess->stat.rtt.max = rtt;
-
-	    sess->stat.rtt.avg = 
-		(sess->stat.rtt.avg * sess->stat.rtt_update_cnt + rtt) / 
-		(sess->stat.rtt_update_cnt + 1);
-
-	    sess->stat.rtt.last = rtt;
-	    sess->stat.rtt_update_cnt++;
+	    /* Update RTT stat */
+	    pj_math_stat_update(&sess->stat.rtt, rtt);
 
 	} else {
Index: /pjproject/trunk/pjmedia/src/pjmedia/rtcp_xr.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia/rtcp_xr.c	(revision 1960)
+++ /pjproject/trunk/pjmedia/src/pjmedia/rtcp_xr.c	(revision 1961)
@@ -27,5 +27,5 @@
 #include <pj/string.h>
 
-#if defined(PJMEDIA_HAS_RTCP_XR) && (PJMEDIA_HAS_RTCP_XR != 0)
+#if 1 //defined(PJMEDIA_HAS_RTCP_XR) && (PJMEDIA_HAS_RTCP_XR != 0)
 
 #define THIS_FILE "rtcp_xr.c"
@@ -58,25 +58,4 @@
 #   define TRACE_(x)	;
 #endif
-
-/* Integer square root for calculating standard deviation */
-static pj_uint32_t my_isqrt(pj_uint32_t i)
-{
-    pj_uint32_t res = 1, prev;
-    
-    /* Rough guess */
-    prev = i >> 2;
-    while (prev) {
-	prev >>= 2;
-	res <<= 1;
-    }
-
-    /* Babilonian method */
-    do {
-	prev = res;
-	res = (prev + i/prev) >> 1;
-    } while ((prev+res)>>1 != res);
-
-    return res;
-}
 
 void pjmedia_rtcp_xr_init( pjmedia_rtcp_xr_session *session, 
@@ -231,16 +210,14 @@
 	    r->jitter_min = pj_htonl(sess->stat.rx.stat_sum.jitter.min);
 	    r->jitter_max = pj_htonl(sess->stat.rx.stat_sum.jitter.max);
-	    r->jitter_mean = pj_htonl(sess->stat.rx.stat_sum.jitter.mean);
-	    sess->stat.rx.stat_sum.jitter.dev = 
-				my_isqrt(sess->stat.rx.stat_sum.jitter.dev);
-	    r->jitter_dev = pj_htonl(sess->stat.rx.stat_sum.jitter.dev);
+	    r->jitter_mean = 
+		pj_htonl((unsigned)sess->stat.rx.stat_sum.jitter.mean);
+	    r->jitter_dev = 
+		pj_htonl(pj_math_stat_get_stddev(&sess->stat.rx.stat_sum.jitter));
 	}
 	if (sess->stat.rx.stat_sum.t) {
 	    r->toh_min = sess->stat.rx.stat_sum.toh.min;
 	    r->toh_max = sess->stat.rx.stat_sum.toh.max;
-	    r->toh_mean = sess->stat.rx.stat_sum.toh.mean;
-	    sess->stat.rx.stat_sum.toh.dev = 
-				my_isqrt(sess->stat.rx.stat_sum.toh.dev);
-	    r->toh_dev = sess->stat.rx.stat_sum.toh.dev;
+	    r->toh_mean = (unsigned) sess->stat.rx.stat_sum.toh.mean;
+	    r->toh_dev = pj_math_stat_get_stddev(&sess->stat.rx.stat_sum.toh);
 	}
 
@@ -293,5 +270,5 @@
 
 	/* Calculate burst and densities. */
-	if (ctotal) {
+	if (c11 && (c23 || c33)) {
 	    p32 = c32 / (c31 + c32 + c33);
 	    if((c22 + c23) < 1) {
@@ -518,15 +495,12 @@
 	     */
 	    if (eedelay <= 30 * 1000 * 1000UL) {
-		if (sess->stat.rtt.update_cnt == 0)
-		    sess->stat.rtt.min = rtt;
-
 		/* "Normalize" rtt value that is exceptionally high.
 		 * For such values, "normalize" the rtt to be three times
 		 * the average value.
 		 */
-		if (rtt>(sess->stat.rtt.avg*3) && sess->stat.rtt.update_cnt!=0)
+		if (rtt>((unsigned)sess->stat.rtt.mean*3) && sess->stat.rtt.n!=0)
 		{
 		    unsigned orig_rtt = rtt;
-		    rtt = sess->stat.rtt.avg*3;
+		    rtt = (unsigned)sess->stat.rtt.mean*3;
 		    PJ_LOG(5,(sess->name, 
 			      "RTT value %d usec is normalized to %d usec",
@@ -535,16 +509,5 @@
     	
 		TRACE_((sess->name, "RTCP RTT is set to %d usec", rtt));
-
-		if (rtt < sess->stat.rtt.min && rtt)
-		    sess->stat.rtt.min = rtt;
-		if (rtt > sess->stat.rtt.max)
-		    sess->stat.rtt.max = rtt;
-
-		sess->stat.rtt.avg = 
-		    (sess->stat.rtt.avg * sess->stat.rtt.update_cnt + rtt) / 
-		    (sess->stat.rtt.update_cnt + 1);
-
-		sess->stat.rtt.last = rtt;
-		sess->stat.rtt.update_cnt++;
+		pj_math_stat_update(&sess->stat.rtt, rtt);
 	    }
 	} else {
@@ -586,6 +549,7 @@
 	    sess->stat.tx.stat_sum.jitter.min = pj_ntohl(rb_stats->jitter_min);
 	    sess->stat.tx.stat_sum.jitter.max = pj_ntohl(rb_stats->jitter_max);
-	    sess->stat.tx.stat_sum.jitter.mean = pj_ntohl(rb_stats->jitter_mean);
-	    sess->stat.tx.stat_sum.jitter.dev = pj_ntohl(rb_stats->jitter_dev);
+	    sess->stat.tx.stat_sum.jitter.mean= pj_ntohl(rb_stats->jitter_mean);
+	    pj_math_stat_set_stddev(&sess->stat.tx.stat_sum.jitter, 
+				    pj_ntohl(rb_stats->jitter_dev));
 	}
 
@@ -593,6 +557,7 @@
 	    sess->stat.tx.stat_sum.toh.min = rb_stats->toh_min;
 	    sess->stat.tx.stat_sum.toh.max = rb_stats->toh_max;
-	    sess->stat.tx.stat_sum.toh.mean = rb_stats->toh_mean;
-	    sess->stat.tx.stat_sum.toh.dev = rb_stats->toh_dev;
+	    sess->stat.tx.stat_sum.toh.mean= rb_stats->toh_mean;
+	    pj_math_stat_set_stddev(&sess->stat.tx.stat_sum.toh, 
+				    pj_ntohl(rb_stats->toh_dev));
 	}
 
@@ -728,46 +693,11 @@
 
     if (jitter >= 0) {
-	pj_int32_t diff;
-
 	sess->stat.rx.stat_sum.j = PJ_TRUE;
-	if (sess->stat.rx.stat_sum.jitter.min > (pj_uint32_t)jitter)
-	    sess->stat.rx.stat_sum.jitter.min = jitter;
-	if (sess->stat.rx.stat_sum.jitter.max < (pj_uint32_t)jitter)
-	    sess->stat.rx.stat_sum.jitter.max = jitter;
-	sess->stat.rx.stat_sum.jitter.mean = 
-	    (jitter + sess->stat.rx.stat_sum.jitter.mean * 
-	     sess->stat.rx.stat_sum.jitter.count) /
-	    (sess->stat.rx.stat_sum.jitter.count + 1);
-
-	diff = sess->stat.rx.stat_sum.jitter.mean - jitter;
-	sess->stat.rx.stat_sum.jitter.dev =
-	    (diff * diff + sess->stat.rx.stat_sum.jitter.dev * 
-	     sess->stat.rx.stat_sum.jitter.count) /
-	    (sess->stat.rx.stat_sum.jitter.count + 1);
-
-	++sess->stat.rx.stat_sum.jitter.count;
+	pj_math_stat_update(&sess->stat.rx.stat_sum.jitter, jitter);
     }
 
     if (toh >= 0) {
-	pj_int32_t diff;
-
 	sess->stat.rx.stat_sum.t = toh_ipv4? 1 : 2;
-
-	if (sess->stat.rx.stat_sum.toh.min > (pj_uint32_t)toh)
-	    sess->stat.rx.stat_sum.toh.min = toh;
-	if (sess->stat.rx.stat_sum.toh.max < (pj_uint32_t)toh)
-	    sess->stat.rx.stat_sum.toh.max = toh;
-	sess->stat.rx.stat_sum.toh.mean = 
-	    (toh + sess->stat.rx.stat_sum.toh.mean * 
-	     sess->stat.rx.stat_sum.toh.count) /
-	    (sess->stat.rx.stat_sum.toh.count + 1);
-
-	diff = sess->stat.rx.stat_sum.toh.mean - toh;
-	sess->stat.rx.stat_sum.toh.dev =
-	    (diff * diff + sess->stat.rx.stat_sum.toh.dev * 
-	     sess->stat.rx.stat_sum.toh.count) /
-	    (sess->stat.rx.stat_sum.toh.count + 1);
-
-	++sess->stat.rx.stat_sum.toh.count;
+	pj_math_stat_update(&sess->stat.rx.stat_sum.toh, toh);
     }
 
Index: /pjproject/trunk/pjmedia/src/pjmedia/stream.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia/stream.c	(revision 1960)
+++ /pjproject/trunk/pjmedia/src/pjmedia/stream.c	(revision 1961)
@@ -501,10 +501,10 @@
 	    pjmedia_jbuf_get_state(stream->jb, &jb_state);
     	    
-	    i = jb_state.size * stream->codec_param.info.frm_ptime;
+	    i = jb_state.avg_delay;
 	    pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session, 
 					PJMEDIA_RTCP_XR_INFO_JB_NOM,
 					i);
 
-	    i = jb_state.max_size* stream->codec_param.info.frm_ptime;
+	    i = jb_state.max_delay;
 	    pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session, 
 					PJMEDIA_RTCP_XR_INFO_JB_MAX,
@@ -1674,10 +1674,10 @@
 	pjmedia_jbuf_get_state(stream->jb, &jb_state);
     	    
-	i = jb_state.size * stream->codec_param.info.frm_ptime;
+	i = jb_state.avg_delay;
 	pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session, 
 				    PJMEDIA_RTCP_XR_INFO_JB_NOM,
 				    i);
 
-	i = jb_state.max_size* stream->codec_param.info.frm_ptime;
+	i = jb_state.max_delay;
 	pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session, 
 				    PJMEDIA_RTCP_XR_INFO_JB_MAX,
Index: /pjproject/trunk/pjsip-apps/src/samples/siprtp.c
===================================================================
--- /pjproject/trunk/pjsip-apps/src/samples/siprtp.c	(revision 1960)
+++ /pjproject/trunk/pjsip-apps/src/samples/siprtp.c	(revision 1961)
@@ -1660,5 +1660,5 @@
 	MIN_(min_stat.rx.jitter.min, audio->rtcp.stat.rx.jitter.min);
 	MAX_(max_stat.rx.jitter.max, audio->rtcp.stat.rx.jitter.max);
-	AVG_(avg_stat.rx.jitter.avg, audio->rtcp.stat.rx.jitter.avg);
+	AVG_(avg_stat.rx.jitter.mean, audio->rtcp.stat.rx.jitter.mean);
 
 
@@ -1693,5 +1693,5 @@
 	MIN_(min_stat.tx.jitter.min, audio->rtcp.stat.tx.jitter.min);
 	MAX_(max_stat.tx.jitter.max, audio->rtcp.stat.tx.jitter.max);
-	AVG_(avg_stat.tx.jitter.avg, audio->rtcp.stat.tx.jitter.avg);
+	AVG_(avg_stat.tx.jitter.mean, audio->rtcp.stat.tx.jitter.mean);
 
 
@@ -1699,5 +1699,5 @@
 	MIN_(min_stat.rtt.min, audio->rtcp.stat.rtt.min);
 	MAX_(max_stat.rtt.max, audio->rtcp.stat.rtt.max);
-	AVG_(avg_stat.rtt.avg, audio->rtcp.stat.rtt.avg);
+	AVG_(avg_stat.rtt.mean, audio->rtcp.stat.rtt.mean);
 
 	++count;
@@ -1768,5 +1768,5 @@
 
 	   min_stat.rx.jitter.min/1000.0, 
-	   avg_stat.rx.jitter.avg/1000.0, 
+	   avg_stat.rx.jitter.mean/1000.0, 
 	   max_stat.rx.jitter.max/1000.0,
 	   "ms",
@@ -1799,5 +1799,5 @@
 
 	   min_stat.tx.jitter.min/1000.0, 
-	   avg_stat.tx.jitter.avg/1000.0, 
+	   avg_stat.tx.jitter.mean/1000.0, 
 	   max_stat.tx.jitter.max/1000.0,
 	   "ms",
@@ -1805,5 +1805,5 @@
 	   /* rtt */
 	   min_stat.rtt.min/1000.0, 
-	   avg_stat.rtt.avg/1000.0, 
+	   avg_stat.rtt.mean/1000.0, 
 	   max_stat.rtt.max/1000.0,
 	   "ms"
Index: /pjproject/trunk/pjsip-apps/src/samples/siprtp_report.c
===================================================================
--- /pjproject/trunk/pjsip-apps/src/samples/siprtp_report.c	(revision 1960)
+++ /pjproject/trunk/pjsip-apps/src/samples/siprtp_report.c	(revision 1961)
@@ -161,10 +161,10 @@
 	   "",
 	   audio->rtcp.stat.rx.loss_period.min / 1000.0, 
-	   audio->rtcp.stat.rx.loss_period.avg / 1000.0, 
+	   audio->rtcp.stat.rx.loss_period.mean / 1000.0, 
 	   audio->rtcp.stat.rx.loss_period.max / 1000.0,
 	   audio->rtcp.stat.rx.loss_period.last / 1000.0,
 	   "",
 	   audio->rtcp.stat.rx.jitter.min / 1000.0,
-	   audio->rtcp.stat.rx.jitter.avg / 1000.0,
+	   audio->rtcp.stat.rx.jitter.mean / 1000.0,
 	   audio->rtcp.stat.rx.jitter.max / 1000.0,
 	   audio->rtcp.stat.rx.jitter.last / 1000.0,
@@ -205,10 +205,10 @@
 	   "",
 	   audio->rtcp.stat.tx.loss_period.min / 1000.0, 
-	   audio->rtcp.stat.tx.loss_period.avg / 1000.0, 
+	   audio->rtcp.stat.tx.loss_period.mean / 1000.0, 
 	   audio->rtcp.stat.tx.loss_period.max / 1000.0,
 	   audio->rtcp.stat.tx.loss_period.last / 1000.0,
 	   "",
 	   audio->rtcp.stat.tx.jitter.min / 1000.0,
-	   audio->rtcp.stat.tx.jitter.avg / 1000.0,
+	   audio->rtcp.stat.tx.jitter.mean / 1000.0,
 	   audio->rtcp.stat.tx.jitter.max / 1000.0,
 	   audio->rtcp.stat.tx.jitter.last / 1000.0,
@@ -220,5 +220,5 @@
 	   "             RTT delay      : %7.3f %7.3f %7.3f %7.3f%s\n", 
 	   audio->rtcp.stat.rtt.min / 1000.0,
-	   audio->rtcp.stat.rtt.avg / 1000.0,
+	   audio->rtcp.stat.rtt.mean / 1000.0,
 	   audio->rtcp.stat.rtt.max / 1000.0,
 	   audio->rtcp.stat.rtt.last / 1000.0,
Index: /pjproject/trunk/pjsip-apps/src/samples/streamutil.c
===================================================================
--- /pjproject/trunk/pjsip-apps/src/samples/streamutil.c	(revision 1960)
+++ /pjproject/trunk/pjsip-apps/src/samples/streamutil.c	(revision 1961)
@@ -769,7 +769,7 @@
 	   "    total %s packets %sB received (%sB +IP hdr)%s\n"
 	   "    pkt loss=%d (%3.1f%%), dup=%d (%3.1f%%), reorder=%d (%3.1f%%)%s\n"
-	   "          (msec)    min     avg     max     last\n"
-	   "    loss period: %7.3f %7.3f %7.3f %7.3f%s\n"
-	   "    jitter     : %7.3f %7.3f %7.3f %7.3f%s\n",
+	   "          (msec)    min     avg     max     last    dev\n"
+	   "    loss period: %7.3f %7.3f %7.3f %7.3f %7.3f%s\n"
+	   "    jitter     : %7.3f %7.3f %7.3f %7.3f %7.3f%s\n",
 	   last_update,
 	   good_number(packets, stat.rx.pkt),
@@ -785,12 +785,14 @@
 	   "",
 	   stat.rx.loss_period.min / 1000.0, 
-	   stat.rx.loss_period.avg / 1000.0, 
+	   stat.rx.loss_period.mean / 1000.0, 
 	   stat.rx.loss_period.max / 1000.0,
 	   stat.rx.loss_period.last / 1000.0,
+	   pj_math_stat_get_stddev(&stat.rx.loss_period) / 1000.0,
 	   "",
 	   stat.rx.jitter.min / 1000.0,
-	   stat.rx.jitter.avg / 1000.0,
+	   stat.rx.jitter.mean / 1000.0,
 	   stat.rx.jitter.max / 1000.0,
 	   stat.rx.jitter.last / 1000.0,
+	   pj_math_stat_get_stddev(&stat.rx.jitter) / 1000.0,
 	   ""
 	   );
@@ -812,7 +814,7 @@
 	   "    total %s packets %sB sent (%sB +IP hdr)%s\n"
 	   "    pkt loss=%d (%3.1f%%), dup=%d (%3.1f%%), reorder=%d (%3.1f%%)%s\n"
-	   "          (msec)    min     avg     max     last\n"
-	   "    loss period: %7.3f %7.3f %7.3f %7.3f%s\n"
-	   "    jitter     : %7.3f %7.3f %7.3f %7.3f%s\n",
+	   "          (msec)    min     avg     max     last    dev\n"
+	   "    loss period: %7.3f %7.3f %7.3f %7.3f %7.3f%s\n"
+	   "    jitter     : %7.3f %7.3f %7.3f %7.3f %7.3f%s\n",
 	   last_update,
 	   good_number(packets, stat.tx.pkt),
@@ -828,21 +830,24 @@
 	   "",
 	   stat.tx.loss_period.min / 1000.0, 
-	   stat.tx.loss_period.avg / 1000.0, 
+	   stat.tx.loss_period.mean / 1000.0, 
 	   stat.tx.loss_period.max / 1000.0,
 	   stat.tx.loss_period.last / 1000.0,
+	   pj_math_stat_get_stddev(&stat.tx.loss_period) / 1000.0,
 	   "",
 	   stat.tx.jitter.min / 1000.0,
-	   stat.tx.jitter.avg / 1000.0,
+	   stat.tx.jitter.mean / 1000.0,
 	   stat.tx.jitter.max / 1000.0,
 	   stat.tx.jitter.last / 1000.0,
+	   pj_math_stat_get_stddev(&stat.tx.jitter) / 1000.0,
 	   ""
 	   );
 
 
-    printf(" RTT delay     : %7.3f %7.3f %7.3f %7.3f%s\n", 
+    printf(" RTT delay     : %7.3f %7.3f %7.3f %7.3f %7.3f%s\n", 
 	   stat.rtt.min / 1000.0,
-	   stat.rtt.avg / 1000.0,
+	   stat.rtt.mean / 1000.0,
 	   stat.rtt.max / 1000.0,
 	   stat.rtt.last / 1000.0,
+	   pj_math_stat_get_stddev(&stat.rtt) / 1000.0,
 	   ""
 	   );
@@ -886,6 +891,7 @@
 	    SAMPLES_TO_USEC(jmean, xr_stat.rx.stat_sum.jitter.mean, 
 			    port->info.clock_rate);
-	    SAMPLES_TO_USEC(jdev, xr_stat.rx.stat_sum.jitter.dev, 
-			    port->info.clock_rate);
+	    SAMPLES_TO_USEC(jdev, 
+			   pj_math_stat_get_stddev(&xr_stat.rx.stat_sum.jitter),
+			   port->info.clock_rate);
 	    sprintf(jitter, "%7.3f %7.3f %7.3f %7.3f", 
 		    jmin/1000.0, jmean/1000.0, jmax/1000.0, jdev/1000.0);
@@ -898,5 +904,5 @@
 		    xr_stat.rx.stat_sum.toh.mean,
 		    xr_stat.rx.stat_sum.toh.max,
-		    xr_stat.rx.stat_sum.toh.dev);
+		    pj_math_stat_get_stddev(&xr_stat.rx.stat_sum.toh));
 	} else
 	    sprintf(toh, "(report not available)");
@@ -948,6 +954,7 @@
 	    SAMPLES_TO_USEC(jmean, xr_stat.tx.stat_sum.jitter.mean, 
 			    port->info.clock_rate);
-	    SAMPLES_TO_USEC(jdev, xr_stat.tx.stat_sum.jitter.dev, 
-			    port->info.clock_rate);
+	    SAMPLES_TO_USEC(jdev, 
+			   pj_math_stat_get_stddev(&xr_stat.tx.stat_sum.jitter),
+			   port->info.clock_rate);
 	    sprintf(jitter, "%7.3f %7.3f %7.3f %7.3f", 
 		    jmin/1000.0, jmean/1000.0, jmax/1000.0, jdev/1000.0);
@@ -960,5 +967,5 @@
 		    xr_stat.tx.stat_sum.toh.mean,
 		    xr_stat.tx.stat_sum.toh.max,
-		    xr_stat.tx.stat_sum.toh.dev);
+		    pj_math_stat_get_stddev(&xr_stat.rx.stat_sum.toh));
 	} else
 	    sprintf(toh,    "(report not available)");
@@ -1169,11 +1176,12 @@
 
 
-	/* RTT delay, need this? */
-	printf("          (msec)    min     avg     max     last\n");
-	printf(" RTT delay     : %7.3f %7.3f %7.3f %7.3f%s\n", 
+	/* RTT delay (by receiver side) */
+	printf("          (msec)    min     avg     max     last    dev\n");
+	printf(" RTT delay     : %7.3f %7.3f %7.3f %7.3f %7.3f%s\n", 
 	       xr_stat.rtt.min / 1000.0,
-	       xr_stat.rtt.avg / 1000.0,
+	       xr_stat.rtt.mean / 1000.0,
 	       xr_stat.rtt.max / 1000.0,
 	       xr_stat.rtt.last / 1000.0,
+	       pj_math_stat_get_stddev(&xr_stat.rtt) / 1000.0,
 	       ""
 	       );
Index: /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c	(revision 1960)
+++ /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c	(revision 1961)
@@ -2059,7 +2059,7 @@
 	       "%s        total %spkt %sB (%sB +IP hdr) @avg=%sbps/%sbps\n"
 	       "%s        pkt loss=%d (%3.1f%%), dup=%d (%3.1f%%), reorder=%d (%3.1f%%)\n"
-	       "%s              (msec)    min     avg     max     last\n"
-	       "%s        loss period: %7.3f %7.3f %7.3f %7.3f\n"
-	       "%s        jitter     : %7.3f %7.3f %7.3f %7.3f%s",
+	       "%s              (msec)    min     avg     max     last    dev\n"
+	       "%s        loss period: %7.3f %7.3f %7.3f %7.3f %7.3f\n"
+	       "%s        jitter     : %7.3f %7.3f %7.3f %7.3f %7.3f%s",
 	       indent, info.stream_info[i].fmt.pt,
 	       last_update,
@@ -2079,12 +2079,14 @@
 	       indent, indent,
 	       stat.rx.loss_period.min / 1000.0, 
-	       stat.rx.loss_period.avg / 1000.0, 
+	       stat.rx.loss_period.mean / 1000.0, 
 	       stat.rx.loss_period.max / 1000.0,
 	       stat.rx.loss_period.last / 1000.0,
+	       pj_math_stat_get_stddev(&stat.rx.loss_period) / 1000.0,
 	       indent,
 	       stat.rx.jitter.min / 1000.0,
-	       stat.rx.jitter.avg / 1000.0,
+	       stat.rx.jitter.mean / 1000.0,
 	       stat.rx.jitter.max / 1000.0,
 	       stat.rx.jitter.last / 1000.0,
+	       pj_math_stat_get_stddev(&stat.rx.jitter) / 1000.0,
 	       ""
 	       );
@@ -2115,7 +2117,7 @@
 	       "%s        total %spkt %sB (%sB +IP hdr) @avg %sbps/%sbps\n"
 	       "%s        pkt loss=%d (%3.1f%%), dup=%d (%3.1f%%), reorder=%d (%3.1f%%)\n"
-	       "%s              (msec)    min     avg     max     last\n"
-	       "%s        loss period: %7.3f %7.3f %7.3f %7.3f\n"
-	       "%s        jitter     : %7.3f %7.3f %7.3f %7.3f%s",
+	       "%s              (msec)    min     avg     max     last    dev \n"
+	       "%s        loss period: %7.3f %7.3f %7.3f %7.3f %7.3f\n"
+	       "%s        jitter     : %7.3f %7.3f %7.3f %7.3f %7.3f%s",
 	       indent,
 	       info.stream_info[i].tx_pt,
@@ -2141,12 +2143,14 @@
 	       indent, indent,
 	       stat.tx.loss_period.min / 1000.0, 
-	       stat.tx.loss_period.avg / 1000.0, 
+	       stat.tx.loss_period.mean / 1000.0, 
 	       stat.tx.loss_period.max / 1000.0,
 	       stat.tx.loss_period.last / 1000.0,
+	       pj_math_stat_get_stddev(&stat.tx.loss_period) / 1000.0,
 	       indent,
 	       stat.tx.jitter.min / 1000.0,
-	       stat.tx.jitter.avg / 1000.0,
+	       stat.tx.jitter.mean / 1000.0,
 	       stat.tx.jitter.max / 1000.0,
 	       stat.tx.jitter.last / 1000.0,
+	       pj_math_stat_get_stddev(&stat.tx.jitter) / 1000.0,
 	       ""
 	       );
@@ -2162,10 +2166,11 @@
 
 	len = pj_ansi_snprintf(p, end-p,
-	       "%s    RTT msec       : %7.3f %7.3f %7.3f %7.3f", 
+	       "%s    RTT msec       : %7.3f %7.3f %7.3f %7.3f %7.3f", 
 	       indent,
 	       stat.rtt.min / 1000.0,
-	       stat.rtt.avg / 1000.0,
+	       stat.rtt.mean / 1000.0,
 	       stat.rtt.max / 1000.0,
-	       stat.rtt.last / 1000.0
+	       stat.rtt.last / 1000.0,
+	       pj_math_stat_get_stddev(&stat.rtt) / 1000.0
 	       );
 	if (len < 1 || len > end-p) {
