Changeset 381 for pjproject/trunk/pjsip-apps/src/samples/siprtp.c
- Timestamp:
- Apr 4, 2006 7:43:24 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.