Changeset 4363


Ignore:
Timestamp:
Feb 21, 2013 4:43:24 PM (12 years ago)
Author:
bennylp
Message:

Re #1623: fixed deadlock between conference mutex and ICE. Scenario:

  • sound device thread calls put_frame() which gets the conf mutex, and is calling transport sendto() to send RTP packet which requires ICE mutex.
  • The worker thread finished ICE negotiation and notifies PJSUA-LIB and application while holding ICE group lock, app then do conf_connect() which causes deadlock.

This fix defer the callback to a timer.

File:
1 edited

Legend:

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

    r4345 r4363  
    553553#endif 
    554554 
    555 static void med_tp_timer_cb(void *user_data) 
     555/* Deferred callback to notify ICE init complete */ 
     556static void ice_init_complete_cb(void *user_data) 
    556557{ 
    557558    pjsua_call_media *call_med = (pjsua_call_media*)user_data; 
     
    571572        pjsip_dialog *dlg = NULL; 
    572573 
    573         if (acquire_call("med_tp_timer_cb", call_med->call->index, 
     574        if (acquire_call("ice_init_complete_cb", call_med->call->index, 
    574575                         &call, &dlg) != PJ_SUCCESS) 
    575576        { 
     
    586587} 
    587588 
     589/* Deferred callback to notify ICE negotiation failure */ 
     590static void ice_failed_nego_cb(void *user_data) 
     591{ 
     592    int call_id = (int)(long)user_data; 
     593    pjsua_call *call = NULL; 
     594    pjsip_dialog *dlg = NULL; 
     595 
     596    if (acquire_call("ice_failed_nego_cb", call_id, 
     597                     &call, &dlg) != PJ_SUCCESS) 
     598    { 
     599        /* Call have been terminated */ 
     600        return; 
     601    } 
     602 
     603    pjsua_var.ua_cfg.cb.on_call_media_state(call_id); 
     604 
     605    if (dlg) 
     606        pjsip_dlg_dec_lock(dlg); 
     607 
     608} 
    588609 
    589610/* This callback is called when ICE negotiation completes */ 
     
    603624    case PJ_ICE_STRANS_OP_INIT: 
    604625        call_med->tp_result = result; 
    605         pjsua_schedule_timer2(&med_tp_timer_cb, call_med, 1); 
     626        pjsua_schedule_timer2(&ice_init_complete_cb, call_med, 1); 
    606627        break; 
    607628    case PJ_ICE_STRANS_OP_NEGOTIATION: 
     
    616637            call_med->dir = PJMEDIA_DIR_NONE; 
    617638            if (call && pjsua_var.ua_cfg.cb.on_call_media_state) { 
    618                 pjsua_var.ua_cfg.cb.on_call_media_state(call->index); 
     639                /* Defer the callback to a timer */ 
     640                pjsua_schedule_timer2(&ice_failed_nego_cb, 
     641                                      (void*)(long)call->index, 1); 
    619642            } 
    620643        } 
Note: See TracChangeset for help on using the changeset viewer.