Changeset 3938


Ignore:
Timestamp:
Jan 9, 2012 11:51:56 AM (12 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.

Location:
pjproject/trunk/pjsip
Files:
4 edited

Legend:

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

    r3925 r3938  
    19971997 * 
    19981998 * @param entry         Timer heap entry. 
    1999  * @param delay     The interval to expire. 
     1999 * @param delay         The interval to expire. 
    20002000 * 
    20012001 * @return              PJ_SUCCESS on success, or the appropriate error code. 
     
    20062006                                          const pj_time_val *delay); 
    20072007 
     2008/** 
     2009 * Schedule a callback function to be called after a specified time interval. 
     2010 * Note that the callback may be executed by different thread, depending on 
     2011 * whether worker thread is enabled or not. 
     2012 * 
     2013 * @param cb            The callback function. 
     2014 * @param user_data     The user data. 
     2015 * @param msec_delay    The time interval in msec. 
     2016 * 
     2017 * @return              PJ_SUCCESS on success, or the appropriate error code. 
     2018 */ 
     2019PJ_DECL(pj_status_t) pjsua_schedule_timer2(void (*cb)(void *user_data), 
     2020                                           void *user_data, 
     2021                                           unsigned msec_delay); 
    20082022 
    20092023/** 
  • pjproject/trunk/pjsip/include/pjsua-lib/pjsua_internal.h

    r3928 r3938  
    7777    pjmedia_transport   *tp;        /**< Current media transport (can be 0) */ 
    7878    pj_status_t          tp_ready;  /**< Media transport status.            */ 
     79    pj_status_t          tp_result; /**< Media transport creation result.   */ 
    7980    pjmedia_transport   *tp_orig;   /**< Original media transport           */ 
    8081    pj_bool_t            tp_auto_del; /**< May delete media transport       */ 
     
    457458    pjsua_vid_win        win[PJSUA_MAX_VID_WINS]; /**< Array of windows */ 
    458459#endif 
     460 
     461    /* Timer entry list */ 
     462    struct timer_list 
     463    { 
     464        PJ_DECL_LIST_MEMBER(struct timer_list); 
     465        pj_timer_entry          entry; 
     466        void                  (*cb)(void *user_data); 
     467        void                   *user_data; 
     468    } timer_list; 
     469    pj_mutex_t          *timer_mutex; 
    459470}; 
    460471 
  • 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. 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c

    r3929 r3938  
    767767#endif 
    768768 
     769static void med_tp_timer_cb(void *user_data) 
     770{ 
     771    pjsua_call_media *call_med = (pjsua_call_media*)user_data; 
     772 
     773    PJSUA_LOCK(); 
     774 
     775    call_med->tp_ready = call_med->tp_result; 
     776    if (call_med->med_create_cb) 
     777        (*call_med->med_create_cb)(call_med, call_med->tp_ready, 
     778                                   call_med->call->secure_level, NULL); 
     779 
     780    PJSUA_UNLOCK(); 
     781} 
     782 
    769783/* This callback is called when ICE negotiation completes */ 
    770784static void on_ice_complete(pjmedia_transport *tp,  
     
    779793    switch (op) { 
    780794    case PJ_ICE_STRANS_OP_INIT: 
    781         PJSUA_LOCK(); 
    782         call_med->tp_ready = result; 
    783         if (call_med->med_create_cb) 
    784             (*call_med->med_create_cb)(call_med, result, 
    785                                        call_med->call->secure_level, NULL); 
    786         PJSUA_UNLOCK(); 
     795        call_med->tp_result = result; 
     796        pjsua_schedule_timer2(&med_tp_timer_cb, call_med, 1); 
    787797        break; 
    788798    case PJ_ICE_STRANS_OP_NEGOTIATION: 
     
    15391549            pjsua_call_media *call_med = &call->media[mi]; 
    15401550 
    1541             if (call_med->med_init_cb || 
    1542                 call_med->tp_st == PJSUA_MED_TP_NULL) 
    1543             { 
     1551            if (call_med->med_init_cb) { 
    15441552                pj_mutex_unlock(call->med_ch_mutex); 
    15451553                return PJ_SUCCESS; 
Note: See TracChangeset for help on using the changeset viewer.