[Asterisk-cvs] asterisk/channels chan_iax2.c,1.127,1.128

markster at lists.digium.com markster at lists.digium.com
Fri Apr 23 01:30:11 CDT 2004


Update of /usr/cvsroot/asterisk/channels
In directory mongoose.digium.com:/tmp/cvs-serv28140/channels

Modified Files:
	chan_iax2.c 
Log Message:
Fix timestamps on IAX2 trunk mode transmit direction


Index: chan_iax2.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_iax2.c,v
retrieving revision 1.127
retrieving revision 1.128
diff -u -d -r1.127 -r1.128
--- chan_iax2.c	22 Apr 2004 19:16:52 -0000	1.127
+++ chan_iax2.c	23 Apr 2004 05:35:12 -0000	1.128
@@ -2529,17 +2529,19 @@
 	return tmp;
 }
 
-static unsigned int calc_txpeerstamp(struct iax2_peer *peer)
+static unsigned int calc_txpeerstamp(struct iax2_peer *peer, int sampms)
 {
 	struct timeval tv;
-	unsigned int mssincetx;
-	unsigned int ms;
+	long int mssincetx;
+	long int ms, pred;
+
 	gettimeofday(&tv, NULL);
 	mssincetx = (tv.tv_sec - peer->lasttxtime.tv_sec) * 1000 + (tv.tv_usec - peer->lasttxtime.tv_usec) / 1000;
 	if (mssincetx > 5000) {
 		/* If it's been at least 5 seconds since the last time we transmitted on this trunk, reset our timers */
 		peer->txtrunktime.tv_sec = tv.tv_sec;
 		peer->txtrunktime.tv_usec = tv.tv_usec;
+		peer->lastsent = 999999;
 	}
 	/* Update last transmit time now */
 	peer->lasttxtime.tv_sec = tv.tv_sec;
@@ -2547,6 +2549,10 @@
 	
 	/* Calculate ms offset */
 	ms = (tv.tv_sec - peer->txtrunktime.tv_sec) * 1000 + (tv.tv_usec - peer->txtrunktime.tv_usec) / 1000;
+	/* Predict from last value */
+	pred = peer->lastsent + sampms;
+	if (abs(ms - pred) < 640)
+		ms = pred;
 	
 	/* We never send the same timestamp twice, so fudge a little if we must */
 	if (ms == peer->lastsent)
@@ -4244,7 +4250,7 @@
 		meta->zeros = 0;
 		meta->metacmd = IAX_META_TRUNK;
 		meta->cmddata = 0;
-		mth->ts = htonl(calc_txpeerstamp(peer));
+		mth->ts = htonl(calc_txpeerstamp(peer, trunkfreq));
 		/* And the rest of the ast_iax2 header */
 		fr->direction = DIRECTION_OUTGRESS;
 		fr->retrans = -1;
@@ -5737,6 +5743,7 @@
 		memset(peer, 0, sizeof(struct iax2_peer));
 		peer->expire = -1;
 		peer->pokeexpire = -1;
+		peer->lastsent = 999999;
 	}
 	if (peer) {
 		if (!found) {




More information about the svn-commits mailing list