Changeset 621
- Timestamp:
- Jul 22, 2006 12:53:04 PM (18 years ago)
- Location:
- pjproject/trunk/pjsip-apps/src/samples
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/samples/siprtp.c
r615 r621 718 718 } 719 719 720 PJ_LOG(3,(THIS_FILE, "Call #%d disconnected. Reason=% s",720 PJ_LOG(3,(THIS_FILE, "Call #%d disconnected. Reason=%d (%.*s)", 721 721 call->index, 722 pjsip_get_status_text(inv->cause)->ptr)); 722 inv->cause, 723 (int)inv->cause_text.slen, 724 inv->cause_text.ptr)); 723 725 PJ_LOG(3,(THIS_FILE, "Call #%d statistics:", call->index)); 724 726 print_call(call->index); … … 1145 1147 1146 1148 /* Let things settle */ 1147 pj_thread_sleep(100 0);1149 pj_thread_sleep(100); 1148 1150 1149 1151 msec_interval = strm->samples_per_frame * 1000 / strm->clock_rate; … … 1389 1391 * USER INTERFACE STUFFS 1390 1392 */ 1393 1394 static void call_get_duration(int call_index, pj_time_val *dur) 1395 { 1396 struct call *call = &app.call[call_index]; 1397 pjsip_inv_session *inv; 1398 1399 dur->sec = dur->msec = 0; 1400 1401 if (!call) 1402 return; 1403 1404 inv = call->inv; 1405 if (!inv) 1406 return; 1407 1408 if (inv->state >= PJSIP_INV_STATE_CONFIRMED && call->connect_time.sec) { 1409 1410 pj_gettimeofday(dur); 1411 PJ_TIME_VAL_SUB((*dur), call->connect_time); 1412 } 1413 } 1414 1415 1416 static const char *good_number(char *buf, pj_int32_t val) 1417 { 1418 if (val < 1000) { 1419 pj_ansi_sprintf(buf, "%d", val); 1420 } else if (val < 1000000) { 1421 pj_ansi_sprintf(buf, "%d.%02dK", 1422 val / 1000, 1423 (val % 1000) / 100); 1424 } else { 1425 pj_ansi_sprintf(buf, "%d.%02dM", 1426 val / 1000000, 1427 (val % 1000000) / 10000); 1428 } 1429 1430 return buf; 1431 } 1432 1433 1434 1435 static void print_avg_stat(void) 1436 { 1437 #define MIN_(var,val) if ((int)val < (int)var) var = val 1438 #define MAX_(var,val) if ((int)val > (int)var) var = val 1439 #define AVG_(var,val) var = ( ((var * count) + val) / (count+1) ) 1440 #define BIGVAL 0x7FFFFFFFL 1441 struct stat_entry 1442 { 1443 int min, avg, max; 1444 }; 1445 1446 struct stat_entry call_dur, call_pdd; 1447 pjmedia_rtcp_stat min_stat, avg_stat, max_stat; 1448 1449 char srx_min[16], srx_avg[16], srx_max[16]; 1450 char brx_min[16], brx_avg[16], brx_max[16]; 1451 char stx_min[16], stx_avg[16], stx_max[16]; 1452 char btx_min[16], btx_avg[16], btx_max[16]; 1453 1454 1455 unsigned i, count; 1456 1457 pj_bzero(&call_dur, sizeof(call_dur)); 1458 call_dur.min = BIGVAL; 1459 1460 pj_bzero(&call_pdd, sizeof(call_pdd)); 1461 call_pdd.min = BIGVAL; 1462 1463 pj_bzero(&min_stat, sizeof(min_stat)); 1464 min_stat.rx.pkt = min_stat.tx.pkt = BIGVAL; 1465 min_stat.rx.bytes = min_stat.tx.bytes = BIGVAL; 1466 min_stat.rx.loss = min_stat.tx.loss = BIGVAL; 1467 min_stat.rx.dup = min_stat.tx.dup = BIGVAL; 1468 min_stat.rx.reorder = min_stat.tx.reorder = BIGVAL; 1469 min_stat.rx.jitter.min = min_stat.tx.jitter.min = BIGVAL; 1470 min_stat.rtt.min = BIGVAL; 1471 1472 pj_bzero(&avg_stat, sizeof(avg_stat)); 1473 pj_bzero(&max_stat, sizeof(max_stat)); 1474 1475 1476 for (i=0, count=0; i<app.max_calls; ++i) { 1477 1478 struct call *call = &app.call[i]; 1479 struct media_stream *audio = &call->media[0]; 1480 pj_time_val dur; 1481 unsigned msec_dur; 1482 1483 if (call->inv == NULL || 1484 call->inv->state < PJSIP_INV_STATE_CONFIRMED || 1485 call->connect_time.sec == 0) 1486 { 1487 continue; 1488 } 1489 1490 /* Duration */ 1491 call_get_duration(i, &dur); 1492 msec_dur = PJ_TIME_VAL_MSEC(dur); 1493 1494 MIN_(call_dur.min, msec_dur); 1495 MAX_(call_dur.max, msec_dur); 1496 AVG_(call_dur.avg, msec_dur); 1497 1498 /* Connect delay */ 1499 if (call->connect_time.sec) { 1500 pj_time_val t = call->connect_time; 1501 PJ_TIME_VAL_SUB(t, call->start_time); 1502 msec_dur = PJ_TIME_VAL_MSEC(t); 1503 } else { 1504 msec_dur = 10; 1505 } 1506 1507 MIN_(call_pdd.min, msec_dur); 1508 MAX_(call_pdd.max, msec_dur); 1509 AVG_(call_pdd.avg, msec_dur); 1510 1511 /* RX Statistisc: */ 1512 1513 /* Packets */ 1514 MIN_(min_stat.rx.pkt, audio->rtcp.stat.rx.pkt); 1515 MAX_(max_stat.rx.pkt, audio->rtcp.stat.rx.pkt); 1516 AVG_(avg_stat.rx.pkt, audio->rtcp.stat.rx.pkt); 1517 1518 /* Bytes */ 1519 MIN_(min_stat.rx.bytes, audio->rtcp.stat.rx.bytes); 1520 MAX_(max_stat.rx.bytes, audio->rtcp.stat.rx.bytes); 1521 AVG_(avg_stat.rx.bytes, audio->rtcp.stat.rx.bytes); 1522 1523 1524 /* Packet loss */ 1525 MIN_(min_stat.rx.loss, audio->rtcp.stat.rx.loss); 1526 MAX_(max_stat.rx.loss, audio->rtcp.stat.rx.loss); 1527 AVG_(avg_stat.rx.loss, audio->rtcp.stat.rx.loss); 1528 1529 /* Packet dup */ 1530 MIN_(min_stat.rx.dup, audio->rtcp.stat.rx.dup); 1531 MAX_(max_stat.rx.dup, audio->rtcp.stat.rx.dup); 1532 AVG_(avg_stat.rx.dup, audio->rtcp.stat.rx.dup); 1533 1534 /* Packet reorder */ 1535 MIN_(min_stat.rx.reorder, audio->rtcp.stat.rx.reorder); 1536 MAX_(max_stat.rx.reorder, audio->rtcp.stat.rx.reorder); 1537 AVG_(avg_stat.rx.reorder, audio->rtcp.stat.rx.reorder); 1538 1539 /* Jitter */ 1540 MIN_(min_stat.rx.jitter.min, audio->rtcp.stat.rx.jitter.min); 1541 MAX_(max_stat.rx.jitter.max, audio->rtcp.stat.rx.jitter.max); 1542 AVG_(avg_stat.rx.jitter.avg, audio->rtcp.stat.rx.jitter.avg); 1543 1544 1545 /* TX Statistisc: */ 1546 1547 /* Packets */ 1548 MIN_(min_stat.tx.pkt, audio->rtcp.stat.tx.pkt); 1549 MAX_(max_stat.tx.pkt, audio->rtcp.stat.tx.pkt); 1550 AVG_(avg_stat.tx.pkt, audio->rtcp.stat.tx.pkt); 1551 1552 /* Bytes */ 1553 MIN_(min_stat.tx.bytes, audio->rtcp.stat.tx.bytes); 1554 MAX_(max_stat.tx.bytes, audio->rtcp.stat.tx.bytes); 1555 AVG_(avg_stat.tx.bytes, audio->rtcp.stat.tx.bytes); 1556 1557 /* Packet loss */ 1558 MIN_(min_stat.tx.loss, audio->rtcp.stat.tx.loss); 1559 MAX_(max_stat.tx.loss, audio->rtcp.stat.tx.loss); 1560 AVG_(avg_stat.tx.loss, audio->rtcp.stat.tx.loss); 1561 1562 /* Packet dup */ 1563 MIN_(min_stat.tx.dup, audio->rtcp.stat.tx.dup); 1564 MAX_(max_stat.tx.dup, audio->rtcp.stat.tx.dup); 1565 AVG_(avg_stat.tx.dup, audio->rtcp.stat.tx.dup); 1566 1567 /* Packet reorder */ 1568 MIN_(min_stat.tx.reorder, audio->rtcp.stat.tx.reorder); 1569 MAX_(max_stat.tx.reorder, audio->rtcp.stat.tx.reorder); 1570 AVG_(avg_stat.tx.reorder, audio->rtcp.stat.tx.reorder); 1571 1572 /* Jitter */ 1573 MIN_(min_stat.tx.jitter.min, audio->rtcp.stat.tx.jitter.min); 1574 MAX_(max_stat.tx.jitter.max, audio->rtcp.stat.tx.jitter.max); 1575 AVG_(avg_stat.tx.jitter.avg, audio->rtcp.stat.tx.jitter.avg); 1576 1577 1578 /* RTT */ 1579 MIN_(min_stat.rtt.min, audio->rtcp.stat.rtt.min); 1580 MAX_(max_stat.rtt.max, audio->rtcp.stat.rtt.max); 1581 AVG_(avg_stat.rtt.avg, audio->rtcp.stat.rtt.avg); 1582 1583 ++count; 1584 } 1585 1586 if (count == 0) { 1587 puts("No active calls"); 1588 return; 1589 } 1590 1591 printf("Total %d call(s) active.\n" 1592 " Average Statistics\n" 1593 " min avg max \n" 1594 " -----------------------\n" 1595 " call duration: %7d %7d %7d %s\n" 1596 " connect delay: %7d %7d %7d %s\n" 1597 " RX stat:\n" 1598 " packets: %7s %7s %7s %s\n" 1599 " payload: %7s %7s %7s %s\n" 1600 " loss: %7d %7d %7d %s\n" 1601 " percent loss: %7.3f %7.3f %7.3f %s\n" 1602 " dup: %7d %7d %7d %s\n" 1603 " reorder: %7d %7d %7d %s\n" 1604 " jitter: %7.3f %7.3f %7.3f %s\n" 1605 " TX stat:\n" 1606 " packets: %7s %7s %7s %s\n" 1607 " payload: %7s %7s %7s %s\n" 1608 " loss: %7d %7d %7d %s\n" 1609 " percent loss: %7.3f %7.3f %7.3f %s\n" 1610 " dup: %7d %7d %7d %s\n" 1611 " reorder: %7d %7d %7d %s\n" 1612 " jitter: %7.3f %7.3f %7.3f %s\n" 1613 " RTT : %7.3f %7.3f %7.3f %s\n" 1614 , 1615 count, 1616 call_dur.min/1000, call_dur.avg/1000, call_dur.max/1000, 1617 "seconds", 1618 1619 call_pdd.min, call_pdd.avg, call_pdd.max, 1620 "ms", 1621 1622 /* rx */ 1623 1624 good_number(srx_min, min_stat.rx.pkt), 1625 good_number(srx_avg, avg_stat.rx.pkt), 1626 good_number(srx_max, max_stat.rx.pkt), 1627 "packets", 1628 1629 good_number(brx_min, min_stat.rx.bytes), 1630 good_number(brx_avg, avg_stat.rx.bytes), 1631 good_number(brx_max, max_stat.rx.bytes), 1632 "bytes", 1633 1634 min_stat.rx.loss, avg_stat.rx.loss, max_stat.rx.loss, 1635 "packets", 1636 1637 min_stat.rx.loss*100.0/(min_stat.rx.pkt+min_stat.rx.loss), 1638 avg_stat.rx.loss*100.0/(avg_stat.rx.pkt+avg_stat.rx.loss), 1639 max_stat.rx.loss*100.0/(max_stat.rx.pkt+max_stat.rx.loss), 1640 "%", 1641 1642 1643 min_stat.rx.dup, avg_stat.rx.dup, max_stat.rx.dup, 1644 "packets", 1645 1646 min_stat.rx.reorder, avg_stat.rx.reorder, max_stat.rx.reorder, 1647 "packets", 1648 1649 min_stat.rx.jitter.min/1000.0, 1650 avg_stat.rx.jitter.avg/1000.0, 1651 max_stat.rx.jitter.max/1000.0, 1652 "ms", 1653 1654 /* tx */ 1655 1656 good_number(stx_min, min_stat.tx.pkt), 1657 good_number(stx_avg, avg_stat.tx.pkt), 1658 good_number(stx_max, max_stat.tx.pkt), 1659 "packets", 1660 1661 good_number(btx_min, min_stat.tx.bytes), 1662 good_number(btx_avg, avg_stat.tx.bytes), 1663 good_number(btx_max, max_stat.tx.bytes), 1664 "bytes", 1665 1666 min_stat.tx.loss, avg_stat.tx.loss, max_stat.tx.loss, 1667 "packets", 1668 1669 min_stat.rx.loss*100.0/(min_stat.rx.pkt+min_stat.rx.loss), 1670 avg_stat.rx.loss*100.0/(avg_stat.rx.pkt+avg_stat.rx.loss), 1671 max_stat.rx.loss*100.0/(max_stat.rx.pkt+max_stat.rx.loss), 1672 "%", 1673 1674 min_stat.tx.dup, avg_stat.tx.dup, max_stat.tx.dup, 1675 "packets", 1676 1677 min_stat.tx.reorder, avg_stat.tx.reorder, max_stat.tx.reorder, 1678 "packets", 1679 1680 min_stat.tx.jitter.min/1000.0, 1681 avg_stat.tx.jitter.avg/1000.0, 1682 max_stat.tx.jitter.max/1000.0, 1683 "ms", 1684 1685 /* rtt */ 1686 min_stat.rtt.min/1000.0, 1687 avg_stat.rtt.avg/1000.0, 1688 max_stat.rtt.max/1000.0, 1689 "ms" 1690 ); 1691 1692 } 1693 1694 1391 1695 #include "siprtp_report.c" 1392 1696 … … 1455 1759 "\n" 1456 1760 "Enter menu character:\n" 1761 " s Summary\n" 1457 1762 " l List all calls\n" 1458 1763 " h Hangup a call\n" … … 1475 1780 1476 1781 switch (input1[0]) { 1782 1783 case 's': 1784 print_avg_stat(); 1785 break; 1786 1477 1787 case 'l': 1478 1788 list_calls(); -
pjproject/trunk/pjsip-apps/src/samples/siprtp_report.c
r568 r621 26 26 * functionality (such as writing to XML file). 27 27 */ 28 29 static const char *good_number(char *buf, pj_int32_t val)30 {31 if (val < 1000) {32 pj_ansi_sprintf(buf, "%d", val);33 } else if (val < 1000000) {34 pj_ansi_sprintf(buf, "%d.%dK",35 val / 1000,36 (val % 1000) / 100);37 } else {38 pj_ansi_sprintf(buf, "%d.%02dM",39 val / 1000000,40 (val % 1000000) / 10000);41 }42 43 return buf;44 }45 28 46 29 … … 55 38 char duration[80], last_update[80]; 56 39 char bps[16], ipbps[16], packets[16], bytes[16], ipbytes[16]; 40 unsigned decor; 57 41 pj_time_val now; 42 43 44 decor = pj_log_get_decor(); 45 pj_log_set_decor(PJ_LOG_HAS_NEWLINE); 58 46 59 47 pj_gettimeofday(&now); … … 80 68 81 69 /* Call number and state */ 82 printf("Call #%d: %s%s\n", call_index, pjsip_inv_state_name(inv->state), 83 duration); 70 PJ_LOG(3, (THIS_FILE, 71 "Call #%d: %s%s", 72 call_index, pjsip_inv_state_name(inv->state), 73 duration)); 84 74 85 75 … … 92 82 userinfo[len] = '\0'; 93 83 94 printf(" %s\n", userinfo);84 PJ_LOG(3, (THIS_FILE, " %s", userinfo)); 95 85 96 86 … … 98 88 call->connect_time.sec == 0) 99 89 { 90 pj_log_set_decor(decor); 100 91 return; 101 92 } … … 124 115 } 125 116 126 printf(" Signaling quality: %s%s\n", pdd, connectdelay); 127 } 128 129 130 printf(" Stream #0: audio %.*s@%dHz, %dms/frame, %sB/s (%sB/s +IP hdr)\n", 117 PJ_LOG(3, (THIS_FILE, 118 " Signaling quality: %s%s", pdd, connectdelay)); 119 } 120 121 122 PJ_LOG(3, (THIS_FILE, 123 " Stream #0: audio %.*s@%dHz, %dms/frame, %sB/s (%sB/s +IP hdr)", 131 124 (int)audio->si.fmt.encoding_name.slen, 132 125 audio->si.fmt.encoding_name.ptr, … … 134 127 audio->samples_per_frame * 1000 / audio->clock_rate, 135 128 good_number(bps, audio->bytes_per_frame * audio->clock_rate / audio->samples_per_frame), 136 good_number(ipbps, (audio->bytes_per_frame+32) * audio->clock_rate / audio->samples_per_frame)) ;129 good_number(ipbps, (audio->bytes_per_frame+32) * audio->clock_rate / audio->samples_per_frame))); 137 130 138 131 if (audio->rtcp.stat.rx.update_cnt == 0) … … 148 141 } 149 142 150 printf(" RX stat last update: %s\n" 143 PJ_LOG(3, (THIS_FILE, 144 " RX stat last update: %s\n" 151 145 " total %s packets %sB received (%sB +IP hdr)%s\n" 152 146 " pkt loss=%d (%3.1f%%), dup=%d (%3.1f%%), reorder=%d (%3.1f%%)%s\n" 153 147 " (msec) min avg max last\n" 154 148 " loss period: %7.3f %7.3f %7.3f %7.3f%s\n" 155 " jitter : %7.3f %7.3f %7.3f %7.3f%s \n",149 " jitter : %7.3f %7.3f %7.3f %7.3f%s", 156 150 last_update, 157 151 good_number(packets, audio->rtcp.stat.rx.pkt), … … 176 170 audio->rtcp.stat.rx.jitter.last / 1000.0, 177 171 "" 178 ) ;172 )); 179 173 180 174 … … 191 185 } 192 186 193 printf(" TX stat last update: %s\n" 187 PJ_LOG(3, (THIS_FILE, 188 " TX stat last update: %s\n" 194 189 " total %s packets %sB sent (%sB +IP hdr)%s\n" 195 190 " pkt loss=%d (%3.1f%%), dup=%d (%3.1f%%), reorder=%d (%3.1f%%)%s\n" 196 191 " (msec) min avg max last\n" 197 192 " loss period: %7.3f %7.3f %7.3f %7.3f%s\n" 198 " jitter : %7.3f %7.3f %7.3f %7.3f%s \n",193 " jitter : %7.3f %7.3f %7.3f %7.3f%s", 199 194 last_update, 200 195 good_number(packets, audio->rtcp.stat.tx.pkt), … … 219 214 audio->rtcp.stat.tx.jitter.last / 1000.0, 220 215 "" 221 ); 222 223 224 printf(" RTT delay : %7.3f %7.3f %7.3f %7.3f%s\n", 216 )); 217 218 219 PJ_LOG(3, (THIS_FILE, 220 " RTT delay : %7.3f %7.3f %7.3f %7.3f%s\n", 225 221 audio->rtcp.stat.rtt.min / 1000.0, 226 222 audio->rtcp.stat.rtt.avg / 1000.0, … … 228 224 audio->rtcp.stat.rtt.last / 1000.0, 229 225 "" 230 ); 231 226 )); 227 228 pj_log_set_decor(decor); 232 229 } 233 230
Note: See TracChangeset
for help on using the changeset viewer.