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

Changed RTCP timing to use high resolution timestamp

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.