在iOS中使用PJSIP 2.5以编程方式进行调用

时间:2016-06-15 13:00:45

标签: ios call voip codec pjsip

在集成PJSIP后,要从我的应用程序拨打电话,我正在使用此代码:

sip_dial(voipManager._sip_acc_id, [dialedUser UTF8String], &id_call);

但它在跟踪时返回420006状态代码,显示:

  

无法找到默认音频设备(PJMEDIA_EAUD_NODEFDEV)[status = 420006]

我已经从经理文件中启用了编解码器,并且在编译时也显示“已启用”。我错过或误导的地方在哪里?

1 个答案:

答案 0 :(得分:4)

- (int)startPjsipAndRegisterOnServer:(char *)sipDomain withUserName:(char *)sipUser andPassword:(char *)password callback:(RegisterCallBack)callback
{
    //Disconnect connection(Registration).
//    pjsua_destroy();

    pj_status_t status;

    // Create pjsua first
    status = pjsua_create();
    if (status != PJ_SUCCESS) error_exit("Error in pjsua_create()", status);

    // Init pjsua
    {
        // Init the config structure
        pjsua_config cfg;
        pjsua_logging_config log_cfg;

        pjsua_config_default (&cfg);

        //Media
        pjsua_media_config media_cfg;//Extra
        pjsua_media_config_default(&media_cfg);//Extra

        cfg.cb.on_incoming_call = &on_incoming_call;
        cfg.cb.on_call_media_state = &on_call_media_state;
        cfg.cb.on_call_state = &on_call_state;
        cfg.cb.on_reg_state2 = &on_reg_state2;//Extra

        // Init the logging config structure
        pjsua_logging_config_default(&log_cfg);
        log_cfg.console_level = 4;

        // Init the pjsua
        status = pjsua_init(&cfg, &log_cfg, &media_cfg);
        if (status != PJ_SUCCESS) error_exit("Error in pjsua_init()", status);
    }

    // Add UDP transport.
    {
        // Init transport config structure
        pjsua_transport_config cfg;
        pjsua_transport_config_default(&cfg);
        cfg.port = 5060;

        // Add TCP transport.
        status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &cfg, NULL);
        if (status != PJ_SUCCESS) error_exit("Error creating transport", status);
    }

    /*
    // Add TCP transport.
    {
        // Init transport config structure
        pjsua_transport_config cfg;
        pjsua_transport_config_default(&cfg);
        cfg.port = 5060;

        // Add TCP transport.
        status = pjsua_transport_create(PJSIP_TRANSPORT_TCP, &cfg, NULL);
        if (status != PJ_SUCCESS) error_exit("Error creating transport", status);
    }
    */

    // Initialization is done, now start pjsua
    status = pjsua_start();
    if (status != PJ_SUCCESS) error_exit("Error starting pjsua", status);

    // Register the account on local sip server/* Register to SIP server by creating SIP account. */
    {
        pjsua_acc_config cfg;

        pjsua_acc_config_default(&cfg);

        // Account ID
        char sipId[MAX_SIP_ID_LENGTH];
        sprintf(sipId, "sip:%s@%s", sipUser, sipDomain);
        cfg.id = pj_str(sipId);

        // Reg URI
        char regUri[MAX_SIP_REG_URI_LENGTH];
        sprintf(regUri, "sip:%s", sipDomain);
        cfg.reg_uri = pj_str(regUri);

        // Account cred info
        cfg.cred_count = 1;
        cfg.cred_info[0].scheme = pj_str("digest");
        cfg.cred_info[0].realm = pj_str(sipDomain);
        cfg.cred_info[0].username = pj_str(sipUser);
        cfg.cred_info[0].data_type = PJSIP_CRED_DATA_PLAIN_PASSWD;
        cfg.cred_info[0].data = pj_str(password);

        status = pjsua_acc_add(&cfg, PJ_TRUE, &_acc_id);
        if (status != PJ_SUCCESS) error_exit("Error adding account", status);
    }

    _registerCallBack = callback;

    return 0;
}

- (void)makeCallTo:(char*)destUri
{
    pj_status_t status;
    pj_str_t uri = pj_str(destUri);
    //current register id _acc_id
    status = pjsua_call_make_call(_acc_id, &uri, 0, NULL, NULL, NULL);
    if (status != PJ_SUCCESS) error_exit("Error making call", status);
}