Index: pjproject/trunk/pjmedia/src/pjmedia/stream.c
===================================================================
--- pjproject/trunk/pjmedia/src/pjmedia/stream.c	(revision 4613)
+++ pjproject/trunk/pjmedia/src/pjmedia/stream.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
  */
 #include <pjmedia/stream.h>
@@ -185,14 +185,14 @@
      */
     pj_bool_t		     has_g722_mpeg_bug;
-					    /**< Flag to specify whether 
-						 normalization process 
+					    /**< Flag to specify whether
+						 normalization process
 						 is needed		    */
     unsigned		     rtp_tx_ts_len_per_pkt;
 					    /**< Normalized ts length per packet
-						 transmitted according to 
+						 transmitted according to
 						 'erroneous' definition	    */
     unsigned		     rtp_rx_ts_len_per_frame;
 					    /**< Normalized ts length per frame
-						 received according to 
+						 received according to
 						 'erroneous' definition	    */
     unsigned		     rtp_rx_last_cnt;/**< Nb of frames in last pkt  */
@@ -203,9 +203,9 @@
 
 #if defined(PJMEDIA_HAS_RTCP_XR) && (PJMEDIA_HAS_RTCP_XR != 0)
-    pj_uint32_t		     rtcp_xr_last_tx;  /**< RTCP XR tx time 
+    pj_uint32_t		     rtcp_xr_last_tx;  /**< RTCP XR tx time
 					            in timestamp.           */
     pj_uint32_t		     rtcp_xr_interval; /**< Interval, in timestamp. */
-    pj_sockaddr		     rtcp_xr_dest;     /**< Additional remote RTCP XR 
-						    dest. If sin_family is 
+    pj_sockaddr		     rtcp_xr_dest;     /**< Additional remote RTCP XR
+						    dest. If sin_family is
 						    zero, it will be ignored*/
     unsigned		     rtcp_xr_dest_len; /**< Length of RTCP XR dest
@@ -231,6 +231,6 @@
 
 /* RFC 2833 digit */
-static const char digitmap[16] = { '0', '1', '2', '3', 
-				   '4', '5', '6', '7', 
+static const char digitmap[16] = { '0', '1', '2', '3',
+				   '4', '5', '6', '7',
 				   '8', '9', '*', '#',
 				   'A', 'B', 'C', 'D'};
@@ -285,5 +285,5 @@
 }
 
