Ignore:
Timestamp:
Jan 9, 2012 11:51:56 AM (9 years ago)
Author:
ming
Message:

Fixes #1442: Unable to make call if disabled media is included

Add an API pjsua_schedule_timer2() to allow application to schedule a callback function to be executed after a specified time interval. This enables app to post a delayed job which, in this case, allows the initialization of all media transport creations to finish first before we get the media transport creations result.

File:
1 edited

Legend:

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

    r3891 r3938  
    713713    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
    714714 
     715    /* Init timer entry list */ 
     716    pj_list_init(&pjsua_var.timer_list); 
     717 
     718    /* Create timer mutex */ 
     719    status = pj_mutex_create_recursive(pjsua_var.pool, "pjsua_timer",  
     720                                       &pjsua_var.timer_mutex); 
     721    if (status != PJ_SUCCESS) { 
     722        pj_log_pop_indent(); 
     723        pjsua_perror(THIS_FILE, "Unable to create mutex", status); 
     724        return status; 
     725    } 
     726 
    715727    pjsua_set_state(PJSUA_STATE_CREATED); 
    716728    pj_log_pop_indent(); 
     
    26042616} 
    26052617 
     2618/* Timer callback */ 
     2619static void timer_cb( pj_timer_heap_t *th, 
     2620                      pj_timer_entry *entry) 
     2621{ 
     2622    struct timer_list *tmr = (struct timer_list *)entry->user_data; 
     2623    void (*cb)(void *user_data) = tmr->cb; 
     2624    void *user_data = tmr->user_data; 
     2625 
     2626    PJ_UNUSED_ARG(th); 
     2627 
     2628    pj_mutex_lock(pjsua_var.timer_mutex); 
     2629    pj_list_push_back(&pjsua_var.timer_list, tmr); 
     2630    pj_mutex_unlock(pjsua_var.timer_mutex); 
     2631 
     2632    if (cb) 
     2633        (*cb)(user_data); 
     2634} 
     2635 
     2636/* 
     2637 * Schedule a timer callback.  
     2638 */ 
     2639PJ_DEF(pj_status_t) pjsua_schedule_timer2( void (*cb)(void *user_data), 
     2640                                           void *user_data, 
     2641                                           unsigned msec_delay) 
     2642{ 
     2643    struct timer_list *tmr = NULL; 
     2644    pj_status_t status; 
     2645    pj_time_val delay; 
     2646 
     2647    pj_mutex_lock(pjsua_var.timer_mutex); 
     2648 
     2649    if (pj_list_empty(&pjsua_var.timer_list)) { 
     2650        tmr = PJ_POOL_ALLOC_T(pjsua_var.pool, struct timer_list); 
     2651    } else { 
     2652        tmr = pjsua_var.timer_list.next; 
     2653        pj_list_erase(tmr); 
     2654    } 
     2655    pj_timer_entry_init(&tmr->entry, 0, tmr, timer_cb); 
     2656    tmr->cb = cb; 
     2657    tmr->user_data = user_data; 
     2658    delay.sec = 0; 
     2659    delay.msec = msec_delay; 
     2660 
     2661    status = pjsip_endpt_schedule_timer(pjsua_var.endpt, &tmr->entry, &delay); 
     2662    if (status != PJ_SUCCESS) { 
     2663        pj_list_push_back(&pjsua_var.timer_list, tmr); 
     2664    } 
     2665 
     2666    pj_mutex_unlock(pjsua_var.timer_mutex); 
     2667 
     2668    return status; 
     2669} 
     2670 
    26062671/* 
    26072672 * Cancel the previously scheduled timer. 
Note: See TracChangeset for help on using the changeset viewer.