Changeset 455 for pjproject/trunk


Ignore:
Timestamp:
May 18, 2006 6:35:05 PM (19 years ago)
Author:
bennylp
Message:

Changed the way average jitter is calculated in rtcp

Location:
pjproject/trunk/pjmedia
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/include/pjmedia/rtcp.h

    r427 r455  
    176176 
    177177    struct { 
     178        unsigned    count;      /**< Number of updates.                     */ 
    178179        unsigned    min;        /**< Minimum jitter (in usec)               */ 
    179180        unsigned    avg;        /**< Average jitter (in usec)               */ 
     
    216217 */ 
    217218typedef struct pjmedia_rtcp_stat pjmedia_rtcp_stat; 
     219 
     220 
     221#if defined(PJ_HAS_FLOATING_POINT) && PJ_HAS_FLOATING_POINT!=0 
     222  typedef double PJMEDIA_AVG_JITTER_TYPE; 
     223#else 
     224  typedef pj_uint32_t PJMEDIA_AVG_JITTER_TYPE; 
     225#endif; 
    218226 
    219227 
     
    245253     
    246254    pjmedia_rtcp_stat       stat;       /**< Bidirectional stream stat.     */ 
     255 
     256    /* Keep jitter calculation in floating point to prevent the values 
     257     * from being rounded-down to nearest integer. 
     258     */ 
     259    PJMEDIA_AVG_JITTER_TYPE avg_jitter; /**< Average RX jitter.             */ 
    247260}; 
    248261 
  • pjproject/trunk/pjmedia/src/pjmedia/rtcp.c

    r427 r455  
    139139    /* Reset statistics */ 
    140140    pj_memset(&sess->stat, 0, sizeof(pjmedia_rtcp_stat)); 
     141    sess->avg_jitter = 0; 
    141142 
    142143    /* Name */ 
     
    286287            } 
    287288 
     289            /* Add to average */ 
     290            sess->avg_jitter =  
     291                (jitter + sess->avg_jitter * sess->stat.rx.jitter.count) / 
     292                (sess->stat.rx.jitter.count + 1); 
     293            sess->stat.rx.jitter.avg = (unsigned)sess->avg_jitter; 
     294            ++sess->stat.rx.jitter.count; 
     295 
    288296            /* Update jitter stat */ 
    289297            if (jitter < sess->stat.rx.jitter.min) 
     
    291299            if (jitter > sess->stat.rx.jitter.max) 
    292300                sess->stat.rx.jitter.max = jitter; 
     301 
    293302            sess->stat.rx.jitter.last = jitter; 
    294303        } 
     
    394403 
    395404    /* Update jitter statistics */ 
    396     if (sess->stat.tx.update_cnt == 0) 
     405    if (sess->stat.tx.jitter.count == 0) 
    397406        sess->stat.tx.jitter.min = jitter; 
    398407    if (jitter < sess->stat.tx.jitter.min && jitter) 
     
    401410        sess->stat.tx.jitter.max = jitter; 
    402411    sess->stat.tx.jitter.avg =  
    403         (sess->stat.tx.jitter.avg * sess->stat.tx.update_cnt + jitter) / 
    404         (sess->stat.tx.update_cnt + 1); 
     412        (sess->stat.tx.jitter.avg * sess->stat.tx.jitter.count + jitter) / 
     413        (sess->stat.tx.jitter.count + 1); 
     414    ++sess->stat.tx.jitter.count; 
    405415    sess->stat.tx.jitter.last = jitter; 
    406416 
     
    509519{ 
    510520    pj_uint32_t expected, expected_interval, received_interval, lost_interval; 
    511     pj_uint32_t jitter_samp, jitter; 
    512521    pjmedia_rtcp_pkt *rtcp_pkt = &sess->rtcp_pkt; 
    513522    pj_timestamp ts_now; 
     
    528537 
    529538    /* Jitter */ 
    530     jitter_samp = (sess->jitter >> 4); 
    531     rtcp_pkt->rr.jitter = pj_htonl(jitter_samp); 
    532      
    533     /* Calculate jitter in usec, avoiding overflows */ 
    534     if (jitter_samp <= 4294) 
    535         jitter = jitter_samp * 1000000 / sess->clock_rate; 
    536     else { 
    537         jitter = jitter_samp * 1000 / sess->clock_rate; 
    538         jitter *= 1000; 
    539     } 
    540  
    541     /* Update jitter statistics */ 
    542     sess->stat.rx.jitter.avg =  
    543         (sess->stat.rx.jitter.avg * sess->stat.rx.update_cnt + jitter) / 
    544         (sess->stat.rx.update_cnt + 1); 
     539    rtcp_pkt->rr.jitter = pj_htonl(sess->jitter >> 4); 
     540     
    545541     
    546542    /* Total lost. */ 
Note: See TracChangeset for help on using the changeset viewer.