Ignore:
Timestamp:
Mar 6, 2006 4:25:59 PM (18 years ago)
Author:
bennylp
Message:

Added --uas-duration and --uas-refresh option (the later is broken)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c

    r293 r305  
    2828 
    2929#define THIS_FILE   "pjsua_inv.c" 
     30 
     31 
     32#define REFRESH_CALL_TIMER      0x63 
     33#define HANGUP_CALL_TIMER       0x64 
     34 
     35/* Proto */ 
     36static void schedule_call_timer( pjsua_call *call, pj_timer_entry *e, 
     37                                 int timer_type, int duration ); 
     38 
     39/* 
     40 * Timer callback when UAS needs to send re-INVITE to see if remote 
     41 * is still there. 
     42 */ 
     43static void call_on_timer(pj_timer_heap_t *ht, pj_timer_entry *e) 
     44{ 
     45    pjsua_call *call = e->user_data; 
     46 
     47    PJ_UNUSED_ARG(ht); 
     48 
     49    if (e->id == REFRESH_CALL_TIMER) { 
     50 
     51        /* If call is still not connected, hangup. */ 
     52        if (call->inv->state != PJSIP_INV_STATE_CONFIRMED) { 
     53            PJ_LOG(3,(THIS_FILE, "Refresh call timer is called when " 
     54                      "invite is still not confirmed. Call %d will " 
     55                      "disconnect.", call->index)); 
     56            pjsua_call_hangup(call->index); 
     57        } else { 
     58            PJ_LOG(3,(THIS_FILE, "Refreshing call %d", call->index)); 
     59            schedule_call_timer(call,e,REFRESH_CALL_TIMER,pjsua.uas_refresh); 
     60            pjsua_call_reinvite(call->index); 
     61        } 
     62 
     63    } else if (e->id == HANGUP_CALL_TIMER) { 
     64        PJ_LOG(3,(THIS_FILE, "Call %d duration exceeded, disconnecting call", 
     65                             call->index)); 
     66        pjsua_call_hangup(call->index); 
     67 
     68    } 
     69} 
     70 
     71/* 
     72 * Schedule call timer. 
     73 */ 
     74static void schedule_call_timer( pjsua_call *call, pj_timer_entry *e, 
     75                                 int timer_type, int duration ) 
     76{ 
     77    pj_time_val timeout; 
     78 
     79    if (duration == 0) { 
     80        /* Cancel timer. */ 
     81        if (e->id != 0) { 
     82            pjsip_endpt_cancel_timer(pjsua.endpt, e); 
     83            e->id = 0; 
     84        } 
     85 
     86    } else { 
     87        /* Schedule timer. */ 
     88        timeout.sec = duration; 
     89        timeout.msec = 0; 
     90 
     91        e->cb = &call_on_timer; 
     92        e->id = timer_type; 
     93        e->user_data = call; 
     94 
     95        pjsip_endpt_schedule_timer( pjsua.endpt, e, &timeout); 
     96    } 
     97} 
    3098 
    3199 
     
    335403    ++pjsua.call_cnt; 
    336404 
     405    /* Schedule timer to refresh. */ 
     406    if (pjsua.uas_refresh > 0) { 
     407        schedule_call_timer( &pjsua.calls[call_index],  
     408                             &pjsua.calls[call_index].refresh_tm, 
     409                             REFRESH_CALL_TIMER, 
     410                             pjsua.uas_refresh); 
     411    } 
     412 
     413    /* Schedule timer to hangup call. */ 
     414    if (pjsua.uas_duration > 0) { 
     415        schedule_call_timer( &pjsua.calls[call_index],  
     416                             &pjsua.calls[call_index].hangup_tm, 
     417                             HANGUP_CALL_TIMER, 
     418                             pjsua.uas_duration); 
     419    } 
     420 
    337421    /* This INVITE request has been handled. */ 
    338422    return PJ_TRUE; 
     
    419503        } 
    420504 
     505        /* Remove timers. */ 
     506        schedule_call_timer(call, &call->refresh_tm, REFRESH_CALL_TIMER, 0); 
     507        schedule_call_timer(call, &call->hangup_tm, HANGUP_CALL_TIMER, 0); 
     508 
     509        /* Free call */ 
    421510        call->inv = NULL; 
    422511        --pjsua.call_cnt; 
Note: See TracChangeset for help on using the changeset viewer.