Changeset 305


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)

Location:
pjproject/trunk/pjsip
Files:
4 edited

Legend:

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

    r300 r305  
    101101 
    102102    void                *app_data;  /**< Application data.                  */ 
     103    pj_timer_entry       refresh_tm;/**< Timer to send re-INVITE.           */ 
     104    pj_timer_entry       hangup_tm; /**< Timer to hangup call.              */ 
    103105}; 
    104106 
     
    197199    /* User Agent behaviour: */ 
    198200    int              auto_answer;   /**< Automatically answer in calls. */ 
     201    int              uas_refresh;   /**< Time to re-INVITE.             */ 
     202    int              uas_duration;  /**< Max call duration.             */ 
    199203 
    200204    /* Account: */ 
  • 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; 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c

    r293 r305  
    7070 
    7171 
     72    /* Default call settings. */ 
     73    pjsua.uas_refresh = -1; 
     74    pjsua.uas_duration = -1; 
     75 
    7276    /* Default: do not use STUN: */ 
    7377    pjsua.stun_port1 = pjsua.stun_port2 = 0; 
     
    9195 
    9296    /* Init call array: */ 
    93     for (i=0; i<PJ_ARRAY_SIZE(pjsua.calls); ++i) 
     97    for (i=0; i<PJ_ARRAY_SIZE(pjsua.calls); ++i) { 
    9498        pjsua.calls[i].index = i; 
     99        pjsua.calls[i].refresh_tm._timer_id = -1; 
     100        pjsua.calls[i].hangup_tm._timer_id = -1; 
     101    } 
    95102 
    96103    /* Default max nb of calls. */ 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_settings.c

    r300 r305  
    102102    puts  ("  --auto-answer=code  Automatically answer incoming calls with code (e.g. 200)"); 
    103103    puts  ("  --max-calls=N       Maximum number of concurrent calls (default:4, max:255)"); 
     104    puts  ("  --uas-refresh=N     Interval in UAS to send re-INVITE (default:-1)"); 
     105    puts  ("  --uas-duration=N    Maximum duration of incoming call (default:-1)"); 
    104106    puts  (""); 
    105107    fflush(stdout); 
     
    226228           OPT_PLAY_FILE, OPT_WB, OPT_UWB, OPT_RTP_PORT, OPT_ADD_CODEC, 
    227229           OPT_COMPLEXITY, OPT_QUALITY, 
    228            OPT_NEXT_ACCOUNT, OPT_NEXT_CRED, OPT_MAX_CALLS, 
     230           OPT_NEXT_ACCOUNT, OPT_NEXT_CRED, OPT_MAX_CALLS, OPT_UAS_REFRESH, 
     231           OPT_UAS_DURATION, 
    229232    }; 
    230233    struct pj_getopt_option long_options[] = { 
     
    266269        { "next-cred",  0, 0, OPT_NEXT_CRED}, 
    267270        { "max-calls",  1, 0, OPT_MAX_CALLS}, 
     271        { "uas-refresh",1, 0, OPT_UAS_REFRESH}, 
     272        { "uas-duration",1,0, OPT_UAS_DURATION}, 
    268273        { NULL, 0, 0, 0} 
    269274    }; 
     
    534539            if (pjsua.max_calls < 1 || pjsua.max_calls > 255) { 
    535540                PJ_LOG(1,(THIS_FILE,"Too many calls for max-calls (1-255)")); 
     541                return -1; 
     542            } 
     543            break; 
     544 
     545        case OPT_UAS_REFRESH: 
     546            pjsua.uas_refresh = my_atoi(pj_optarg); 
     547            if (pjsua.uas_refresh < 1) { 
     548                PJ_LOG(1,(THIS_FILE,"Invalid value for --uas-refresh (must be >0)")); 
     549                return -1; 
     550            } 
     551            break; 
     552 
     553        case OPT_UAS_DURATION: 
     554            pjsua.uas_duration = my_atoi(pj_optarg); 
     555            if (pjsua.uas_duration < 1) { 
     556                PJ_LOG(1,(THIS_FILE,"Invalid value for --uas-duration (must be >0)")); 
    536557                return -1; 
    537558            } 
     
    916937    pj_strcat2(&cfg, line); 
    917938 
     939    /* Uas-refresh. */ 
     940    if (pjsua.uas_refresh > 0) { 
     941        pj_ansi_sprintf(line, "--uas-refresh %d\n", 
     942                        pjsua.uas_refresh); 
     943        pj_strcat2(&cfg, line); 
     944    } 
     945 
     946    /* Uas-duration. */ 
     947    if (pjsua.uas_duration > 0) { 
     948        pj_ansi_sprintf(line, "--uas-duration %d\n", 
     949                        pjsua.uas_duration); 
     950        pj_strcat2(&cfg, line); 
     951    } 
    918952 
    919953    pj_strcat2(&cfg, "#\n# Buddies:\n#\n"); 
Note: See TracChangeset for help on using the changeset viewer.