Changeset 384 for pjproject/trunk
- Timestamp:
- Apr 5, 2006 4:56:19 PM (19 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/include/pjmedia/rtcp.h
r383 r384 164 164 pj_timestamp ts_freq; /**< System timestamp frequency. */ 165 165 166 pjmedia_rtcp_ntp_rec rtcp_lsr; 166 pjmedia_rtcp_ntp_rec rtcp_lsr; /**< NTP ts in last SR received */ 167 167 pj_timestamp rtcp_lsr_time;/**< Time when last SR is received*/ 168 pj_uint32_t peer_ssrc; 169 unsigned ee_delay; /**< End-to-end delay, in msec. */168 pj_uint32_t peer_ssrc; /**< Peer SSRC */ 169 unsigned rtt_us; /**< End-to-end delay, in usec. */ 170 170 }; 171 171 -
pjproject/trunk/pjmedia/src/pjmedia/rtcp.c
r383 r384 20 20 #include <pjmedia/errno.h> 21 21 #include <pj/assert.h> 22 #include <pj/log.h> 22 23 #include <pj/os.h> 23 24 #include <pj/sock.h> 24 25 #include <pj/string.h> 25 26 27 #define THIS_FILE "rtcp.c" 26 28 27 29 #define RTCP_SR 200 … … 33 35 #endif 34 36 37 #if 0 38 # define TRACE_(x) PJ_LOG(3,x) 39 #else 40 # define TRACE_(x) 41 #endif 35 42 36 43 /* … … 183 190 pj_get_timestamp(&session->rtcp_lsr_time); 184 191 185 /* Calculate ee_delayif it has RR */192 /* Calculate RTT if it has RR */ 186 193 if (size >= sizeof(pjmedia_rtcp_pkt)) { 187 194 188 195 /* Can only calculate if LSR and DLSR is present in RR */ 189 196 if (rtcp->rr.lsr && rtcp->rr.dlsr) { 190 pj_uint32_t lsr, now, dlsr, eedelay; 197 pj_uint32_t lsr, now, dlsr; 198 pj_uint64_t eedelay; 191 199 pjmedia_rtcp_ntp_rec ntp; 192 200 … … 207 215 eedelay = now - lsr - dlsr; 208 216 209 /* Convert end to end delay to msec: 217 /* Convert end to end delay to usec (keeping the calculation in 218 * 64bit space):: 210 219 * session->ee_delay = (eedelay * 1000) / 65536; 211 220 */ 212 session->ee_delay = (eedelay * 1000) >> 16; 221 eedelay = (eedelay * 1000000) >> 16; 222 223 TRACE_((THIS_FILE, "Rx RTCP: lsr=%p, dlsr=%p (%d:%03dms), " 224 "now=%p, rtt=%p", 225 lsr, dlsr, dlsr/65536, (dlsr%65536)*1000/65536, 226 now, (pj_uint32_t)eedelay)); 227 228 /* Only save calculation if "now" is greater than lsr, or 229 * otherwise rtt will be invalid 230 */ 231 if (now-dlsr >= lsr) { 232 session->rtt_us = (pj_uint32_t)eedelay; 233 } else { 234 TRACE_((THIS_FILE, "NTP clock running backwards?")); 235 } 213 236 } 214 237 } … … 272 295 rtcp_pkt->sr.ntp_frac = pj_htonl(ntp.lo); 273 296 274 if (session->rtcp_lsr_time.u64 == 0 || session->rtcp_lsr.lo == 0) {297 if (session->rtcp_lsr_time.u64 == 0) { 275 298 rtcp_pkt->rr.lsr = 0; 276 299 rtcp_pkt->rr.dlsr = 0; … … 290 313 pj_get_timestamp(&ts); 291 314 315 /* Calculate DLSR */ 316 ts.u64 -= session->rtcp_lsr_time.u64; 317 292 318 /* Convert interval to 1/65536 seconds value */ 293 319 ts.u64 = ((ts.u64 - session->rtcp_lsr_time.u64) << 16) / -
pjproject/trunk/pjsip-apps/src/samples/siprtp.c
r383 r384 59 59 unsigned loss_min, loss_avg, loss_max; 60 60 char *loss_type; 61 unsigned jitter_min , jitter_avg, jitter_max;61 unsigned jitter_min_us, jitter_avg_us, jitter_max_us; 62 62 unsigned rtcp_cnt; 63 63 }; … … 254 254 { 255 255 pj_sockaddr_in addr; 256 256 pjsip_host_port addrname; 257 258 pj_memset(&addr, 0, sizeof(addr)); 257 259 addr.sin_family = PJ_AF_INET; 258 260 addr.sin_addr.s_addr = 0; 259 261 addr.sin_port = pj_htons((pj_uint16_t)app.sip_port); 260 262 261 status = pjsip_udp_transport_start( app.sip_endpt, &addr, NULL, 263 if (app.local_addr) { 264 addrname.host = pj_str(app.local_addr); 265 addrname.port = app.sip_port; 266 } 267 268 status = pjsip_udp_transport_start( app.sip_endpt, &addr, 269 (app.local_addr ? &addrname:NULL), 262 270 1, NULL); 263 if (status != PJ_SUCCESS) 271 if (status != PJ_SUCCESS) { 272 app_perror(THIS_FILE, "Unable to start UDP transport", status); 264 273 return status; 274 } 265 275 } 266 276 … … 365 375 return -1; 366 376 } 367 368 377 369 378 /* RTP port counter */ … … 1124 1133 unsigned jitter; 1125 1134 1126 jitter = pj_ntohl(strm->rem_rtcp.rr.jitter) * 1000 / 1127 strm->clock_rate; 1128 if (jitter < strm->tx_stat.jitter_min) 1129 strm->tx_stat.jitter_min = jitter; 1130 if (jitter > strm->tx_stat.jitter_max) 1131 strm->tx_stat.jitter_max = jitter; 1132 strm->tx_stat.jitter_avg = (strm->tx_stat.jitter_avg * strm->tx_stat.rtcp_cnt + 1133 jitter) / (strm->tx_stat.rtcp_cnt + 1); 1135 jitter = (unsigned)(pj_ntohl(strm->rem_rtcp.rr.jitter) * 1136 1000000.0 / strm->clock_rate); 1137 if (jitter < strm->tx_stat.jitter_min_us) 1138 strm->tx_stat.jitter_min_us = jitter; 1139 if (jitter > strm->tx_stat.jitter_max_us) 1140 strm->tx_stat.jitter_max_us = jitter; 1141 strm->tx_stat.jitter_avg_us = 1142 (strm->tx_stat.jitter_avg_us * strm->tx_stat.rtcp_cnt + 1143 jitter) / (strm->tx_stat.rtcp_cnt + 1); 1134 1144 1135 1145 strm->tx_stat.rtcp_cnt++; … … 1219 1229 unsigned jitter; 1220 1230 1221 jitter = pj_ntohl(rtcp_pkt->rr.jitter) * 1000 / 1222 strm->clock_rate; 1223 if (jitter < strm->rx_stat.jitter_min) 1224 strm->rx_stat.jitter_min = jitter; 1225 if (jitter > strm->rx_stat.jitter_max) 1226 strm->rx_stat.jitter_max = jitter; 1227 strm->rx_stat.jitter_avg = (strm->rx_stat.jitter_avg * strm->rx_stat.rtcp_cnt + 1228 jitter) / (strm->rx_stat.rtcp_cnt + 1); 1231 jitter = (unsigned) (pj_ntohl(rtcp_pkt->rr.jitter) * 1232 1000000.0 / strm->clock_rate); 1233 if (jitter < strm->rx_stat.jitter_min_us) 1234 strm->rx_stat.jitter_min_us = jitter; 1235 if (jitter > strm->rx_stat.jitter_max_us) 1236 strm->rx_stat.jitter_max_us = jitter; 1237 strm->rx_stat.jitter_avg_us = 1238 (strm->rx_stat.jitter_avg_us * strm->rx_stat.rtcp_cnt + 1239 jitter) / (strm->rx_stat.rtcp_cnt + 1); 1229 1240 1230 1241 strm->rx_stat.rtcp_cnt++; … … 1233 1244 next_rtcp.u64 += (freq.u64 * RTCP_INTERVAL); 1234 1245 } 1235 1236 1246 } 1237 1247 … … 1247 1257 pj_pool_t *pool; 1248 1258 struct media_stream *audio; 1249 pjmedia_sdp_session *local_sdp, *remote_sdp;1259 const pjmedia_sdp_session *local_sdp, *remote_sdp; 1250 1260 struct codec *codec_desc = NULL; 1251 1261 unsigned i; … … 1408 1418 PJ_TIME_VAL_SUB(now, call->connect_time); 1409 1419 1410 sprintf(duration, " [duration: %02 d:%02d:%02d.%03d]",1420 sprintf(duration, " [duration: %02ld:%02ld:%02ld.%03ld]", 1411 1421 now.sec / 3600, 1412 1422 (now.sec % 3600) / 60, … … 1444 1454 t = call->response_time; 1445 1455 PJ_TIME_VAL_SUB(t, call->start_time); 1446 sprintf(pdd, "got 1st response in % d ms", PJ_TIME_VAL_MSEC(t));1456 sprintf(pdd, "got 1st response in %ld ms", PJ_TIME_VAL_MSEC(t)); 1447 1457 } else { 1448 1458 pdd[0] = '\0'; … … 1452 1462 t = call->connect_time; 1453 1463 PJ_TIME_VAL_SUB(t, call->start_time); 1454 sprintf(connectdelay, ", connected after: %d ms", PJ_TIME_VAL_MSEC(t)); 1464 sprintf(connectdelay, ", connected after: %ld ms", 1465 PJ_TIME_VAL_MSEC(t)); 1455 1466 } else { 1456 1467 connectdelay[0] = '\0'; … … 1465 1476 } 1466 1477 1467 printf(" Stream #0: audio %.*s@%dHz, %dms/frame, %s bps (%sbps +IP hdr)\n",1468 1469 1470 1471 1472 1473 1478 printf(" Stream #0: audio %.*s@%dHz, %dms/frame, %sB/s (%sB/s +IP hdr)\n", 1479 (int)audio->si.fmt.encoding_name.slen, 1480 audio->si.fmt.encoding_name.ptr, 1481 audio->clock_rate, 1482 audio->samples_per_frame * 1000 / audio->clock_rate, 1483 good_number(bps, audio->bytes_per_frame * audio->clock_rate / audio->samples_per_frame), 1484 good_number(ipbps, (audio->bytes_per_frame+32) * audio->clock_rate / audio->samples_per_frame)); 1474 1485 1475 1486 total_loss = (audio->rtcp.rtcp_pkt.rr.total_lost_2 << 16) + … … 1479 1490 printf(" RX total %s packets %sB received (%sB +IP hdr)%s\n" 1480 1491 " pkt discards=%d (%3.1f%%), loss=%d (%3.1f%%), reorder=%d (%3.1f%%)%s\n" 1481 " loss period min=%d ms, avg=%d ms, max=%dms%s\n"1482 " jitter min=% d ms, avg=%d ms, max=%d ms, current=%dms%s\n",1492 " loss period min=%dms, avg=%dms, max=%dms%s\n" 1493 " jitter min=%5.3fms, avg=%5.3fms, max=%5.3fms, curr=%5.3f ms%s\n", 1483 1494 good_number(packets, audio->rx_stat.pkt), 1484 1495 good_number(bytes, audio->rx_stat.payload), … … 1493 1504 -1, -1, -1, 1494 1505 "", 1495 (audio->rx_stat.rtcp_cnt ? audio->rx_stat.jitter_min : -1),1496 (audio->rx_stat.rtcp_cnt ? audio->rx_stat.jitter_avg : -1),1497 (audio->rx_stat.rtcp_cnt ? audio->rx_stat.jitter_max : -1),1498 (audio->rx_stat.rtcp_cnt ? pj_ntohl(audio->rtcp.rtcp_pkt.rr.jitter)*1000/audio->clock_rate : -1),1506 (audio->rx_stat.rtcp_cnt? audio->rx_stat.jitter_min_us/1000.0 : -1.), 1507 (audio->rx_stat.rtcp_cnt? audio->rx_stat.jitter_avg_us/1000.0 : -1.), 1508 (audio->rx_stat.rtcp_cnt? audio->rx_stat.jitter_max_us/1000.0 : -1.), 1509 (audio->rx_stat.rtcp_cnt? pj_ntohl(audio->rtcp.rtcp_pkt.rr.jitter)*1000.0/audio->clock_rate : -1.), 1499 1510 "" 1500 1511 ); … … 1507 1518 printf(" TX total %s packets %sB sent (%sB +IP hdr)%s\n" 1508 1519 " pkt discards=%d (%3.1f%%), loss=%d (%3.1f%%), reorder=%d (%3.1f%%)%s\n" 1509 " loss period min=%d ms, avg=%d ms, max=%dms%s\n"1510 " jitter min=% d ms, avg=%d ms, max=%d ms, current=%dms%s\n",1520 " loss period min=%dms, avg=%dms, max=%dms%s\n" 1521 " jitter min=%5.3fms, avg=%5.3fms, max=%5.3fms, curr=%5.3f ms%s\n", 1511 1522 good_number(packets, audio->tx_stat.pkt), 1512 1523 good_number(bytes, audio->tx_stat.payload), … … 1521 1532 -1, -1, -1, 1522 1533 "", 1523 (audio->tx_stat.rtcp_cnt ? audio->tx_stat.jitter_min : -1),1524 (audio->tx_stat.rtcp_cnt ? audio->tx_stat.jitter_avg : -1),1525 (audio->tx_stat.rtcp_cnt ? audio->tx_stat.jitter_max : -1),1526 (audio->tx_stat.rtcp_cnt ? pj_ntohl(audio->rem_rtcp.rr.jitter)*1000/audio->clock_rate : -1),1534 (audio->tx_stat.rtcp_cnt? audio->tx_stat.jitter_min_us/1000.0 : -1.), 1535 (audio->tx_stat.rtcp_cnt? audio->tx_stat.jitter_avg_us/1000.0 : -1.), 1536 (audio->tx_stat.rtcp_cnt? audio->tx_stat.jitter_max_us/1000.0 : -1.), 1537 (audio->tx_stat.rtcp_cnt? pj_ntohl(audio->rem_rtcp.rr.jitter)*1000.0/audio->clock_rate : -1.), 1527 1538 "" 1528 1539 ); 1529 1540 1530 printf(" End to end delay: %u ms\n", audio->rtcp.ee_delay); 1541 printf(" End to end delay: %5.3f ms\n", 1542 audio->rtcp.rtt_us / 1000.0); 1531 1543 1532 1544 }
Note: See TracChangeset
for help on using the changeset viewer.