Ignore:
Timestamp:
Dec 1, 2011 9:06:14 AM (12 years ago)
Author:
nanang
Message:

Re #1419, implement media count manipulation per call basis:

  • moved the media count setting from account setting to call setting
  • introduced pjsua_call_setting, to be used by pjsua_call_make_call() and some new APIs: pjsua_call_answer2(), pjsua_call_reinvite2(), pjsua_call_update2()
File:
1 edited

Legend:

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

    r3849 r3891  
    117117        call_med->tp_auto_del = PJ_TRUE; 
    118118    } 
     119    pjsua_call_setting_default(&call->opt); 
    119120} 
    120121 
     
    342343    pjsua_acc *acc = &pjsua_var.acc[call->acc_id]; 
    343344    pjsip_dialog *dlg = call->async_call.dlg; 
    344     unsigned options = call->async_call.call_var.out_call.options; 
     345    unsigned options = 0; 
    345346    pjsip_tx_data *tdata; 
    346347    pj_status_t status = (info? info->status: PJ_SUCCESS); 
     
    488489 
    489490/* 
     491 * Initialize call settings based on account ID. 
     492 */ 
     493PJ_DEF(void) pjsua_call_setting_default(pjsua_call_setting *opt) 
     494{ 
     495    pj_assert(opt); 
     496 
     497    pj_bzero(opt, sizeof(*opt)); 
     498    opt->flag = PJSUA_CALL_INCLUDE_DISABLED_MEDIA; 
     499    opt->audio_cnt = 1; 
     500 
     501#if defined(PJMEDIA_HAS_VIDEO) && (PJMEDIA_HAS_VIDEO != 0) 
     502    opt->video_cnt = 1; 
     503    //{ 
     504    //  unsigned i; 
     505    //  for (i = 0; i < PJ_ARRAY_SIZE(opt->vid_cap_dev); ++i) 
     506    //      opt->vid_cap_dev[i] = PJMEDIA_VID_DEFAULT_CAPTURE_DEV; 
     507    //} 
     508#endif 
     509} 
     510 
     511static pj_status_t apply_call_setting(pjsua_call *call, 
     512                                      const pjsua_call_setting *opt, 
     513                                      const pjmedia_sdp_session *rem_sdp) 
     514{ 
     515    pj_assert(call); 
     516 
     517    if (!opt) 
     518        return PJ_SUCCESS; 
     519 
     520#if !PJMEDIA_HAS_VIDEO 
     521    pj_assert(opt->video_cnt == 0); 
     522#endif 
     523 
     524    /* If call is established, reinit media channel */ 
     525    if (call->inv && call->inv->state == PJSIP_INV_STATE_CONFIRMED) { 
     526        pjsua_call_setting old_opt; 
     527        pj_status_t status; 
     528 
     529        old_opt = call->opt; 
     530        call->opt = *opt; 
     531 
     532        /* Reinit media channel when media count is changed */ 
     533        if (opt->audio_cnt != old_opt.audio_cnt || 
     534            opt->video_cnt != old_opt.video_cnt) 
     535        { 
     536            pjsip_role_e role = rem_sdp? PJSIP_ROLE_UAS : PJSIP_ROLE_UAC; 
     537            status = pjsua_media_channel_init(call->index, role, 
     538                                              call->secure_level, 
     539                                              call->inv->pool_prov, 
     540                                              rem_sdp, NULL, 
     541                                              PJ_FALSE, NULL); 
     542            if (status != PJ_SUCCESS) { 
     543                pjsua_perror(THIS_FILE, "Error re-initializing media channel", 
     544                             status); 
     545                return status; 
     546            } 
     547        } 
     548    } else { 
     549        call->opt = *opt; 
     550    } 
     551 
     552    return PJ_SUCCESS; 
     553} 
     554 
     555/* 
    490556 * Make outgoing call to the specified URI using the specified account. 
    491557 */ 
    492 PJ_DEF(pj_status_t) pjsua_call_make_call( pjsua_acc_id acc_id, 
    493                                           const pj_str_t *dest_uri, 
    494                                           unsigned options, 
    495                                           void *user_data, 
    496                                           const pjsua_msg_data *msg_data, 
    497                                           pjsua_call_id *p_call_id) 
     558PJ_DEF(pj_status_t) pjsua_call_make_call(pjsua_acc_id acc_id, 
     559                                         const pj_str_t *dest_uri, 
     560                                         const pjsua_call_setting *opt, 
     561                                         void *user_data, 
     562                                         const pjsua_msg_data *msg_data, 
     563                                         pjsua_call_id *p_call_id) 
    498564{ 
    499565    pj_pool_t *tmp_pool = NULL; 
     
    555621    call->acc_id = acc_id; 
    556622    call->call_hold_type = acc->cfg.call_hold_type; 
     623 
     624    /* Apply call setting */ 
     625    status = apply_call_setting(call, opt, NULL); 
     626    if (status != PJ_SUCCESS) { 
     627        pjsua_perror(THIS_FILE, "Failed to apply call setting", status); 
     628        goto on_error; 
     629    } 
    557630 
    558631    /* Create temporary pool */ 
     
    623696     * media transport creation is completed. 
    624697     */ 
    625     call->async_call.call_var.out_call.options = options; 
    626698    if (msg_data) { 
    627699        call->async_call.call_var.out_call.msg_data = pjsua_msg_data_clone( 
     
    14661538               sizeof(info->buf_.call_id)); 
    14671539 
     1540    /* call setting */ 
     1541    pj_memcpy(&info->setting, &call->opt, sizeof(call->opt)); 
     1542 
    14681543    /* state, state_text */ 
    14691544    info->state = (call->inv? call->inv->state: PJSIP_INV_STATE_DISCONNECTED); 
     
    14871562    } 
    14881563     
     1564    /* Audio & video count offered by remote */ 
     1565    info->rem_offerer   = call->rem_offerer; 
     1566    if (call->rem_offerer) { 
     1567        info->rem_audio_cnt = call->rem_aud_cnt; 
     1568        info->rem_video_cnt = call->rem_vid_cnt; 
     1569    } 
     1570 
    14891571    /* Build array of media status and dir */ 
    14901572    info->media_cnt = 0; 
     
    17611843                                       const pjsua_msg_data *msg_data) 
    17621844{ 
     1845    return pjsua_call_answer2(call_id, NULL, code, reason, msg_data); 
     1846} 
     1847 
     1848 
     1849/* 
     1850 * Send response to incoming INVITE request. 
     1851 */ 
     1852PJ_DEF(pj_status_t) pjsua_call_answer2(pjsua_call_id call_id, 
     1853                                       const pjsua_call_setting *opt, 
     1854                                       unsigned code, 
     1855                                       const pj_str_t *reason, 
     1856                                       const pjsua_msg_data *msg_data) 
     1857{ 
    17631858    pjsua_call *call; 
    17641859    pjsip_dialog *dlg = NULL; 
     
    17751870    if (status != PJ_SUCCESS) 
    17761871        goto on_return; 
     1872 
     1873    /* Apply call setting */ 
     1874    status = apply_call_setting(call, opt, NULL); 
     1875    if (status != PJ_SUCCESS) { 
     1876        pjsua_perror(THIS_FILE, "Failed to apply call setting", status); 
     1877        goto on_return; 
     1878    } 
    17771879 
    17781880    PJSUA_LOCK(); 
     
    20172119                                         const pjsua_msg_data *msg_data) 
    20182120{ 
     2121    pjsua_call *call; 
     2122    pjsip_dialog *dlg = NULL; 
     2123    pj_status_t status; 
     2124 
     2125    status = acquire_call("pjsua_call_reinvite()", call_id, &call, &dlg); 
     2126    if (status != PJ_SUCCESS) 
     2127        goto on_return; 
     2128 
     2129    if (options != call->opt.flag) 
     2130        call->opt.flag = options; 
     2131 
     2132    status = pjsua_call_reinvite2(call_id, NULL, msg_data); 
     2133 
     2134on_return: 
     2135    if (dlg) pjsip_dlg_dec_lock(dlg); 
     2136    return status; 
     2137} 
     2138 
     2139 
     2140/* 
     2141 * Send re-INVITE (to release hold). 
     2142 */ 
     2143PJ_DEF(pj_status_t) pjsua_call_reinvite2(pjsua_call_id call_id, 
     2144                                         const pjsua_call_setting *opt, 
     2145                                         const pjsua_msg_data *msg_data) 
     2146{ 
    20192147    pjmedia_sdp_session *sdp; 
    20202148    pj_str_t *new_contact = NULL; 
     
    20312159    pj_log_push_indent(); 
    20322160 
    2033     status = acquire_call("pjsua_call_reinvite()", call_id, &call, &dlg); 
     2161    status = acquire_call("pjsua_call_reinvite2()", call_id, &call, &dlg); 
    20342162    if (status != PJ_SUCCESS) 
    20352163        goto on_return; 
     
    20412169    } 
    20422170 
     2171    status = apply_call_setting(call, opt, NULL); 
     2172    if (status != PJ_SUCCESS) { 
     2173        pjsua_perror(THIS_FILE, "Failed to apply call setting", status); 
     2174        goto on_return; 
     2175    } 
     2176 
    20432177    /* Create SDP */ 
    2044     if (call->local_hold && (options & PJSUA_CALL_UNHOLD)==0) { 
     2178    if (call->local_hold && (call->opt.flag & PJSUA_CALL_UNHOLD)==0) { 
    20452179        status = create_sdp_of_call_hold(call, &sdp); 
    20462180    } else { 
     
    20562190    } 
    20572191 
    2058     if ((options & PJSUA_CALL_UPDATE_CONTACT) & 
     2192    if ((call->opt.flag & PJSUA_CALL_UPDATE_CONTACT) & 
    20592193            pjsua_acc_is_valid(call->acc_id)) 
    20602194    { 
     
    20912225PJ_DEF(pj_status_t) pjsua_call_update( pjsua_call_id call_id, 
    20922226                                       unsigned options, 
     2227                                       const pjsua_msg_data *msg_data) 
     2228{ 
     2229    pjsua_call *call; 
     2230    pjsip_dialog *dlg = NULL; 
     2231    pj_status_t status; 
     2232 
     2233    status = acquire_call("pjsua_call_update()", call_id, &call, &dlg); 
     2234    if (status != PJ_SUCCESS) 
     2235        goto on_return; 
     2236 
     2237    if (options != call->opt.flag) 
     2238        call->opt.flag = options; 
     2239 
     2240    status = pjsua_call_update2(call_id, NULL, msg_data); 
     2241 
     2242on_return: 
     2243    if (dlg) pjsip_dlg_dec_lock(dlg); 
     2244    return status; 
     2245} 
     2246 
     2247 
     2248/* 
     2249 * Send UPDATE request. 
     2250 */ 
     2251PJ_DEF(pj_status_t) pjsua_call_update2(pjsua_call_id call_id, 
     2252                                       const pjsua_call_setting *opt, 
    20932253                                       const pjsua_msg_data *msg_data) 
    20942254{ 
     
    21002260    pj_status_t status; 
    21012261 
    2102     PJ_UNUSED_ARG(options); 
    2103  
    21042262    PJ_ASSERT_RETURN(call_id>=0 && call_id<(int)pjsua_var.ua_cfg.max_calls, 
    21052263                     PJ_EINVAL); 
     
    21082266    pj_log_push_indent(); 
    21092267 
    2110     status = acquire_call("pjsua_call_update()", call_id, &call, &dlg); 
     2268    status = acquire_call("pjsua_call_update2()", call_id, &call, &dlg); 
    21112269    if (status != PJ_SUCCESS) 
    21122270        goto on_return; 
     2271 
     2272    status = apply_call_setting(call, opt, NULL); 
     2273    if (status != PJ_SUCCESS) { 
     2274        pjsua_perror(THIS_FILE, "Failed to apply call setting", status); 
     2275        goto on_return; 
     2276    } 
    21132277 
    21142278    /* Create SDP */ 
     
    21222286    } 
    21232287 
    2124     if ((options & PJSUA_CALL_UPDATE_CONTACT) & 
     2288    if ((call->opt.flag & PJSUA_CALL_UPDATE_CONTACT) & 
    21252289            pjsua_acc_is_valid(call->acc_id)) 
    21262290    { 
     
    33573521    pjmedia_sdp_session *answer; 
    33583522    unsigned i; 
     3523    int vid_idx; 
    33593524    pj_status_t status; 
    33603525 
     
    33673532              call->index)); 
    33683533    pj_log_push_indent(); 
     3534 
     3535#if 0 && PJMEDIA_HAS_VIDEO 
     3536    /* If current session has no video, let's just stay with no video. 
     3537     * If application want to enable video, it must send re-INVITE 
     3538     * with video. 
     3539     */ 
     3540    vid_idx = pjsua_call_get_vid_stream_idx(call->index); 
     3541    if (vid_idx == -1 || call->media[vid_idx].dir == PJMEDIA_DIR_NONE) 
     3542        call->opt.video_cnt = 0; 
     3543#endif 
     3544 
     3545    /* Re-init media for the new remote offer before creating SDP */ 
     3546    status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAS, 
     3547                                      call->secure_level, 
     3548                                      call->inv->pool_prov, 
     3549                                      offer, NULL, 
     3550                                      PJ_FALSE, NULL); 
     3551    if (status != PJ_SUCCESS) { 
     3552        pjsua_perror(THIS_FILE, "Error re-initializing media channel", status); 
     3553        goto on_return; 
     3554    } 
    33693555 
    33703556    status = pjsua_media_channel_create_sdp(call->index,  
Note: See TracChangeset for help on using the changeset viewer.