[Asterisk-Users] Codec Voodoo: piece of evidence: probable fix
Andres
andres at telesip.net
Sun Mar 28 20:55:56 MST 2004
Hi Ray,
I tried this fix. Did a fresh checkout on 2 servers and established a
SIP-IAX2-SIP call. I still see ocasional jumps of 152 and 168 samples
in the RTP Timestamp. Any other ideas on how to fix this?
Andres
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;
>}
>
>
>
>
More information about the asterisk-users
mailing list