Ignore:
Timestamp:
Jul 20, 2018 2:19:41 AM (6 years ago)
Author:
ming
Message:

Fixed #2128: Add feature to allow responding incoming INVITE/re-INVITE asynchronously and set the SDP answer

File:
1 edited

Legend:

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

    r5816 r5828  
    8080 */ 
    8181static void pjsua_call_on_rx_offer(pjsip_inv_session *inv, 
    82                                    const pjmedia_sdp_session *offer); 
     82                                struct pjsip_inv_on_rx_offer_cb_param *param); 
     83 
     84/* 
     85 * Called when receiving re-INVITE. 
     86 */ 
     87static pj_status_t pjsua_call_on_rx_reinvite(pjsip_inv_session *inv, 
     88                                             const pjmedia_sdp_session *offer, 
     89                                             pjsip_rx_data *rdata); 
    8390 
    8491/* 
     
    191198    inv_cb.on_new_session = &pjsua_call_on_forked; 
    192199    inv_cb.on_media_update = &pjsua_call_on_media_update; 
    193     inv_cb.on_rx_offer = &pjsua_call_on_rx_offer; 
     200    inv_cb.on_rx_offer2 = &pjsua_call_on_rx_offer; 
    194201    inv_cb.on_create_offer = &pjsua_call_on_create_offer; 
    195202    inv_cb.on_tsx_state_changed = &pjsua_call_on_tsx_state_changed; 
    196203    inv_cb.on_redirected = &pjsua_call_on_redirected; 
     204    if (pjsua_var.ua_cfg.cb.on_call_rx_reinvite) { 
     205        inv_cb.on_rx_reinvite = &pjsua_call_on_rx_reinvite; 
     206    } 
    197207 
    198208    /* Initialize invite session module: */ 
     
    24042414 
    24052415/* 
     2416 * Send response to incoming INVITE request. 
     2417 */ 
     2418PJ_DEF(pj_status_t) 
     2419pjsua_call_answer_with_sdp(pjsua_call_id call_id, 
     2420                           const pjmedia_sdp_session *sdp,  
     2421                           const pjsua_call_setting *opt, 
     2422                           unsigned code, 
     2423                           const pj_str_t *reason, 
     2424                           const pjsua_msg_data *msg_data) 
     2425{ 
     2426    pjsua_call *call; 
     2427    pjsip_dialog *dlg = NULL; 
     2428    pj_status_t status; 
     2429 
     2430    PJ_ASSERT_RETURN(call_id>=0 && call_id<(int)pjsua_var.ua_cfg.max_calls, 
     2431                     PJ_EINVAL); 
     2432 
     2433    status = acquire_call("pjsua_call_answer_with_sdp()", 
     2434                          call_id, &call, &dlg); 
     2435    if (status != PJ_SUCCESS) 
     2436        return status; 
     2437 
     2438    status = pjsip_inv_set_sdp_answer(call->inv, sdp); 
     2439 
     2440    pjsip_dlg_dec_lock(dlg); 
     2441     
     2442    if (status != PJ_SUCCESS) 
     2443        return status; 
     2444     
     2445    return pjsua_call_answer2(call_id, opt, code, reason, msg_data); 
     2446} 
     2447 
     2448 
     2449/* 
    24062450 * Hangup call by using method that is appropriate according to the 
    24072451 * call state. 
     
    42644308 */ 
    42654309static void pjsua_call_on_rx_offer(pjsip_inv_session *inv, 
    4266                                    const pjmedia_sdp_session *offer) 
     4310                                struct pjsip_inv_on_rx_offer_cb_param *param) 
    42674311{ 
    42684312    pjsua_call *call; 
     
    42704314    unsigned i; 
    42714315    pj_status_t status; 
     4316    const pjmedia_sdp_session *offer = param->offer; 
     4317    pjsua_call_setting opt; 
     4318    pj_bool_t async = PJ_FALSE; 
    42724319 
    42734320    call = (pjsua_call*) inv->dlg->mod_data[pjsua_var.mod.id]; 
     
    42854332 
    42864333    cleanup_call_setting_flag(&call->opt); 
    4287  
    4288     if (pjsua_var.ua_cfg.cb.on_call_rx_offer) { 
     4334    opt = call->opt; 
     4335 
     4336    if (pjsua_var.ua_cfg.cb.on_call_rx_reinvite && 
     4337        param->rdata->msg_info.msg->type == PJSIP_REQUEST_MSG && 
     4338        param->rdata->msg_info.msg->line.req.method.id == PJSIP_INVITE_METHOD) 
     4339    { 
     4340        pjsip_status_code code = PJSIP_SC_OK; 
     4341 
     4342        /* If on_call_rx_reinvite() callback is implemented, 
     4343         * call it first. 
     4344         */ 
     4345        (*pjsua_var.ua_cfg.cb.on_call_rx_reinvite)( 
     4346                                                call->index, offer, 
     4347                                                (pjsip_rx_data *)param->rdata, 
     4348                                                NULL, &async, &code, &opt); 
     4349        if (async) { 
     4350            pjsip_tx_data *response; 
     4351 
     4352            status = pjsip_inv_initial_answer(inv, 
     4353                                              (pjsip_rx_data *)param->rdata, 
     4354                                              100, NULL, NULL, &response); 
     4355            if (status != PJ_SUCCESS) { 
     4356                PJ_LOG(3, (THIS_FILE, "Failed to create initial answer"));  
     4357                goto on_return; 
     4358            } 
     4359 
     4360            status = pjsip_inv_send_msg(inv, response); 
     4361            if (status != PJ_SUCCESS) { 
     4362                PJ_LOG(3, (THIS_FILE, "Failed to send initial answer"));  
     4363                goto on_return; 
     4364            } 
     4365 
     4366            PJ_LOG(4,(THIS_FILE, "App will manually answer the re-INVITE " 
     4367                                 "on call %d", call->index)); 
     4368        } 
     4369        if (code != PJSIP_SC_OK) { 
     4370            PJ_LOG(4,(THIS_FILE, "Rejecting re-INVITE updated media offer " 
     4371                                 "on call %d", call->index)); 
     4372            goto on_return; 
     4373        } 
     4374 
     4375        call->opt = opt; 
     4376    } 
     4377 
     4378    if (pjsua_var.ua_cfg.cb.on_call_rx_offer && !async) { 
    42894379        pjsip_status_code code = PJSIP_SC_OK; 
    4290         pjsua_call_setting opt; 
    4291  
    4292         opt = call->opt; 
     4380 
    42934381        (*pjsua_var.ua_cfg.cb.on_call_rx_offer)(call->index, offer, NULL, 
    42944382                                                &code, &opt); 
     
    43134401    if (status != PJ_SUCCESS) { 
    43144402        pjsua_perror(THIS_FILE, "Unable to create local SDP", status); 
     4403        goto on_return; 
     4404    } 
     4405 
     4406    if (async) { 
     4407        call->rx_reinv_async = async; 
    43154408        goto on_return; 
    43164409    } 
     
    43614454on_return: 
    43624455    pj_log_pop_indent(); 
     4456} 
     4457 
     4458 
     4459/* 
     4460 * Called when receiving re-INVITE. 
     4461 */ 
     4462static pj_status_t pjsua_call_on_rx_reinvite(pjsip_inv_session *inv, 
     4463                                             const pjmedia_sdp_session *offer, 
     4464                                             pjsip_rx_data *rdata) 
     4465{ 
     4466    pjsua_call *call; 
     4467    pj_bool_t async; 
     4468 
     4469    PJ_UNUSED_ARG(offer); 
     4470    PJ_UNUSED_ARG(rdata); 
     4471 
     4472    call = (pjsua_call*) inv->dlg->mod_data[pjsua_var.mod.id]; 
     4473    async = call->rx_reinv_async; 
     4474    call->rx_reinv_async = PJ_FALSE; 
     4475 
     4476    return (async? PJ_SUCCESS: !PJ_SUCCESS); 
    43634477} 
    43644478 
Note: See TracChangeset for help on using the changeset viewer.