当我进行Sip通话时,有时我想发送dtmf数字。
为此,我创建了一个自定义拨号盘,当按下某个键时,该拨号盘应播放该键的声音,但在Sip通话过程中不会播放该声音(当没有通话时,会播放声音)。
这些声音是通过AudioToolbox.h
库(AudioServicesPlaySystemSound(soundID)
)中的功能播放的。
我需要在pjsip(pjsua)或AudioToolbox库中设置一些属性来启用在Sip呼叫期间播放声音吗?
我知道这是可能的(Bria也有,Groundwire也有,不确定他们是否正在使用pjsip来实现sip)。
该答案是来自以下两个链接的代码段的组合:PJSUA-API Media Manipulation和pjsipDll_PlayWav.cpp。
当pjsua进行呼叫时,它使用端口(会议端口)将呼叫目的地的媒体传输到设备扬声器。您可以同时打开多个端口。
因此,要播放键盘按钮单击声音,我们要做的是再打开一个端口并播放声音(在这种情况下,它是一个wav文件,并且您会注意到,还有一个pjsua函数可用于传输avi文件) 。
为此,我们将使用以下功能:
pj_status_t pjsua_conf_connect (pjsua_conf_port_id source, pjsua_conf_port_id sink)
我们的接收器端口是设备扬声器端口,在这种情况下(大多数情况下)为0。
以下所有功能均添加到pjsua_app.c文件中。在Objective-C类中使用它们的地方之前,您必须添加以下行:
pj_status_t play_sound_during_call(pj_str_t sound_file);
在这里播放声音的功能是:
pj_status_t play_sound_during_call(pj_str_t sound_file)
{
pjsua_player_id player_id;
pj_status_t status;
status = pjsua_player_create(&sound_file, 0, &player_id);
if (status != PJ_SUCCESS)
return status;
pjmedia_port *player_media_port;
status = pjsua_player_get_port(player_id, &player_media_port);
if (status != PJ_SUCCESS)
{
return status;
}
pj_pool_t *pool = pjsua_pool_create("my_eof_data", 512, 512);
struct pjsua_player_eof_data *eof_data = PJ_POOL_ZALLOC_T(pool, struct pjsua_player_eof_data);
eof_data->pool = pool;
eof_data->player_id = player_id;
pjmedia_wav_player_set_eof_cb(player_media_port, eof_data, &on_pjsua_wav_file_end_callback);
status = pjsua_conf_connect(pjsua_player_get_conf_port(player_id), 0);
if (status != PJ_SUCCESS)
{
return status;
}
return status;
}
这是回调函数,可在您的wav文件读取(播放)结束时侦听:
struct pjsua_player_eof_data
{
pj_pool_t *pool;
pjsua_player_id player_id;
};
static PJ_DEF(pj_status_t) on_pjsua_wav_file_end_callback(pjmedia_port* media_port, void* args)
{
pj_status_t status;
struct pjsua_player_eof_data *eof_data = (struct pjsua_player_eof_data *)args;
status = pjsua_player_destroy(eof_data->player_id);
PJ_LOG(3,(THIS_FILE, "End of Wav File, media_port: %d", media_port));
if (status == PJ_SUCCESS)
{
return -1;// Here it is important to return a value other than PJ_SUCCESS
//Check link below
}
return PJ_SUCCESS;
}
pjmedia_wav_player_set_eof_cb回调函数应返回除PJ_SUCCESS之外的值的原因是因为pjmedia_wav_player_set_eof_cb这里的文档说:
请注意,如果应用程序破坏了回调中的文件端口,则它必须在此处返回non-PJ_SUCCESS。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句