Changeset 381


Ignore:
Timestamp:
Apr 4, 2006 7:43:24 PM (18 years ago)
Author:
bennylp
Message:

Changed RTCP timing to use high resolution timestamp

Location:
pjproject/trunk
Files:
4 edited

Legend:

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

    r321 r381  
    2727#include <pjmedia/types.h> 
    2828#include <pjmedia/rtp.h> 
     29 
    2930 
    3031PJ_BEGIN_DECL 
     
    149150    pjmedia_rtp_seq_session seq_ctrl;   /**< RTCP sequence number control.  */ 
    150151 
     152    unsigned        clock_rate;     /**< Clock rate.                        */ 
    151153    pj_uint32_t     received;       /**< # pkts received                    */ 
    152154    pj_uint32_t     expected_prior; /**< # pkts expected at last interval   */ 
     
    154156    pj_int32_t      transit;        /**< Relative trans time for prev pkt   */ 
    155157    pj_uint32_t     jitter;         /**< Estimated jitter                   */ 
    156      
     158    pj_timestamp    ts_freq;        /**< System timestamp frequency.        */ 
     159 
    157160    pjmedia_rtcp_ntp_rec rtcp_lsr;       /**< NTP ts in last SR received    */ 
    158161    unsigned             rtcp_lsr_time;  /**< Time when last SR is received.*/ 
     
    174177 */ 
    175178PJ_DECL(void) pjmedia_rtcp_init( pjmedia_rtcp_session *session,  
     179                                 unsigned clock_rate, 
    176180                                 pj_uint32_t ssrc ); 
    177181 
  • pjproject/trunk/pjmedia/src/pjmedia/rtcp.c

    r378 r381  
    2828 
    2929 
     30#define USE_TIMESTAMP   PJ_HAS_HIGH_RES_TIMER 
     31 
    3032 
    3133/* 
     
    4648 
    4749PJ_DEF(void) pjmedia_rtcp_init(pjmedia_rtcp_session *s,  
     50                               unsigned clock_rate, 
    4851                               pj_uint32_t ssrc) 
    4952{ 
     
    5255    pj_memset(rtcp_pkt, 0, sizeof(pjmedia_rtcp_pkt)); 
    5356     
     57    /* Set clock rate */ 
     58    s->clock_rate = clock_rate; 
     59 
    5460    /* Init time */ 
    5561    s->rtcp_lsr.hi = s->rtcp_lsr.lo = 0; 
     
    6571    rtcp_pkt->sr.ssrc = pj_htonl(ssrc); 
    6672     
     73    /* Get timestamp frequency */ 
     74#if USE_TIMESTAMP 
     75    pj_get_timestamp_freq(&s->ts_freq); 
     76#endif 
     77 
    6778    /* RR will be initialized on receipt of the first RTP packet. */ 
    6879} 
     
    91102    pj_uint32_t arrival; 
    92103    pj_int32_t transit; 
    93     unsigned long timer_tick; 
    94     pj_time_val tv; 
    95104    int status; 
    96105 
     
    107116    ++s->received; 
    108117 
    109     pj_gettimeofday(&tv); 
    110     timer_tick = tv.sec * 1000 + tv.msec; 
    111      
    112118    /* 
    113119     * Calculate jitter (s->jitter is in timer tick unit) 
    114120     */ 
    115     PJ_TODO(SUPPORT_JITTER_CALCULATION_FOR_NON_8KHZ_SAMPLE_RATE) 
    116  
    117     arrival = timer_tick << 3;  // 8 samples per ms. 
     121#if USE_TIMESTAMP 
     122    { 
     123        pj_timestamp ts; 
     124 
     125        pj_get_timestamp(&ts); 
     126 
     127        /* Convert timestamp to samples */ 
     128        ts.u64 = ts.u64 * s->clock_rate / s->ts_freq.u64; 
     129        arrival = (pj_uint32_t)ts.u64; 
     130    } 
     131#else 
     132    { 
     133        pj_time_val tv; 
     134        unsigned long timer_tick; 
     135 
     136        pj_gettimeofday(&tv); 
     137        timer_tick = tv.sec * 1000 + tv.msec; 
     138 
     139        /* Convert timer tick to samples */ 
     140        arrival = timer_tick * s->clock_rate / 1000; 
     141    } 
     142#endif 
     143 
    118144    transit = arrival - rtp_ts; 
    119145     
  • pjproject/trunk/pjmedia/src/pjmedia/stream.c

    r350 r381  
    739739    /* Init RTCP session: */ 
    740740 
    741     pjmedia_rtcp_init(&stream->rtcp, info->ssrc); 
     741    pjmedia_rtcp_init(&stream->rtcp, info->fmt.sample_rate, info->ssrc); 
    742742 
    743743 
  • pjproject/trunk/pjsip-apps/src/samples/siprtp.c

    r380 r381  
    2929 
    3030#include <stdlib.h> 
     31 
     32 
     33#if PJ_HAS_HIGH_RES_TIMER==0 
     34#   error "High resolution timer is needed for this sample" 
     35#endif 
    3136 
    3237#define THIS_FILE       "siprtp.c" 
     
    989994static int media_thread(void *arg) 
    990995{ 
     996    enum { RTCP_INTERVAL = 5 }; 
    991997    struct media_stream *strm = arg; 
    992998    char packet[1500]; 
    993     pj_time_val next_rtp, next_rtcp; 
    994  
    995     pj_gettimeofday(&next_rtp); 
    996     next_rtp.msec += strm->samples_per_frame * 1000 / strm->clock_rate; 
    997     pj_time_val_normalize(&next_rtp); 
     999    unsigned msec_interval; 
     1000    pj_timestamp freq, next_rtp, next_rtcp; 
     1001 
     1002    msec_interval = strm->samples_per_frame * 1000 / strm->clock_rate; 
     1003    pj_get_timestamp_freq(&freq); 
     1004 
     1005    pj_get_timestamp(&next_rtp); 
     1006    next_rtp.u64 += (freq.u64 * msec_interval / 1000); 
    9981007 
    9991008    next_rtcp = next_rtp; 
    1000     next_rtcp.sec += 5; 
     1009    next_rtcp.u64 += (freq.u64 * RTCP_INTERVAL); 
    10011010 
    10021011 
    10031012    while (!strm->thread_quit_flag) { 
    10041013        pj_fd_set_t set; 
    1005         pj_time_val now, lesser, timeout; 
     1014        pj_timestamp now, lesser; 
     1015        pj_time_val timeout; 
    10061016        int rc; 
    10071017 
    10081018        /* Determine how long to sleep */ 
    1009         if (PJ_TIME_VAL_LT(next_rtp, next_rtcp)) 
     1019        if (next_rtp.u64 < next_rtcp.u64) 
    10101020            lesser = next_rtp; 
    10111021        else 
    10121022            lesser = next_rtcp; 
    10131023 
    1014         pj_gettimeofday(&now); 
    1015         if (PJ_TIME_VAL_LTE(lesser, now)) 
     1024        pj_get_timestamp(&now); 
     1025        if (lesser.u64 <= now.u64) { 
    10161026            timeout.sec = timeout.msec = 0; 
    1017         else { 
    1018             timeout = lesser; 
    1019             PJ_TIME_VAL_SUB(timeout, now); 
     1027            //printf("immediate "); fflush(stdout); 
     1028        } else { 
     1029            pj_uint64_t tick_delay; 
     1030            tick_delay = lesser.u64 - now.u64; 
     1031            timeout.sec = 0; 
     1032            timeout.msec = (pj_uint32_t)(tick_delay * 1000 / freq.u64); 
     1033            pj_time_val_normalize(&timeout); 
     1034 
     1035            //printf("%d:%03d ", timeout.sec, timeout.msec); fflush(stdout); 
    10201036        } 
    10211037 
     
    10261042        rc = pj_sock_select(FD_SETSIZE, &set, NULL, NULL, &timeout); 
    10271043 
    1028         if (PJ_FD_ISSET(strm->rtp_sock, &set)) { 
     1044        if (rc > 0 && PJ_FD_ISSET(strm->rtp_sock, &set)) { 
    10291045 
    10301046            /* 
     
    10751091                                pj_ntohl(hdr->ts)); 
    10761092 
    1077         } else if (PJ_FD_ISSET(strm->rtcp_sock, &set)) { 
     1093        }  
     1094         
     1095        if (rc > 0 && PJ_FD_ISSET(strm->rtcp_sock, &set)) { 
    10781096 
    10791097            /* 
     
    11151133 
    11161134 
    1117         pj_gettimeofday(&now); 
    1118  
    1119         if (PJ_TIME_VAL_LTE(next_rtp, now)) { 
     1135        pj_get_timestamp(&now); 
     1136 
     1137        if (next_rtp.u64 <= now.u64) { 
    11201138            /* 
    11211139             * Time to send RTP packet. 
     
    11551173 
    11561174            /* Schedule next send */ 
    1157             next_rtp.msec += strm->samples_per_frame * 1000 / strm->clock_rate; 
    1158             pj_time_val_normalize(&next_rtp); 
     1175            next_rtp.u64 += (msec_interval * freq.u64 / 1000); 
    11591176 
    11601177            /* Update stats */ 
     
    11641181 
    11651182 
    1166         if (PJ_TIME_VAL_LTE(next_rtcp, now)) { 
     1183        if (next_rtcp.u64 <= now.u64) { 
    11671184            /* 
    11681185             * Time to send RTCP packet. 
     
    12091226            } 
    12101227 
    1211             next_rtcp.sec += 5; 
     1228            next_rtcp.u64 += (freq.u64 * RTCP_INTERVAL); 
    12121229        } 
    12131230 
     
    12821299                             pj_rand()); 
    12831300    pjmedia_rtp_session_init(&audio->in_sess, audio->si.fmt.pt, 0); 
    1284     pjmedia_rtcp_init(&audio->rtcp, 0); 
     1301    pjmedia_rtcp_init(&audio->rtcp, audio->clock_rate, 0); 
    12851302 
    12861303 
     
    17801797    } 
    17811798 
     1799    /* Start worker threads */ 
     1800    for (i=0; i<app.thread_count; ++i) { 
     1801        pj_thread_create( app.pool, "app", &worker_thread, NULL, 
     1802                          0, 0, &app.thread[i]); 
     1803    } 
     1804 
    17821805    /* If URL is specified, then make call immediately */ 
    17831806    if (app.uri_to_call.slen) { 
     
    18011824    } 
    18021825 
    1803     /* Start worker threads */ 
    1804     for (i=0; i<app.thread_count; ++i) { 
    1805         pj_thread_create( app.pool, "app", &worker_thread, NULL, 
    1806                           0, 0, &app.thread[i]); 
    1807     } 
    1808  
    18091826    /* Start user interface loop */ 
    18101827    console_main(); 
Note: See TracChangeset for help on using the changeset viewer.