NO IMAGE

在pjsip 2.6的pjproject-2.6\pjsip-apps\src\pjsua 目錄下,有個很好的例子,可以撥打單方通話和多方通話。

        示例在:pjsua_app_cli.c裡面static pj_status_t cmd_make_multi_call(pj_cli_cmd_val *cval)函式中。

多方通話的邏輯和單獨撥打一個電話的邏輯是一樣的,只是撥打一個電話,呼叫一次pjsua_call_make_call,而多方通話多次呼叫該介面,撥出多個電話。另外,在on_call_media_state中主要connect port,否則是聽不到聲音的。

       撥打多方通話的程式碼:

    for (i=0; i<count;   i) {
pj_status_t status;
status = pjsua_call_make_call(current_acc, &tmp, &call_opt, NULL, NULL, NULL);
if (status != PJ_SUCCESS)
break;
}

connect port的方法:

比如A 先打電話給B,在打電話給C,進行3方通話,正常情況下,
A和B通話是這樣連線:
/* Callback called by the library when call’s media state has changed */
static void on_call_media_state(pjsua_call_id call_id)
{
    pjsua_call_info AandB;

    pjsua_call_get_info(call_id, &AandB);

    if (ci.media_status == PJSUA_CALL_MEDIA_ACTIVE) {
        // When media is active, connect call to sound device.
        pjsua_conf_connect(AandB.conf_slot, 0);
        pjsua_conf_connect(0, AandB.conf_slot);
    }
}

A和C通話是這樣連線:
/* Callback called by the library when call’s media state has changed */
static void on_call_media_state(pjsua_call_id call_id)
{
    pjsua_call_info AandC;

    pjsua_call_get_info(call_id, &AandC);

    if (ci.media_status == PJSUA_CALL_MEDIA_ACTIVE) {
        // When media is active, connect call to sound device.
        pjsua_conf_connect(AandC.conf_slot, 0);
        pjsua_conf_connect(0, AandC.conf_slot);
    }
}

上面這樣連結後,A可以和B/C通話,但是B和C互相聽不到對方的聲音。
需要加入下面的步驟,這個可以在A和C的on_call_media_state呼叫後,在加入下面的兩個connect:
pjsua_conf_connect(AandB.conf_slot, AandC.conf_slot);
pjsua_conf_connect(AandC, AandB.conf_slot);

這樣A/B/C互相之間,都會聽到對方的聲音了。