菜鸟教程小白 发表于 2022-12-13 03:57:52

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


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

<pre><code>+(NSString *)startRecording:(int)callid userfilename:(NSString
*)filename
{

pjsua_recorder_id recorder_id;

pj_status_t status;

NSArray       *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString*documentsDirectory = ;
NSString *strPath = ;

pj_str_t fileName = pj_str();
status = pjsua_recorder_create(&amp;fileName, 0, NULL, 0, 0, &amp;recorder_id);
NSLog(@&#34;status issss--&gt;%d&#34;,status);

pjsua_call_info call_info;

status = pjsua_recorder_create(&amp;fileName, 0, NULL, -1, 0, &amp;app_config.rec_id);
isRecordingStarted = 1;
if (status != PJ_SUCCESS)
{
    pjsua_perror(THIS_FILE, &#34;error dll_startAudioCapture from pjsua_recorder_create&#34;, status);
}
else
{
    app_config.rec_port = pjsua_recorder_get_conf_port(app_config.rec_id);
    PJ_LOG(5, (THIS_FILE, &#34;dll_startAudioCapture recId=%d confPort=%d&#34;, 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, &#34;error dll_startAudioCapture edia_conf_connect_port snd-&gt;recport&#34;, status);
    }
    /* connect caller&#39;s port to recorder port */
    pjsua_call_get_info(0, &amp;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, @&#34;error dll_startAudioCapture pjmedia_conf_connect_port caller-&gt;recport&#34;, status);
    }
    //boost callTaker&#39;s and caller audio levels as configured
    if ((status = pjmedia_conf_adjust_rx_level(pjsua_var.mconf, pjsua_var.recorder.slot,0)) == PJ_SUCCESS)
    {
      //                PJ_LOG(5, (THIS_FILE, &#34;dll_startAudioCapture pjmedia_conf_adjust_rx_level by %d&#34;, g_audCapClientBoost));
    }
    else
    {
      pjsua_perror(THIS_FILE, &#34;Error dll_startAudioCapture pjmedia_conf_adjust_rx_level&#34;, status);
    }
    if ((status = pjmedia_conf_adjust_tx_level(pjsua_var.mconf,pjsua_var.recorder.slot,0)) == PJ_SUCCESS)
    {
      //                PJ_LOG(5, (THIS_FILE, &#34;dll_startAudioCapture pjmedia_conf_adjust_tx_level by %d&#34;, g_audCapServerBoost));
    }
    else
    {
      pjsua_perror(THIS_FILE, &#34;Error dll_startAudioCapture pjmedia_conf_adjust_tx_level&#34;, status);
    }
}
NSLog(@&#34;str path is====&gt;%@&#34;,strPath);
return strPath;
}
</code></pre>

<p>停止录制:</p>

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

}

}
</code></pre>

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

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

<p>谢谢。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><pre><code>+(NSString *)startRecording:(int)callid userfilename:(NSString
*)filename
{
pjsua_recorder_id recorder_id;

pj_status_t status;

NSArray       *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString*documentsDirectory = ;
NSString *strPath = ;

pj_str_t fileName = pj_str();
status = pjsua_recorder_create(&amp;fileName, 0, NULL, -1, 0, &amp;recorder_id);
NSLog(@&#34;status issss--&gt;%d&#34;,status);

[ setInteger:recorder_id forKey:@&#34;recording_id&#34;];
[ synchronize];

pjsua_call_info call_info;

NSLog(@&#34;recordder id id---&gt;%d&#34;,recorder_id);
NSLog(@&#34;recording is for start recording is---&gt;%d&#34;,app_config.rec_id);

//status = pjsua_recorder_create(&amp;fileName, 0, NULL, -1, 0, &amp;app_config.rec_id);
isRecordingStarted = 1;
if (status != PJ_SUCCESS)
{
    pjsua_perror(THIS_FILE, &#34;error dll_startAudioCapture from pjsua_recorder_create&#34;, 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, &#34;dll_startAudioCapture recId=%d confPort=%d&#34;, 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, &#34;error dll_startAudioCapture edia_conf_connect_port snd-&gt;recport&#34;, status);
    }
    /* connect caller&#39;s port to recorder port */
    pjsua_call_get_info(0, &amp;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, @&#34;error dll_startAudioCapture pjmedia_conf_connect_port caller-&gt;recport&#34;, status);
    }
    //boost callTaker&#39;s and caller audio levels as configured
    if ((status = pjmedia_conf_adjust_rx_level(pjsua_var.mconf, pjsua_var.recorder.slot,0)) == PJ_SUCCESS)
    {
      //                PJ_LOG(5, (THIS_FILE, &#34;dll_startAudioCapture pjmedia_conf_adjust_rx_level by %d&#34;, g_audCapClientBoost));
    }
    else
    {
      pjsua_perror(THIS_FILE, &#34;Error dll_startAudioCapture pjmedia_conf_adjust_rx_level&#34;, status);
    }
    if ((status = pjmedia_conf_adjust_tx_level(pjsua_var.mconf,pjsua_var.recorder.slot,0)) == PJ_SUCCESS)
    {
      //                PJ_LOG(5, (THIS_FILE, &#34;dll_startAudioCapture pjmedia_conf_adjust_tx_level by %d&#34;, g_audCapServerBoost));
    }
    else
    {
      pjsua_perror(THIS_FILE, &#34;Error dll_startAudioCapture pjmedia_conf_adjust_tx_level&#34;, status);
    }
}

NSLog(@&#34;str path is====&gt;%@&#34;,strPath);
return strPath;
}

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

NSInteger int_recording_id = [ integerForKey:@&#34;recording_id&#34;];

pjsua_recorder_id recorder_id = int_recording_id;

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

pj_status_t status = pjsua_recorder_destroy(recorder_id);
NSLog(@&#34;sttaus iiisss ----&gt; %d&#34;,status);
NSLog(@&#34;recording id is----&gt;%d&#34;,recorder_id);
isRecordingStarted = 0;


//}
}
</code></pre>

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

<p>谢谢。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 如何在 ios 中使用 pjsip 进行通话录音?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/48622924/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/48622924/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 如何在 ios 中使用 pjsip 进行通话录音?