-PJ_INLINE(int) trace_jb_print_state(pjmedia_stream *stream, 
+PJ_INLINE(int) trace_jb_print_state(pjmedia_stream *stream,
 				    char **buf, pj_ssize_t len)
 {
@@ -460,5 +460,5 @@
 
 #else
-    
+
     PJ_UNUSED_ARG(stream);
 
@@ -498,10 +498,10 @@
     samples_per_frame = stream->codec_param.info.frm_ptime *
 			stream->codec_param.info.clock_rate *
-			stream->codec_param.info.channel_cnt / 
+			stream->codec_param.info.channel_cnt /
 			1000;
     p_out_samp = (pj_int16_t*) frame->buf;
 
-    for (samples_count=0; samples_count < samples_required; 
-	 samples_count += samples_per_frame) 
+    for (samples_count=0; samples_count < samples_required;
+	 samples_count += samples_per_frame)
     {
 	char frame_type;
@@ -518,9 +518,9 @@
 
 	if (frame_type == PJMEDIA_JB_MISSING_FRAME) {
-	    
+
 	    /* Activate PLC */
-	    if (stream->codec->op->recover && 
+	    if (stream->codec->op->recover &&
 		stream->codec_param.setting.plc &&
-		stream->plc_cnt < stream->max_plc_cnt) 
+		stream->plc_cnt < stream->max_plc_cnt)
 	    {
 		pjmedia_frame frame_out;
@@ -561,5 +561,5 @@
 	    /* Jitter buffer is empty. If this is the first "empty" state,
 	     * activate PLC to smoothen the fade-out, otherwise zero
-	     * the frame. 
+	     * the frame.
 	     */
 	    //Using this "if" will only invoke PLC for the first packet
@@ -568,7 +568,7 @@
 	    if (1) {
 		/* Activate PLC to smoothen the missing frame */
-		if (stream->codec->op->recover && 
+		if (stream->codec->op->recover &&
 		    stream->codec_param.setting.plc &&
-		    stream->plc_cnt < stream->max_plc_cnt) 
+		    stream->plc_cnt < stream->max_plc_cnt)
 		{
 		    pjmedia_frame frame_out;
@@ -590,5 +590,5 @@
 
 		    with_plc = ", plc invoked";
-		} 
+		}
 	    }
 
@@ -604,6 +604,6 @@
 		/* Report changing frame type event */
 		pjmedia_jbuf_get_state(stream->jb, &jb_state);
-		PJ_LOG(5,(stream->port.info.name.ptr, 
-			  "Jitter buffer empty (prefetch=%d)%s", 
+		PJ_LOG(5,(stream->port.info.name.ptr,
+			  "Jitter buffer empty (prefetch=%d)%s",
 			  jb_state.prefetch, with_plc));
 
@@ -623,7 +623,7 @@
 
 	    /* Always activate PLC when it's available.. */
-	    if (stream->codec->op->recover && 
+	    if (stream->codec->op->recover &&
 		stream->codec_param.setting.plc &&
-		stream->plc_cnt < stream->max_plc_cnt) 
+		stream->plc_cnt < stream->max_plc_cnt)
 	    {
 		pjmedia_frame frame_out;
@@ -645,5 +645,5 @@
 
 		with_plc = ", plc invoked";
-	    } 
+	    }
 
 	    if (samples_count < samples_required) {
@@ -658,6 +658,6 @@
 		/* Report changing frame type event */
 		pjmedia_jbuf_get_state(stream->jb, &jb_state);
-		PJ_LOG(5,(stream->port.info.name.ptr, 
-			  "Jitter buffer is bufferring (prefetch=%d)%s", 
+		PJ_LOG(5,(stream->port.info.name.ptr,
+			  "Jitter buffer is bufferring (prefetch=%d)%s",
 			  jb_state.prefetch, with_plc));
 
@@ -684,11 +684,11 @@
 	    frame_out.size = frame->size - samples_count*BYTES_PER_SAMPLE;
 	    status = pjmedia_codec_decode( stream->codec, &frame_in,
-					   (unsigned)frame_out.size, 
+					   (unsigned)frame_out.size,
 					   &frame_out);
 	    if (status != 0) {
-		LOGERR_((port->info.name.ptr, "codec decode() error", 
+		LOGERR_((port->info.name.ptr, "codec decode() error",
 			 status));
 
-		pjmedia_zero_samples(p_out_samp + samples_count, 
+		pjmedia_zero_samples(p_out_samp + samples_count,
 				     samples_per_frame);
 	    }
@@ -696,5 +696,5 @@
 	    if (stream->jb_last_frm != frame_type) {
 		/* Report changing frame type event */
-		PJ_LOG(5,(stream->port.info.name.ptr, 
+		PJ_LOG(5,(stream->port.info.name.ptr,
 			  "Jitter buffer starts returning normal frames "
 			  "(after %d empty/lost)",
@@ -753,5 +753,5 @@
     samples_per_frame = stream->codec_param.info.frm_ptime *
 			stream->codec_param.info.clock_rate *
-			stream->codec_param.info.channel_cnt / 
+			stream->codec_param.info.channel_cnt /
 			1000;
 
@@ -774,5 +774,5 @@
 	trace_jb_get(stream, frame_type, frame_size);
 #endif
-	
+
 	/* Unlock jitter buffer mutex. */
 	pj_mutex_unlock( stream->jb_mutex );
@@ -791,5 +791,5 @@
 					   0, frame);
 	    if (status != PJ_SUCCESS) {
-		LOGERR_((port->info.name.ptr, "codec decode() error", 
+		LOGERR_((port->info.name.ptr, "codec decode() error",
 			 status));
 		pjmedia_frame_ext_append_subframe(f, NULL, 0,
@@ -799,5 +799,5 @@
 	    if (stream->jb_last_frm != frame_type) {
 		/* Report changing frame type event */
-		PJ_LOG(5,(stream->port.info.name.ptr, 
+		PJ_LOG(5,(stream->port.info.name.ptr,
 			  "Jitter buffer starts returning normal frames "
 			  "(after %d empty/lost)",
@@ -817,5 +817,5 @@
 		status = pjmedia_codec_recover(stream->codec, 0, frame);
 	    }
-	    
+
 	    /* No PLC or PLC failed */
 	    if (!stream->codec->op->recover || status != PJ_SUCCESS) {
@@ -840,6 +840,6 @@
 		    /* Report changing frame type event */
 		    pjmedia_jbuf_get_state(stream->jb, &jb_state);
-		    PJ_LOG(5,(stream->port.info.name.ptr, 
-			      "Jitter buffer empty (prefetch=%d)", 
+		    PJ_LOG(5,(stream->port.info.name.ptr,
+			      "Jitter buffer empty (prefetch=%d)",
 			      jb_state.prefetch));
 
@@ -859,5 +859,5 @@
 		    /* Report changing frame type event */
 		    pjmedia_jbuf_get_state(stream->jb, &jb_state);
-		    PJ_LOG(5,(stream->port.info.name.ptr, 
+		    PJ_LOG(5,(stream->port.info.name.ptr,
 			      "Jitter buffer is bufferring (prefetch=%d)",
 			      jb_state.prefetch));
@@ -879,5 +879,5 @@
  * Transmit DTMF
  */
-static void create_dtmf_payload(pjmedia_stream *stream, 
+static void create_dtmf_payload(pjmedia_stream *stream,
 			        struct pjmedia_frame *frame_out,
 			        int forced_last, int *first, int *last)
@@ -885,5 +885,4 @@
     pjmedia_rtp_dtmf_event *event;
     struct dtmf *digit = &stream->tx_dtmf_buf[0];
-    pj_uint32_t cur_ts;
 
     pj_assert(sizeof(pjmedia_rtp_dtmf_event) == 4);
@@ -892,8 +891,7 @@
 
     event = (pjmedia_rtp_dtmf_event*) frame_out->buf;
-    cur_ts = pj_ntohl(stream->enc->rtp.out_hdr.ts);
 
     if (digit->duration == 0) {
-	PJ_LOG(5,(stream->port.info.name.ptr, "Sending DTMF digit id %c", 
+	PJ_LOG(5,(stream->port.info.name.ptr, "Sending DTMF digit id %c",
 		  digitmap[digit->event]));
 	*first = 1;
@@ -988,12 +986,12 @@
 	/* Update RTCP XR with current JB states */
 	pjmedia_jbuf_get_state(stream->jb, &jb_state);
-    	    
+
 	i = jb_state.avg_delay;
-	status = pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session, 
+	status = pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session,
 					     PJMEDIA_RTCP_XR_INFO_JB_NOM, i);
 	pj_assert(status == PJ_SUCCESS);
 
 	i = jb_state.max_delay;
-	status = pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session, 
+	status = pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session,
 					     PJMEDIA_RTCP_XR_INFO_JB_MAX, i);
 	pj_assert(status == PJ_SUCCESS);
@@ -1008,7 +1006,7 @@
 	    /* Send the RTCP XR to third-party destination if specified */
 	    if (stream->rtcp_xr_dest_len) {
-		pjmedia_transport_send_rtcp2(stream->transport, 
+		pjmedia_transport_send_rtcp2(stream->transport,
 					     &stream->rtcp_xr_dest,
-					     stream->rtcp_xr_dest_len, 
+					     stream->rtcp_xr_dest_len,
 					     xr_pkt, xr_len);
 	    }
@@ -1050,5 +1048,5 @@
 static void check_tx_rtcp(pjmedia_stream *stream, pj_uint32_t timestamp)
 {
-    /* Note that timestamp may represent local or remote timestamp, 
+    /* Note that timestamp may represent local or remote timestamp,
      * depending on whether this function is called from put_frame()
      * or get_frame().
@@ -1056,5 +1054,5 @@
 
     if (stream->rtcp_last_tx == 0) {
-	
+
 	stream->rtcp_last_tx = timestamp;
 
@@ -1067,5 +1065,5 @@
 	    if (stream->rtcp_xr_last_tx == 0) {
 		stream->rtcp_xr_last_tx = timestamp;
-	    } else if (timestamp - stream->rtcp_xr_last_tx >= 
+	    } else if (timestamp - stream->rtcp_xr_last_tx >=
 		       stream->rtcp_xr_interval)
 	    {
@@ -1131,5 +1129,5 @@
 
     /* How many samples are needed */
-    count = stream->codec_param.info.enc_ptime * 
+    count = stream->codec_param.info.enc_ptime *
 	    PJMEDIA_PIA_SRATE(&stream->port.info) / 1000;
 
@@ -1154,5 +1152,5 @@
  * put_frame_imp()
  */
-static pj_status_t put_frame_imp( pjmedia_port *port, 
+static pj_status_t put_frame_imp( pjmedia_port *port,
 				  pjmedia_frame *frame )
 {
@@ -1175,5 +1173,5 @@
 	pj_uint32_t dtx_duration;
 
-	dtx_duration = pj_timestamp_diff32(&stream->last_frm_ts_sent, 
+	dtx_duration = pj_timestamp_diff32(&stream->last_frm_ts_sent,
 					   &frame->timestamp);
 	if (dtx_duration >
@@ -1194,5 +1192,5 @@
     /* Number of samples in the frame */
     if (frame->type == PJMEDIA_FRAME_TYPE_AUDIO)
-	ts_len = ((unsigned)frame->size >> 1) / 
+	ts_len = ((unsigned)frame->size >> 1) /
 		 stream->codec_param.info.channel_cnt;
     else if (frame->type == PJMEDIA_FRAME_TYPE_EXTENDED)
@@ -1206,5 +1204,5 @@
 
 #if defined(PJMEDIA_HANDLE_G722_MPEG_BUG) && (PJMEDIA_HANDLE_G722_MPEG_BUG!=0)
-    /* Handle special case for audio codec with RTP timestamp inconsistence 
+    /* Handle special case for audio codec with RTP timestamp inconsistence
      * e.g: G722, MPEG audio.
      */
@@ -1225,5 +1223,5 @@
 
 
-    /* If we have DTMF digits in the queue, transmit the digits. 
+    /* If we have DTMF digits in the queue, transmit the digits.
      * Otherwise encode the PCM buffer.
      */
@@ -1235,15 +1233,15 @@
 	/* Encapsulate into RTP packet. Note that:
          *  - RTP marker should be set on the beginning of a new event
-	 *  - RTP timestamp is constant for the same packet. 
+	 *  - RTP timestamp is constant for the same packet.
          */
-	status = pjmedia_rtp_encode_rtp( &channel->rtp, 
-					 stream->tx_event_pt, first, 
+	status = pjmedia_rtp_encode_rtp( &channel->rtp,
+					 stream->tx_event_pt, first,
 					 (int)frame_out.size,
-					 (first ? rtp_ts_len : 0), 
-					 (const void**)&rtphdr, 
+					 (first ? rtp_ts_len : 0),
+					 (const void**)&rtphdr,
 					 &rtphdrlen);
 
 	if (last) {
-	    /* This is the last packet for the event. 
+	    /* This is the last packet for the event.
 	     * Increment the RTP timestamp of the RTP session, for next
 	     * RTP packets.
@@ -1272,5 +1270,5 @@
 	       stream->codec_param.info.channel_cnt *
 	       stream->codec_param.info.clock_rate/1000 <
-		  PJ_ARRAY_SIZE(zero_frame)) 
+		  PJ_ARRAY_SIZE(zero_frame))
     {
 	pjmedia_frame silence_frame;
@@ -1283,12 +1281,12 @@
 	silence_frame.type = PJMEDIA_FRAME_TYPE_AUDIO;
 	silence_frame.timestamp.u32.lo = pj_ntohl(stream->enc->rtp.out_hdr.ts);
-	
+
 	/* Encode! */
 	status = pjmedia_codec_encode( stream->codec, &silence_frame,
-				       channel->out_pkt_size - 
+				       channel->out_pkt_size -
 				       sizeof(pjmedia_rtp_hdr),
 				       &frame_out);
 	if (status != PJ_SUCCESS) {
-	    LOGERR_((stream->port.info.name.ptr, 
+	    LOGERR_((stream->port.info.name.ptr,
 		    "Codec encode() error", status));
 	    return status;
@@ -1296,8 +1294,8 @@
 
 	/* Encapsulate. */
-	status = pjmedia_rtp_encode_rtp( &channel->rtp, 
-					 channel->pt, 0, 
-					 (int)frame_out.size, rtp_ts_len, 
-					 (const void**)&rtphdr, 
+	status = pjmedia_rtp_encode_rtp( &channel->rtp,
+					 channel->pt, 0,
+					 (int)frame_out.size, rtp_ts_len,
+					 (const void**)&rtphdr,
 					 &rtphdrlen);
 
@@ -1309,10 +1307,10 @@
     {
 	/* Encode! */
-	status = pjmedia_codec_encode( stream->codec, frame, 
-				       channel->out_pkt_size - 
+	status = pjmedia_codec_encode( stream->codec, frame,
+				       channel->out_pkt_size -
 				       sizeof(pjmedia_rtp_hdr),
 				       &frame_out);
 	if (status != PJ_SUCCESS) {
-	    LOGERR_((stream->port.info.name.ptr, 
+	    LOGERR_((stream->port.info.name.ptr,
 		    "Codec encode() error", status));
 	    return status;
@@ -1320,8 +1318,8 @@
 
 	/* Encapsulate. */
-	status = pjmedia_rtp_encode_rtp( &channel->rtp, 
-					 channel->pt, 0, 
-					 (int)frame_out.size, rtp_ts_len, 
-					 (const void**)&rtphdr, 
+	status = pjmedia_rtp_encode_rtp( &channel->rtp,
+					 channel->pt, 0,
+					 (int)frame_out.size, rtp_ts_len,
+					 (const void**)&rtphdr,
 					 &rtphdrlen);
 
@@ -1329,8 +1327,8 @@
 
 	/* Just update RTP session's timestamp. */
-	status = pjmedia_rtp_encode_rtp( &channel->rtp, 
-					 0, 0, 
-					 0, rtp_ts_len, 
-					 (const void**)&rtphdr, 
+	status = pjmedia_rtp_encode_rtp( &channel->rtp,
+					 0, 0,
+					 0, rtp_ts_len,
+					 (const void**)&rtphdr,
 					 &rtphdrlen);
 
@@ -1338,10 +1336,10 @@
 
     if (status != PJ_SUCCESS) {
-	LOGERR_((stream->port.info.name.ptr, 
+	LOGERR_((stream->port.info.name.ptr,
 		"RTP encode_rtp() error", status));
 	return status;
     }
 
-    /* Check if now is the time to transmit RTCP SR/RR report. 
+    /* Check if now is the time to transmit RTCP SR/RR report.
      * We only do this when stream direction is not "decoding only", because
      * when it is, check_tx_rtcp() will be handled by get_frame().
@@ -1414,5 +1412,5 @@
  * RTP packet, and transmit to peer.
  */
-static pj_status_t put_frame( pjmedia_port *port, 
+static pj_status_t put_frame( pjmedia_port *port,
 			      pjmedia_frame *frame )
 {
@@ -1462,5 +1460,5 @@
      */
     if (stream->vad_enabled != stream->codec_param.setting.vad &&
-	(stream->tx_duration - stream->ts_vad_disabled) > 
+	(stream->tx_duration - stream->ts_vad_disabled) >
            PJMEDIA_PIA_SRATE(&stream->port.info) *
 	  PJMEDIA_STREAM_VAD_SUSPEND_MSEC / 1000)
@@ -1479,5 +1477,5 @@
 	pj_status_t status = PJ_SUCCESS;
 
-	/* Copy original frame to temporary frame since we need 
+	/* Copy original frame to temporary frame since we need
 	 * to modify it.
 	 */
@@ -1546,5 +1544,5 @@
  * Handle incoming DTMF digits.
  */
-static void handle_incoming_dtmf( pjmedia_stream *stream, 
+static void handle_incoming_dtmf( pjmedia_stream *stream,
 				  const void *payload, unsigned payloadlen)
 {
@@ -1572,5 +1570,5 @@
     /* Ignore unknown event. */
     if (event->event > 15) {
-	PJ_LOG(5,(stream->port.info.name.ptr, 
+	PJ_LOG(5,(stream->port.info.name.ptr,
 		  "Ignored RTP pkt with bad DTMF event %d",
     		  event->event));
@@ -1591,5 +1589,5 @@
     if (stream->dtmf_cb) {
 
-	stream->dtmf_cb(stream, stream->dtmf_cb_user_data, 
+	stream->dtmf_cb(stream, stream->dtmf_cb_user_data,
 			digitmap[event->event]);
 
@@ -1601,5 +1599,5 @@
 	if (stream->rx_dtmf_count >= PJ_ARRAY_SIZE(stream->rx_dtmf_buf)) {
 	    /* DTMF digits overflow.  Discard the oldest digit. */
-	    pj_array_erase(stream->rx_dtmf_buf, 
+	    pj_array_erase(stream->rx_dtmf_buf,
 			   sizeof(stream->rx_dtmf_buf[0]),
 			   stream->rx_dtmf_count, 0);
@@ -1614,7 +1612,7 @@
 /*
  * This callback is called by stream transport on receipt of packets
- * in the RTP socket. 
- */
-static void on_rx_rtp( void *data, 
+ * in the RTP socket.
+ */
+static void on_rx_rtp( void *data,
 		       void *pkt,
                        pj_ssize_t bytes_read)
@@ -1632,5 +1630,5 @@
     /* Check for errors */
     if (bytes_read < 0) {
-	LOGERR_((stream->port.info.name.ptr, "RTP recv() error", 
+	LOGERR_((stream->port.info.name.ptr, "RTP recv() error",
 		(pj_status_t)-bytes_read));
 	return;
@@ -1660,7 +1658,7 @@
 			        hdr->pt != stream->rx_event_pt);
     if (seq_st.status.value) {
-	TRC_  ((stream->port.info.name.ptr, 
+	TRC_  ((stream->port.info.name.ptr,
 		"RTP status: badpt=%d, badssrc=%d, dup=%d, "
-		"outorder=%d, probation=%d, restart=%d", 
+		"outorder=%d, probation=%d, restart=%d",
 		seq_st.status.flag.badpt,
 		seq_st.status.flag.badssrc,
@@ -1737,6 +1735,6 @@
 				     payloadlen, &ts, &count, frames);
 	if (status != PJ_SUCCESS) {
-	    LOGERR_((stream->port.info.name.ptr, 
-		     "Codec parse() error", 
+	    LOGERR_((stream->port.info.name.ptr,
+		     "Codec parse() error",
 		     status));
 	    count = 0;
@@ -1746,5 +1744,5 @@
 	/* This code is used to learn the samples per frame value that is put
 	 * by remote endpoint, for codecs with inconsistent clock rate such
-	 * as G.722 or MPEG audio. We need to learn the samples per frame 
+	 * as G.722 or MPEG audio. We need to learn the samples per frame
 	 * value as it is used as divider when inserting frames into the
 	 * jitter buffer.
@@ -1752,9 +1750,9 @@
 	if (stream->has_g722_mpeg_bug) {
 	    if (stream->rtp_rx_check_cnt) {
-		/* Make sure the detection performed only on two consecutive 
+		/* Make sure the detection performed only on two consecutive
 		 * packets with valid RTP sequence and no wrapped timestamp.
 		 */
-		if (seq_st.diff == 1 && stream->rtp_rx_last_ts && 
-		    ts.u64 > stream->rtp_rx_last_ts && 
+		if (seq_st.diff == 1 && stream->rtp_rx_last_ts &&
+		    ts.u64 > stream->rtp_rx_last_ts &&
 		    stream->rtp_rx_last_cnt > 0)
 		{
@@ -1768,6 +1766,6 @@
 
 		    /* Get remote frame timestamp span */
-		    peer_frm_ts_diff = 
-			((pj_uint32_t)ts.u64-stream->rtp_rx_last_ts) / 
+		    peer_frm_ts_diff =
+			((pj_uint32_t)ts.u64-stream->rtp_rx_last_ts) /
 			stream->rtp_rx_last_cnt;
 
@@ -1778,5 +1776,5 @@
 		     */
 		    if (stream->codec_param.info.pt == PJMEDIA_RTP_PT_G722 &&
-			(peer_frm_ts_diff == frm_ts_span || 
+			(peer_frm_ts_diff == frm_ts_span ||
 			 peer_frm_ts_diff == (frm_ts_span>>1)))
 		    {
@@ -1790,7 +1788,7 @@
 			if (--stream->rtp_rx_check_cnt == 0) {
     			    PJ_LOG(4, (THIS_FILE, "G722 codec used, remote"
-				       " samples per frame detected = %d", 
+				       " samples per frame detected = %d",
 				       stream->rtp_rx_ts_len_per_frame));
-			    
+
 			    /* Reset jitter buffer once detection done */
 			    pjmedia_jbuf_reset(stream->jb);
@@ -1811,10 +1809,10 @@
 
 	} else {
-	    ts_span = stream->codec_param.info.frm_ptime * 
+	    ts_span = stream->codec_param.info.frm_ptime *
 		      stream->codec_param.info.clock_rate /
 		      1000;
 	}
 #else
-	ts_span = stream->codec_param.info.frm_ptime * 
+	ts_span = stream->codec_param.info.frm_ptime *
 		  stream->codec_param.info.clock_rate /
 		  1000;
@@ -1842,5 +1840,5 @@
 
     /* Check if now is the time to transmit RTCP SR/RR report.
-     * We only do this when stream direction is "decoding only", 
+     * We only do this when stream direction is "decoding only",
      * because otherwise check_tx_rtcp() will be handled by put_frame()
      */
@@ -1850,5 +1848,5 @@
 
     if (status != 0) {
-	LOGERR_((stream->port.info.name.ptr, "Jitter buffer put() error", 
+	LOGERR_((stream->port.info.name.ptr, "Jitter buffer put() error",
 		status));
 	pkt_discarded = PJ_TRUE;
@@ -1880,8 +1878,8 @@
 /*
  * This callback is called by stream transport on receipt of packets
- * in the RTCP socket. 
+ * in the RTCP socket.
  */
 static void on_rx_rtcp( void *data,
-                        void *pkt, 
+                        void *pkt,
                         pj_ssize_t bytes_read)
 {
@@ -1890,5 +1888,5 @@
     /* Check for errors */
     if (bytes_read < 0) {
-	LOGERR_((stream->port.info.name.ptr, "RTCP recv() error", 
+	LOGERR_((stream->port.info.name.ptr, "RTCP recv() error",
 		(pj_status_t)-bytes_read));
 	return;
@@ -1911,5 +1909,5 @@
     pjmedia_channel *channel;
     pj_status_t status;
-    
+
     /* Allocate memory for channel descriptor */
 
@@ -1924,11 +1922,11 @@
     channel->pt = pt;
 
-    
+
     /* Allocate buffer for outgoing packet. */
 
     if (param->type == PJMEDIA_TYPE_AUDIO) {
-        channel->out_pkt_size = sizeof(pjmedia_rtp_hdr) + 
-			        stream->codec_param.info.max_bps * 
-			        PJMEDIA_MAX_FRAME_DURATION_MS / 
+        channel->out_pkt_size = sizeof(pjmedia_rtp_hdr) +
+			        stream->codec_param.info.max_bps *
+			        PJMEDIA_MAX_FRAME_DURATION_MS /
 			        8 / 1000;
         if (channel->out_pkt_size > PJMEDIA_MAX_MTU -
@@ -2078,6 +2076,6 @@
 	stream->codec_param = *info->param;
     else {
-	status = pjmedia_codec_mgr_get_default_param(stream->codec_mgr, 
-						     &info->fmt, 
+	status = pjmedia_codec_mgr_get_default_param(stream->codec_mgr,
+						     &info->fmt,
 						     &stream->codec_param);
 	if (status != PJ_SUCCESS)
@@ -2137,5 +2135,5 @@
     /* If encoder and decoder's ptime are asymmetric, then we need to
      * create buffer on the encoder side. This could happen for example
-     * with iLBC 
+     * with iLBC
      */
     if (stream->codec_param.info.enc_ptime!=0 &&
@@ -2185,5 +2183,5 @@
         stream->frame_size = stream->codec_param.info.max_rx_frame_size;
     } else {
-        stream->frame_size = stream->codec_param.info.max_bps * 
+        stream->frame_size = stream->codec_param.info.max_bps *
 			     stream->codec_param.info.frm_ptime / 8 / 1000;
         if ((stream->codec_param.info.max_bps *
@@ -2218,5 +2216,5 @@
     /* Init jitter buffer parameters: */
     if (info->jb_max >= stream->codec_param.info.frm_ptime)
-	jb_max = (info->jb_max + stream->codec_param.info.frm_ptime - 1) / 
+	jb_max = (info->jb_max + stream->codec_param.info.frm_ptime - 1) /
 		 stream->codec_param.info.frm_ptime;
     else
@@ -2243,5 +2241,5 @@
     /* Create jitter buffer */
     status = pjmedia_jbuf_create(pool, &stream->port.info.name,
-				 stream->frame_size, 
+				 stream->frame_size,
 				 stream->codec_param.info.frm_ptime,
 				 jb_max, &stream->jb);
@@ -2255,5 +2253,5 @@
     /* Create decoder channel: */
 
-    status = create_channel( pool, stream, PJMEDIA_DIR_DECODING, 
+    status = create_channel( pool, stream, PJMEDIA_DIR_DECODING,
 			     info->rx_pt, info, &stream->dec);
     if (status != PJ_SUCCESS)
@@ -2263,5 +2261,5 @@
     /* Create encoder channel: */
 
-    status = create_channel( pool, stream, PJMEDIA_DIR_ENCODING, 
+    status = create_channel( pool, stream, PJMEDIA_DIR_ENCODING,
 			     info->tx_pt, info, &stream->enc);
     if (status != PJ_SUCCESS)
@@ -2316,7 +2314,7 @@
 
     /* Only attach transport when stream is ready. */
-    status = pjmedia_transport_attach(tp, stream, &info->rem_addr, 
-				      &info->rem_rtcp, 
-				      pj_sockaddr_get_len(&info->rem_addr), 
+    status = pjmedia_transport_attach(tp, stream, &info->rem_addr,
+				      &info->rem_rtcp,
+				      pj_sockaddr_get_len(&info->rem_addr),
                                       &on_rx_rtp, &on_rx_rtcp);
     if (status != PJ_SUCCESS)
@@ -2336,6 +2334,6 @@
 	    stream->rtcp_xr_interval = info->rtcp_xr_interval;
 	else
-	    stream->rtcp_xr_interval = (PJMEDIA_RTCP_INTERVAL + 
-				       (pj_rand() % 8000)) * 
+	    stream->rtcp_xr_interval = (PJMEDIA_RTCP_INTERVAL +
+				       (pj_rand() % 8000)) *
 				       info->fmt.clock_rate / 1000;
 
@@ -2349,5 +2347,5 @@
 	/* jitter buffer adaptive info */
 	i = PJMEDIA_RTCP_XR_JB_ADAPTIVE;
-	pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session, 
+	pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session,
 				    PJMEDIA_RTCP_XR_INFO_CONF_JBA,
 				    i);
@@ -2355,5 +2353,5 @@
 	/* Jitter buffer aggressiveness info (estimated) */
 	i = 7;
-	pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session, 
+	pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session,
 				    PJMEDIA_RTCP_XR_INFO_CONF_JBR,
 				    i);
@@ -2361,5 +2359,5 @@
 	/* Jitter buffer absolute maximum delay */
 	i = jb_max * stream->codec_param.info.frm_ptime;
-	pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session, 
+	pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session,
 				    PJMEDIA_RTCP_XR_INFO_JB_ABS_MAX,
 				    i);
@@ -2374,5 +2372,5 @@
 	    i = PJMEDIA_RTCP_XR_PLC_DIS;
 #endif
-	pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session, 
+	pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session,
 				    PJMEDIA_RTCP_XR_INFO_CONF_PLC,
 				    i);
@@ -2396,5 +2394,5 @@
 	pj_ssize_t len;
 
-	pj_ansi_snprintf(trace_name, sizeof(trace_name), 
+	pj_ansi_snprintf(trace_name, sizeof(trace_name),
 			 TRACE_JB_PATH_PREFIX "%s.csv",
 			 stream->port.info.name.ptr);
@@ -2402,5 +2400,5 @@
 	if (status != PJ_SUCCESS) {
 	    stream->trace_jb_fd = TRACE_JB_INVALID_FD;
-	    PJ_LOG(3,(THIS_FILE, "Failed creating RTP trace file '%s'", 
+	    PJ_LOG(3,(THIS_FILE, "Failed creating RTP trace file '%s'",
 		      trace_name));
 	} else {
@@ -2490,5 +2488,5 @@
     }
 
-    /* Detach from transport 
+    /* Detach from transport
      * MUST NOT hold stream mutex while detaching from transport, as
      * it may cause deadlock. See ticket #460 for the details.
@@ -2513,5 +2511,5 @@
 
     /* Free mutex */
-    
+
     if (stream->jb_mutex) {
 	pj_mutex_destroy(stream->jb_mutex);
@@ -2724,7 +2722,7 @@
 	return PJMEDIA_RTP_EREMNORFC2833;
     }
-    
+
     pj_mutex_lock(stream->jb_mutex);
-    
+
     if (stream->tx_dtmf_count+digit_char->slen >=
 	(long)PJ_ARRAY_SIZE(stream->tx_dtmf_buf))
@@ -2735,5 +2733,5 @@
 
 	/* convert ASCII digits into payload type first, to make sure
-	 * that all digits are valid. 
+	 * that all digits are valid.
 	 */
 	for (i=0; i<digit_char->slen; ++i) {
@@ -2744,5 +2742,5 @@
 	    {
 		pt = dig - '0';
-	    } 
+	    }
 	    else if (dig >= 'a' && dig <= 'd')
 	    {
@@ -2830,7 +2828,7 @@
  */
 PJ_DEF(pj_status_t) pjmedia_stream_set_dtmf_callback(pjmedia_stream *stream,
-				 void (*cb)(pjmedia_stream*, 
-					    void *user_data, 
-					    int digit), 
+				 void (*cb)(pjmedia_stream*,
+					    void *user_data,
+					    int digit),
 				 void *user_data)
 {
