Changeset 381
- Timestamp:
- Apr 4, 2006 7:43:24 PM (19 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/include/pjmedia/rtcp.h
r321 r381 27 27 #include <pjmedia/types.h> 28 28 #include <pjmedia/rtp.h> 29 29 30 30 31 PJ_BEGIN_DECL … … 149 150 pjmedia_rtp_seq_session seq_ctrl; /**< RTCP sequence number control. */ 150 151 152 unsigned clock_rate; /**< Clock rate. */ 151 153 pj_uint32_t received; /**< # pkts received */ 152 154 pj_uint32_t expected_prior; /**< # pkts expected at last interval */ … … 154 156 pj_int32_t transit; /**< Relative trans time for prev pkt */ 155 157 pj_uint32_t jitter; /**< Estimated jitter */ 156 158 pj_timestamp ts_freq; /**< System timestamp frequency. */ 159 157 160 pjmedia_rtcp_ntp_rec rtcp_lsr; /**< NTP ts in last SR received */ 158 161 unsigned rtcp_lsr_time; /**< Time when last SR is received.*/ … … 174 177 */ 175 178 PJ_DECL(void) pjmedia_rtcp_init( pjmedia_rtcp_session *session, 179 unsigned clock_rate, 176 180 pj_uint32_t ssrc ); 177 181 -
pjproject/trunk/pjmedia/src/pjmedia/rtcp.c
r378 r381 28 28 29 29 30 #define USE_TIMESTAMP PJ_HAS_HIGH_RES_TIMER 31 30 32 31 33 /* … … 46 48 47 49 PJ_DEF(void) pjmedia_rtcp_init(pjmedia_rtcp_session *s, 50 unsigned clock_rate, 48 51 pj_uint32_t ssrc) 49 52 { … … 52 55 pj_memset(rtcp_pkt, 0, sizeof(pjmedia_rtcp_pkt)); 53 56 57 /* Set clock rate */ 58 s->clock_rate = clock_rate; 59 54 60 /* Init time */ 55 61 s->rtcp_lsr.hi = s->rtcp_lsr.lo = 0; … … 65 71 rtcp_pkt->sr.ssrc = pj_htonl(ssrc); 66 72 73 /* Get timestamp frequency */ 74 #if USE_TIMESTAMP 75 pj_get_timestamp_freq(&s->ts_freq); 76 #endif 77 67 78 /* RR will be initialized on receipt of the first RTP packet. */ 68 79 } … … 91 102 pj_uint32_t arrival; 92 103 pj_int32_t transit; 93 unsigned long timer_tick;94 pj_time_val tv;95 104 int status; 96 105 … … 107 116 ++s->received; 108 117 109 pj_gettimeofday(&tv);110 timer_tick = tv.sec * 1000 + tv.msec;111 112 118 /* 113 119 * Calculate jitter (s->jitter is in timer tick unit) 114 120 */ 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 118 144 transit = arrival - rtp_ts; 119 145 -
pjproject/trunk/pjmedia/src/pjmedia/stream.c
r350 r381 739 739 /* Init RTCP session: */ 740 740 741 pjmedia_rtcp_init(&stream->rtcp, info-> ssrc);741 pjmedia_rtcp_init(&stream->rtcp, info->fmt.sample_rate, info->ssrc); 742 742 743 743 -
pjproject/trunk/pjsip-apps/src/samples/siprtp.c
r380 r381 29 29 30 30 #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 31 36 32 37 #define THIS_FILE "siprtp.c" … … 989 994 static int media_thread(void *arg) 990 995 { 996 enum { RTCP_INTERVAL = 5 }; 991 997 struct media_stream *strm = arg; 992 998 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); 998 1007 999 1008 next_rtcp = next_rtp; 1000 next_rtcp. sec += 5;1009 next_rtcp.u64 += (freq.u64 * RTCP_INTERVAL); 1001 1010 1002 1011 1003 1012 while (!strm->thread_quit_flag) { 1004 1013 pj_fd_set_t set; 1005 pj_time_val now, lesser, timeout; 1014 pj_timestamp now, lesser; 1015 pj_time_val timeout; 1006 1016 int rc; 1007 1017 1008 1018 /* Determine how long to sleep */ 1009 if ( PJ_TIME_VAL_LT(next_rtp, next_rtcp))1019 if (next_rtp.u64 < next_rtcp.u64) 1010 1020 lesser = next_rtp; 1011 1021 else 1012 1022 lesser = next_rtcp; 1013 1023 1014 pj_get timeofday(&now);1015 if ( PJ_TIME_VAL_LTE(lesser, now))1024 pj_get_timestamp(&now); 1025 if (lesser.u64 <= now.u64) { 1016 1026 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); 1020 1036 } 1021 1037 … … 1026 1042 rc = pj_sock_select(FD_SETSIZE, &set, NULL, NULL, &timeout); 1027 1043 1028 if ( PJ_FD_ISSET(strm->rtp_sock, &set)) {1044 if (rc > 0 && PJ_FD_ISSET(strm->rtp_sock, &set)) { 1029 1045 1030 1046 /* … … 1075 1091 pj_ntohl(hdr->ts)); 1076 1092 1077 } else if (PJ_FD_ISSET(strm->rtcp_sock, &set)) { 1093 } 1094 1095 if (rc > 0 && PJ_FD_ISSET(strm->rtcp_sock, &set)) { 1078 1096 1079 1097 /* … … 1115 1133 1116 1134 1117 pj_get timeofday(&now);1118 1119 if ( PJ_TIME_VAL_LTE(next_rtp, now)) {1135 pj_get_timestamp(&now); 1136 1137 if (next_rtp.u64 <= now.u64) { 1120 1138 /* 1121 1139 * Time to send RTP packet. … … 1155 1173 1156 1174 /* 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); 1159 1176 1160 1177 /* Update stats */ … … 1164 1181 1165 1182 1166 if ( PJ_TIME_VAL_LTE(next_rtcp, now)) {1183 if (next_rtcp.u64 <= now.u64) { 1167 1184 /* 1168 1185 * Time to send RTCP packet. … … 1209 1226 } 1210 1227 1211 next_rtcp. sec += 5;1228 next_rtcp.u64 += (freq.u64 * RTCP_INTERVAL); 1212 1229 } 1213 1230 … … 1282 1299 pj_rand()); 1283 1300 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); 1285 1302 1286 1303 … … 1780 1797 } 1781 1798 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 1782 1805 /* If URL is specified, then make call immediately */ 1783 1806 if (app.uri_to_call.slen) { … … 1801 1824 } 1802 1825 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 1809 1826 /* Start user interface loop */ 1810 1827 console_main();
Note: See TracChangeset
for help on using the changeset viewer.