Megha Parmar
Megha Parmar

Reputation: 256

Make call programmatically using PJSIP 2.5 in iOS

After integration of PJSIP, to make a call from my application I am using this code:

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

But it returns a 420006 status code while tracing, which shows:

Unable to find default audio device (PJMEDIA_EAUD_NODEFDEV) [status=420006]

I have enabled codecs from manager file, and it's showing "enabled" while compiling also. Where is the point I am missing or misleading?

Upvotes: 3

Views: 1610

Answers (1)

Ravi Kumar
Ravi Kumar

Reputation: 1366

- (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);
}

Upvotes: 4

Related Questions