FreeCalypso > hg > rtp-debug-utils
changeset 13:d59dbdfe1778
rtp-stream-dump: compute and print time-of-arrival delta (toad)
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 27 Jul 2024 23:39:50 +0000 |
parents | b5e73d5ebcd1 |
children | e7f43262efa1 |
files | pcap-study/rtp-stream-dump.c |
diffstat | 1 files changed, 23 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/pcap-study/rtp-stream-dump.c Wed May 15 02:50:50 2024 +0000 +++ b/pcap-study/rtp-stream-dump.c Sat Jul 27 23:39:50 2024 +0000 @@ -22,8 +22,9 @@ static u_short match_udp_port; static unsigned iphdr_addr_offset, udphdr_port_offset; static unsigned link_hdr_len, ethertype_offset; -static int stream_init_flag; +static int stream_init_flag, toad_init_flag; static unsigned last_seq, last_tstamp, stream_ssrc; +static struct timeval last_pkt_time; static void check_dl_type() @@ -85,11 +86,14 @@ } static void -process_packet(pkt, caplen, pkt_idx) +process_packet(pkt, caplen, pkt_idx, pkt_time) u_char *pkt; unsigned caplen, pkt_idx; + struct timeval *pkt_time; { unsigned udplen, payload_len; + struct timeval toad; + unsigned toad_ms, toad_us; if (caplen < link_hdr_len + 28) return; @@ -132,9 +136,23 @@ exit(1); } rtp_stream_logic(pkt + 28, pkt_idx); - printf("pkt #%u seq 0x%04X ts 0x%08X: pt=%u M=%u len=%u\n", pkt_idx, + printf("pkt #%u seq 0x%04X ts 0x%08X: pt=%u M=%u len=%u", pkt_idx, last_seq, last_tstamp, pkt[29] & 0x7F, pkt[29] >> 7, udplen - 20); + if (toad_init_flag && timercmp(pkt_time, &last_pkt_time, >=)) { + timersub(pkt_time, &last_pkt_time, &toad); + if (toad.tv_sec) + printf(", toad %u.%06u s", (unsigned) toad.tv_sec, + (unsigned) toad.tv_usec); + else { + toad_ms = toad.tv_usec / 1000; + toad_us = toad.tv_usec % 1000; + printf(", toad %u.%03u ms", toad_ms, toad_us); + } + } + putchar('\n'); + bcopy(pkt_time, &last_pkt_time, sizeof(struct timeval)); + toad_init_flag = 1; } main(argc, argv) @@ -178,7 +196,8 @@ pkt = pcap_next(pcap, &pkthdr); if (!pkt) break; - process_packet(pkt, (unsigned) pkthdr.caplen, pkt_idx); + process_packet(pkt, (unsigned) pkthdr.caplen, pkt_idx, + &pkthdr.ts); } if (!stream_init_flag) { fprintf(stderr, "error: specified RTP stream not found\n");