rtp timestamp to timeval calculation fix

The rtp timestamp to timeval calculation was only
accurate for 8kHz audio. This patch corrects this.

Review: https://reviewboard.asterisk.org/r/468/

SWP-648



git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@241714 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
David Vossel
2010-01-20 21:14:47 +00:00
parent 1da8e44be8
commit e469483d82

View File

@@ -1214,21 +1214,10 @@ static int ast_rtp_write(struct ast_rtp_instance *instance, struct ast_frame *fr
return 0; return 0;
} }
static void sanitize_tv(struct timeval *tv)
{
while (tv->tv_usec < 0) {
tv->tv_usec += 1000000;
tv->tv_sec -= 1;
}
while (tv->tv_usec >= 1000000) {
tv->tv_usec -= 1000000;
tv->tv_sec += 1;
}
}
static void calc_rxstamp(struct timeval *tv, struct ast_rtp *rtp, unsigned int timestamp, int mark) static void calc_rxstamp(struct timeval *tv, struct ast_rtp *rtp, unsigned int timestamp, int mark)
{ {
struct timeval now; struct timeval now;
struct timeval tmp;
double transit; double transit;
double current_time; double current_time;
double d; double d;
@@ -1242,18 +1231,17 @@ static void calc_rxstamp(struct timeval *tv, struct ast_rtp *rtp, unsigned int t
rtp->drxcore = (double) rtp->rxcore.tv_sec + (double) rtp->rxcore.tv_usec / 1000000; rtp->drxcore = (double) rtp->rxcore.tv_sec + (double) rtp->rxcore.tv_usec / 1000000;
/* map timestamp to a real time */ /* map timestamp to a real time */
rtp->seedrxts = timestamp; /* Their RTP timestamp started with this */ rtp->seedrxts = timestamp; /* Their RTP timestamp started with this */
rtp->rxcore.tv_sec -= timestamp / rate; tmp = ast_samp2tv(timestamp, rate);
rtp->rxcore.tv_usec -= (timestamp % rate) * 125; rtp->rxcore = ast_tvsub(rtp->rxcore, tmp);
/* Round to 0.1ms for nice, pretty timestamps */ /* Round to 0.1ms for nice, pretty timestamps */
rtp->rxcore.tv_usec -= rtp->rxcore.tv_usec % 100; rtp->rxcore.tv_usec -= rtp->rxcore.tv_usec % 100;
sanitize_tv(&rtp->rxcore);
} }
gettimeofday(&now,NULL); gettimeofday(&now,NULL);
/* rxcore is the mapping between the RTP timestamp and _our_ real time from gettimeofday() */ /* rxcore is the mapping between the RTP timestamp and _our_ real time from gettimeofday() */
tv->tv_sec = rtp->rxcore.tv_sec + timestamp / rate; tmp = ast_samp2tv(timestamp, rate);
tv->tv_usec = rtp->rxcore.tv_usec + (timestamp % rate) * 125; *tv = ast_tvadd(rtp->rxcore, tmp);
sanitize_tv(tv);
prog = (double)((timestamp-rtp->seedrxts)/(float)(rate)); prog = (double)((timestamp-rtp->seedrxts)/(float)(rate));
dtv = (double)rtp->drxcore + (double)(prog); dtv = (double)rtp->drxcore + (double)(prog);
current_time = (double)now.tv_sec + (double)now.tv_usec/1000000; current_time = (double)now.tv_sec + (double)now.tv_usec/1000000;