Changeset 398


Ignore:
Timestamp:
Apr 9, 2006 4:46:05 PM (18 years ago)
Author:
bennylp
Message:

Added call duration in pjsua

Location:
pjproject/trunk/pjsip
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h

    r350 r398  
    9393    unsigned             index;     /**< Index in pjsua array.              */ 
    9494    pjsip_inv_session   *inv;       /**< The invite session.                */ 
     95    pj_time_val          start_time;/**< First INVITE sent/received.        */ 
     96    pj_time_val          res_time;  /**< First response sent/received.      */ 
     97    pj_time_val          conn_time; /**< Connected/confirmed time.          */ 
     98    pj_time_val          dis_time;  /**< Disconnect time.                   */ 
    9599    int                  acc_index; /**< Account index being used.          */ 
    96100    pjmedia_session     *session;   /**< The media session.                 */ 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c

    r376 r398  
    193193    } 
    194194 
     195    /* Mark call start time. */ 
     196    pj_gettimeofday(&pjsua.calls[call_index].start_time); 
     197 
     198    /* Reset first response time */ 
     199    pjsua.calls[call_index].res_time.sec = 0; 
     200 
    195201    /* Create outgoing dialog: */ 
    196  
    197202    status = pjsip_dlg_create_uac( pjsip_ua_instance(),  
    198203                                   &pjsua.acc[acc_index].local_uri, 
     
    359364    } 
    360365 
     366    /* Mark call start time. */ 
     367    pj_gettimeofday(&pjsua.calls[call_index].start_time); 
     368 
     369    /* Reset first response time */ 
     370    pjsua.calls[call_index].res_time.sec = 0; 
    361371 
    362372    /* Get media capability from media endpoint: */ 
     
    498508    pjsua_call *call = inv->dlg->mod_data[pjsua.mod.id]; 
    499509 
     510    if (!call) 
     511        return; 
     512 
     513    /* Get call times */ 
     514    switch (inv->state) { 
     515        case PJSIP_INV_STATE_EARLY: 
     516        case PJSIP_INV_STATE_CONNECTING: 
     517            if (call->res_time.sec == 0) 
     518                pj_gettimeofday(&call->res_time); 
     519            break; 
     520        case PJSIP_INV_STATE_CONFIRMED: 
     521            pj_gettimeofday(&call->conn_time); 
     522            break; 
     523        case PJSIP_INV_STATE_DISCONNECTED: 
     524            pj_gettimeofday(&call->dis_time); 
     525            break; 
     526    } 
     527 
    500528    /* If this is an outgoing INVITE that was created because of 
    501529     * REFER/transfer, send NOTIFY to transferer. 
    502530     */ 
    503     if (call && call->xfer_sub && e->type==PJSIP_EVENT_TSX_STATE)  { 
     531    if (call->xfer_sub && e->type==PJSIP_EVENT_TSX_STATE)  { 
    504532        int st_code = -1; 
    505533        pjsip_evsub_state ev_state = PJSIP_EVSUB_STATE_ACTIVE; 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_settings.c

    r393 r398  
    694694        PJ_LOG(3,(THIS_FILE,  
    695695               "                  RX pt=%d, stat last update: %s\n" 
    696                "                     total %s packets %sB received (%sB +IP hdr)%s\n" 
     696               "                     total %spkt %sB (%sB +IP hdr)%s\n" 
    697697               "                     pkt loss=%d (%3.1f%%), dup=%d (%3.1f%%), reorder=%d (%3.1f%%)%s\n" 
    698698               "                           (msec)    min     avg     max     last\n" 
     
    739739        PJ_LOG(3,(THIS_FILE, 
    740740               "                  TX pt=%d, stat last update: %s\n" 
    741                "                     total %s packets %sB received (%sB +IP hdr)%s\n" 
     741               "                     total %spkt %sB (%sB +IP hdr)%s\n" 
    742742               "                     pkt loss=%d (%3.1f%%), dup=%d (%3.1f%%), reorder=%d (%3.1f%%)%s\n" 
    743743               "                           (msec)    min     avg     max     last\n" 
     
    816816        for (i=0; i<pjsua.max_calls; ++i) { 
    817817 
    818             if (pjsua.calls[i].inv == NULL) 
     818            pjsua_call *call = &pjsua.calls[i]; 
     819            pj_time_val duration, res_delay, con_delay; 
     820 
     821            if (call->inv == NULL) 
    819822                continue; 
    820823 
     
    822825            PJ_LOG(3,(THIS_FILE, "%s", buf)); 
    823826 
    824             if (pjsua.calls[i].session) 
    825                 dump_media_session(pjsua.calls[i].session); 
     827            /* Calculate call duration */ 
     828            if (call->inv->state >= PJSIP_INV_STATE_CONFIRMED) { 
     829                pj_gettimeofday(&duration); 
     830                PJ_TIME_VAL_SUB(duration, call->conn_time); 
     831                con_delay = call->conn_time; 
     832                PJ_TIME_VAL_SUB(con_delay, call->start_time); 
     833            } else { 
     834                duration.sec = duration.msec = 0; 
     835                con_delay.sec = con_delay.msec = 0; 
     836            } 
     837 
     838            /* Calculate first response delay */ 
     839            if (call->inv->state >= PJSIP_INV_STATE_EARLY) { 
     840                res_delay = call->res_time; 
     841                PJ_TIME_VAL_SUB(res_delay, call->start_time); 
     842            } else { 
     843                res_delay.sec = res_delay.msec = 0; 
     844            } 
     845 
     846            /* Print duration */ 
     847            PJ_LOG(3,(THIS_FILE,  
     848                      "               Call time: %02dh:%02dm:%02ds, " 
     849                      "1st res in %d ms, conn in %dms", 
     850                      (duration.sec / 3600), 
     851                      ((duration.sec % 3600)/60), 
     852                      (duration.sec % 60), 
     853                      PJ_TIME_VAL_MSEC(res_delay),  
     854                      PJ_TIME_VAL_MSEC(con_delay))); 
     855 
     856            /* Dump session statistics */ 
     857            if (call->session) 
     858                dump_media_session(call->session); 
    826859        } 
    827860    } 
Note: See TracChangeset for help on using the changeset viewer.