[asterisk-bugs] [JIRA] (ASTERISK-26566) RTCP miscalculation on res_rtp_asterisk.c

Hector Royo Concepcion (JIRA) noreply at issues.asterisk.org
Tue Nov 8 07:17:10 CST 2016


Hector Royo Concepcion created ASTERISK-26566:
-------------------------------------------------

             Summary: RTCP miscalculation on res_rtp_asterisk.c
                 Key: ASTERISK-26566
                 URL: https://issues.asterisk.org/jira/browse/ASTERISK-26566
             Project: Asterisk
          Issue Type: Bug
      Security Level: None
    Affects Versions: 13.11.2, 13.9.0
            Reporter: Hector Royo Concepcion


I have an Asterisk, with PJSIP. We are saving the RTCP stats to a CDR database, and I've found that RTT values are mostly wrong, showing values over 4.000 seconds. 

I've been reading how the RTT is calculated on the RTCP RFC, and I think that the code on res_rtp_asterisk.c is miscalculating the LSW of the RTT.
{quote}
rtt_lsw = (rtt & 0x0000ffff) << 16; // This will cause overflow
rtt_tv.tv_usec = ((rtt_lsw << 6) / 3650) - (rtt_lsw >> 12) - (rtt_lsw >> 8); // This will lose precision
rtp->rtcp->rtt = (double)rtt_tv.tv_sec + (double)(rtt_tv.tv_usec/1000000.);
{quote}
This lines above can easily overflow the LSW. Since it is a *fixed point* value, I think it should be calculated like this (probably not the most efficient way):
{quote}
rtt_lsw = (rtt & 0x0000ffff);               // No shift!!
rtt_tv.tv_usec = (rtt_lsw * 999985/65535);  // Better precision

rtp->rtcp->rtt = (double)rtt_tv.tv_sec + (double)(rtt_tv.tv_usec/1000000.);
{quote}

Using this version of the code, values that were 4000~ seconds are now 60-70ms. This new values matches the RTT values I'm getting from Wireshark.

Values 65535 and 999985 came from:
{quote}
655535 = 0xffff = 0b1111111111111111
999985 = (2⁻¹ + 2⁻² + ... +2⁻¹⁵ + 2⁻¹⁶)*1000000
{quote}



--
This message was sent by Atlassian JIRA
(v6.2#6252)



More information about the asterisk-bugs mailing list