[Asterisk-Users] Codec Voodoo: piece of evidence: probable fix
Ray Burkholder
ray at oneunified.net
Sat Mar 27 14:50:46 MST 2004
>
> static unsigned int calc_txstamp(struct ast_rtp *rtp, struct timeval
> *delivery)
> {
> struct timeval now;
> unsigned int ms;
> if (!rtp->txcore.tv_sec && !rtp->txcore.tv_usec) {
> gettimeofday(&rtp->txcore, NULL);
> }
> gettimeofday(&now, NULL);
> ms = (now.tv_sec - rtp->txcore.tv_sec) * 1000;
> ms += (now.tv_usec - rtp->txcore.tv_usec) / 1000;
> /* Use what we just got for next time */
> rtp->txcore.tv_sec = now.tv_sec;
> rtp->txcore.tv_usec = now.tv_usec;
> return ms;
> }
This snippet is from old code. Here is a corrected new snippet with proper
rounding that I think fixes the issue (the two lines are marked [sorry
didn't think to do a diff until afterwards]):
static unsigned int calc_txstamp(struct ast_rtp *rtp, struct timeval
*delivery)
{
struct timeval now;
unsigned int ms;
if (!rtp->txcore.tv_sec && !rtp->txcore.tv_usec) {
gettimeofday(&rtp->txcore, NULL);
rtp->txcore.tv_usec -= rtp->txcore.tv_usec % 20000;
}
if (delivery && (delivery->tv_sec || delivery->tv_usec)) {
/* Use previous txcore */
=> ms = (delivery->tv_sec - rtp->txcore.tv_sec) * 1000;
ms += ((delivery->tv_usec - rtp->txcore.tv_usec) + 500) /
1000;
rtp->txcore.tv_sec = delivery->tv_sec;
rtp->txcore.tv_usec = delivery->tv_usec;
} else {
gettimeofday(&now, NULL);
ms = (now.tv_sec - rtp->txcore.tv_sec) * 1000;
=> ms += ((now.tv_usec - rtp->txcore.tv_usec) + 500 ) / 1000;
/* Use what we just got for next time */
rtp->txcore.tv_sec = now.tv_sec;
rtp->txcore.tv_usec = now.tv_usec;
}
return ms;
}
--
Scanned for viruses and dangerous content at
http://www.oneunified.net and is believed to be clean.
More information about the asterisk-users
mailing list