[Asterisk-Users] Codec Voodoo: piece of evidence: probable fix

Andres andres at telesip.net
Sat Mar 27 17:31:25 MST 2004


Hi Ray,

I did report this to Mark Spencer a few days ago.  Look at my last 
comment in bug: http://bugs.digium.com/bug_view_page.php?bug_id=0001260

Maybe you can open up a bug report and provide your solution. 

Ray Burkholder wrote:

>>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;
>}
>
>
>  
>


-- 
Andres
Network Admin
http://www.telesip.net





More information about the asterisk-users mailing list