comparison pcap/rtp-cont-check.c @ 172:693a0958a303

yet another refactoring of RTP tools: the program that prints each time delta is now rtp-jitter-view, whereas rtp-cont-check now reports min and max instead.
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 26 Dec 2022 22:42:41 +0000
parents 75607bc26f57
children 10f11a2d4042
comparison
equal deleted inserted replaced
171:75607bc26f57 172:693a0958a303
2 * This program reads a pcap file, extracts packets belonging to a 2 * This program reads a pcap file, extracts packets belonging to a
3 * particular RTP stream as identified by a source or destination 3 * particular RTP stream as identified by a source or destination
4 * IP:port, and checks its continuity: verifies that the sequence 4 * IP:port, and checks its continuity: verifies that the sequence
5 * number always increments by 1 and that the timestamp always 5 * number always increments by 1 and that the timestamp always
6 * increments by 160 units. Finally, this program prints out 6 * increments by 160 units. Finally, this program prints out
7 * the Rx time delta of each stream packet (the capture time of 7 * the minimum and maximum observed capture time deltas between
8 * the current packet minus the capture time of the previous packet) 8 * successive packets of the stream.
9 * on stdout, allowing visual timing analysis.
10 * 9 *
11 * The codec can be anything, and this program can also be used to 10 * The codec can be anything, and this program can also be used to
12 * check continuity of RTP streams coming from PSTN/SIP, but the 11 * check continuity of RTP streams coming from PSTN/SIP, but the
13 * core assumption is that packets must arrive every 20 ms, with 12 * core assumption is that packets must arrive every 20 ms, with
14 * the timestamp field incrementing by 160 units each time. 13 * the timestamp field incrementing by 160 units each time.
28 static pcap_t *pcap; 27 static pcap_t *pcap;
29 static in_addr_t match_ip_addr; 28 static in_addr_t match_ip_addr;
30 static u_short match_udp_port; 29 static u_short match_udp_port;
31 static unsigned iphdr_addr_offset, udphdr_port_offset; 30 static unsigned iphdr_addr_offset, udphdr_port_offset;
32 static unsigned link_hdr_len, ethertype_offset; 31 static unsigned link_hdr_len, ethertype_offset;
33 static int stream_init_flag; 32 static int stream_init_flag, deltat_init_flag;
34 static unsigned last_seq, last_tstamp, stream_ssrc; 33 static unsigned last_seq, last_tstamp, stream_ssrc;
35 static struct timeval last_pkt_time; 34 static struct timeval last_pkt_time;
35 static unsigned deltat_min, deltat_max;
36 36
37 static void 37 static void
38 check_dl_type() 38 check_dl_type()
39 { 39 {
40 int dltype; 40 int dltype;
103 fprintf(stderr, 103 fprintf(stderr,
104 "packet #%u timing error: Rx time gap >= 1 s\n", 104 "packet #%u timing error: Rx time gap >= 1 s\n",
105 pkt_idx); 105 pkt_idx);
106 exit(1); 106 exit(1);
107 } 107 }
108 printf("Packet #%u: time delta %u us\n", pkt_idx, 108 if (deltat_init_flag) {
109 (unsigned) deltat.tv_usec); 109 if (deltat.tv_usec < deltat_min)
110 deltat_min = deltat.tv_usec;
111 if (deltat.tv_usec > deltat_max)
112 deltat_max = deltat.tv_usec;
113 } else {
114 deltat_min = deltat.tv_usec;
115 deltat_max = deltat.tv_usec;
116 deltat_init_flag = 1;
117 }
110 } else { 118 } else {
111 stream_init_flag = 1; 119 stream_init_flag = 1;
112 stream_ssrc = cur_ssrc; 120 stream_ssrc = cur_ssrc;
113 } 121 }
114 last_seq = cur_seq; 122 last_seq = cur_seq;
213 } 221 }
214 if (!stream_init_flag) { 222 if (!stream_init_flag) {
215 fprintf(stderr, "error: specified RTP stream not found\n"); 223 fprintf(stderr, "error: specified RTP stream not found\n");
216 exit(1); 224 exit(1);
217 } 225 }
226 if (!deltat_init_flag) {
227 fprintf(stderr, "error: found only one matching packet\n");
228 exit(1);
229 }
230 printf("Minimum time delta: %u us\n", deltat_min);
231 printf("Maximum time delta: %u us\n", deltat_max);
218 exit(0); 232 exit(0);
219 } 233 }