2

i make VOIP app.Now I required implementing call recording feature. i am using the following function for call recording:

+(NSString *)startRecording:(int)callid userfilename:(NSString 
*)filename
{

pjsua_recorder_id recorder_id;

pj_status_t status;

NSArray       *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString  *documentsDirectory = [paths objectAtIndex:0];
NSString *strPath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,filename];

pj_str_t fileName = pj_str([strPath UTF8String]);
status = pjsua_recorder_create(&fileName, 0, NULL, 0, 0, &recorder_id);
NSLog(@"status issss-->%d",status);

pjsua_call_info call_info;

status = pjsua_recorder_create(&fileName, 0, NULL, -1, 0, &app_config.rec_id);
isRecordingStarted = 1;
if (status != PJ_SUCCESS)
{
    pjsua_perror(THIS_FILE, "error dll_startAudioCapture from pjsua_recorder_create", status);
}
else
{
    app_config.rec_port = pjsua_recorder_get_conf_port(app_config.rec_id);
    PJ_LOG(5, (THIS_FILE, "dll_startAudioCapture recId=%d confPort=%d", app_config.rec_id, app_config.rec_port));
    /* connect sound port to recorder port */
    status = pjmedia_conf_connect_port(pjsua_var.mconf, 0, app_config.rec_port, 0);
    if (status != PJ_SUCCESS)
    {
        pjsua_perror(THIS_FILE, "error dll_startAudioCapture edia_conf_connect_port snd->recport", status);
    }
    /* connect caller's port to recorder port */
    pjsua_call_get_info(0, &call_info); //callid
    status = pjmedia_conf_connect_port(pjsua_var.mconf, call_info.conf_slot, app_config.rec_port, 0);
    if (status != PJ_SUCCESS)
    {
        //                pjsua_perror(THIS_FILE, @"error dll_startAudioCapture pjmedia_conf_connect_port caller->recport", status);
    }
    //boost callTaker's and caller audio levels as configured
    if ((status = pjmedia_conf_adjust_rx_level(pjsua_var.mconf, pjsua_var.recorder[app_config.rec_id].slot,0)) == PJ_SUCCESS)
    {
        //                PJ_LOG(5, (THIS_FILE, "dll_startAudioCapture pjmedia_conf_adjust_rx_level by %d", g_audCapClientBoost));
    }
    else
    {
        pjsua_perror(THIS_FILE, "Error dll_startAudioCapture pjmedia_conf_adjust_rx_level", status);
    }
    if ((status = pjmedia_conf_adjust_tx_level(pjsua_var.mconf,pjsua_var.recorder[app_config.rec_id].slot,0)) == PJ_SUCCESS)
    {
        //                PJ_LOG(5, (THIS_FILE, "dll_startAudioCapture pjmedia_conf_adjust_tx_level by %d", g_audCapServerBoost));
    }
    else
    {
        pjsua_perror(THIS_FILE, "Error dll_startAudioCapture pjmedia_conf_adjust_tx_level", status);
    }
}
NSLog(@"str path is====>%@",strPath);
return strPath;
}

For stop recording :

+(void)stopRecording:(int)callid
{
    //    pjsua_call_info call_info;
   //    pjsua_call_get_info(callid, &call_info);
   if(app_config.rec_id != 0)
   {
    pj_status_t status = pjsua_recorder_destroy(app_config.rec_id);
    NSLog(@"sttaus iiisss ----> %d",status);
    NSLog(@"recording id is---->%d",app_config.rec_id);
    isRecordingStarted = 0;

  }

}

Above code is working perfectly for 3 recording.When i started 4th recording at that time give me error "error dll_startAudioCapture from pjsua_recorder_create"

so anyone has a solution for call recording using pjsip then please help me.

Thank you.

Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116

1 Answers1

2
+(NSString *)startRecording:(int)callid userfilename:(NSString 
  *)filename
 {
pjsua_recorder_id recorder_id;

pj_status_t status;

NSArray       *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString  *documentsDirectory = [paths objectAtIndex:0];
NSString *strPath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,filename];

pj_str_t fileName = pj_str([strPath UTF8String]);
status = pjsua_recorder_create(&fileName, 0, NULL, -1, 0, &recorder_id);
NSLog(@"status issss-->%d",status);

[[NSUserDefaults standardUserDefaults] setInteger:recorder_id forKey:@"recording_id"];
[[NSUserDefaults standardUserDefaults] synchronize];

pjsua_call_info call_info;

NSLog(@"recordder id id--->%d",recorder_id);
NSLog(@"recording is for start recording is--->%d",app_config.rec_id);

//status = pjsua_recorder_create(&fileName, 0, NULL, -1, 0, &app_config.rec_id);
isRecordingStarted = 1;
if (status != PJ_SUCCESS)
{
    pjsua_perror(THIS_FILE, "error dll_startAudioCapture from pjsua_recorder_create", status);
}
else
{
    //        app_config.rec_port = pjsua_recorder_get_conf_port(app_config.rec_id);

    app_config.rec_port = pjsua_recorder_get_conf_port(recorder_id);
    PJ_LOG(5, (THIS_FILE, "dll_startAudioCapture recId=%d confPort=%d", app_config.rec_id, app_config.rec_port));
    /* connect sound port to recorder port */
    status = pjmedia_conf_connect_port(pjsua_var.mconf, 0, app_config.rec_port, 0);
    if (status != PJ_SUCCESS)
    {
        pjsua_perror(THIS_FILE, "error dll_startAudioCapture edia_conf_connect_port snd->recport", status);
    }
    /* connect caller's port to recorder port */
    pjsua_call_get_info(0, &call_info); //callid
    status = pjmedia_conf_connect_port(pjsua_var.mconf, call_info.conf_slot, app_config.rec_port, 0);
    if (status != PJ_SUCCESS)
    {
        //                pjsua_perror(THIS_FILE, @"error dll_startAudioCapture pjmedia_conf_connect_port caller->recport", status);
    }
    //boost callTaker's and caller audio levels as configured
    if ((status = pjmedia_conf_adjust_rx_level(pjsua_var.mconf, pjsua_var.recorder[app_config.rec_id].slot,0)) == PJ_SUCCESS)
    {
        //                PJ_LOG(5, (THIS_FILE, "dll_startAudioCapture pjmedia_conf_adjust_rx_level by %d", g_audCapClientBoost));
    }
    else
    {
        pjsua_perror(THIS_FILE, "Error dll_startAudioCapture pjmedia_conf_adjust_rx_level", status);
    }
    if ((status = pjmedia_conf_adjust_tx_level(pjsua_var.mconf,pjsua_var.recorder[app_config.rec_id].slot,0)) == PJ_SUCCESS)
    {
        //                PJ_LOG(5, (THIS_FILE, "dll_startAudioCapture pjmedia_conf_adjust_tx_level by %d", g_audCapServerBoost));
    }
    else
    {
        pjsua_perror(THIS_FILE, "Error dll_startAudioCapture pjmedia_conf_adjust_tx_level", status);
    }
}

NSLog(@"str path is====>%@",strPath);
return strPath;
}

+(void)stopRecording:(int)callid
{
//    pjsua_call_info call_info;
//    pjsua_call_get_info(callid, &call_info);

NSInteger int_recording_id = [[NSUserDefaults standardUserDefaults] integerForKey:@"recording_id"];

pjsua_recorder_id recorder_id = int_recording_id;

//    if(recorder_id != 0)
//    {

pj_status_t status = pjsua_recorder_destroy(recorder_id);
NSLog(@"sttaus iiisss ----> %d",status);
NSLog(@"recording id is---->%d",recorder_id);
isRecordingStarted = 0;


//  }
}

Please replace above method. I have stored recording_id in user default at the time of start recording.For stop, recording gets value from user default and then stop that recording_id recording.

Thank you.

  • what is pjsua_var.mconf ? where did you get that struct variable and values? – Nandhakumar Kittusamy Mar 13 '18 at 09:36
  • @NandhaKumar , that i don't know i just get the code from web and apply recording id related changes. – shraddha k vaishanani Mar 13 '18 at 09:44
  • Hello NandhaKumar, have you implemented video call using pjsip?if yes then please give me suggestion or code snippets. – shraddha k vaishanani Apr 11 '18 at 04:32
  • use openh264 codec for video and follow the link https://trac.pjsip.org/repos/wiki/Video_Users_Guide#OutgoingVideoCall – Nandhakumar Kittusamy Apr 11 '18 at 04:38
  • @nandhaKumar, we have already followed this link but not display video calling UI.So we don't know how to set up video calling UI. – shraddha k vaishanani Apr 11 '18 at 04:41
  • video stream is received by the application, but want to show the video streaming in the UI? enable all the flags for video streaming – Nandhakumar Kittusamy Apr 11 '18 at 04:55
  • what error did you get while implementing video call? – Nandhakumar Kittusamy Apr 11 '18 at 05:15
  • ok, I will enable all video streaming flag and then test.if any error generates then message you. – shraddha k vaishanani Apr 11 '18 at 08:52
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/168712/discussion-between-nandhakumar-and-shraddha-vaishnani). – Nandhakumar Kittusamy Apr 11 '18 at 08:53
  • Hello @nadhakumar,i have one issue related to pjsip random crash. sometimes give me following error and app crash. "Assertion failed: (pjsua_var.acc_cnt!=0), function pjsua_acc_find_for_incoming, file ../src/pjsua-lib/pjsua_acc.c, line 2908." if you have any solution please help me. – shraddha k vaishanani May 11 '18 at 07:11
  • there is no account registered, when the method(pjsua_acc_find_for_incoming) is called. – Nandhakumar Kittusamy May 11 '18 at 07:24
  • but i have not found any solution to solve this error.you have then please help me. – shraddha k vaishanani May 11 '18 at 07:42
  • you need to have atleast one registered account always on your app. then the error will not happen – Nandhakumar Kittusamy May 11 '18 at 07:44
  • hello @NandhaKumar i tried following code: if (pjsua_acc_is_valid(*acc_id)) { pj_status_t statusDelete = pjsua_acc_del(*acc_id); if (statusDelete != PJ_SUCCESS) { pjsua_perror(THIS_FILE, "Error removing new account", status); } } status = pjsua_acc_add(&acc_cfg, PJ_TRUE, acc_id); before adding delete acc but not execute delete the block.so any changes required then please help me. – shraddha k vaishanani May 11 '18 at 09:46
  • Hello Nandakumar, I required your help. My problem is : I tried to call using pjsip with Bluetooth but voice not transfers each other.so how to enable Bluetooth for pjsip call. – shraddha k vaishanani Jul 20 '18 at 06:55
  • My code :- pjmedia_aud_dev_route route = PJMEDIA_AUD_DEV_ROUTE_BLUETOOTH; pj_status_t status = pjsua_snd_set_setting(PJMEDIA_AUD_DEV_CAP_INPUT_ROUTE, &route, PJ_TRUE); UInt32 allowBluetoothInput = 1; OSStatus ostatus = AudioSessionSetProperty ( kAudioSessionProperty_OverrideCategoryEnableBluetoothInput, sizeof(allowBluetoothInput), &allowBluetoothInput); – shraddha k vaishanani Jul 20 '18 at 06:57
  • Please check this link, this is your [problem?](http://lists.pjsip.org/pipermail/pjsip_lists.pjsip.org/2010-October/012006.html) and [pjsip audio api](http://www.pjsip.org/pjmedia/docs/html/group__s2__audio__device__reference.htm#gga33abc31c4f70f6c3445425e0bc1cd141a08a559eff2c480ada54555778fd1add2) – Nandhakumar Kittusamy Jul 20 '18 at 09:25
  • Hello nandhakumar ,below link is my problem http://lists.pjsip.org/pipermail/pjsip_lists.pjsip.org/2015-May/018394.html 420008 error getting. – shraddha k vaishanani Jul 20 '18 at 09:28
  • please replay in below question :- https://stackoverflow.com/questions/51396267/enable-bluetooth-for-pjsip-voice-call-in-ios – shraddha k vaishanani Jul 20 '18 at 09:32
  • 2
    What is pjsua_var.mconf? It is null, I am getting crash (SIGABRT). When calling, status = pjmedia_conf_connect_port(pjsua_var.mconf, 0, app_config.rec_port, 0); – Mavya Soni Jul 09 '19 at 05:20
  • Someone, please answer, https://stackoverflow.com/questions/56933439/crash-in-recording-call-when-pjmedia-conf-connect-port-executed-sigabrt-in-pjsi – Paresh. P Nov 19 '19 at 13:05