Ignore:
Timestamp:
Apr 5, 2006 4:56:19 PM (18 years ago)
Author:
bennylp
Message:

Fixed bug in RTT calculation in RTCP and increase RTT resolution to usec

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/src/pjmedia/rtcp.c

    r383 r384  
    2020#include <pjmedia/errno.h> 
    2121#include <pj/assert.h> 
     22#include <pj/log.h> 
    2223#include <pj/os.h> 
    2324#include <pj/sock.h> 
    2425#include <pj/string.h> 
    2526 
     27#define THIS_FILE "rtcp.c" 
    2628 
    2729#define RTCP_SR   200 
     
    3335#endif 
    3436 
     37#if 0 
     38#   define TRACE_(x)    PJ_LOG(3,x) 
     39#else 
     40#   define TRACE_(x) 
     41#endif 
    3542 
    3643/* 
     
    183190    pj_get_timestamp(&session->rtcp_lsr_time); 
    184191 
    185     /* Calculate ee_delay if it has RR */ 
     192    /* Calculate RTT if it has RR */ 
    186193    if (size >= sizeof(pjmedia_rtcp_pkt)) { 
    187194         
    188195        /* Can only calculate if LSR and DLSR is present in RR */ 
    189196        if (rtcp->rr.lsr && rtcp->rr.dlsr) { 
    190             pj_uint32_t lsr, now, dlsr, eedelay; 
     197            pj_uint32_t lsr, now, dlsr; 
     198            pj_uint64_t eedelay; 
    191199            pjmedia_rtcp_ntp_rec ntp; 
    192200 
     
    207215            eedelay = now - lsr - dlsr; 
    208216 
    209             /* Convert end to end delay to msec:  
     217            /* Convert end to end delay to usec (keeping the calculation in 
     218             * 64bit space):: 
    210219             *   session->ee_delay = (eedelay * 1000) / 65536; 
    211220             */ 
    212             session->ee_delay = (eedelay * 1000) >> 16; 
     221            eedelay = (eedelay * 1000000) >> 16; 
     222 
     223            TRACE_((THIS_FILE, "Rx RTCP: lsr=%p, dlsr=%p (%d:%03dms), " 
     224                               "now=%p, rtt=%p", 
     225                    lsr, dlsr, dlsr/65536, (dlsr%65536)*1000/65536, 
     226                    now, (pj_uint32_t)eedelay)); 
     227             
     228            /* Only save calculation if "now" is greater than lsr, or 
     229             * otherwise rtt will be invalid  
     230             */ 
     231            if (now-dlsr >= lsr) { 
     232                session->rtt_us = (pj_uint32_t)eedelay; 
     233            } else { 
     234                TRACE_((THIS_FILE, "NTP clock running backwards?")); 
     235            } 
    213236        } 
    214237    } 
     
    272295    rtcp_pkt->sr.ntp_frac = pj_htonl(ntp.lo); 
    273296     
    274     if (session->rtcp_lsr_time.u64 == 0 || session->rtcp_lsr.lo == 0) { 
     297    if (session->rtcp_lsr_time.u64 == 0) { 
    275298        rtcp_pkt->rr.lsr = 0; 
    276299        rtcp_pkt->rr.dlsr = 0; 
     
    290313        pj_get_timestamp(&ts); 
    291314 
     315        /* Calculate DLSR */ 
     316        ts.u64 -= session->rtcp_lsr_time.u64; 
     317 
    292318        /* Convert interval to 1/65536 seconds value */ 
    293319        ts.u64 = ((ts.u64 - session->rtcp_lsr_time.u64) << 16) /  
Note: See TracChangeset for help on using the changeset viewer.