• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

ios - 如何在 ios 中使用 pjsip 进行通话录音?

[复制链接]
菜鸟教程小白 发表于 2022-12-13 03:57:52 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我制作了 VOIP 应用程序。现在我需要实现通话录音功能。 我正在使用以下功能进行通话录音:

+(NSString *)startRecordingint)callid userfilenameNSString 
*)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;
}

停止录制:

+(void)stopRecordingint)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;

  }

}

上面的代码非常适合 3 次录音。当我开始第 4 次录音时,给我错误 "error dll_startAudioCapture from pjsua_recorder_create"

所以任何人都有使用 pjsip 进行通话录音的解决方案,请帮助我。

谢谢。



Best Answer-推荐答案


+(NSString *)startRecordingint)callid userfilenameNSString 
  *)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)stopRecordingint)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;


//  }
}

请替换上述方法。 我在开始录制时已将recording_id 存储在用户默认值中。对于停止,录制从用户默认值中获取值,然后停止该recording_id 录制。

谢谢。

关于ios - 如何在 ios 中使用 pjsip 进行通话录音?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48622924/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap