summaryrefslogtreecommitdiff
path: root/pjsip
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2006-04-09 16:46:05 +0000
committerBenny Prijono <bennylp@teluu.com>2006-04-09 16:46:05 +0000
commit7c33ce56e9b9399e0f437553102d9a4d612502f7 (patch)
treee783ecf01cb824448a6d9fbf8dc0bef7eee53f78 /pjsip
parent3cbe17249a51ff90ecb1eac049d2d655229bb6c9 (diff)
Added call duration in pjsua
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@398 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip')
-rw-r--r--pjsip/include/pjsua-lib/pjsua.h4
-rw-r--r--pjsip/src/pjsua-lib/pjsua_call.c32
-rw-r--r--pjsip/src/pjsua-lib/pjsua_settings.c43
3 files changed, 72 insertions, 7 deletions
diff --git a/pjsip/include/pjsua-lib/pjsua.h b/pjsip/include/pjsua-lib/pjsua.h
index d5f447ae..dc179cb3 100644
--- a/pjsip/include/pjsua-lib/pjsua.h
+++ b/pjsip/include/pjsua-lib/pjsua.h
@@ -92,6 +92,10 @@ struct pjsua_call
{
unsigned index; /**< Index in pjsua array. */
pjsip_inv_session *inv; /**< The invite session. */
+ pj_time_val start_time;/**< First INVITE sent/received. */
+ pj_time_val res_time; /**< First response sent/received. */
+ pj_time_val conn_time; /**< Connected/confirmed time. */
+ pj_time_val dis_time; /**< Disconnect time. */
int acc_index; /**< Account index being used. */
pjmedia_session *session; /**< The media session. */
unsigned conf_slot; /**< Slot # in conference bridge. */
diff --git a/pjsip/src/pjsua-lib/pjsua_call.c b/pjsip/src/pjsua-lib/pjsua_call.c
index 55976880..b5e32780 100644
--- a/pjsip/src/pjsua-lib/pjsua_call.c
+++ b/pjsip/src/pjsua-lib/pjsua_call.c
@@ -192,8 +192,13 @@ pj_status_t pjsua_make_call(int acc_index,
return PJ_ETOOMANY;
}
- /* Create outgoing dialog: */
+ /* Mark call start time. */
+ pj_gettimeofday(&pjsua.calls[call_index].start_time);
+
+ /* Reset first response time */
+ pjsua.calls[call_index].res_time.sec = 0;
+ /* Create outgoing dialog: */
status = pjsip_dlg_create_uac( pjsip_ua_instance(),
&pjsua.acc[acc_index].local_uri,
&pjsua.acc[acc_index].contact_uri,
@@ -358,6 +363,11 @@ pj_bool_t pjsua_call_on_incoming(pjsip_rx_data *rdata)
return PJ_TRUE;
}
+ /* Mark call start time. */
+ pj_gettimeofday(&pjsua.calls[call_index].start_time);
+
+ /* Reset first response time */
+ pjsua.calls[call_index].res_time.sec = 0;
/* Get media capability from media endpoint: */
@@ -497,10 +507,28 @@ static void pjsua_call_on_state_changed(pjsip_inv_session *inv,
{
pjsua_call *call = inv->dlg->mod_data[pjsua.mod.id];
+ if (!call)
+ return;
+
+ /* Get call times */
+ switch (inv->state) {
+ case PJSIP_INV_STATE_EARLY:
+ case PJSIP_INV_STATE_CONNECTING:
+ if (call->res_time.sec == 0)
+ pj_gettimeofday(&call->res_time);
+ break;
+ case PJSIP_INV_STATE_CONFIRMED:
+ pj_gettimeofday(&call->conn_time);
+ break;
+ case PJSIP_INV_STATE_DISCONNECTED:
+ pj_gettimeofday(&call->dis_time);
+ break;
+ }
+
/* If this is an outgoing INVITE that was created because of
* REFER/transfer, send NOTIFY to transferer.
*/
- if (call && call->xfer_sub && e->type==PJSIP_EVENT_TSX_STATE) {
+ if (call->xfer_sub && e->type==PJSIP_EVENT_TSX_STATE) {
int st_code = -1;
pjsip_evsub_state ev_state = PJSIP_EVSUB_STATE_ACTIVE;
diff --git a/pjsip/src/pjsua-lib/pjsua_settings.c b/pjsip/src/pjsua-lib/pjsua_settings.c
index 334413b6..4a02ca11 100644
--- a/pjsip/src/pjsua-lib/pjsua_settings.c
+++ b/pjsip/src/pjsua-lib/pjsua_settings.c
@@ -693,7 +693,7 @@ static void dump_media_session(pjmedia_session *session)
PJ_LOG(3,(THIS_FILE,
" RX pt=%d, stat last update: %s\n"
- " total %s packets %sB received (%sB +IP hdr)%s\n"
+ " total %spkt %sB (%sB +IP hdr)%s\n"
" pkt loss=%d (%3.1f%%), dup=%d (%3.1f%%), reorder=%d (%3.1f%%)%s\n"
" (msec) min avg max last\n"
" loss period: %7.3f %7.3f %7.3f %7.3f%s\n"
@@ -738,7 +738,7 @@ static void dump_media_session(pjmedia_session *session)
PJ_LOG(3,(THIS_FILE,
" TX pt=%d, stat last update: %s\n"
- " total %s packets %sB received (%sB +IP hdr)%s\n"
+ " total %spkt %sB (%sB +IP hdr)%s\n"
" pkt loss=%d (%3.1f%%), dup=%d (%3.1f%%), reorder=%d (%3.1f%%)%s\n"
" (msec) min avg max last\n"
" loss period: %7.3f %7.3f %7.3f %7.3f%s\n"
@@ -815,14 +815,47 @@ void pjsua_dump(pj_bool_t detail)
for (i=0; i<pjsua.max_calls; ++i) {
- if (pjsua.calls[i].inv == NULL)
+ pjsua_call *call = &pjsua.calls[i];
+ pj_time_val duration, res_delay, con_delay;
+
+ if (call->inv == NULL)
continue;
print_call(" ", i, buf, sizeof(buf));
PJ_LOG(3,(THIS_FILE, "%s", buf));
- if (pjsua.calls[i].session)
- dump_media_session(pjsua.calls[i].session);
+ /* Calculate call duration */
+ if (call->inv->state >= PJSIP_INV_STATE_CONFIRMED) {
+ pj_gettimeofday(&duration);
+ PJ_TIME_VAL_SUB(duration, call->conn_time);
+ con_delay = call->conn_time;
+ PJ_TIME_VAL_SUB(con_delay, call->start_time);
+ } else {
+ duration.sec = duration.msec = 0;
+ con_delay.sec = con_delay.msec = 0;
+ }
+
+ /* Calculate first response delay */
+ if (call->inv->state >= PJSIP_INV_STATE_EARLY) {
+ res_delay = call->res_time;
+ PJ_TIME_VAL_SUB(res_delay, call->start_time);
+ } else {
+ res_delay.sec = res_delay.msec = 0;
+ }
+
+ /* Print duration */
+ PJ_LOG(3,(THIS_FILE,
+ " Call time: %02dh:%02dm:%02ds, "
+ "1st res in %d ms, conn in %dms",
+ (duration.sec / 3600),
+ ((duration.sec % 3600)/60),
+ (duration.sec % 60),
+ PJ_TIME_VAL_MSEC(res_delay),
+ PJ_TIME_VAL_MSEC(con_delay)));
+
+ /* Dump session statistics */
+ if (call->session)
+ dump_media_session(call->session);
}
}