blob: adba64d681b89b815f266988331f294a5dbfaeaf [file] [log] [blame]
Benny Prijono16a6b0e2006-05-12 10:20:03 +00001/* $Id$ */
2/*
Benny Prijonoa771a512007-02-19 01:13:53 +00003 * Copyright (C) 2003-2007 Benny Prijono <benny@prijono.org>
Benny Prijono16a6b0e2006-05-12 10:20:03 +00004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20
21/*
22 * DO NOT COMPILE THIS FILE ON ITS OWN!
23 *
24 * This file is included by siprtp.c to implement the reporting capability
25 * to a separate file, so that user can implement different reporting
26 * functionality (such as writing to XML file).
27 */
28
Benny Prijono16a6b0e2006-05-12 10:20:03 +000029
30static void print_call(int call_index)
31{
32 struct call *call = &app.call[call_index];
33 int len;
34 pjsip_inv_session *inv = call->inv;
35 pjsip_dialog *dlg = inv->dlg;
36 struct media_stream *audio = &call->media[0];
37 char userinfo[128];
38 char duration[80], last_update[80];
39 char bps[16], ipbps[16], packets[16], bytes[16], ipbytes[16];
Benny Prijono258ece92006-07-22 12:53:04 +000040 unsigned decor;
Benny Prijono16a6b0e2006-05-12 10:20:03 +000041 pj_time_val now;
42
Benny Prijono258ece92006-07-22 12:53:04 +000043
44 decor = pj_log_get_decor();
45 pj_log_set_decor(PJ_LOG_HAS_NEWLINE);
46
Benny Prijono16a6b0e2006-05-12 10:20:03 +000047 pj_gettimeofday(&now);
48
Benny Prijonofcb36722006-05-18 18:34:21 +000049 if (app.report_filename)
50 puts(app.report_filename);
51
Benny Prijono16a6b0e2006-05-12 10:20:03 +000052 /* Print duration */
Benny Prijono65382db2006-05-14 18:50:09 +000053 if (inv->state >= PJSIP_INV_STATE_CONFIRMED && call->connect_time.sec) {
Benny Prijono16a6b0e2006-05-12 10:20:03 +000054
55 PJ_TIME_VAL_SUB(now, call->connect_time);
56
57 sprintf(duration, " [duration: %02ld:%02ld:%02ld.%03ld]",
58 now.sec / 3600,
59 (now.sec % 3600) / 60,
60 (now.sec % 60),
61 now.msec);
62
63 } else {
64 duration[0] = '\0';
65 }
66
67
68
69 /* Call number and state */
Benny Prijono258ece92006-07-22 12:53:04 +000070 PJ_LOG(3, (THIS_FILE,
71 "Call #%d: %s%s",
72 call_index, pjsip_inv_state_name(inv->state),
73 duration));
Benny Prijono16a6b0e2006-05-12 10:20:03 +000074
75
76
77 /* Call identification */
78 len = pjsip_hdr_print_on(dlg->remote.info, userinfo, sizeof(userinfo));
79 if (len < 1)
80 pj_ansi_strcpy(userinfo, "<--uri too long-->");
81 else
82 userinfo[len] = '\0';
83
Benny Prijono258ece92006-07-22 12:53:04 +000084 PJ_LOG(3, (THIS_FILE, " %s", userinfo));
Benny Prijono16a6b0e2006-05-12 10:20:03 +000085
86
87 if (call->inv == NULL || call->inv->state < PJSIP_INV_STATE_CONFIRMED ||
88 call->connect_time.sec == 0)
89 {
Benny Prijono258ece92006-07-22 12:53:04 +000090 pj_log_set_decor(decor);
Benny Prijono16a6b0e2006-05-12 10:20:03 +000091 return;
92 }
93
94
95 /* Signaling quality */
96 {
97 char pdd[64], connectdelay[64];
98 pj_time_val t;
99
100 if (call->response_time.sec) {
101 t = call->response_time;
102 PJ_TIME_VAL_SUB(t, call->start_time);
103 sprintf(pdd, "got 1st response in %ld ms", PJ_TIME_VAL_MSEC(t));
104 } else {
105 pdd[0] = '\0';
106 }
107
108 if (call->connect_time.sec) {
109 t = call->connect_time;
110 PJ_TIME_VAL_SUB(t, call->start_time);
111 sprintf(connectdelay, ", connected after: %ld ms",
112 PJ_TIME_VAL_MSEC(t));
113 } else {
114 connectdelay[0] = '\0';
115 }
116
Benny Prijono258ece92006-07-22 12:53:04 +0000117 PJ_LOG(3, (THIS_FILE,
118 " Signaling quality: %s%s", pdd, connectdelay));
Benny Prijono16a6b0e2006-05-12 10:20:03 +0000119 }
120
121
Benny Prijono258ece92006-07-22 12:53:04 +0000122 PJ_LOG(3, (THIS_FILE,
123 " Stream #0: audio %.*s@%dHz, %dms/frame, %sB/s (%sB/s +IP hdr)",
Benny Prijono16a6b0e2006-05-12 10:20:03 +0000124 (int)audio->si.fmt.encoding_name.slen,
125 audio->si.fmt.encoding_name.ptr,
126 audio->clock_rate,
127 audio->samples_per_frame * 1000 / audio->clock_rate,
128 good_number(bps, audio->bytes_per_frame * audio->clock_rate / audio->samples_per_frame),
Benny Prijono258ece92006-07-22 12:53:04 +0000129 good_number(ipbps, (audio->bytes_per_frame+32) * audio->clock_rate / audio->samples_per_frame)));
Benny Prijono16a6b0e2006-05-12 10:20:03 +0000130
131 if (audio->rtcp.stat.rx.update_cnt == 0)
132 strcpy(last_update, "never");
133 else {
134 pj_gettimeofday(&now);
135 PJ_TIME_VAL_SUB(now, audio->rtcp.stat.rx.update);
136 sprintf(last_update, "%02ldh:%02ldm:%02ld.%03lds ago",
137 now.sec / 3600,
138 (now.sec % 3600) / 60,
139 now.sec % 60,
140 now.msec);
141 }
142
Benny Prijono258ece92006-07-22 12:53:04 +0000143 PJ_LOG(3, (THIS_FILE,
144 " RX stat last update: %s\n"
Benny Prijono16a6b0e2006-05-12 10:20:03 +0000145 " total %s packets %sB received (%sB +IP hdr)%s\n"
146 " pkt loss=%d (%3.1f%%), dup=%d (%3.1f%%), reorder=%d (%3.1f%%)%s\n"
147 " (msec) min avg max last\n"
148 " loss period: %7.3f %7.3f %7.3f %7.3f%s\n"
Benny Prijono258ece92006-07-22 12:53:04 +0000149 " jitter : %7.3f %7.3f %7.3f %7.3f%s",
Benny Prijono16a6b0e2006-05-12 10:20:03 +0000150 last_update,
151 good_number(packets, audio->rtcp.stat.rx.pkt),
152 good_number(bytes, audio->rtcp.stat.rx.bytes),
153 good_number(ipbytes, audio->rtcp.stat.rx.bytes + audio->rtcp.stat.rx.pkt * 32),
154 "",
155 audio->rtcp.stat.rx.loss,
Benny Prijonof9016512006-06-29 09:41:34 +0000156 audio->rtcp.stat.rx.loss * 100.0 / (audio->rtcp.stat.rx.pkt + audio->rtcp.stat.rx.loss),
Benny Prijono16a6b0e2006-05-12 10:20:03 +0000157 audio->rtcp.stat.rx.dup,
Benny Prijonob12106f2006-06-29 14:45:17 +0000158 audio->rtcp.stat.rx.dup * 100.0 / (audio->rtcp.stat.rx.pkt + audio->rtcp.stat.rx.loss),
Benny Prijono16a6b0e2006-05-12 10:20:03 +0000159 audio->rtcp.stat.rx.reorder,
Benny Prijonob12106f2006-06-29 14:45:17 +0000160 audio->rtcp.stat.rx.reorder * 100.0 / (audio->rtcp.stat.rx.pkt + audio->rtcp.stat.rx.loss),
Benny Prijono16a6b0e2006-05-12 10:20:03 +0000161 "",
162 audio->rtcp.stat.rx.loss_period.min / 1000.0,
163 audio->rtcp.stat.rx.loss_period.avg / 1000.0,
164 audio->rtcp.stat.rx.loss_period.max / 1000.0,
165 audio->rtcp.stat.rx.loss_period.last / 1000.0,
166 "",
167 audio->rtcp.stat.rx.jitter.min / 1000.0,
168 audio->rtcp.stat.rx.jitter.avg / 1000.0,
169 audio->rtcp.stat.rx.jitter.max / 1000.0,
170 audio->rtcp.stat.rx.jitter.last / 1000.0,
171 ""
Benny Prijono258ece92006-07-22 12:53:04 +0000172 ));
Benny Prijono16a6b0e2006-05-12 10:20:03 +0000173
174
175 if (audio->rtcp.stat.tx.update_cnt == 0)
176 strcpy(last_update, "never");
177 else {
178 pj_gettimeofday(&now);
179 PJ_TIME_VAL_SUB(now, audio->rtcp.stat.tx.update);
180 sprintf(last_update, "%02ldh:%02ldm:%02ld.%03lds ago",
181 now.sec / 3600,
182 (now.sec % 3600) / 60,
183 now.sec % 60,
184 now.msec);
185 }
186
Benny Prijono258ece92006-07-22 12:53:04 +0000187 PJ_LOG(3, (THIS_FILE,
188 " TX stat last update: %s\n"
Benny Prijono16a6b0e2006-05-12 10:20:03 +0000189 " total %s packets %sB sent (%sB +IP hdr)%s\n"
190 " pkt loss=%d (%3.1f%%), dup=%d (%3.1f%%), reorder=%d (%3.1f%%)%s\n"
191 " (msec) min avg max last\n"
192 " loss period: %7.3f %7.3f %7.3f %7.3f%s\n"
Benny Prijono258ece92006-07-22 12:53:04 +0000193 " jitter : %7.3f %7.3f %7.3f %7.3f%s",
Benny Prijono16a6b0e2006-05-12 10:20:03 +0000194 last_update,
195 good_number(packets, audio->rtcp.stat.tx.pkt),
196 good_number(bytes, audio->rtcp.stat.tx.bytes),
197 good_number(ipbytes, audio->rtcp.stat.tx.bytes + audio->rtcp.stat.tx.pkt * 32),
198 "",
199 audio->rtcp.stat.tx.loss,
Benny Prijonof9016512006-06-29 09:41:34 +0000200 audio->rtcp.stat.tx.loss * 100.0 / (audio->rtcp.stat.tx.pkt + audio->rtcp.stat.tx.loss),
Benny Prijono16a6b0e2006-05-12 10:20:03 +0000201 audio->rtcp.stat.tx.dup,
Benny Prijonob12106f2006-06-29 14:45:17 +0000202 audio->rtcp.stat.tx.dup * 100.0 / (audio->rtcp.stat.tx.pkt + audio->rtcp.stat.tx.loss),
Benny Prijono16a6b0e2006-05-12 10:20:03 +0000203 audio->rtcp.stat.tx.reorder,
Benny Prijonob12106f2006-06-29 14:45:17 +0000204 audio->rtcp.stat.tx.reorder * 100.0 / (audio->rtcp.stat.tx.pkt + audio->rtcp.stat.tx.loss),
Benny Prijono16a6b0e2006-05-12 10:20:03 +0000205 "",
206 audio->rtcp.stat.tx.loss_period.min / 1000.0,
207 audio->rtcp.stat.tx.loss_period.avg / 1000.0,
208 audio->rtcp.stat.tx.loss_period.max / 1000.0,
209 audio->rtcp.stat.tx.loss_period.last / 1000.0,
210 "",
211 audio->rtcp.stat.tx.jitter.min / 1000.0,
212 audio->rtcp.stat.tx.jitter.avg / 1000.0,
213 audio->rtcp.stat.tx.jitter.max / 1000.0,
214 audio->rtcp.stat.tx.jitter.last / 1000.0,
215 ""
Benny Prijono258ece92006-07-22 12:53:04 +0000216 ));
Benny Prijono16a6b0e2006-05-12 10:20:03 +0000217
218
Benny Prijono258ece92006-07-22 12:53:04 +0000219 PJ_LOG(3, (THIS_FILE,
220 " RTT delay : %7.3f %7.3f %7.3f %7.3f%s\n",
Benny Prijono16a6b0e2006-05-12 10:20:03 +0000221 audio->rtcp.stat.rtt.min / 1000.0,
222 audio->rtcp.stat.rtt.avg / 1000.0,
223 audio->rtcp.stat.rtt.max / 1000.0,
224 audio->rtcp.stat.rtt.last / 1000.0,
225 ""
Benny Prijono258ece92006-07-22 12:53:04 +0000226 ));
Benny Prijono16a6b0e2006-05-12 10:20:03 +0000227
Benny Prijono258ece92006-07-22 12:53:04 +0000228 pj_log_set_decor(decor);
Benny Prijono16a6b0e2006-05-12 10:20:03 +0000229}
230