From 90778ada6d7ecd5da0d47a5aa5c768a02703fa64 Mon Sep 17 00:00:00 2001 From: Mark Spencer Date: Fri, 23 Apr 2004 05:35:12 +0000 Subject: [PATCH] Fix timestamps on IAX2 trunk mode transmit direction git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@2752 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- channels/chan_iax2.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c index bdf83c6acf..1624b26b7e 100755 --- a/channels/chan_iax2.c +++ b/channels/chan_iax2.c @@ -2529,17 +2529,19 @@ static struct ast_channel *ast_iax2_new(struct chan_iax2_pvt *i, int state, int 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 @@ static unsigned int calc_txpeerstamp(struct iax2_peer *peer) /* 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 @@ static int send_trunk(struct iax2_peer *peer) 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 @@ static struct iax2_peer *build_peer(char *name, struct ast_variable *v) memset(peer, 0, sizeof(struct iax2_peer)); peer->expire = -1; peer->pokeexpire = -1; + peer->lastsent = 999999; } if (peer) { if (!found) {